Merge pull request #253 from tumGER/AverageRating

Added average company rating
This commit is contained in:
Eduard Urbach 2020-10-23 08:38:40 +09:00 committed by GitHub
commit 287a1837e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 5 deletions

View File

@ -1,5 +1,5 @@
component Rating(value float64, userCount int, user *arn.User) component Rating(value float64, userCount int, user *arn.User)
if user == nil 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 else
.anime-rating.tip(aria-label="Rated by " + stringutils.Plural(userCount, "user"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value) .anime-rating.tip(aria-label="Based on " + stringutils.Plural(userCount, "rating"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value)

View File

@ -52,6 +52,28 @@ func Get(ctx aero.Context) error {
var closeCompanies []*arn.Company var closeCompanies []*arn.Company
distances := map[string]float64{} 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() { if company.Location.IsValid() {
closeCompanies = arn.FilterCompanies(func(closeCompany *arn.Company) bool { closeCompanies = arn.FilterCompanies(func(closeCompany *arn.Company) bool {
if closeCompany.ID == company.ID { 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))
} }

View File

@ -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) CompanyTabs(company, user)
.company-page .company-page
@ -13,6 +13,30 @@ component CompanyPage(company *arn.Company, studioAnime, producedAnime, licensed
CompanyAnimes("Licensed:", licensedAnime, user) CompanyAnimes("Licensed:", licensedAnime, user)
.company-sidebar .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 if company.Location.Latitude != 0 && company.Location.Longitude != 0
h3.mountable Location 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") 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")

View File

@ -41,3 +41,16 @@
.company-anime-item-image .company-anime-item-image
anime-mini-item-image 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