-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (55 loc) · 2.01 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Author: Shawn Smith <ShawnSmith0828@gmail.com>
// Description: Provides some utility usage statistics to assist in alternative energy source sizing
package main
import (
"fmt"
"path/filepath"
"strconv"
"time"
"github.com/HelixSpiral/greenbuttonxml"
)
// Populated from the csv files
type meterReading struct {
dateTime int64
value float64
}
func main() {
var inputFiles []string // List of the input files we have
// Get the current directory
dir, _ := filepath.Abs("./")
// Add \Input to the current path for the Input folder.
inputFolder := fmt.Sprintf("%s\\\\Input", dir)
// Get all the files we want to take input from
inputFiles = returnInputFiles(inputFolder)
meterData := getMeterData(inputFiles)
processedData := processData(meterData)
writeFile("Output\\processedData.txt", processedData)
}
func getMeterData(files []string) map[string]map[string]map[string][]meterReading {
meterData := make(map[string]map[string]map[string][]meterReading)
for _, file := range files {
greenButtonUtilityData := greenbuttonxml.ParseGreenButtonXML(file)
// Loop for all the readings we got
for _, y := range greenButtonUtilityData.ServicePoint.Channel.ReadingData {
// Parse the date and grab the year, month, and day values
dateTime, _ := time.Parse("1/2/2006 15:04:05 PM", y.DateTime)
yearValue := dateTime.Format("2006")
monthValue := dateTime.Format("January")
dayValue := dateTime.Format("02")
// Create maps if they don't exist
if _, ok := meterData[yearValue]; !ok {
meterData[yearValue] = make(map[string]map[string][]meterReading)
}
if _, ok := meterData[yearValue][monthValue]; !ok {
meterData[yearValue][monthValue] = make(map[string][]meterReading)
}
// Get the reading from the meter and append it to the slice
meterValue, _ := strconv.ParseFloat(y.Value, 64)
meterData[yearValue][monthValue][dayValue] = append(meterData[yearValue][monthValue][dayValue], meterReading{
dateTime: dateTime.Unix(),
value: meterValue,
})
}
}
return meterData
}