flags
This commit is contained in:
parent
f6d7b984a4
commit
4cfd4fbd28
39
heatmap.go
39
heatmap.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -18,7 +19,37 @@ type ActivityLine struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
csvFile, _ := os.Open("heat.csv")
|
var csvPathArg string
|
||||||
|
var endDateArg string
|
||||||
|
var startDateArg string
|
||||||
|
var outputPath string
|
||||||
|
flag.StringVar(&csvPathArg, "csv", "heat.csv", "Specify csv path, default is heat.csv.")
|
||||||
|
flag.StringVar(&outputPath, "o", "heatmap.svg", "Specify output path, default is heatmeap.svg.")
|
||||||
|
flag.StringVar(&startDateArg, "s", "", "Specify start date (2006-01-02). Default is 1 year previous to end date.")
|
||||||
|
flag.StringVar(&endDateArg, "e", "", "Specify end date (2006-01-02). Default is today.")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
endDate := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
|
||||||
|
if endDateArg != "" {
|
||||||
|
var err error
|
||||||
|
endDate, err = time.Parse("2006-01-02", endDateArg)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("failed to parse end time")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start := time.Date(endDate.Year()-1, endDate.Month(), endDate.Day(), 0, 0, 0, 0, time.Local)
|
||||||
|
if startDateArg != "" {
|
||||||
|
var err error
|
||||||
|
start, err = time.Parse("2006-01-02", startDateArg)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("failed to parse start time")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
csvFile, _ := os.Open(csvPathArg)
|
||||||
reader := csv.NewReader(bufio.NewReader(csvFile))
|
reader := csv.NewReader(bufio.NewReader(csvFile))
|
||||||
var length int = 17
|
var length int = 17
|
||||||
var days = make(map[time.Time]uint64)
|
var days = make(map[time.Time]uint64)
|
||||||
@ -42,11 +73,9 @@ func main() {
|
|||||||
|
|
||||||
days[thisTime] = days[thisTime] + cals
|
days[thisTime] = days[thisTime] + cals
|
||||||
}
|
}
|
||||||
start := time.Date(time.Now().Year()-1, time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
|
|
||||||
svg := "<svg width=\"960\" height=\"152\"><g transform=\"translate(29.5,24)\"><g fill=\"none\" stroke=\"#ccc\">"
|
svg := "<svg width=\"960\" height=\"152\"><g transform=\"translate(29.5,24)\"><g fill=\"none\" stroke=\"#ccc\">"
|
||||||
datePointer := start
|
datePointer := start
|
||||||
var week int = 0
|
var week int = 0
|
||||||
midnightThisMorning := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
|
|
||||||
|
|
||||||
var monthChange = false
|
var monthChange = false
|
||||||
var monthLabelSpots = make(map[string]int)
|
var monthLabelSpots = make(map[string]int)
|
||||||
@ -61,7 +90,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
datePointer = datePointer.Add(time.Hour * 24)
|
datePointer = datePointer.Add(time.Hour * 24)
|
||||||
|
|
||||||
if datePointer.After(midnightThisMorning) {
|
if datePointer.After(endDate) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if datePointer.Day() == 1 {
|
if datePointer.Day() == 1 {
|
||||||
@ -89,5 +118,5 @@ func main() {
|
|||||||
svg = fmt.Sprintf("%s</g>", svg)
|
svg = fmt.Sprintf("%s</g>", svg)
|
||||||
|
|
||||||
svg = fmt.Sprintf("%s</svg>", svg)
|
svg = fmt.Sprintf("%s</svg>", svg)
|
||||||
ioutil.WriteFile("heatmap.svg", []byte(svg), 0644)
|
ioutil.WriteFile(outputPath, []byte(svg), 0644)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user