Show statistics on the public overview page

This commit is contained in:
Tom Wiesing 2022-11-16 17:00:10 +01:00
parent 964e74a9f4
commit bc1bf0db1c
No known key found for this signature in database
4 changed files with 47 additions and 15 deletions

View file

@ -25,6 +25,9 @@
<h3>{{.Slug}}</h3>
<p>
<a href="{{.URL}}" target="_blank" rel="noopener noreferrer">{{.URL}}</a><br>
<small>
{{ .Statistics.Bundles.Summary }}
</small>
</p>
</div>
{{ end }}

View file

@ -73,7 +73,7 @@ func (home *Home) homeRender() ([]byte, error) {
i := i
wissKI := instance
eg.Go(func() (err error) {
context.Instances[i], err = wissKI.Info().Information(true)
context.Instances[i], err = wissKI.Info().Information(false)
return
})
}

View file

@ -1,6 +1,7 @@
package ingredient
import (
"fmt"
"time"
"github.com/FAU-CDI/wisski-distillery/internal/models"
@ -62,20 +63,7 @@ type Statistics struct {
} `json:"pageVisits"`
TotalEditsLastWeek int `json:"totalEditsLastWeek"`
} `json:"activity"`
Bundles struct {
Bundles []struct {
Label string `json:"label"`
MachineName string `json:"machineName"`
Count int `json:"entities"`
LastEdit int `json:"lastEdit"`
MainBundle phpx.BooleanIsh `json:"mainBundle"`
} `json:"bundleStatistics"`
TotalBundles int `json:"totalBundles"`
TotalMainBundles int `json:"totalMainBundles"`
} `json:"bundles"`
Bundles BundleStatistics `json:"bundles"`
Triplestore struct {
Graphs []struct {
URI string `json:"uri"`
@ -88,3 +76,40 @@ type Statistics struct {
TotalUsers int `json:"totalUsers"`
} `json:"users"`
}
type BundleStatistics struct {
Bundles []struct {
Label string `json:"label"`
MachineName string `json:"machineName"`
Count int `json:"entities"`
LastEdit int `json:"lastEdit"`
MainBundle phpx.BooleanIsh `json:"mainBundle"`
} `json:"bundleStatistics"`
TotalBundles int `json:"totalBundles"`
TotalMainBundles int `json:"totalMainBundles"`
}
func (bs BundleStatistics) Summary() string {
var totalCount int
for _, bundle := range bs.Bundles {
totalCount += bundle.Count
}
if totalCount == 0 {
return ""
}
entitySubject := "Entities"
if totalCount == 1 {
entitySubject = "Entity"
}
bundleSubject := "Bundles"
if len(bs.Bundles) == 1 {
bundleSubject = "Bundle"
}
return fmt.Sprintf("%d %s in %d %s", totalCount, entitySubject, len(bs.Bundles), bundleSubject)
}