ircstats

package
v0.0.0-...-73bf3c5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DaysDiff

func DaysDiff(a, b time.Time) (days int64)

Days diff for time.Time a - b in days

func DaysDiffUnix

func DaysDiffUnix(unixTimeA int64, unixTimeB int64) (days int64)

Days diff for unix time a - b in days

Types

type Averages

type Averages struct {
	Hour    float64 // Average lines by Hour (24 hours)
	Day     float64 // Average lines by day (365 days)
	Week    float64 // Average lines by week (week 1 - week 52)
	WeekDay float64 // Average lines by week day (monday - sunday)
}

type Channel

type Channel struct {
	Name              string          // Channel Name
	ActiveUsers       map[string]User // Active users in past 30 days
	UserCount         int64           // Total Number of users in Channel
	LineCount         int64           // Total Number of lines in Channel
	WordCount         int64           // Total Word count for Channel
	MaxDay            MaxDay          // Calculated Max Day
	MaxHour           MaxHour         // Calculated Max Hour
	MaxWeek           MaxWeek         // Calculated Max Week
	Averages          Averages        // Calculated Averages
	HoursAndDaysStats                 // Inherited Hour And Days methods
	Seen                              // First & Last Seen
}

Channel Statistics

type Config

type Config struct {
	Location          string
	SaveLocation      string
	DatabaseLocation  string
	PageTitle         string
	PageDescription   string
	HeatMapInterval   uint
	ActivityPeriod    uint
	Ignore            []string
	NickNameMapping   map[string][]string
	NickNameHashTable map[string]string
	Profiles          map[string]map[string]string
}

func (*Config) Load

func (c *Config) Load(path string) (err error)

type Database

type Database struct {
	Users         map[string]User // Users
	LastGenerated int64           // Unix timestamp of last generated
	Version       string          // Version of application that this works with, if the version changes we need to check for incompatibility
	Channel       Channel         // Channel counters for storage
}

Cached data that has been parsed is stored in the Database struct. Once execution is complete is can save to disk this saves us from restarting from the beginning of the file.

The primary data that is stored here is parsed user stats

func (*Database) AddUser

func (d *Database) AddUser(u User)

Add new User

func (Database) CheckVersion

func (d Database) CheckVersion(version string) (ok bool, err error)

At some point this needs to check the version @todo implement this

func (Database) CountUsers

func (d Database) CountUsers() int64

Return count of Users in data store

func (Database) GetUser

func (d Database) GetUser(nick string) (user User, err error)

Get User by nick, returns an error if User not found

func (Database) HasUser

func (d Database) HasUser(nick string) bool

Check to see if Database contains User by nick

func (*Database) Load

func (d *Database) Load(path string) (err error)

Load Database from disk

func (Database) Save

func (d Database) Save(path string) (err error)

Save Database to disk

func (*Database) SetUser

func (d *Database) SetUser(nick string, u User)

Set User by nick

type HoursAndDaysStats

type HoursAndDaysStats struct {
	Weeks [54]int64        // lines per 52 weeks
	Hours [24]int64        // lines per 24 hours @todo check that all 24 elements are being filled...
	Days  map[string]int64 // words per day
}

func (HoursAndDaysStats) FindDayAverage

func (s HoursAndDaysStats) FindDayAverage() (avg float64)

func (HoursAndDaysStats) FindHourAverage

func (s HoursAndDaysStats) FindHourAverage() (avg float64)

func (HoursAndDaysStats) FindPeakDay

func (s HoursAndDaysStats) FindPeakDay() (date string, total int64)

func (HoursAndDaysStats) FindPeakHour

func (s HoursAndDaysStats) FindPeakHour() (hour int64, total int64)

func (HoursAndDaysStats) FindPeakWeek

func (s HoursAndDaysStats) FindPeakWeek() (week int64, total int64)

func (HoursAndDaysStats) FindPeakWeekDay

func (s HoursAndDaysStats) FindPeakWeekDay() (weekday int64, total int64)

func (HoursAndDaysStats) FindWeekAverage

func (s HoursAndDaysStats) FindWeekAverage() (avg float64)

func (HoursAndDaysStats) FindWeekDayAverage

func (s HoursAndDaysStats) FindWeekDayAverage() (avg float64)

func (HoursAndDaysStats) HasDay

func (s HoursAndDaysStats) HasDay(day string) bool

func (*HoursAndDaysStats) IncrementDay

func (s *HoursAndDaysStats) IncrementDay(date string, increment int64)

Increment Days by an input number

func (*HoursAndDaysStats) IncrementHour

func (s *HoursAndDaysStats) IncrementHour(hour uint)

Increment Hours by one

func (*HoursAndDaysStats) IncrementWeek

func (s *HoursAndDaysStats) IncrementWeek(week int, increment int64)

Increment Weeks by an input number

func (*HoursAndDaysStats) Initiate

func (s *HoursAndDaysStats) Initiate()

type IrcLogReader

type IrcLogReader struct {
	RegexAction       *regexp.Regexp
	RegexMessage      *regexp.Regexp
	RegexParseAction  *regexp.Regexp
	RegexParseMessage *regexp.Regexp

	NickNameHashTable map[string]string            // Nickname hash table from configuration
	Profiles          map[string]map[string]string // Profile hash table from configuration
	Ignore            []string                     // Ignore list from configuration
	// contains filtered or unexported fields
}

