mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: importing data from wakapi instance (resolve #428)
This commit is contained in:
parent
f182b804bb
commit
4cc8c21f67
@ -3,6 +3,7 @@ package v1
|
|||||||
import (
|
import (
|
||||||
"github.com/muety/wakapi/models"
|
"github.com/muety/wakapi/models"
|
||||||
"github.com/muety/wakapi/utils"
|
"github.com/muety/wakapi/utils"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://wakatime.com/developers#all_time_since_today
|
// https://wakatime.com/developers#all_time_since_today
|
||||||
@ -28,11 +29,19 @@ type AllTimeRange struct {
|
|||||||
|
|
||||||
func NewAllTimeFrom(summary *models.Summary) *AllTimeViewModel {
|
func NewAllTimeFrom(summary *models.Summary) *AllTimeViewModel {
|
||||||
total := summary.TotalTime()
|
total := summary.TotalTime()
|
||||||
|
tzName, _ := summary.FromTime.T().Zone()
|
||||||
return &AllTimeViewModel{
|
return &AllTimeViewModel{
|
||||||
Data: &AllTimeData{
|
Data: &AllTimeData{
|
||||||
TotalSeconds: float32(total.Seconds()),
|
TotalSeconds: float32(total.Seconds()),
|
||||||
Text: utils.FmtWakatimeDuration(total),
|
Text: utils.FmtWakatimeDuration(total),
|
||||||
IsUpToDate: true,
|
IsUpToDate: true,
|
||||||
|
Range: &AllTimeRange{
|
||||||
|
End: summary.ToTime.T().Format(time.RFC3339),
|
||||||
|
EndDate: utils.FormatDate(summary.ToTime.T()),
|
||||||
|
Start: summary.FromTime.T().Format(time.RFC3339),
|
||||||
|
StartDate: utils.FormatDate(summary.FromTime.T()),
|
||||||
|
Timezone: tzName,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,17 +57,19 @@ func (w *WakatimeHeartbeatImporter) Import(user *models.User, minFrom time.Time,
|
|||||||
endDate = maxTo
|
endDate = maxTo
|
||||||
}
|
}
|
||||||
|
|
||||||
userAgents, err := w.fetchUserAgents(baseUrl)
|
userAgents := map[string]*wakatime.UserAgentEntry{}
|
||||||
if err != nil {
|
//userAgents, err := w.fetchUserAgents(baseUrl)
|
||||||
config.Log().Error("failed to fetch user agents while importing wakatime heartbeats for user '%s' - %v", user.ID, err)
|
// if err != nil {
|
||||||
return
|
// config.Log().Error("failed to fetch user agents while importing wakatime heartbeats for user '%s' - %v", user.ID, err)
|
||||||
}
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
machinesNames, err := w.fetchMachineNames(baseUrl)
|
machinesNames := map[string]*wakatime.MachineEntry{}
|
||||||
if err != nil {
|
// machinesNames, err := w.fetchMachineNames(baseUrl)
|
||||||
config.Log().Error("failed to fetch machine names while importing wakatime heartbeats for user '%s' - %v", user.ID, err)
|
// if err != nil {
|
||||||
return
|
// config.Log().Error("failed to fetch machine names while importing wakatime heartbeats for user '%s' - %v", user.ID, err)
|
||||||
}
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
days := generateDays(startDate, endDate)
|
days := generateDays(startDate, endDate)
|
||||||
|
|
||||||
@ -259,9 +261,17 @@ func mapHeartbeat(
|
|||||||
) *models.Heartbeat {
|
) *models.Heartbeat {
|
||||||
ua := userAgents[entry.UserAgentId]
|
ua := userAgents[entry.UserAgentId]
|
||||||
if ua == nil {
|
if ua == nil {
|
||||||
ua = &wakatime.UserAgentEntry{
|
// try to parse id as an actual user agent string (as returned by wakapi)
|
||||||
Editor: "unknown",
|
if opSys, editor, err := utils.ParseUserAgent(entry.UserAgentId); err == nil {
|
||||||
Os: "unknown",
|
ua = &wakatime.UserAgentEntry{
|
||||||
|
Editor: opSys,
|
||||||
|
Os: editor,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ua = &wakatime.UserAgentEntry{
|
||||||
|
Editor: "unknown",
|
||||||
|
Os: "unknown",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user