New statistics

This commit is contained in:
Eduard Urbach 2017-07-07 10:57:48 +02:00
parent 1fb5b4210e
commit fc2130b2df
4 changed files with 63 additions and 2 deletions

View File

@ -93,6 +93,7 @@ func configure(app *aero.Application) *aero.Application {
app.Ajax("/import/anilist/animelist/finish", listimportanilist.Finish) app.Ajax("/import/anilist/animelist/finish", listimportanilist.Finish)
app.Ajax("/admin", admin.Get) app.Ajax("/admin", admin.Get)
app.Ajax("/statistics", statistics.Get) app.Ajax("/statistics", statistics.Get)
app.Ajax("/statistics/anime", statistics.Anime)
app.Ajax("/search", search.Get) app.Ajax("/search", search.Get)
app.Ajax("/search/:term", search.Get) app.Ajax("/search/:term", search.Get)
app.Ajax("/users", users.Get) app.Ajax("/users", users.Get)

48
pages/statistics/anime.go Normal file
View File

@ -0,0 +1,48 @@
package statistics
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// Anime ...
func Anime(ctx *aero.Context) string {
allAnime, err := arn.AllAnime()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Couldn't fetch anime", err)
}
shoboi := stats{}
anilist := stats{}
status := stats{}
types := stats{}
for _, anime := range allAnime {
if anime.GetMapping("shoboi/anime") != "" {
shoboi["Connected with Shoboi"]++
} else {
shoboi["Not connected with Shoboi"]++
}
if anime.GetMapping("anilist/anime") != "" {
anilist["Connected with Anilist"]++
} else {
anilist["Not connected with Anilist"]++
}
status[anime.Status]++
types[anime.Type]++
}
return ctx.HTML(components.Statistics(
utils.NewPieChart("Type", types),
utils.NewPieChart("Status", status),
utils.NewPieChart("Anilist", anilist),
utils.NewPieChart("Shoboi", shoboi),
))
}

View File

@ -18,7 +18,7 @@ func Get(ctx *aero.Context) string {
analytics, err := arn.AllAnalytics() analytics, err := arn.AllAnalytics()
if err != nil { if err != nil {
return ctx.Error(http.StatusInternalServerError, "Couldn't retrieve analytics", err) return ctx.Error(http.StatusInternalServerError, "Couldn't fetch analytics", err)
} }
screenSize := stats{} screenSize := stats{}
@ -63,9 +63,9 @@ func Get(ctx *aero.Context) string {
utils.NewPieChart("OS", os), utils.NewPieChart("OS", os),
// utils.NewPieChart("Platform", platform), // utils.NewPieChart("Platform", platform),
utils.NewPieChart("Screen size", screenSize), utils.NewPieChart("Screen size", screenSize),
utils.NewPieChart("Pixel ratio", pixelRatio),
utils.NewPieChart("Browser", browser), utils.NewPieChart("Browser", browser),
utils.NewPieChart("Country", country), utils.NewPieChart("Country", country),
utils.NewPieChart("Gender", gender), utils.NewPieChart("Gender", gender),
utils.NewPieChart("Pixel ratio", pixelRatio),
)) ))
} }

View File

@ -1,12 +1,24 @@
component Statistics(pieCharts ...*utils.PieChart) component Statistics(pieCharts ...*utils.PieChart)
h1 Statistics h1 Statistics
StatisticsHeader
.widgets.statistics .widgets.statistics
each pie in pieCharts each pie in pieCharts
.widget .widget
h3.widget-title= pie.Title h3.widget-title= pie.Title
PieChart(pie.Slices) PieChart(pie.Slices)
component StatisticsHeader
.buttons.tabs
a.button.tab.action(href="/statistics", data-action="diff", data-trigger="click")
Icon("user")
span User
a.button.tab.action(href="/statistics/anime", data-action="diff", data-trigger="click")
Icon("tv")
span Anime
component PieChart(slices []*utils.PieChartSlice) component PieChart(slices []*utils.PieChartSlice)
svg.pie-chart(viewBox="-1.1 -1.1 2.2 2.2") svg.pie-chart(viewBox="-1.1 -1.1 2.2 2.2")
each slice in slices each slice in slices