From fc2130b2df0c41bedb02240e995dcada2f03173f Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 7 Jul 2017 10:57:48 +0200 Subject: [PATCH] New statistics --- main.go | 1 + pages/statistics/anime.go | 48 ++++++++++++++++++++++++++++++++ pages/statistics/statistics.go | 4 +-- pages/statistics/statistics.pixy | 12 ++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 pages/statistics/anime.go diff --git a/main.go b/main.go index 626c5003..e810fd01 100644 --- a/main.go +++ b/main.go @@ -93,6 +93,7 @@ func configure(app *aero.Application) *aero.Application { app.Ajax("/import/anilist/animelist/finish", listimportanilist.Finish) app.Ajax("/admin", admin.Get) app.Ajax("/statistics", statistics.Get) + app.Ajax("/statistics/anime", statistics.Anime) app.Ajax("/search", search.Get) app.Ajax("/search/:term", search.Get) app.Ajax("/users", users.Get) diff --git a/pages/statistics/anime.go b/pages/statistics/anime.go new file mode 100644 index 00000000..98fa115d --- /dev/null +++ b/pages/statistics/anime.go @@ -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), + )) +} diff --git a/pages/statistics/statistics.go b/pages/statistics/statistics.go index c3063328..4343706c 100644 --- a/pages/statistics/statistics.go +++ b/pages/statistics/statistics.go @@ -18,7 +18,7 @@ func Get(ctx *aero.Context) string { analytics, err := arn.AllAnalytics() 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{} @@ -63,9 +63,9 @@ func Get(ctx *aero.Context) string { utils.NewPieChart("OS", os), // utils.NewPieChart("Platform", platform), utils.NewPieChart("Screen size", screenSize), - utils.NewPieChart("Pixel ratio", pixelRatio), utils.NewPieChart("Browser", browser), utils.NewPieChart("Country", country), utils.NewPieChart("Gender", gender), + utils.NewPieChart("Pixel ratio", pixelRatio), )) } diff --git a/pages/statistics/statistics.pixy b/pages/statistics/statistics.pixy index d342ebe9..0899237f 100644 --- a/pages/statistics/statistics.pixy +++ b/pages/statistics/statistics.pixy @@ -1,12 +1,24 @@ component Statistics(pieCharts ...*utils.PieChart) h1 Statistics + StatisticsHeader + .widgets.statistics each pie in pieCharts .widget h3.widget-title= pie.Title 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) svg.pie-chart(viewBox="-1.1 -1.1 2.2 2.2") each slice in slices