Skip to content

Commit

Permalink
add average rating as a column
Browse files Browse the repository at this point in the history
  • Loading branch information
gantoine committed Jan 10, 2025
1 parent 9e4e716 commit b5d2cad
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
1 change: 1 addition & 0 deletions backend/endpoints/responses/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class RomSchema(BaseModel):
# Metadata fields
first_release_date: int | None
youtube_video_id: str | None
average_rating: float
alternative_names: list[str]
genres: list[str]
franchises: list[str]
Expand Down
16 changes: 16 additions & 0 deletions backend/models/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ def first_release_date(self) -> int:
return self.igdb_metadata.get("first_release_date", 0) * 1000
return 0

@property
def average_rating(self) -> float:
igdb_rating = (
float(self.igdb_metadata.get("total_rating", 0))
if self.igdb_metadata
else 0.0
)
moby_rating = (
float(self.moby_metadata.get("moby_score", 0))
if self.moby_metadata
else 0.0
)
ratings = [igdb_rating, moby_rating * 10] # Moby rating is out of 10

return sum(ratings) / len([r for r in ratings if r]) if any(ratings) else 0.0

@property
def genres(self) -> list[str]:
return (
Expand Down
1 change: 1 addition & 0 deletions frontend/src/__generated__/models/DetailedRomSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/__generated__/models/RomSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/__generated__/models/SimpleRomSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 36 additions & 13 deletions frontend/src/components/common/Game/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ const HEADERS = [
sortable: true,
key: "first_release_date",
},
{
title: "Rating",
align: "start",
sortable: true,
key: "average_rating",
},
{
title: "Languages",
align: "start",
Expand All @@ -76,7 +82,12 @@ const HEADERS = [
sortable: false,
key: "regions",
},
{ title: "", align: "center", key: "actions", sortable: false },
{
title: "",
align: "center",
key: "actions",
sortable: false,
},
] as const;
const selectedRomIDs = computed(() => selectedRoms.value.map((rom) => rom.id));
Expand Down Expand Up @@ -199,30 +210,38 @@ onMounted(() => {
</td>
</template>
<template #item.file_size_bytes="{ item }">
<v-chip size="x-small" label>{{
formatBytes(item.file_size_bytes)
}}</v-chip>
<span class="text-no-wrap">{{ formatBytes(item.file_size_bytes) }}</span>
</template>
<template #item.created_at="{ item }">
<v-chip v-if="item.created_at" size="x-small" label>{{
<span v-if="item.created_at" class="text-no-wrap">{{
new Date(item.created_at).toLocaleDateString("en-US", {
day: "2-digit",
month: "short",
year: "numeric",
})
}}</v-chip>
}}</span>
<span v-else>-</span>
</template>
<template #item.first_release_date="{ item }">
<v-chip v-if="item.first_release_date" size="x-small" label>{{
<span v-if="item.first_release_date" class="text-no-wrap">{{
new Date(item.first_release_date).toLocaleDateString("en-US", {
day: "2-digit",
month: "short",
year: "numeric",
})
}}</v-chip>
}}</span>
<span v-else>-</span>
</template>
<template #item.average_rating="{ item }">
<span v-if="item.average_rating" class="text-no-wrap">{{
Intl.NumberFormat("en-US", {
maximumSignificantDigits: 3,
}).format(item.average_rating)
}}</span>
<span v-else>-</span>
</template>
<template #item.languages="{ item }">
<div class="d-flex">
<div class="text-no-wrap" v-if="item.languages.length > 0">
<span
class="emoji"
v-for="language in item.languages.slice(0, 3)"
Expand All @@ -239,9 +258,10 @@ onMounted(() => {
}}
</spa>
</div>
<span v-else>-</span>
</template>
<template #item.regions="{ item }">
<div class="d-flex">
<div class="text-no-wrap" v-if="item.regions.length > 0">
<span
class="emoji"
v-for="region in item.regions.slice(0, 3)"
Expand All @@ -250,10 +270,13 @@ onMounted(() => {
>
{{ regionToEmoji(region) }}
</span>
<spa class="reglang-super">
{{
item.regions.length > 3 ? `&nbsp;+${item.regions.length - 3}` : ""
}}
</spa>
</div>
<spa class="reglang-super">
{{ item.regions.length > 3 ? `&nbsp;+${item.regions.length - 3}` : "" }}
</spa>
<span v-else>-</span>
</template>
<template #item.actions="{ item }">
<v-btn-group density="compact">
Expand Down

0 comments on commit b5d2cad

Please sign in to comment.