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 }