Skip to content

Commit

Permalink
Fix stuff here and there (#158)
Browse files Browse the repository at this point in the history
* Fix stuff here and there

* Fix eslint issue

* Delete unused report

* Fix responsiveness of report cards

* Fix eslint issues
  • Loading branch information
th0th authored Feb 22, 2023
1 parent 6470ef1 commit 2394334
Show file tree
Hide file tree
Showing 45 changed files with 249 additions and 481 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
path: ~/.npm

- name: Pull docker images
run: docker compose pull clickhouse nginx-proxy postgres redis
run: docker compose pull --ignore-buildable

- env:
DEBUG: ${{ vars.DEBUG }}
Expand Down
1 change: 0 additions & 1 deletion backend/migrations/clickhouse/000001_create_tables.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ CREATE TABLE "events" (
"locale" Nullable(String),
"operating_system_name" Nullable(String),
"operating_system_version" Nullable(String),
"path" String,
"referrer" Nullable(String),
"site_id" UInt64,
"time_zone" Nullable(String),
Expand Down
8 changes: 0 additions & 8 deletions backend/pkg/model/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type Event struct {
Locale *string
OperatingSystemName *string
OperatingSystemVersion *string
Path string
Referrer *string
SiteId uint64
TimeZone *string
Expand All @@ -55,11 +54,6 @@ const (
EventKindPageView EventKind = "PAGE_VIEW"
)

const (
EventUserAgentMaxLength = 2000
EventUserAgentMinLength = 2
)

func (e *Event) TableName() string {
return "events_buffer"
}
Expand Down Expand Up @@ -104,8 +98,6 @@ func (e *Event) FillFromUrl(url string, safeQueryParameters []string) {

u.RawQuery = q.Encode()
e.Url = u.String()

e.Path = u.Path
}

func (e *Event) FillFromUserAgent(userAgent string) {
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/restapi/sitereport/device_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package sitereport
import (
"github.com/gofiber/fiber/v2"
dm "github.com/th0th/poeticmetric/backend/pkg/restapi/middleware/depot"
"github.com/th0th/poeticmetric/backend/pkg/service/sitedevicetypereport"
"github.com/th0th/poeticmetric/backend/pkg/service/sitereport/devicetype"
)

func deviceType(c *fiber.Ctx) error {
dp := dm.Get(c)

report, err := sitedevicetypereport.Get(dp, getFilters(c))
report, err := devicetype.Get(dp, getFilters(c))
if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions backend/pkg/restapi/sitereport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func Add(app *fiber.App) {
group.Get("/overview", overview)
group.Get("/page-view", pageView)
group.Get("/page-view-trends", pageViewTrends)
group.Get("/path-duration", pathDuration)
group.Get("/path", paginationCursorMiddleware[path2.PaginationCursor], path)
group.Get("/referrer-path", paginationCursorMiddleware[referrerpath.PaginationCursor], referrerPath)
group.Get("/referrer-site", paginationCursorMiddleware[referrersite.PaginationCursor], referrerSite)
Expand All @@ -53,7 +52,6 @@ func Add(app *fiber.App) {
group.Get("/utm-source", paginationCursorMiddleware[utmsource.PaginationCursor], utmSource)
group.Get("/utm-term", paginationCursorMiddleware[utmterm.PaginationCursor], utmTerm)
group.Get("/visitor", visitor)
group.Get("/visitor-page-view", visitorPageView)
group.Get("/visitor-trends", visitorTrends)
}

Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/restapi/sitereport/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package sitereport
import (
"github.com/gofiber/fiber/v2"
dm "github.com/th0th/poeticmetric/backend/pkg/restapi/middleware/depot"
"github.com/th0th/poeticmetric/backend/pkg/service/siteoverviewreport"
overview2 "github.com/th0th/poeticmetric/backend/pkg/service/sitereport/overview"
)

func overview(c *fiber.Ctx) error {
dp := dm.Get(c)

report, err := siteoverviewreport.Get(dp, getFilters(c))
report, err := overview2.Get(dp, getFilters(c))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/restapi/sitereport/page_view_trends.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package sitereport
import (
"github.com/gofiber/fiber/v2"
dm "github.com/th0th/poeticmetric/backend/pkg/restapi/middleware/depot"
"github.com/th0th/poeticmetric/backend/pkg/service/sitepageviewtrends"
"github.com/th0th/poeticmetric/backend/pkg/service/sitereport/pageviewtrends"
)

func pageViewTrends(c *fiber.Ctx) error {
dp := dm.Get(c)

report, err := sitepageviewtrends.Get(dp, getFilters(c))
report, err := pageviewtrends.Get(dp, getFilters(c))
if err != nil {
return err
}
Expand Down
18 changes: 0 additions & 18 deletions backend/pkg/restapi/sitereport/path_duration.go

This file was deleted.

18 changes: 0 additions & 18 deletions backend/pkg/restapi/sitereport/visitor_page_view.go

This file was deleted.

10 changes: 5 additions & 5 deletions backend/pkg/service/bootstrap/create_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func createSite(dp *depot.Depot) error {
event.Referrer = pointer.Get(fmt.Sprintf("%s%s", gofakeit.RandomString(referrerSites), gofakeit.RandomString(referrerPaths)))
}

event.FillFromUrl(gofakeit.RandomString(urls), nil)
event.FillFromUserAgent(gofakeit.RandomString(userAgents))

event.VisitorId = gofakeit.RandomString(visitorIds)

//lint:ignore SA4000 we use double Bool() here to reduce the possibility
if gofakeit.Bool() && gofakeit.Bool() {
event.UtmSource = pointer.Get(gofakeit.RandomString(utmSources))
Expand All @@ -90,11 +95,6 @@ func createSite(dp *depot.Depot) error {
event.UtmTerm = pointer.Get(gofakeit.RandomString(utmTerms))
}

event.FillFromUrl(gofakeit.RandomString(urls), nil)
event.FillFromUserAgent(gofakeit.RandomString(userAgents))

event.VisitorId = gofakeit.RandomString(visitorIds)

events = append(events, event)
}

Expand Down
39 changes: 0 additions & 39 deletions backend/pkg/service/sitepathdurationreport/main.go

This file was deleted.

90 changes: 0 additions & 90 deletions backend/pkg/service/sitepathdurationreport/main_test.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sitedevicetypereport
package devicetype

import (
"strings"
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/service/sitereport/filter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Apply(dp *depot.Depot, filters *Filters) *gorm.DB {
}

if filters.Path != nil {
clickHouseSession.Where("path = ?", *filters.Path)
clickHouseSession.Where("pathFull(url) = ?", *filters.Path)
}

if filters.Referrer != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package siteoverviewreport
package overview

import (
"context"
Expand Down
18 changes: 10 additions & 8 deletions backend/pkg/service/sitereport/pageview/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

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

type Report struct {
Expand All @@ -23,9 +23,9 @@ type Report struct {
}

func Get(dp *depot.Depot, filters *filter.Filters) (*Report, error) {
interval := interval.GetVisitorPageViewInterval(filters)
interval2 := interval.GetVisitorPageViewInterval(filters)
report := &Report{
Interval: interval,
Interval: interval2,
}

q := filter.Apply(dp, filters)
Expand All @@ -37,7 +37,7 @@ func Get(dp *depot.Depot, filters *filter.Filters) (*Report, error) {
"count(*) as page_view_count",
}, ","),
map[string]interface{}{
"timeWindowInterval": gorm.Expr(interval.ToQuery()),
"timeWindowInterval": gorm.Expr(interval2.ToQuery()),
"timeZone": filters.GetTimeZone(),
},
).
Expand All @@ -49,12 +49,12 @@ func Get(dp *depot.Depot, filters *filter.Filters) (*Report, error) {
"select",
strings.Join([]string{
"@start + interval arrayJoin(range(0, toUInt64(dateDiff('second', @start, @end)), @intervalSeconds)) second as date_time",
"0 as page_view_count",
"if(date_time > now(), null, 0) as page_view_count",
}, ","),
}, " "),
map[string]any{
"end": filters.End,
"intervalSeconds": interval.ToDuration().Seconds(),
"intervalSeconds": interval2.ToDuration().Seconds(),
"start": filters.Start,
},
)
Expand All @@ -78,8 +78,10 @@ func Get(dp *depot.Depot, filters *filter.Filters) (*Report, error) {
var pageViewCountsLength float64 = 0

for _, d := range report.Data {
pageViewCountsSum += float64(d.PageViewCount)
pageViewCountsLength += 1
if d.PageViewCount != nil {
pageViewCountsSum += float64(*d.PageViewCount)
pageViewCountsLength += 1
}
}

if pageViewCountsLength != 0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sitepageviewtrends
package pageviewtrends

import (
"strings"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sitepageviewtrends
package pageviewtrends

import (
"fmt"
Expand Down
Loading

0 comments on commit 2394334

Please sign in to comment.