Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions src/api/apis/BoardGameGeekAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class BoardGameGeekAPI extends APIModel {

const title = boardgame.querySelector('name[primary=true]')?.textContent;
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
const subType = boardgame.querySelector('boardgamesubdomain')?.textContent ?? '';
const image = boardgame.querySelector('image')?.textContent ?? undefined;
const onlineRating = Number.parseFloat(boardgame.querySelector('statistics ratings average')?.textContent ?? '0');
const genres = Array.from(boardgame.querySelectorAll('boardgamecategory'))
Expand All @@ -90,25 +91,59 @@ export class BoardGameGeekAPI extends APIModel {
const minPlayers = Number.parseFloat(boardgame.querySelector('minplayers')?.textContent ?? '0');
const maxPlayers = Number.parseFloat(boardgame.querySelector('maxplayers')?.textContent ?? '0');
const playtime = (boardgame.querySelector('playingtime')?.textContent ?? 'unknown') + ' minutes';
const age = Number.parseFloat(boardgame.querySelector('age')?.textContent ?? '0');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

age is a quite generic term. Is this the recommended age, or the minimum age to play?

const publishers = Array.from(boardgame.querySelectorAll('boardgamepublisher'))
.map(n => n.textContent)
.filter(n => n !== null);
const boardGameFamilies = Array.from(boardgame.querySelectorAll('boardgamefamily'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to include some not very relevant categories for some games.

.map(n => n.textContent)
.filter(n => n !== null);
const boardGameMechanics = Array.from(boardgame.querySelectorAll('boardgamemechanic'))
.map(n => n.textContent)
.filter(n => n !== null);
const awards = Array.from(boardgame.querySelectorAll('boardgamehonor'))
.map(n => n.textContent)
.filter(n => n !== null);
const description = boardgame.querySelector('description')?.textContent.replace(/<[^>]*>/g, '') ?? '';

let languageDependenceMostVotes = 0;
let languageDependence = '';
for (const result of Array.from(response.querySelectorAll('poll[name=language_dependence] results result'))) {
const votes = Number.parseInt(result.attributes.getNamedItem('numvotes')?.value ?? '0');
if (votes > languageDependenceMostVotes) {
languageDependenceMostVotes = votes;
languageDependence = result.attributes.getNamedItem('value')?.value ?? '';
}
}

const bestWithPlayers =
response.querySelector('poll-summary[name=suggested_numplayers] result[name=bestwith]')?.attributes.getNamedItem('value')?.value ?? '';
const recommendedWithPlayers =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only including one of those two would be better, as we already have min and max players.

response.querySelector('poll-summary[name=suggested_numplayers] result[name=recommmendedwith]')?.attributes.getNamedItem('value')?.value ?? '';

return new BoardGameModel({
title: title ?? undefined,
englishTitle: title ?? undefined,
title: title ?? '',
englishTitle: title ?? '',
year: year === '0' ? '' : year,
dataSource: this.apiName,
url: `https://boardgamegeek.com/boardgame/${id}`,
id: id,

subType: subType,
genres: genres,
onlineRating: onlineRating,
complexityRating: complexityRating,
minPlayers: minPlayers,
maxPlayers: maxPlayers,
playtime: playtime,
age: age,
publishers: publishers,
boardGameFamilies: boardGameFamilies,
boardGameMechanics: boardGameMechanics,
awards: awards,
description: description.replace(/<[^>]*>/g, ''),
languageDependence: languageDependence,
bestWithPlayers: bestWithPlayers,
recommendedWithPlayers: recommendedWithPlayers,
image: image,

released: true,
Expand Down
16 changes: 16 additions & 0 deletions src/models/BoardGameModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ export class BoardGameModel extends MediaTypeModel {
minPlayers: number;
maxPlayers: number;
playtime: string;
age: number;
publishers: string[];
boardGameFamilies?: string[];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new properties could be better sorted. E.g. all the player counts together.

boardGameMechanics?: string[];
awards?: string[];
description: string;
languageDependence: string;
bestWithPlayers: string;
recommendedWithPlayers: string;
image?: string;

released: boolean;
Expand All @@ -31,7 +39,15 @@ export class BoardGameModel extends MediaTypeModel {
this.minPlayers = 0;
this.maxPlayers = 0;
this.playtime = '';
this.age = 0;
this.publishers = [];
this.boardGameFamilies = [];
this.boardGameMechanics = [];
this.awards = [];
this.description = '';
this.languageDependence = '';
this.bestWithPlayers = '';
this.recommendedWithPlayers = '';
this.image = '';

this.released = false;
Expand Down