Skip to content
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

Fix some "_id" fields not being unique. #17

Merged
merged 12 commits into from May 28, 2018
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -169,6 +169,7 @@ Rewards not tied to a specific location, like mods dropped by Nightmare Mode mis
```json
"transientRewards": [
{
"_id": "b3c734177040ffb494609a27d87d4841",
"objectiveName": "Derelict Vault",
"rewards": [
{
Expand Down
2 changes: 1 addition & 1 deletion data/all.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/builds/888d284f1b3af25d5689af8d252a3106.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/enemyModTables.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/info.json
@@ -1 +1 @@
{"hash":"888d284f1b3af25d5689af8d252a3106","timestamp":1526569212093,"modified":1526569000000}
{"hash":"888d284f1b3af25d5689af8d252a3106","timestamp":1527088657604,"modified":1526569000000}
2 changes: 1 addition & 1 deletion data/modLocations.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/transientRewards.json

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions lib/enemyModTables.js
Expand Up @@ -2,33 +2,30 @@ const {hash, parseChance} = require("./utils.js")

module.exports = function($) {
const table = $("#enemyModTables").next("table")

const tbody = table.children()['0']

let enemy = null

let enemies = []

for(let tr of tbody.children) {
for (let tr of tbody.children) {
let elem = tr.children[0]
let text = $(elem).text()

if(elem.name === "th" && tr.children.length === 2) {
if(enemy) {
if (elem.name === "th" && tr.children.length === 2) {
if (enemy) {
enemy._id = hash(`${enemy.enemyName} ${enemy.enemyModDropChance} ${enemy.mods.length}`)
enemies.push(enemy)
}

let moddropchance = $(tr.children[1]).text()

moddropchance = moddropchance.slice("Mod Drop Chance: ".length, moddropchance.length - 1)

enemy = {_id: hash(text), enemyName: text, ememyModDropChance: moddropchance, mods: []}
enemy = {enemyName: text, enemyModDropChance: moddropchance, mods: []}
}

if(elem.name === "td" && elem.attribs.class !== "blank-row") {
if (elem.name === "td" && elem.attribs.class !== "blank-row") {
let chanceElem = tr.children[2]
let chance = parseChance($(chanceElem).text())

let modName = $(tr.children[1]).text()

enemy.mods.push({
Expand All @@ -41,6 +38,7 @@ module.exports = function($) {
}

// push the last one too
enemy._id = hash(`${enemy.enemyName} ${enemy.enemyModDropChance} ${enemy.mods.length}`)
enemies.push(enemy)

return enemies
Expand Down
21 changes: 10 additions & 11 deletions lib/modLocations.js
Expand Up @@ -2,43 +2,42 @@ const {hash, parseChance} = require("./utils.js")

module.exports = function($) {
const table = $("#modLocations").next("table")

const tbody = table.children()['0']

let mod = null

let mods = []

for(let tr of tbody.children) {
for (let tr of tbody.children) {
let elem = tr.children[0]
let text = $(elem).text()

if(elem.name === "th" && tr.children.length === 1) {

if(mod) {
if (elem.name === "th" && tr.children.length === 1) {
if (mod) {
mod._id = hash(`${mod.modName} ${mod.enemies.length}`)
mods.push(mod)
}

mod = {_id: hash(text), modName: text, enemies: []}
mod = {modName: text, enemies: []}
}

if(elem.name === "td" && elem.attribs.class !== "blank-row") {
if (elem.name === "td" && elem.attribs.class !== "blank-row") {
let chanceElem = tr.children[2]
let chance = parseChance($(chanceElem).text())

let enemyModDropChance = $(tr.children[1]).text()
enemyModDropChance = Number(enemyModDropChance.slice(0, enemyModDropChance.length - 1))

mod.enemies.push({
_id: hash(text),
_id: hash(`${text} ${enemyModDropChance} ${chance.rarity}`),
Copy link
Member

Choose a reason for hiding this comment

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

now there's spaces, which shouldn't be there....

Copy link
Contributor Author

@Senexis Senexis May 23, 2018

Choose a reason for hiding this comment

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

This doesn't matter to be fair, as the output will be the same length and will change no matter what due to the earlier changes.

enemyName: text,
enemyModDropChance: Number(enemyModDropChance.slice(0, enemyModDropChance.length - 1)),
enemyModDropChance: enemyModDropChance,
rarity: chance.rarity,
chance: Number(chance.chance)
})
}
}

// push the last one too
mod._id = hash(`${mod.modName} ${mod.enemies.length}`)
mods.push(mod)

return mods
Expand Down
33 changes: 16 additions & 17 deletions lib/transientRewards.js
Expand Up @@ -2,43 +2,40 @@ const {hash, parseLocation, parseRotation, parseChance} = require("./utils.js")

module.exports = function($) {
const table = $("#transientRewards").next("table")

const tbody = table.children()['0']

let name = null
let transient = null
let transients = []
let rotation = null

let transientRewards = []
let curr = {}

for(let tr of tbody.children) {
for (let tr of tbody.children) {
let elem = tr.children[0]
let text = $(elem).text()

if(elem.name === "th") {
if (elem.name === "th") {
let tmp = parseRotation(text)

if(tmp) {
if (tmp) {
rotation = tmp
} else {
if(name) {
transientRewards.push(curr)
if (transient) {
transient._id = hash(`${transient.objectiveName} ${transient.rewards.length}`)
transients.push(transient)
}

name = text
curr = {objectiveName: name, rewards: []}
transient = {objectiveName: text, rewards: []}
}
}

if(elem.attribs.class === "blank-row") {
if (elem.attribs.class === "blank-row") {
rotation = null
}

if(elem.name === "td" && elem.attribs.class !== "blank-row") {
if (elem.name === "td" && elem.attribs.class !== "blank-row") {
let chanceElem = tr.children[1]
let chance = parseChance($(chanceElem).text())

curr.rewards.push({
transient.rewards.push({
_id: hash(text),
rotation: rotation,
itemName: text,
Expand All @@ -48,7 +45,9 @@ module.exports = function($) {
}
}

transientRewards.push(curr)
// push the last one too
transient._id = hash(`${transient.objectiveName} ${transient.rewards.length}`)
transients.push(transient)

return transientRewards
return transients
}