feat: add per weekday stats to report (resolve #493)

This commit is contained in:
Ferdinand Mütsch 2023-07-08 19:54:15 +02:00
parent 35ef323b19
commit 5278dba4f4
4 changed files with 959 additions and 921 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,8 +3,9 @@ package models
import "time"
type Report struct {
From time.Time
To time.Time
User *User
Summary *Summary
From time.Time
To time.Time
User *User
Summary *Summary
DailySummaries []*Summary
}

View File

@ -1,12 +1,14 @@
package services
import (
"github.com/duke-git/lancet/v2/datetime"
"github.com/duke-git/lancet/v2/slice"
"github.com/emvi/logbuch"
"github.com/leandro-lugaresi/hub"
"github.com/muety/artifex/v2"
"github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
"github.com/muety/wakapi/utils"
"math/rand"
"time"
)
@ -100,17 +102,34 @@ func (srv *ReportService) SendReport(user *models.User, duration time.Duration)
end := time.Now().In(user.TZ())
start := time.Now().Add(-1 * duration)
summary, err := srv.summaryService.Aliased(start, end, user, srv.summaryService.Retrieve, nil, false)
fullSummary, err := srv.summaryService.Aliased(start, end, user, srv.summaryService.Retrieve, nil, false)
if err != nil {
config.Log().Error("failed to generate report for '%s' - %v", user.ID, err)
return err
}
// generate per-day summaries
dayIntervals := utils.SplitRangeByDays(start, end)
dailySummaries := make([]*models.Summary, len(dayIntervals))
for i, interval := range dayIntervals {
from, to := datetime.BeginOfDay(interval[0]), interval[1]
summary, err := srv.summaryService.Aliased(from, to, user, srv.summaryService.Retrieve, nil, false)
if err != nil {
config.Log().Error("failed to generate day summary (%v to %v) for report for '%s' - %v", from, to, user.ID, err)
break
}
summary.FromTime = models.CustomTime(from)
summary.ToTime = models.CustomTime(to.Add(-1 * time.Second))
dailySummaries[i] = summary
}
report := &models.Report{
From: start,
To: end,
User: user,
Summary: summary,
From: start,
To: end,
User: user,
Summary: fullSummary,
DailySummaries: dailySummaries,
}
if err := srv.mailService.SendReport(user, report); err != nil {

View File

@ -32,6 +32,20 @@
</tbody>
</table>
{{ if len .Report.DailySummaries }}
<p style="font-family: sans-serif; font-size: 16px; font-weight: 500; margin: 0; Margin-bottom: 15px; Margin-top: 30px;">Weekdays</p>
<table border="0" cellpadding="0" cellspacing="0" class="btn btn-primary" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; box-sizing: border-box;">
<tbody>
{{ range $i, $summary := .Report.DailySummaries }}
<tr>
<td align="left" style="width: 300px; font-family: sans-serif; font-size: 14px; vertical-align: top; padding-bottom: 15px; font-weight: 800;">{{ $summary.FromTime.T | date }}:</td>
<td align="left" style="font-family: sans-serif; font-size: 14px; vertical-align: top; padding-bottom: 15px;">{{ $summary.TotalTime | duration }}</td>
</tr>
{{ end }}
</tbody>
</table>
{{ end }}
<p style="font-family: sans-serif; font-size: 16px; font-weight: 500; margin: 0; Margin-bottom: 15px; Margin-top: 30px;">Languages</p>
<table border="0" cellpadding="0" cellspacing="0" class="btn btn-primary" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; box-sizing: border-box;">
<tbody>