Skip to content

Commit

Permalink
Added Daily stats tracker under /admin?tab=billing to give more insight
Browse files Browse the repository at this point in the history
  • Loading branch information
Frikky authored and Frikky committed Jul 25, 2023
1 parent 6939417 commit 35c3f97
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"strings"
"sort"

"encoding/json"
"io/ioutil"
Expand Down Expand Up @@ -343,6 +344,33 @@ func HandleGetStatistics(resp http.ResponseWriter, request *http.Request) {
return
}

// Should remove the FIRST day as it's very scewed
// Do this based on the Timestamp (date)

if len(info.DailyStatistics) > 0 {
skipIndex := 0
lowestTimestamp := info.DailyStatistics[0].Date
for _, timestamp := range info.DailyStatistics{
if timestamp.Date.Before(lowestTimestamp) {
lowestTimestamp = timestamp.Date
}
}

if skipIndex >= 0 {
info.DailyStatistics = append(info.DailyStatistics[:skipIndex], info.DailyStatistics[skipIndex+1:]...)
}

// Sort the array
sort.Slice(info.DailyStatistics, func(i, j int) bool {
return info.DailyStatistics[i].Date.Before(info.DailyStatistics[j].Date)
})

// Get a max of the last 60 days
if len(info.DailyStatistics) > 60 {
info.DailyStatistics = info.DailyStatistics[len(info.DailyStatistics)-60:]
}
}

newjson, err := json.Marshal(info)
if err != nil {
log.Printf("[ERROR] Failed marshal in get org stats: %s", err)
Expand Down

0 comments on commit 35c3f97

Please sign in to comment.