Commit e1d778f1 authored by Thomas Bella's avatar Thomas Bella

Calculate average messages per day

parent 5f2242a2
Pipeline #1084 passed with stages
in 2 minutes and 5 seconds
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"io/ioutil"
"log"
"math"
"os"
"os/signal"
"sort"
......@@ -122,7 +123,7 @@ func init() {
// WriteData writes the current data to stats.json
func WriteData() {
stats, _ := json.Marshal(MessageData.GetAll())
stats, _ := json.MarshalIndent(MessageData.GetAll(), "", " ")
err := ioutil.WriteFile(`/var/lib/utelebot/stats.json`, stats, 0644)
if err != nil {
log.Println(err)
......@@ -183,7 +184,11 @@ func GetStringResponse(chatID int64) []string {
}
}
return []string{text, "*Summary*\nStats since " + chatData.FirstMessage.Format("02.01.2006 15:04:05") + "\n" + strconv.FormatUint(summaryMessagesTotal, 10) + " messages sent\n" + strconv.Itoa(summaryActiveLastHour) + " users active within the last hour\n" + strconv.Itoa(summaryActiveLastDay) + " users active within the last 24 hours"}
// Calculate average messages per day
days := time.Now().Sub(chatData.FirstMessage).Hours() / 24
averageMessages := summaryMessagesTotal / uint64(math.Ceil(days))
return []string{text, "*Summary*\nStats since " + chatData.FirstMessage.Format("02.01.2006 15:04:05") + "\n" + strconv.FormatUint(summaryMessagesTotal, 10) + " messages sent\n" + strconv.Itoa(summaryActiveLastHour) + " users active within the last hour\n" + strconv.Itoa(summaryActiveLastDay) + " users active within the last 24 hours\nOn average " + strconv.FormatUint(averageMessages, 10) + " messages per day"}
}
// AddRecord increases the message count
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment