analytics

package
v0.0.0-...-5cd70b9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type AnalyticsBackgroundService

type AnalyticsBackgroundService struct {
	// contains filtered or unexported fields
}

func NewAnalyticsBackgroundService

func NewAnalyticsBackgroundService(analytics ViewsService, log *zap.SugaredLogger, lc fx.Lifecycle) *AnalyticsBackgroundService

func (*AnalyticsBackgroundService) Start

func (s *AnalyticsBackgroundService) Start()

func (*AnalyticsBackgroundService) Stop

func (s *AnalyticsBackgroundService) Stop()

type AnalyticsPeriod

type AnalyticsPeriod int32
const ANALYTICS_PERIOD_TOTAL AnalyticsPeriod = 0

type AnalyticsPeriods

type AnalyticsPeriods struct {
	Hour  AnalyticsPeriod
	Day   AnalyticsPeriod
	Week  AnalyticsPeriod
	Month AnalyticsPeriod
	Year  AnalyticsPeriod
}

func CurrentAnalyticsPeriods

func CurrentAnalyticsPeriods(now time.Time) AnalyticsPeriods

type BookViewEntry

type BookViewEntry struct {
	BookID int64
	Views  int64
}

type Counters

type Counters interface {
	Namespace(name string) CountersNamespace
}

func NewAnalyticsCounters

func NewAnalyticsCounters(redisClient *redis.Client, log *zap.SugaredLogger) Counters

type CountersNamespace

type CountersNamespace interface {
	Incr(ctx context.Context, key, uniqueId string, incrBy int64, expire time.Duration) error
	Get(ctx context.Context, key string) (int64, error)
	Delete(ctx context.Context, key string) error
	PullPendingCounters(ctx context.Context, delete bool) (map[string]int64, error)
}

type RedisCounters

type RedisCounters struct {
	// contains filtered or unexported fields
}

func (*RedisCounters) Namespace

func (c *RedisCounters) Namespace(name string) CountersNamespace

type ViewMetadata

type ViewMetadata struct {
	UserID uuid.NullUUID
	IP     net.IP
}

func (ViewMetadata) UniqueID

func (m ViewMetadata) UniqueID() string

type Views

type Views struct {
	Total int64 `json:"total"`
	Year  int64 `json:"year"`
	Month int64 `json:"month"`
	Week  int64 `json:"week"`
	Day   int64 `json:"day"`
	Hour  int64 `json:"hour"`
}

type ViewsService

type ViewsService interface {
	IncrBookView(ctx context.Context, bookID int64, meta ViewMetadata) error
	IncrChapterView(ctx context.Context, bookID, chapterID int64, meta ViewMetadata) error
	GetBookViews(ctx context.Context, bookID int64) (Views, error)
	GetBooksViews(ctx context.Context, bookIDs []int64) (map[int64]Views, error)
	GetMostViewedBooks(ctx context.Context, period AnalyticsPeriod) ([]BookViewEntry, error)
	CommitPendingViewsToDB(ctx context.Context)
}

func NewAnalyticsDummyViewsService

func NewAnalyticsDummyViewsService() ViewsService

func NewAnalyticsViewsService

func NewAnalyticsViewsService(db store.DBTX, counters Counters, log *zap.SugaredLogger) ViewsService

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL