From a46d1403c31ec7046282a142ca3bd5a2ebd71965 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 27 Feb 2023 02:16:43 +0100 Subject: [PATCH] p2: add a way to run visualise.py cmd --- p2/run.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/p2/run.go b/p2/run.go index 0390ba1..c2b5742 100644 --- a/p2/run.go +++ b/p2/run.go @@ -3,11 +3,15 @@ package main import ( "flag" "log" + "os/exec" "git.dotya.ml/wanderer/ak9im/p2/stats" ) -var datafile = flag.String("datafile", "", "read data from this file") +var ( + datafile = flag.String("datafile", "", "read data from this file") + vis = flag.Bool("vis", false, "run 'python visualise.py' to produce visualisations") +) func run() error { flag.Parse() @@ -76,5 +80,29 @@ func run() error { } } + if *vis { + err := visualise() + if err != nil { + return err + } + } + + return nil +} + +func visualise() error { + red := "\033[31m" + cyan := "\033[36m" + reset := "\033[0m" + f := "visualise.py" + + log.Printf("running %s`python %s`%s", cyan, f, reset) + + out, err := exec.Command("python", f).CombinedOutput() + if err != nil { + log.Printf("visualise failed with:\n\n%s%s%s\n", red, out, reset) + return err + } + return nil }