2020-09-06 13:15:46 +03:00
|
|
|
package v1
|
|
|
|
|
2020-09-12 00:24:51 +03:00
|
|
|
import (
|
|
|
|
"github.com/muety/wakapi/models"
|
|
|
|
"github.com/muety/wakapi/utils"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-09-06 13:15:46 +03:00
|
|
|
// https://wakatime.com/developers#all_time_since_today
|
|
|
|
|
2020-09-12 17:09:23 +03:00
|
|
|
type AllTimeViewModel struct {
|
|
|
|
Data *allTimeData `json:"data"`
|
2020-09-12 00:24:51 +03:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:09:23 +03:00
|
|
|
type allTimeData struct {
|
2020-09-12 00:24:51 +03:00
|
|
|
TotalSeconds float32 `json:"total_seconds"` // total number of seconds logged since account created
|
|
|
|
Text string `json:"text"` // total time logged since account created as human readable string>
|
|
|
|
IsUpToDate bool `json:"is_up_to_date"` // true if the stats are up to date; when false, a 202 response code is returned and stats will be refreshed soon>
|
2020-09-06 18:20:37 +03:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:09:23 +03:00
|
|
|
func NewAllTimeFrom(summary *models.Summary, filters *models.Filters) *AllTimeViewModel {
|
2020-09-12 00:24:51 +03:00
|
|
|
var total time.Duration
|
|
|
|
if key := filters.Project; key != "" {
|
2020-11-01 14:50:59 +03:00
|
|
|
total = summary.TotalTimeByFilters(filters)
|
2020-09-12 00:24:51 +03:00
|
|
|
} else {
|
|
|
|
total = summary.TotalTime()
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:09:23 +03:00
|
|
|
return &AllTimeViewModel{
|
|
|
|
Data: &allTimeData{
|
2020-09-12 00:24:51 +03:00
|
|
|
TotalSeconds: float32(total.Seconds()),
|
|
|
|
Text: utils.FmtWakatimeDuration(total),
|
|
|
|
IsUpToDate: true,
|
|
|
|
},
|
|
|
|
}
|
2020-09-06 13:15:46 +03:00
|
|
|
}
|