2020-09-12 17:09:23 +03:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/muety/wakapi/models"
|
|
|
|
"github.com/muety/wakapi/utils"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// https://shields.io/endpoint
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultLabel = "coding time"
|
|
|
|
defaultColor = "#2D3748" // not working
|
|
|
|
)
|
|
|
|
|
|
|
|
type BadgeData struct {
|
|
|
|
SchemaVersion int `json:"schemaVersion"`
|
|
|
|
Label string `json:"label"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
Color string `json:"color"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewBadgeDataFrom(summary *models.Summary, filters *models.Filters) *BadgeData {
|
|
|
|
var total time.Duration
|
2021-01-31 18:23:47 +03:00
|
|
|
if hasFilter, _, _ := filters.One(); hasFilter {
|
2020-11-01 14:50:59 +03:00
|
|
|
total = summary.TotalTimeByFilters(filters)
|
2020-09-12 17:09:23 +03:00
|
|
|
} else {
|
|
|
|
total = summary.TotalTime()
|
|
|
|
}
|
|
|
|
|
|
|
|
return &BadgeData{
|
|
|
|
SchemaVersion: 1,
|
|
|
|
Label: defaultLabel,
|
|
|
|
Message: utils.FmtWakatimeDuration(total),
|
|
|
|
Color: defaultColor,
|
|
|
|
}
|
|
|
|
}
|