Skip to content

Commit

Permalink
Fix time zone for visitor count reports
Browse files Browse the repository at this point in the history
  • Loading branch information
th0th committed May 24, 2023
1 parent 0412316 commit e7d80a6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backend/pkg/service/sitereport/visitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type Datum struct {
DateTime time.Time `json:"dateTime"`
VisitorCount *uint64 `json:"visitorCount"`
VisitorCount *uint64 `json:"visitorCount"`
}

type Report struct {
Expand All @@ -34,11 +34,12 @@ func Get(dp *depot.Depot, filters *filter.Filters) (*Report, error) {
valueSubQuery := q.
Select(
strings.Join([]string{
"toStartOfInterval(date_time, @timeWindowInterval) as date_time",
"toStartOfInterval(date_time, @timeWindowInterval, @timeZone) as date_time",
"count(distinct visitor_id) as visitor_count",
}, ","),
map[string]interface{}{
"timeWindowInterval": gorm.Expr(interval2.ToQuery()),
"timeZone": filters.GetTimeZone(),
},
).
Group("date_time")
Expand All @@ -48,15 +49,14 @@ func Get(dp *depot.Depot, filters *filter.Filters) (*Report, error) {
strings.Join([]string{
"select",
strings.Join([]string{
"toStartOfInterval(@start, @timeWindowInterval) + interval arrayJoin(range(0, toUInt64(dateDiff('second', @start, @end)), @intervalSeconds)) second as date_time",
"@start + interval arrayJoin(range(0, toUInt64(dateDiff('second', @start, @end)), @intervalSeconds)) second as date_time",
"if(date_time > now(), null, 0) as visitor_count",
}, ","),
}, " "),
map[string]any{
"end": filters.End,
"intervalSeconds": interval2.ToDuration().Seconds(),
"start": filters.Start,
"timeWindowInterval": gorm.Expr(interval2.ToQuery()),
},
)

Expand Down

0 comments on commit e7d80a6

Please sign in to comment.