diff --git a/db/beatmap.go b/db/beatmap.go index 47b4c48..ba971a5 100644 --- a/db/beatmap.go +++ b/db/beatmap.go @@ -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"` } diff --git a/db/db.go b/db/db.go index 3026cfa..79f400d 100644 --- a/db/db.go +++ b/db/db.go @@ -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 +} diff --git a/web/templates/index.html b/web/templates/index.html index 94c8a38..b6d74ea 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -1,6 +1,10 @@ {{ define "content" }} -

Last 10 Updated Beatmaps:

+

Stats

+ +Currently tracking {{ .TotalMaps }} maps from {{ .TotalUsers }} users. + +

Last 10 Updated Beatmaps

diff --git a/web/web.go b/web/web.go index b85b9b4..52afa43 100644 --- a/web/web.go +++ b/web/web.go @@ -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, }) })