Skip to content

Commit

Permalink
Use v1 schema for stats in hello world apps
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-quintero committed Sep 26, 2024
1 parent 1f31e32 commit 2da4af5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
26 changes: 16 additions & 10 deletions go-hello-world/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"os"

"github.com/nextmv-io/sdk/run"
"github.com/nextmv-io/sdk/run/statistics"
)

func main() {
// Read the input from stdin.
err := run.CLI(solver).Run(context.Background())
if err != nil {
log.Fatal(err)
Expand All @@ -22,9 +24,9 @@ type input struct {
}

type output struct {
Options options `json:"options"`
Solution any `json:"solution"`
Statistics map[string]any `json:"statistics"`
Options options `json:"options"`
Solution any `json:"solution"`
Statistics *statistics.Statistics `json:"statistics"`
}

type options struct{}
Expand All @@ -34,16 +36,20 @@ func solver(_ context.Context, input input, options options) (output, error) {

// ##### Insert model here

// Print logs that render in the run view in Nextmv Console
fmt.Fprintf(os.Stderr, "Hello, %s\n", name)
// Print logs that render in the run view in Nextmv Console.
message := fmt.Sprintf("Hello, %s", name)
fmt.Fprintln(os.Stderr, message)

// Write output and statistics.
stats := statistics.NewStatistics()
stats.Result = &statistics.Result{}
value := statistics.Float64(1.23)
stats.Result.Value = &value
stats.Result.Custom = map[string]any{"message": message}
output := output{
Options: options,
Solution: map[string]any{},
Statistics: map[string]any{
"message": "Hello, " + name,
},
Options: options,
Solution: map[string]any{},
Statistics: stats,
}

return output, nil
Expand Down
22 changes: 16 additions & 6 deletions java-hello-world/src/main/java/com/nextmv/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class Output {

public Output(String name) {
this.solution = new Solution();
this.statistics = new Statistics("Hello, " + name);
this.statistics = new Statistics();
this.statistics.result = new StatisticsResult();
this.statistics.result.value = 1.23;
this.statistics.result.custom = new StatisticsResultCustom();
this.statistics.result.custom.message = "Hello, " + name;
}

public static void write(Output output) {
Expand All @@ -52,12 +56,18 @@ public static void write(Output output) {

class Solution {}

class Statistics {
String message;
class StatisticsResult {
public double value;
public StatisticsResultCustom custom;
}

public Statistics(String message) {
this.message = message;
}
class StatisticsResultCustom {
public String message;
}

class Statistics {
public String schema = "v1";
public StatisticsResult result;
}


17 changes: 13 additions & 4 deletions python-hello-world/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import nextmv

# Read from stdin.
# Read the input from stdin.
input = nextmv.load_local()
name = input.data["name"]

##### Insert model here

# Print logs that render in the run view in Nextmv Console
nextmv.log(f"Hello, {name}")
# Print logs that render in the run view in Nextmv Console.
message = f"Hello, {name}"
nextmv.log(message)

# Write output and statistics.
output = nextmv.Output(solution=None, statistics={"message": f"Hello, {name}"})
output = nextmv.Output(
solution=None,
statistics=nextmv.Statistics(
result=nextmv.ResultStatistics(
value=1.23,
custom={"message": message},
),
),
)
nextmv.write_local(output)

0 comments on commit 2da4af5

Please sign in to comment.