Skip to content

Commit

Permalink
feature/NR-74 Introduce release date data model (#230)
Browse files Browse the repository at this point in the history
feature: improve way release dates are stored

# introduced new releaseDate data model
# rename getGamesWIthoutReleaseDates -> getXUnreleasedGames
# used new releaseDate data model where ever there is a release date
# games repo now uses comingSoon release date property instead of calculating it on call
# moved release date logic into new data model
# improved tests, used mocks more often
# used new data model in tests/mocks
# added steam app raw tests

Previously, the release date was a simple date. Now, the release date is a data model with its own internal logic. It also has a coming soon boolean property. A true value indicated the game is still unreleased, i.e. it is coming out soon.

Issue-ref: #220
  • Loading branch information
lukatarman authored Jun 4, 2024
1 parent 5205da0 commit d220eab
Show file tree
Hide file tree
Showing 20 changed files with 762 additions and 303 deletions.
4 changes: 4 additions & 0 deletions backend/assets/db-responses/one.game.unchecked.history.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export const oneGameWithUncheckedPlayerHistory = {
},
id: 1838970,
name: "Crush the Castle Legacy Collection",
releaseDate: {
date: null,
comingSoon: true,
},
image: null,
imageUrl: "https://cdn.akamai.steamstatic.com/steam/apps/1838970/header.jpg",
playerHistory: [],
Expand Down
8 changes: 8 additions & 0 deletions backend/assets/db-responses/two.games.unchecked.history.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const twoGamesWithUncheckedPlayerHistory = [
},
id: 1838970,
name: "Crush the Castle Legacy Collection",
releaseDate: {
date: null,
comingSoon: true,
},
image: null,
imageUrl: "https://cdn.akamai.steamstatic.com/steam/apps/1838970/header.jpg",
playerHistory: [],
Expand All @@ -15,6 +19,10 @@ export const twoGamesWithUncheckedPlayerHistory = [
},
id: 1838980,
name: "Polyion",
releaseDate: {
date: null,
comingSoon: true,
},
image: null,
imageUrl: "https://cdn.akamai.steamstatic.com/steam/apps/1838980/header.jpg",
playerHistory: [],
Expand Down
173 changes: 173 additions & 0 deletions backend/assets/steam-api-responses/monster.hunter.coming.soon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
export const monsterHunterSteamApiData = {
type: "game",
name: "Monster Hunter Wilds",
steam_appid: 2246340,
required_age: 0,
is_free: false,
detailed_description: "The hunt is on in Monster Hunter Wilds, the latest installment in the Monster Hunter series, now in development. Experience the pinnacle of excellence in hunting action gameplay.<br><br>Planned for release in 2025.<br><br><strong>Note: Supported languages and other details to be announced at a later date.</strong>",
about_the_game: "The hunt is on in Monster Hunter Wilds, the latest installment in the Monster Hunter series, now in development. Experience the pinnacle of excellence in hunting action gameplay.<br><br>Planned for release in 2025.<br><br><strong>Note: Supported languages and other details to be announced at a later date.</strong>",
short_description: "The hunt is on in Monster Hunter Wilds, the latest installment in the Monster Hunter series, now in development. Experience the pinnacle of excellence in hunting action gameplay. Planned for release in 2025.",
supported_languages: "English",
header_image: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/header.jpg?t=1717124069",
capsule_image: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/capsule_231x87.jpg?t=1717124069",
capsule_imagev5: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/capsule_184x69.jpg?t=1717124069",
website: "https://www.monsterhunter.com/wilds/",
pc_requirements: {
minimum: "<strong>Minimum:</strong><br><ul class=\"bb_ul\"><li><strong>OS:</strong> TBD</li></ul>",
recommended: "<strong>Recommended:</strong><br><ul class=\"bb_ul\"><li><strong>OS:</strong> TBD</li></ul>",
},
mac_requirements: [
],
linux_requirements: [
],
legal_notice: "©CAPCOM",
developers: [
"CAPCOM Co., Ltd.",
],
publishers: [
"CAPCOM Co., Ltd.",
],
package_groups: [
],
platforms: {
windows: true,
mac: false,
linux: false,
},
categories: [
{
id: 2,
description: "Single-player",
},
{
id: 1,
description: "Multi-player",
},
],
genres: [
{
id: "1",
description: "Action",
},
],
screenshots: [
{
id: 0,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_44e68f3f74c173ea10d440dcfdee4d45f9203bf6.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_44e68f3f74c173ea10d440dcfdee4d45f9203bf6.1920x1080.jpg?t=1717124069",
},
{
id: 1,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_161ab6d119fefd78f52b2534fee40b8c456c6bce.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_161ab6d119fefd78f52b2534fee40b8c456c6bce.1920x1080.jpg?t=1717124069",
},
{
id: 2,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_827f69f98cbe1301cb647fb1bcd6364e69a977e5.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_827f69f98cbe1301cb647fb1bcd6364e69a977e5.1920x1080.jpg?t=1717124069",
},
{
id: 3,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_01c4c83d31387049d23be1a7ddd0c636f7119284.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_01c4c83d31387049d23be1a7ddd0c636f7119284.1920x1080.jpg?t=1717124069",
},
{
id: 4,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_11d1e1cba3047bfa8bf0653aee133f8cf0db3d52.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_11d1e1cba3047bfa8bf0653aee133f8cf0db3d52.1920x1080.jpg?t=1717124069",
},
{
id: 5,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_3920e4068e53d526c80fb5b4ba9bbca01629bbfd.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_3920e4068e53d526c80fb5b4ba9bbca01629bbfd.1920x1080.jpg?t=1717124069",
},
{
id: 6,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_c1f44fa0f4a5994cbf331540e46bafa5d7b63836.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_c1f44fa0f4a5994cbf331540e46bafa5d7b63836.1920x1080.jpg?t=1717124069",
},
{
id: 7,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_a41eda5fb16bd283eb64e9ed0aead4fb55a49f24.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_a41eda5fb16bd283eb64e9ed0aead4fb55a49f24.1920x1080.jpg?t=1717124069",
},
{
id: 8,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_ef0d1fc952a50cc8fb63a041fe1b475fa7594715.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_ef0d1fc952a50cc8fb63a041fe1b475fa7594715.1920x1080.jpg?t=1717124069",
},
{
id: 9,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_7772b12d698d02b37f38b2b2af2b56b3a0f011a0.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_7772b12d698d02b37f38b2b2af2b56b3a0f011a0.1920x1080.jpg?t=1717124069",
},
{
id: 10,
path_thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_ed88d2006f292d9f2ca08645e61fed8f47a453d5.600x338.jpg?t=1717124069",
path_full: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/ss_ed88d2006f292d9f2ca08645e61fed8f47a453d5.1920x1080.jpg?t=1717124069",
},
],
movies: [
{
id: 257027129,
name: "05_MHWilds_PV1_Multi_ASIA_1080P",
thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/257027129/movie.293x165.jpg?t=1717124031",
webm: {
"480": "http://cdn.akamai.steamstatic.com/steam/apps/257027129/movie480_vp9.webm?t=1717124031",
max: "http://cdn.akamai.steamstatic.com/steam/apps/257027129/movie_max_vp9.webm?t=1717124031",
},
mp4: {
"480": "http://cdn.akamai.steamstatic.com/steam/apps/257027129/movie480.mp4?t=1717124031",
max: "http://cdn.akamai.steamstatic.com/steam/apps/257027129/movie_max.mp4?t=1717124031",
},
highlight: true,
},
{
id: 256988327,
name: "05_MHWilds_AnnouncePV_Multi_ASIA_1080P",
thumbnail: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/256988327/movie.293x165.jpg?t=1702947717",
webm: {
"480": "http://cdn.akamai.steamstatic.com/steam/apps/256988327/movie480_vp9.webm?t=1702947717",
max: "http://cdn.akamai.steamstatic.com/steam/apps/256988327/movie_max_vp9.webm?t=1702947717",
},
mp4: {
"480": "http://cdn.akamai.steamstatic.com/steam/apps/256988327/movie480.mp4?t=1702947717",
max: "http://cdn.akamai.steamstatic.com/steam/apps/256988327/movie_max.mp4?t=1702947717",
},
highlight: true,
},
],
release_date: {
coming_soon: true,
date: "2025",
},
support_info: {
url: "http://www.capcom.co.jp/support/contact/",
email: "",
},
background: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/page_bg_generated_v6b.jpg?t=1717124069",
background_raw: "https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/2246340/page_bg_generated.jpg?t=1717124069",
content_descriptors: {
ids: [
],
notes: null,
},
ratings: {
dejus: {
rating_generated: "1",
rating: "l",
required_age: "0",
banned: "0",
use_age_gate: "0",
descriptors: "",
},
steam_germany: {
rating_generated: "1",
rating: "0",
required_age: "0",
banned: "0",
use_age_gate: "0",
descriptors: "",
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const partyAnimalsApiMissingData = {
type: "game",
name: "Party Animals",
steam_appid: 1260320,
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class GameIdentifier {
updateGamesWithoutReleaseDates = async () => {
this.#logger.debugc(`updating games without release dates via Steam API`);

const games = await this.#gamesRepository.getGamesWithoutReleaseDates(
const games = await this.#gamesRepository.getXUnreleasedGames(
this.#options.batchSize,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ function createGamesRepositoryMock(gamesRepoRet) {
insertManyGames: Promise.resolve(undefined),
getGamesWithoutDetails: Promise.resolve(gamesRepoRet),
updateGameDetailsFrom: Promise.resolve(undefined),
getGamesWithoutReleaseDates: Promise.resolve(gamesRepoRet),
getXUnreleasedGames: Promise.resolve(gamesRepoRet),
updateReleaseDates: Promise.resolve(undefined),
});
}
Expand Down
35 changes: 7 additions & 28 deletions backend/src/core/models/game.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PlayerHistory } from "./player.history.js";
import cloneDeep from "lodash.clonedeep";
import { ReleaseDate } from "./release.date.js";

export class Game {
id;
Expand Down Expand Up @@ -30,7 +31,7 @@ export class Game {
const game = new Game();
game.id = steamApp.appid;
game.name = steamApp.name;
game.releaseDate = game.#extractReleaseDateViaSteamWeb(page);
game.releaseDate = ReleaseDate.fromSteamWeb(page);
game.developers = game.#extractDevelopersViaSteamWeb(page);
game.genres = game.#extractGenresViaSteamWeb(page);
game.description = game.#extractDescriptionViaSteamWeb(page);
Expand All @@ -40,16 +41,6 @@ export class Game {
return game;
}

#extractReleaseDateViaSteamWeb(page) {
const releaseDateElement = page.querySelector(".release_date .date");

if (!releaseDateElement) return null;

const releaseDate = new Date(`${releaseDateElement.textContent.trim()} UTC`);

return releaseDate == "Invalid Date" ? null : releaseDate;
}

#extractDevelopersViaSteamWeb(page) {
const developers = page.querySelector(".dev_row #developers_list");

Expand Down Expand Up @@ -83,7 +74,7 @@ export class Game {
const game = new Game();
game.id = steamApiApp.id;
game.name = steamApiApp.name;
game.releaseDate = game.#extractReleaseDateViaSteamApi(steamApiApp);
game.releaseDate = steamApiApp.releaseDate.copy();
game.developers = game.#extractDevelopersViaSteamApi(steamApiApp);
game.genres = game.#extractGenresViaSteamApi(steamApiApp);
game.description = game.#extractDescriptionViaSteamApi(steamApiApp);
Expand All @@ -93,14 +84,6 @@ export class Game {
return game;
}

#extractReleaseDateViaSteamApi(steamApiApp) {
if (!steamApiApp.releaseDate) return null;

const releaseDate = new Date(`${steamApiApp.releaseDate} UTC`);

return releaseDate == "Invalid Date" ? null : releaseDate;
}

#extractDevelopersViaSteamApi(steamApiApp) {
if (!steamApiApp.developers) return [];

Expand All @@ -124,7 +107,7 @@ export class Game {
const game = new Game();
game.id = dbEntry.id;
game.name = dbEntry.name;
game.releaseDate = dbEntry.releaseDate;
game.releaseDate = ReleaseDate.fromDb(dbEntry.releaseDate);
game.developers = dbEntry.developers;
game.genres = dbEntry.genres;
game.description = dbEntry.description;
Expand Down Expand Up @@ -167,13 +150,9 @@ export class Game {
});
}

updateReleaseDateViaSteamApi(steamApiApp) {
if (this.releaseDate) return;

const date = this.#extractReleaseDateViaSteamApi(steamApiApp);

if (date === null) return;
updateReleaseDateViaSteamApi(newDate) {
if (!newDate) return;

this.releaseDate = date;
this.releaseDate.updateReleaseDate(newDate);
}
}
Loading

0 comments on commit d220eab

Please sign in to comment.