-
Notifications
You must be signed in to change notification settings - Fork 38
Enhance BoardGameModel and BoardGameGeekAPI: Add age, boardgame famil… #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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')) | ||
|
@@ -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'); | ||
const publishers = Array.from(boardgame.querySelectorAll('boardgamepublisher')) | ||
.map(n => n.textContent) | ||
.filter(n => n !== null); | ||
const boardGameFamilies = Array.from(boardgame.querySelectorAll('boardgamefamily')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,15 @@ export class BoardGameModel extends MediaTypeModel { | |
minPlayers: number; | ||
maxPlayers: number; | ||
playtime: string; | ||
age: number; | ||
publishers: string[]; | ||
boardGameFamilies?: string[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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; | ||
|
There was a problem hiding this comment.
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?