analytics

package
v0.0.0-...-d71c2e5 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HourMapper = []string{
	"zero_hour", "one_hour", "two_hour", "three_hour", "four_hour", "five_hour",
	"six_hour", "seven_hour", "eight_hour", "nine_hour", "ten_hour", "eleven_hour",
	"twelve_hour", "thirteen_hour", "fourteen_hour", "fifteen_hour", "sixteen_hour",
	"seventeen_hour", "eighteen_hour", "nineteen_hour", "twenty_hour", "twentyone_hour",
	"twentytwo_hour", "twentythree_hour",
}

HourMapper is meant to use for mapping a time.Hour() to a string

Functions

func MustMigrate

func MustMigrate(db *sqlx.DB) error

MustMigrate is the same as Migrate, but you don't need to explicitly create a Dependency struct instance. Just supply the database, and you're good to go. It will not panic on error, instead it will just return an error.

Types

type Dependency

type Dependency struct {
	Memory      *bigcache.BigCache
	Bot         *tb.Bot
	DB          *sqlx.DB
	HomeGroupID int64
}

Dependency is the dependency injection struct for the analytics package.

func (*Dependency) GetHourlyDataFromDB

func (d *Dependency) GetHourlyDataFromDB(ctx context.Context) ([]HourlyMap, error)

Return a slice of HourlyMap from the database.

func (*Dependency) GetUserDataFromDB

func (d *Dependency) GetUserDataFromDB(ctx context.Context) ([]GroupMember, error)

Returns a slice of GroupMember from the database.

func (*Dependency) IncrementUserDB

func (d *Dependency) IncrementUserDB(ctx context.Context, member GroupMember) error

IncrementUserDB literally increment a user's counter on the database.

func (*Dependency) Migrate

func (d *Dependency) Migrate(ctx context.Context) error

Migrate creates a migration to the database. This can be called multiple times as it uses PostgreSQL syntax of `IF NOT EXISTS`.

func (*Dependency) NewMessage

func (d *Dependency) NewMessage(m *tb.Message) error

NewMessage handles an incoming message from the group to be noted into the database.

func (*Dependency) NewUser

func (d *Dependency) NewUser(ctx context.Context, m *tb.Message, user *tb.User)

NewUser adds a newly joined user on the group into the database.

If the user has joined before, meaning he left the group for some reason, their data should still be here. But, their joined date will be updated to their newest join date.

func (*Dependency) PurgeBots

func (d *Dependency) PurgeBots(ctx context.Context, m *tb.Message)

func (*Dependency) SwarmLog

func (d *Dependency) SwarmLog(user *tb.User, groupID int64, finishedCaptcha bool)

func (*Dependency) UpdateSwarm

func (d *Dependency) UpdateSwarm(user *tb.User, groupID int64, finishedCaptcha bool)

type GroupMember

type GroupMember struct {
	GroupID     NullInt64 `json:"group_id,omitempty" db:"group_id"`
	UserID      int64     `json:"user_id" db:"user_id"`
	Username    string    `json:"username,omitempty" db:"username" redis:"username"`
	DisplayName string    `json:"display_name,omitempty" db:"display_name" redis:"display_name"`
	Counter     int       `json:"counter" db:"counter" redis:"counter"`
	CreatedAt   time.Time `json:"created_at" db:"created_at"`
	UpdatedAt   time.Time `json:"updated_at" db:"updated_at"`
	JoinedAt    time.Time `json:"joined_at" db:"joined_at"`
}

GroupMember contains information about a user from a group.

func ParseGroupMember

func ParseGroupMember(m *tb.Message) GroupMember

ParseGroupMember converts the tb.Message struct into a GroupMember struct.

type HourlyMap

type HourlyMap struct {
	TodaysDate      string `json:"todays_date" db:"todays_date"`
	ZeroHour        int    `json:"zero_hour" db:"zero_hour"`
	OneHour         int    `json:"one_hour" db:"one_hour"`
	TwoHour         int    `json:"two_hour" db:"two_hour"`
	ThreeHour       int    `json:"three_hour" db:"three_hour"`
	FourHour        int    `json:"four_hour" db:"four_hour"`
	FiveHour        int    `json:"five_hour" db:"five_hour"`
	SixHour         int    `json:"six_hour" db:"six_hour"`
	SevenHour       int    `json:"seven_hour" db:"seven_hour"`
	EightHour       int    `json:"eight_hour" db:"eight_hour"`
	NineHour        int    `json:"nine_hour" db:"nine_hour"`
	TenHour         int    `json:"ten_hour" db:"ten_hour"`
	ElevenHour      int    `json:"eleven_hour" db:"eleven_hour"`
	TwelveHour      int    `json:"twelve_hour" db:"twelve_hour"`
	ThirteenHour    int    `json:"thirteen_hour" db:"thirteen_hour"`
	FourteenHour    int    `json:"fourteen_hour" db:"fourteen_hour"`
	FifteenHour     int    `json:"fifteen_hour" db:"fifteen_hour"`
	SixteenHour     int    `json:"sixteen_hour" db:"sixteen_hour"`
	SeventeenHour   int    `json:"seventeen_hour" db:"seventeen_hour"`
	EighteenHour    int    `json:"eighteen_hour" db:"eighteen_hour"`
	NineteenHour    int    `json:"nineteen_hour" db:"nineteen_hour"`
	TwentyHour      int    `json:"twenty_hour" db:"twenty_hour"`
	TwentyOneHour   int    `json:"twentyone_hour" db:"twentyone_hour"`
	TwentyTwoHour   int    `json:"twentytwo_hour" db:"twentytwo_hour"`
	TwentyThreeHour int    `json:"twentythree_hour" db:"twentythree_hour"`
}

HourlyMap contains the struct surrounding the hourly analytics.

type NullInt64

type NullInt64 sql.NullInt64

func (*NullInt64) MarshalJSON

func (n *NullInt64) MarshalJSON() ([]byte, error)

func (*NullInt64) Scan

func (n *NullInt64) Scan(value interface{}) error

func (*NullInt64) UnmarshalJSON

func (n *NullInt64) UnmarshalJSON(b []byte) error

func (NullInt64) Value

func (n NullInt64) Value() (driver.Value, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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