deat: Added statistics on your log
This commit is contained in:
@@ -3632,6 +3632,50 @@ func (a *App) UpdateQSO(q qso.QSO) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// GetLogStats aggregates the logbook for the Statistics dashboard (operators,
|
||||
// modes, bands, entities, activity over time), restricted to a period.
|
||||
//
|
||||
// fromISO/toISO are "YYYY-MM-DD" (or RFC3339); either may be empty for "no
|
||||
// bound", so two empty strings mean the whole log. `to` is inclusive: a bare date
|
||||
// is stretched to 23:59:59 of that day, otherwise picking today as the end would
|
||||
// silently drop today's QSOs.
|
||||
func (a *App) GetLogStats(fromISO, toISO, contestID string, year int) (qso.Stats, error) {
|
||||
if a.qso == nil {
|
||||
return qso.Stats{}, fmt.Errorf("db not initialized")
|
||||
}
|
||||
from := parseStatsBound(fromISO, false)
|
||||
to := parseStatsBound(toISO, true)
|
||||
return a.qso.Stats(a.ctx, from, to, contestID, year)
|
||||
}
|
||||
|
||||
// GetContestRuns lists the (contest, year) pairs actually present in the log, so
|
||||
// the Statistics picker only ever offers contests you really entered.
|
||||
func (a *App) GetContestRuns() ([]qso.ContestRun, error) {
|
||||
if a.qso == nil {
|
||||
return nil, fmt.Errorf("db not initialized")
|
||||
}
|
||||
return a.qso.ContestRuns(a.ctx)
|
||||
}
|
||||
|
||||
// parseStatsBound turns a UI date into a UTC bound. endOfDay stretches a bare
|
||||
// date to 23:59:59 so an inclusive "to" really includes that day.
|
||||
func parseStatsBound(s string, endOfDay bool) time.Time {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return time.Time{}
|
||||
}
|
||||
if t, err := time.Parse("2006-01-02", s); err == nil {
|
||||
if endOfDay {
|
||||
return t.UTC().Add(24*time.Hour - time.Second)
|
||||
}
|
||||
return t.UTC()
|
||||
}
|
||||
if t, err := time.Parse(time.RFC3339, s); err == nil {
|
||||
return t.UTC()
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (a *App) DeleteQSO(id int64) error {
|
||||
if a.qso == nil {
|
||||
return fmt.Errorf("db not initialized")
|
||||
|
||||
Reference in New Issue
Block a user