Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions internal/controller/http/web/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/vanadium23/kompanion/internal/stats"
"github.com/vanadium23/kompanion/pkg/logger"
"github.com/wcharczuk/go-chart/v2"
charts "github.com/wcharczuk/go-chart/v2"
)

Expand Down Expand Up @@ -64,6 +65,9 @@ func generateDailyStatsChart(stats []stats.DailyStats) ([]byte, error) {
}
return ""
},
NameStyle: charts.Style{
FontColor: chart.GetDefaultColor(0),
},
Range: &charts.ContinuousRange{
Min: 0.0,
Max: maxPages,
Expand Down Expand Up @@ -103,6 +107,9 @@ func generateDailyStatsChart(stats []stats.DailyStats) ([]byte, error) {
Min: 0.0,
Max: maxDuration,
},
NameStyle: charts.Style{
FontColor: chart.GetDefaultColor(1),
},
},
Width: 800,
Height: 400,
Expand All @@ -119,10 +126,11 @@ func generateDailyStatsChart(stats []stats.DailyStats) ([]byte, error) {

func newStatsRoutes(handler *gin.RouterGroup, stats stats.ReadingStats, l logger.Interface) {
handler.GET("/", func(c *gin.Context) {
// Get date range from query params, default to current month
// Get date range from query params, default: a month ago to current day
now := time.Now()
from := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
to := from.AddDate(0, 1, 0).Add(-time.Second)
from := now.AddDate(0, -1, 0)
from = time.Date(from.Year(), from.Month(), from.Day(), 0, 0, 0, 0, time.Local)
to := from.AddDate(0, 1, 1).Add(-time.Second)

// Parse from and to dates if provided
if fromStr := c.Query("from"); fromStr != "" {
Expand Down Expand Up @@ -153,10 +161,11 @@ func newStatsRoutes(handler *gin.RouterGroup, stats stats.ReadingStats, l logger
})

handler.GET("/chart", func(c *gin.Context) {
// Get date range from query params, default to current month
// Get date range from query params, default: a month ago to current day
now := time.Now()
from := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
to := from.AddDate(0, 1, 0).Add(-time.Second)
from := now.AddDate(0, -1, 0)
from = time.Date(from.Year(), from.Month(), from.Day(), 0, 0, 0, 0, time.Local)
to := from.AddDate(0, 1, 1).Add(-time.Second)

// Parse from and to dates if provided
if fromStr := c.Query("from"); fromStr != "" {
Expand Down
Loading