mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: include cumulative total key in wakatime summary compat endpoint (resolve #426)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,14 @@ type SummariesViewModel struct {
|
|||||||
Data []*SummariesData `json:"data"`
|
Data []*SummariesData `json:"data"`
|
||||||
End time.Time `json:"end"`
|
End time.Time `json:"end"`
|
||||||
Start time.Time `json:"start"`
|
Start time.Time `json:"start"`
|
||||||
|
CumulativeTotal *SummariesCumulativeTotal `json:"cummulative_total"` // typo is intended
|
||||||
|
}
|
||||||
|
|
||||||
|
type SummariesCumulativeTotal struct {
|
||||||
|
Decimal string `json:"decimal"`
|
||||||
|
Digital string `json:"digital"`
|
||||||
|
Seconds float64 `json:"seconds"`
|
||||||
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SummariesData struct {
|
type SummariesData struct {
|
||||||
@@ -73,10 +81,23 @@ func NewSummariesFrom(summaries []*models.Summary) *SummariesViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var totalTime time.Duration
|
||||||
|
for _, s := range summaries {
|
||||||
|
totalTime += s.TotalTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
totalHrs, totalMins, totalSecs := totalTime.Hours(), (totalTime - time.Duration(totalTime.Hours())*time.Hour).Minutes(), totalTime.Seconds()
|
||||||
|
|
||||||
return &SummariesViewModel{
|
return &SummariesViewModel{
|
||||||
Data: data,
|
Data: data,
|
||||||
End: maxDate,
|
End: maxDate,
|
||||||
Start: minDate,
|
Start: minDate,
|
||||||
|
CumulativeTotal: &SummariesCumulativeTotal{
|
||||||
|
Decimal: fmt.Sprintf("%.2f", totalHrs),
|
||||||
|
Digital: fmt.Sprintf("%d:%d", int(totalHrs), int(totalMins)),
|
||||||
|
Seconds: totalSecs,
|
||||||
|
Text: utils.FmtWakatimeDuration(totalTime),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user