@@ -15,44 +15,54 @@ fun main() {
1515 objectMapper.setSerializationInclusion(NON_EMPTY )
1616 val listOfBoardgames: MutableList <Boardgame > = mutableListOf ()
1717 val listOfCustomResults: MutableList <CustomBoardgame > = mutableListOf ()
18+ val listOfIds: MutableList <Identifier > = mutableListOf ()
1819 File (" ./" ).listFiles()?.filter { it.isFile }?.filter { it.extension == " xml" }?.forEach {
1920 val boardgames = unmarshaller.unmarshal(it.inputStream()) as Boardgames
20- boardgames.boardgame.forEach {
21- listOfBoardgames.add(it)
22- listOfCustomResults.add(it.toInternal())
23- }
21+ boardgames.boardgame
22+ .filter { it.statistics.ratings.ranks.rank.none { it.valueAttribute == " Not Ranked" } }
23+ .forEach {
24+ listOfBoardgames.add(it)
25+ val customBoardgame = it.toInternal()
26+ listOfCustomResults.add(customBoardgame)
27+ listOfIds.add(Identifier (customBoardgame.objectId, customBoardgame.name, customBoardgame.boardGameRank))
28+ }
2429 }
2530 val writer = FileWriter (" ./boardgames.json" )
26- writer.write(objectMapper.writeValueAsString(listOfBoardgames))
31+ writer.write(objectMapper.writeValueAsString(listOfBoardgames.sortedBy { it.toRank() } ))
2732 writer.flush()
2833 writer.close()
2934 val writer2 = FileWriter (" ./boardgames-custom.json" )
30- writer2.write(objectMapper.writeValueAsString(listOfCustomResults))
35+ writer2.write(objectMapper.writeValueAsString(listOfCustomResults.sortedBy{ it.boardGameRank } ))
3136 writer2.flush()
3237 writer2.close()
38+ val writer3 = FileWriter (" ./object-ids.json" )
39+ writer3.write(objectMapper.writeValueAsString(listOfIds.sortedBy {it.boardGameRank }))
40+ writer3.flush()
41+ writer3.close()
3342}
3443
3544private fun Boardgame.toInternal (): CustomBoardgame {
3645 return CustomBoardgame (
37- objectId = this .objectid,
38- yearPublished = this .yearpublished.toInt(),
39- minPlayers = this .minplayers.toInt() ,
40- maxPlayers = this .maxplayers.toInt() ,
41- playingTime = this .playingtime.toInt() ,
42- minPlayTime = this .minplaytime.toInt() ,
43- maxPlayTime = this .maxplaytime.toInt() ,
44- age = this .age.toInt() ,
45- name = this .name.singleOrNull { it.primary == " true" }?.value ? : this .name.first().value,
46- description = this .description,
47- thumbnailImageLink = this .thumbnail,
48- publisher = this .boardgamepublisher?.value,
49- version = this .boardgameversion?.value,
50- category = this .boardgamecategory?.value,
51- families = this .boardgamefamily?.mapNotNull { it.value } ? : emptyList(),
52- gameMechanics = this .boardgamemechanic?.value,
53- bestPlayedWith = this .poll.single { it.name == " suggested_numplayers" }.results.sortedBy {
54- it.result.single { it.valueAttribute == " Best" }.numvotes.toInt()
55- }.last().numplayers,
56- boardGameRank = this .statistics.ratings.ranks.rank.single { it.name == " boardgame " }.valueAttribute.toInt ()
46+ objectId = this .objectid,
47+ yearPublished = this .yearpublished.toInt(),
48+ minPlayers = this .minplayers,
49+ maxPlayers = this .maxplayers,
50+ playingTime = this .playingtime,
51+ minPlayTime = this .minplaytime,
52+ maxPlayTime = this .maxplaytime,
53+ age = this .age,
54+ name = this .name.singleOrNull { it.primary == " true" }?.value ? : this .name.first().value,
55+ description = this .description,
56+ thumbnailImageLink = this .thumbnail,
57+ publisher = this .boardgamepublisher?.value,
58+ version = this .boardgameversion?.value,
59+ category = this .boardgamecategory?.value,
60+ families = this .boardgamefamily?.mapNotNull { it.value } ? : emptyList(),
61+ gameMechanics = this .boardgamemechanic?.value,
62+ bestPlayedWith = this .poll.single { it.name == " suggested_numplayers" }.results.sortedBy {
63+ it.result.single { it.valueAttribute == " Best" }.numvotes.toInt()
64+ }.last().numplayers,
65+ boardGameRank = this .toRank ()
5766 )
5867}
68+ private fun Boardgame.toRank (): Int = this .statistics.ratings.ranks.rank.single { it.name == " boardgame" }.valueAttribute.toInt()
0 commit comments