Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "encoding/csv"
- //"encoding/json"
- "fmt"
- "gonum.org/v1/plot"
- "gonum.org/v1/plot/plotter"
- "gonum.org/v1/plot/plotutil"
- "gonum.org/v1/plot/vg"
- "io"
- "log"
- "os"
- "strconv"
- "strings"
- "time"
- )
- type Reading struct {
- ID int
- DateTime time.Time
- Value float64
- }
- func read_csv(filepath string) ([]Reading, error) {
- csvFile, err := os.Open(filepath)
- defer csvFile.Close()
- reader := csv.NewReader(bufio.NewReader(csvFile))
- reader.Comma = ' '
- var readings []Reading
- for {
- line, error := reader.Read()
- if error == io.EOF {
- break
- } else if error != nil {
- log.Fatal(error)
- }
- DateTime := fmt.Sprintf("%s %s", line[2], line[3])
- datetime, _ := time.Parse("01/02/2006 15:04:05", DateTime)
- id, _ := strconv.Atoi(line[0])
- val, _ := strconv.ParseFloat(strings.Replace(line[4], ",", ".", 1), 64)
- readings = append(readings, Reading{
- ID: id,
- DateTime: datetime,
- Value: val,
- })
- }
- return readings, err
- }
- func read_and_plot(sensor string) {
- p, err := plot.New()
- p.Title.Text = "values"
- readings, err := read_csv("nmos1/1/" + sensor + ".log")
- if err != nil {
- log.Fatal(err)
- }
- var values []float64
- for _, reading := range readings {
- values = append(values, reading.Value)
- }
- pts := make(plotter.XYs, len(readings))
- for i := range pts {
- pts[i].X = float64(readings[i].ID)
- pts[i].Y = readings[i].Value
- }
- err = plotutil.AddLinePoints(p,
- "val", pts)
- if err := p.Save(4*vg.Inch, 4*vg.Inch, sensor+".png"); err != nil {
- panic(err)
- }
- }
- func main() {
- sensors := [2]string{"radfet_0", "radfet_1"}
- for _, sensor := range sensors {
- fmt.Print(sensor)
- go read_and_plot(sensor)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement