Add some stats at the top
This commit is contained in:
parent
8db272d46c
commit
8f2d1791e1
4 changed files with 20 additions and 2 deletions
|
@ -11,7 +11,7 @@ type Beatmapset struct {
|
||||||
ID int `gorm:"primaryKey"`
|
ID int `gorm:"primaryKey"`
|
||||||
Artist string
|
Artist string
|
||||||
Title string
|
Title string
|
||||||
MapperID int
|
MapperID int `gorm:"mapper_id"`
|
||||||
Mapper User `gorm:"foreignKey:MapperID"`
|
Mapper User `gorm:"foreignKey:MapperID"`
|
||||||
LastUpdated time.Time `gorm:"last_updated"`
|
LastUpdated time.Time `gorm:"last_updated"`
|
||||||
}
|
}
|
||||||
|
|
11
db/db.go
11
db/db.go
|
@ -162,3 +162,14 @@ func (db *Db) GetUser(userId int) (user *User, err error) {
|
||||||
|
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
{{ define "content" }}
|
{{ 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">
|
<table class="table-auto">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
|
@ -76,9 +76,12 @@ func (web *Web) Run() {
|
||||||
|
|
||||||
r.GET("/", func(c *gin.Context) {
|
r.GET("/", func(c *gin.Context) {
|
||||||
beatmapSets := web.listRepos()
|
beatmapSets := web.listRepos()
|
||||||
|
stats := web.db.GetStats()
|
||||||
c.HTML(http.StatusOK, "index.html", gin.H{
|
c.HTML(http.StatusOK, "index.html", gin.H{
|
||||||
"LoggedIn": isLoggedIn(c),
|
"LoggedIn": isLoggedIn(c),
|
||||||
"Beatmapsets": beatmapSets,
|
"Beatmapsets": beatmapSets,
|
||||||
|
"TotalMaps": stats.TotalMaps,
|
||||||
|
"TotalUsers": stats.TotalUsers,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue