p2: add a way to run visualise.py cmd

This commit is contained in:
leo 2023-02-27 02:16:43 +01:00
parent 07b91ea5e4
commit a46d1403c3
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

@ -3,11 +3,15 @@ package main
import ( import (
"flag" "flag"
"log" "log"
"os/exec"
"git.dotya.ml/wanderer/ak9im/p2/stats" "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 { func run() error {
flag.Parse() 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 return nil
} }