This IRC Log Reader parses through each line of the input file and pushes it to Database

func NewIrcLogReader

func NewIrcLogReader(c Config) *IrcLogReader

func (IrcLogReader) IsUserIgnored

func (lr IrcLogReader) IsUserIgnored(username string) bool

Identify if the user is to be ignored

func (*IrcLogReader) Load

func (lr *IrcLogReader) Load(filename string, db *Database) (err error)

func (IrcLogReader) MapNick

func (lr IrcLogReader) MapNick(username string) string

Map the users nick if found in the configuration against a mapping.

func (IrcLogReader) NewLinesFound

func (lr IrcLogReader) NewLinesFound() int64

func (IrcLogReader) ParseTime

func (lr IrcLogReader) ParseTime(inputDate string) time.Time

Parse the input time into a time.Time

type JsonData

type JsonData struct {
	// Configurable options
	HeatMapInterval uint // HeatMap Interval from configuration
	ActivityPeriod  uint // Activity Period from configuration

	// Dates
	GeneratedAt   int64 // Timestamp of last generated at
	FirstSeen     int64 // Timestamp of first message
	LastSeen      int64 // Timestamp of last message
	TotalDaysSeen int64 // Number of days between FirstSeen and LastSeen
	TimeZone      TimeZone

	// Averages
	Averages Averages // Calculated Averages

	// Counters
	MaxDay           MaxDay     // Calculated Max Day
	MaxWeekDay       MaxWeekDay // Calculated Max Week Day
	MaxHour          MaxHour    // Calculated Max Hour
	MaxWeek          MaxWeek    // Calculated Max Week
	TotalLines       int64      // Lines parsed in total
	TotalWords       int64      // Total Words (all words multiplied by times used)
	TotalUsers       int64      // Number of unique users
	TotalActiveUsers int64      // Number of active users within activity period (default 30 days)

	// Graph Data
	Days  []SvgGraphDay
	Hours [24]int64

	// Misc
	Users             map[string]UserData // Users list
	SortedActiveUsers []string            // Sorted Users map by "activity"
	SortedTopUsers    []string            // Sorted Users map by words
}

func (JsonData) Debug

func (j JsonData) Debug()

type MaxDay

type MaxDay struct {
	Day   string
	Lines int64
}

type MaxHour

type MaxHour struct {
	Hour  int64
	Lines int64
}

type MaxWeek

type MaxWeek struct {
	Week  int64
	Lines int64
}

type MaxWeekDay

type MaxWeekDay struct {
	DayOfWeek int64
	Lines     int64
}

type Seen

type Seen struct {
	FirstSeen int64
	LastSeen  int64
}

func (Seen) TotalDaysSeen

func (s Seen) TotalDaysSeen() int64

func (*Seen) UpdateSeen

func (s *Seen) UpdateSeen(seen int64)

type SvgGraphDay

type SvgGraphDay struct {
	Date  string
	Value int64 // e.g. Lines
}

Data mapping for passing day date data to front end JSON This is used for the heatmap

type TimeZone

type TimeZone struct {
	Name   string
	Offset int
}

Data mapping for passing timezone data to front end JSON

func (TimeZone) Format

func (tz TimeZone) Format() string

type User

type User struct {
	Username   string
	Url        string
	Avatar     string
	LineCount  int64
	WordCount  int64 // *
	DaysActive int64 // *
	CharCount  int64 // *
	//WordsLine  int64
	LineLength int64
	LinesDay   int64
	WordsDay   int64
	Vocabulary int64
	//DaysTotal  int64
	//MaxHours   int64
	Words map[string]int64 // A Map of words and usage
	HoursAndDaysStats
	Seen
}

func NewUser

func NewUser(nick string, timestamp int64) *User

User Struct constructor

func (*User) AddWord

func (u *User) AddWord(word string)

Add Word to Words map, or if it already exists incremenet its usage count

func (User) HasWord

func (u User) HasWord(word string) bool

Check to see if User contains word

type UserData

type UserData struct {
	Username           string
	Url                string
	Avatar             string
	FirstSpoke         int64
	LastSpoke          int64
	TotalWords         int64    // Count of words
	Averages           Averages // Used for words/day
	Vocabulary         int64    // Number of different words used
	DaysActiveInPeriod int64
	TotalWordsInPeriod int64
	WordsByDayInPeriod float64
	ActivityPercentage float64 // Overall % contribution to Channel.WordCount
}

Data mapping for front end JSON

type View

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

func NewView

func NewView() *View

func (View) Parse

func (v View) Parse(filename string, data ViewData) (err error)

type ViewData

type ViewData struct {
	PageTitle       string   // Page title from configuration
	PageDescription string   // Page description from configuration
	JsonData        JsonData // Json data for exporting to page
}

This view data struct will contain all the data that will be injected into the view template. Ideally this will be done as a JSON export so that JavaScript within the view can transform it in any way it sees fit.

func NewViewData

func NewViewData(c Config) *ViewData

func (*ViewData) Calculate

func (vd *ViewData) Calculate(db Database)

Calculate stats for View

func (ViewData) GetJsonString

func (vd ViewData) GetJsonString() (j []byte, err error)

Returns a json string of the JsonData, good for debugging.

Jump to

Keyboard shortcuts

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