Loggest thine Stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

71 lines
1.3 KiB

package sprints
import (
"git.aiterp.net/stufflog3/stufflog3/models"
"time"
)
type BurndownDataPoint struct {
Date models.Date `json:"date"`
Value float64 `json:"value"`
}
type burndownGenerator struct {
Points []BurndownDataPoint
}
func (g *burndownGenerator) Add(t time.Time, v float64) {
t = t.In(tz).Add(-time.Minute * 300)
yyyy, mm, dd := t.Date()
date := models.Date{yyyy, int(mm), dd}
found := false
insertIndex := -1
for i, p := range g.Points {
if date == p.Date {
found = true
break
} else if date.Before(p.Date) {
insertIndex = i
break
}
}
if !found {
if insertIndex == -1 {
value := 0.0
if len(g.Points) > 0 {
value = g.Points[len(g.Points)-1].Value
}
g.Points = append(g.Points, BurndownDataPoint{
Date: date,
Value: value,
})
} else {
g.Points = append(g.Points[:insertIndex+1], g.Points[insertIndex:]...)
g.Points[insertIndex].Date = date
if insertIndex > 0 {
g.Points[insertIndex].Value = g.Points[insertIndex-1].Value
} else {
g.Points[insertIndex].Value = 0
}
}
}
for i, p := range g.Points {
if !p.Date.Before(date) {
g.Points[i].Value += v
}
}
}
var tz *time.Location
func init() {
var err error
tz, err = time.LoadLocation("Europe/Oslo")
if err != nil {
panic(err)
}
}