From 7098d6945fac4304a15d2f1f0232b47aae2af37f Mon Sep 17 00:00:00 2001 From: tumGER Date: Thu, 22 Oct 2020 14:33:50 +0200 Subject: [PATCH] Add average company rating --- elements/Rating.pixy | 4 ++-- pages/company/company.go | 24 +++++++++++++++++++++++- pages/company/company.pixy | 26 +++++++++++++++++++++++++- pages/company/company.scarlet | 15 ++++++++++++++- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/elements/Rating.pixy b/elements/Rating.pixy index 59ab724a..2ea05249 100644 --- a/elements/Rating.pixy +++ b/elements/Rating.pixy @@ -1,5 +1,5 @@ component Rating(value float64, userCount int, user *arn.User) if user == nil - .anime-rating.tip(aria-label="Rated by " + stringutils.Plural(userCount, "user"))= fmt.Sprintf("%.1f", value) + .anime-rating.tip(aria-label="Based on " + stringutils.Plural(userCount, "rating"))= fmt.Sprintf("%.1f", value) else - .anime-rating.tip(aria-label="Rated by " + stringutils.Plural(userCount, "user"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value) \ No newline at end of file + .anime-rating.tip(aria-label="Based on " + stringutils.Plural(userCount, "rating"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value) \ No newline at end of file diff --git a/pages/company/company.go b/pages/company/company.go index 90207301..e55fe835 100644 --- a/pages/company/company.go +++ b/pages/company/company.go @@ -52,6 +52,28 @@ func Get(ctx aero.Context) error { var closeCompanies []*arn.Company distances := map[string]float64{} + var overallRating, storyRating, visualsRating, soundtrackRating float64 + var overallCount, storyCount, visualsCount, soundtrackCount int + + for _, anime := range studioAnime { + overallRating += anime.Rating.Overall + storyRating += anime.Rating.Story + visualsRating += anime.Rating.Visuals + soundtrackRating += anime.Rating.Soundtrack + + overallCount += anime.Rating.Count.Overall + storyCount += anime.Rating.Count.Story + visualsCount += anime.Rating.Count.Visuals + soundtrackCount += anime.Rating.Count.Soundtrack + } + + totalStudioAnime := float64(len(studioAnime)) + + overallRating /= totalStudioAnime + storyRating /= totalStudioAnime + visualsRating /= totalStudioAnime + soundtrackRating /= totalStudioAnime + if company.Location.IsValid() { closeCompanies = arn.FilterCompanies(func(closeCompany *arn.Company) bool { if closeCompany.ID == company.ID { @@ -73,5 +95,5 @@ func Get(ctx aero.Context) error { }) } - return ctx.HTML(components.CompanyPage(company, studioAnime, producedAnime, licensedAnime, closeCompanies, distances, user)) + return ctx.HTML(components.CompanyPage(company, studioAnime, producedAnime, licensedAnime, closeCompanies, distances, user, overallRating, storyRating, visualsRating, soundtrackRating, overallCount, storyCount, visualsCount, soundtrackCount)) } diff --git a/pages/company/company.pixy b/pages/company/company.pixy index b6f8e129..2084f11b 100644 --- a/pages/company/company.pixy +++ b/pages/company/company.pixy @@ -1,4 +1,4 @@ -component CompanyPage(company *arn.Company, studioAnime, producedAnime, licensedAnime []*arn.Anime, closeCompanies []*arn.Company, distances map[string]float64, user *arn.User) +component CompanyPage(company *arn.Company, studioAnime, producedAnime, licensedAnime []*arn.Anime, closeCompanies []*arn.Company, distances map[string]float64, user *arn.User, overallRating float64, storyRating float64, visualsRating float64, soundtrackRating float64, overallCount int, storyCount int, visualsCount int, soundtrackCount int) CompanyTabs(company, user) .company-page @@ -13,6 +13,30 @@ component CompanyPage(company *arn.Company, studioAnime, producedAnime, licensed CompanyAnimes("Licensed:", licensedAnime, user) .company-sidebar + h3.mountable Average Ratings: + + table.company-rating-info-table + tbody + tr.mountable(data-mountable-type="ratings") + td.company-rating-info-key Overall: + td.company-rating-info-value + Rating(overallRating, overallCount, user) + + tr.mountable(data-mountable-type="ratings") + td.company-rating-info-key Story: + td.company-rating-info-value + Rating(storyRating, storyCount, user) + + tr.mountable(data-mountable-type="ratings") + td.company-rating-info-key Visuals: + td.company-rating-info-value + Rating(visualsRating, visualsCount, user) + + tr.mountable(data-mountable-type="ratings") + td.company-rating-info-key Soundtrack: + td.company-rating-info-value + Rating(soundtrackRating, soundtrackCount, user) + if company.Location.Latitude != 0 && company.Location.Longitude != 0 h3.mountable Location iframe.company-location.mountable(src="https://www.google.com/maps/embed/v1/place?q=" + fmt.Sprint(company.Location.Latitude) + "," + fmt.Sprint(company.Location.Longitude) + "&key=AIzaSyAsx6fhqRGaMLTixIJMIZBU4Mg6HJmvQf0", importance="low", title=company.Name.English + " location map") diff --git a/pages/company/company.scarlet b/pages/company/company.scarlet index 271a18b5..4ee67101 100644 --- a/pages/company/company.scarlet +++ b/pages/company/company.scarlet @@ -40,4 +40,17 @@ anime-mini-item .company-anime-item-image - anime-mini-item-image \ No newline at end of file + anime-mini-item-image + +.company-rating-info-table + vertical + margin 0 + + tr + horizontal + +.company-rating-info-key + flex 1 + +.company-rating-info-value + text-align right \ No newline at end of file