Add some stats at the top

This commit is contained in:
Michael Zhang 2021-07-22 03:11:48 -05:00
parent 8db272d46c
commit 8f2d1791e1
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 20 additions and 2 deletions

View file

@ -11,7 +11,7 @@ type Beatmapset struct {
ID int `gorm:"primaryKey"`
Artist string
Title string
MapperID int
MapperID int `gorm:"mapper_id"`
Mapper User `gorm:"foreignKey:MapperID"`
LastUpdated time.Time `gorm:"last_updated"`
}

View file

@ -162,3 +162,14 @@ func (db *Db) GetUser(userId int) (user *User, err error) {
return
}
type Stats struct {
TotalMaps int64
TotalUsers int64
}
func (db *Db) GetStats() (stats Stats) {
db.gorm.Model(&Beatmapset{}).Count(&stats.TotalMaps)
db.gorm.Model(&Beatmapset{}).Group("mapper_id").Count(&stats.TotalUsers)
return
}

View file

@ -1,6 +1,10 @@
{{ define "content" }}
<p>Last 10 Updated Beatmaps:</p>
<h3>Stats</h3>
Currently tracking <b>{{ .TotalMaps }}</b> maps from <b>{{ .TotalUsers }}</b> users.
<h3>Last 10 Updated Beatmaps</h3>
<table class="table-auto">
<thead>

View file

@ -76,9 +76,12 @@ func (web *Web) Run() {
r.GET("/", func(c *gin.Context) {
beatmapSets := web.listRepos()
stats := web.db.GetStats()
c.HTML(http.StatusOK, "index.html", gin.H{
"LoggedIn": isLoggedIn(c),
"Beatmapsets": beatmapSets,
"TotalMaps": stats.TotalMaps,
"TotalUsers": stats.TotalUsers,
})
})