ak9im/p2/run.go
leo 01cdd03dac
p2: implement file reading+basic data operations
also, update .pre-commit-config.yaml to:
* first change to ./p2, then run the tests (pre-commit deliberately does
  not allow this by design [1])
* for the above, the https://github.com/dnephin/pre-commit-golang repo
  had to be dropped as it does not allow any customisation either.

also, add some flake updates (would be better split into another commit,
I know):
* use baseurl var
* add statix to shell packages
* fix building p1

refs:
[1]: https://github.com/pre-commit/pre-commit/issues/1110
2023-02-24 23:50:13 +01:00

46 lines
706 B
Go

package main
import (
"flag"
"log"
"os"
"git.dotya.ml/wanderer/ak9im/p2/stats"
)
var datafile = flag.String("datafile", "", "read data from this file")
func run() error {
flag.Parse()
if *datafile != "" {
f, err := os.Open(*datafile)
if err != nil {
return err
}
defer f.Close()
u := 0
y := 1
data, err := readData(f)
if err != nil {
return err
}
meanU := stats.Mean(data[u])
meanY := stats.Mean(data[y])
varianceU := stats.Variance(data[u])
varianceY := stats.Variance(data[y])
log.Printf("len(data): %d\n", len(data[u]))
log.Printf("means - u: %v, y: %v", meanU, meanY)
log.Printf("variance - u: %v, y: %v", varianceU, varianceY)
}
return nil
}