p2: add saveStuff as a way to save...stuff
This commit is contained in:
parent
bd164878a0
commit
e5999e1c39
70
p2/data.go
70
p2/data.go
@ -79,3 +79,73 @@ func readFile(s *string) ([][]float64, error) {
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func saveStuff(
|
||||
meanU, meanY,
|
||||
varianceU, varianceY float64,
|
||||
autocorrelationU, autocorrelationY,
|
||||
mutCorrelationUY, mutCorrelationYU []float64,
|
||||
) error {
|
||||
fFnames := map[string]float64{
|
||||
"mean_u": meanU,
|
||||
"mean_y": meanY,
|
||||
"variance_u": varianceU,
|
||||
"variance_y": varianceY,
|
||||
}
|
||||
sFnames := map[string][]float64{
|
||||
"autocorrelation_u": autocorrelationU,
|
||||
"autocorrelation_y": autocorrelationY,
|
||||
"mutual_correlation_uy": mutCorrelationUY,
|
||||
"mutual_correlation_yu": mutCorrelationYU,
|
||||
}
|
||||
prefix := "data/"
|
||||
suffix := ".txt"
|
||||
|
||||
for k, v := range fFnames {
|
||||
f, err := os.Create(prefix + k + suffix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.WriteString(strconv.FormatFloat(v, 'f', 64, 64))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
suffix = ".csv"
|
||||
|
||||
for k, v := range sFnames {
|
||||
f, err := os.Create(prefix + k + suffix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
w := csv.NewWriter(f)
|
||||
|
||||
s := recordsFromFloat64Slice(v)
|
||||
|
||||
err = w.WriteAll(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func recordsFromFloat64Slice(f []float64) [][]string {
|
||||
s := make([][]string, 0, len(f))
|
||||
|
||||
for i := range f {
|
||||
tmp := strconv.FormatFloat(f[i], 'f', 64, 64)
|
||||
|
||||
s = append(s, []string{tmp})
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
10
p2/run.go
10
p2/run.go
@ -51,6 +51,16 @@ func run() error {
|
||||
log.Printf("autocorrelationY: %v", autocorrelationY)
|
||||
log.Printf("mutual correlation U,Y: %v", mutCorrelationUY)
|
||||
log.Printf("mutual correlation Y,U: %v", mutCorrelationYU)
|
||||
|
||||
err = saveStuff(
|
||||
meanU, meanY,
|
||||
varianceU, varianceY,
|
||||
autocorrelationU, autocorrelationY,
|
||||
mutCorrelationUY, mutCorrelationYU,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user