2021-02-05 20:47:28 +03:00
|
|
|
package v1
|
|
|
|
|
2021-04-30 11:12:28 +03:00
|
|
|
import (
|
2022-01-28 14:28:47 +03:00
|
|
|
"strconv"
|
2022-02-13 12:59:14 +03:00
|
|
|
"time"
|
2022-01-28 14:28:47 +03:00
|
|
|
|
2021-04-30 11:12:28 +03:00
|
|
|
"github.com/muety/wakapi/models"
|
|
|
|
)
|
2021-02-05 20:47:28 +03:00
|
|
|
|
|
|
|
type HeartbeatsViewModel struct {
|
|
|
|
Data []*HeartbeatEntry `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Incomplete, for now, only the subset of fields is implemented
|
|
|
|
// that is actually required for the import
|
|
|
|
|
|
|
|
type HeartbeatEntry struct {
|
2022-02-13 12:59:14 +03:00
|
|
|
Id string `json:"id"`
|
|
|
|
Branch string `json:"branch"`
|
|
|
|
Category string `json:"category"`
|
|
|
|
Entity string `json:"entity"`
|
|
|
|
IsWrite bool `json:"is_write"`
|
|
|
|
Language string `json:"language"`
|
|
|
|
Project string `json:"project"`
|
|
|
|
Time float64 `json:"time"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
UserId string `json:"user_id"`
|
|
|
|
MachineNameId string `json:"machine_name_id"`
|
|
|
|
UserAgentId string `json:"user_agent_id"`
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
2022-01-28 14:28:47 +03:00
|
|
|
}
|
|
|
|
|
2022-02-13 12:59:14 +03:00
|
|
|
func HeartbeatsToCompat(entries []*models.Heartbeat) []*HeartbeatEntry {
|
|
|
|
out := make([]*HeartbeatEntry, len(entries))
|
2022-01-28 14:28:47 +03:00
|
|
|
for i := 0; i < len(entries); i++ {
|
|
|
|
entry := entries[i]
|
2022-02-13 12:59:14 +03:00
|
|
|
out[i] = &HeartbeatEntry{
|
2022-01-28 14:28:47 +03:00
|
|
|
Id: strconv.FormatUint(entry.ID, 10),
|
|
|
|
Branch: entry.Branch,
|
|
|
|
Category: entry.Category,
|
|
|
|
Entity: entry.Entity,
|
|
|
|
IsWrite: entry.IsWrite,
|
|
|
|
Language: entry.Language,
|
|
|
|
Project: entry.Project,
|
|
|
|
Time: float64(entry.Time.T().Unix()),
|
|
|
|
Type: entry.Type,
|
|
|
|
UserId: entry.UserID,
|
|
|
|
MachineNameId: entry.Machine,
|
|
|
|
UserAgentId: entry.UserAgent,
|
2022-02-13 12:59:14 +03:00
|
|
|
CreatedAt: entry.CreatedAt.T(),
|
2022-01-28 14:28:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return out
|
2021-02-05 20:47:28 +03:00
|
|
|
}
|