diff --git a/h43z.js b/h43z.js index 465cd8f..370dec4 100644 --- a/h43z.js +++ b/h43z.js @@ -9,7 +9,7 @@ if (!fs.existsSync("h43z.json")) { let stmt = db.prepare("select * from product"); for (const row of stmt.iterate()) { const item = { - store: row.store == "billa" ? "billa" : "spar", + store: row.shop == "billa" ? "billa" : "spar", id: row.product_id, sparId: row.sparId, name: row.name, @@ -51,4 +51,31 @@ if (!fs.existsSync("h43z.json")) { } items = analysis.readJSON("h43z.json"); +items.forEach((item) => { + // item.priceHistory = item.priceHistory.filter(price => price.date > "2020-01-01") +}); +const currItems = analysis.readJSON("data/latest-canonical.json.br"); +const currLookup = {}; +currItems.forEach((item) => (currLookup[item.store + (item.sparId ? item.sparId : item.id)] = item)); +let missingItems = { + spar: 0, + billa: 0, +}; +let foundItems = { + spar: 0, + billa: 0, +}; +for (item of items) { + const i = lookup[item.id]; + const currItem = currLookup[item.store + item.id]; + if (!currItem) { + missingItems[item.store]++; + } else { + foundItems[item.store]++; + currItem.priceHistory = item.priceHistory; + } +} +console.log(JSON.stringify(missingItems, null, 2)); +console.log(JSON.stringify(foundItems, null, 2)); analysis.writeJSON("h43z.compressed.json", items, false, 0, true); +analysis.writeJSON("data/latest-canonical.h43z.json", currItems, analysis.FILE_COMPRESSOR); diff --git a/site/js/misc.js b/site/js/misc.js index 091466a..137c038 100644 --- a/site/js/misc.js +++ b/site/js/misc.js @@ -106,6 +106,11 @@ exports.parseNumber = (value, defaultValue) => { }; exports.queryItems = (query, items, exactWord) => { + alasql.fn.hasPriceChange = (priceHistory, date, endDate) => { + if (!endDate) return priceHistory.some((price) => price.date == date); + else return priceHistory.some((price) => price.date >= date && price.date <= endDate); + }; + if (query.charAt(0) == "!") { query = query.substring(1); try { diff --git a/site/views/items-chart.js b/site/views/items-chart.js index 88a33ea..c6ee740 100644 --- a/site/views/items-chart.js +++ b/site/views/items-chart.js @@ -84,14 +84,14 @@ class ItemsChart extends View { canvasDom.classList.remove("hidden"); } - const allDates = items.flatMap((product) => product.priceHistory.map((item) => item.date)); + const allDates = items.flatMap((item) => item.priceHistory.map((price) => price.date)); const uniqueDates = [...new Set(allDates)]; uniqueDates.sort(); - const datasets = items.map((product) => { + const datasets = items.map((item) => { let price = null; const prices = uniqueDates.map((date) => { - const priceObj = product.priceHistory.find((item) => item.date === date); + const priceObj = item.priceHistory.find((item) => item.date === date); if (!price && priceObj) price = priceObj.price; return priceObj ? priceObj.price : null; }); @@ -105,7 +105,7 @@ class ItemsChart extends View { } return { - label: (product.store ? product.store + " " : "") + product.name, + label: (item.store ? item.store + " " : "") + item.name, data: prices, }; });