1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-09-15 17:46:55 +00:00

Start of statsweb program

This commit is contained in:
Kane York 2016-01-17 11:11:21 -08:00
parent 56b86ad4e3
commit 9fc946e373
7 changed files with 130 additions and 10 deletions

View file

@ -21,7 +21,7 @@ import (
"time"
"unicode/utf8"
"./logstasher"
"bitbucket.org/stendec/frankerfacez/socketserver/server/logstasher"
)
// SuccessCommand is a Reply Command to indicate success in reply to a C2S Command.

View file

@ -43,13 +43,18 @@ var uniqueCounter PeriodUniqueUsers
var uniqueUserChannel chan uuid.UUID
var uniqueCtrWritingToken chan usageToken
var counterLocation *time.Location = time.FixedZone("UTC-5", int((time.Hour*-5)/time.Second))
var CounterLocation *time.Location = time.FixedZone("UTC-5", int((time.Hour*-5)/time.Second))
func TruncateToMidnight(at time.Time) time.Time {
year, month, day := at.Date()
return time.Date(year, month, day, 0, 0, 0, 0, CounterLocation)
}
// GetCounterPeriod calculates the start and end timestamps for the HLL measurement period that includes the 'at' timestamp.
func GetCounterPeriod(at time.Time) (start time.Time, end time.Time) {
year, month, day := at.Date()
start = time.Date(year, month, day, 0, 0, 0, 0, counterLocation)
end = time.Date(year, month, day+1, 0, 0, 0, 0, counterLocation)
start = time.Date(year, month, day, 0, 0, 0, 0, CounterLocation)
end = time.Date(year, month, day+1, 0, 0, 0, 0, CounterLocation)
return start, end
}
@ -143,7 +148,7 @@ func loadUniqueUsers() {
log.Panicln("could not make unique users data dir:", err)
}
now := time.Now().In(counterLocation)
now := time.Now().In(CounterLocation)
uniqueCounter.Start, uniqueCounter.End = GetCounterPeriod(now)
err = loadHLL(now, &uniqueCounter)
isIgnorableError := err != nil && (false ||
@ -194,9 +199,9 @@ func processNewUsers() {
}
func getNextMidnight() time.Time {
now := time.Now().In(counterLocation)
now := time.Now().In(CounterLocation)
year, month, day := now.Date()
return time.Date(year, month, day+1, 0, 0, 1, 0, counterLocation)
return time.Date(year, month, day+1, 0, 0, 1, 0, CounterLocation)
}
// is_init_func
@ -214,7 +219,7 @@ func rolloverCounters_do() {
var now time.Time
token = <-uniqueCtrWritingToken
now = time.Now().In(counterLocation)
now = time.Now().In(CounterLocation)
// Cycle for period
err := writeHLL_do(&uniqueCounter)
if err != nil {

View file

@ -12,7 +12,7 @@ import (
func TestUniqueConnections(t *testing.T) {
const TestExpectedCount = 1000
testStart := time.Now().In(counterLocation)
testStart := time.Now().In(CounterLocation)
var server *httptest.Server
var backendExpected = NewTBackendRequestChecker(t,
@ -35,7 +35,7 @@ func TestUniqueConnections(t *testing.T) {
TCheckHLLValue(t, TestExpectedCount, readCurrentHLL())
token := <-uniqueCtrWritingToken
uniqueCounter.End = time.Now().In(counterLocation).Add(-1 * time.Second)
uniqueCounter.End = time.Now().In(CounterLocation).Add(-1 * time.Second)
uniqueCtrWritingToken <- token
rolloverCounters_do()