mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-09-24 00:00:27 +02:00
h43z importer almost complete, merges with latest-canonical.json by replacing entire history. should be fixed to only merge in data we don't have.
This commit is contained in:
parent
b5f35f34e5
commit
7b9a6fe969
29
h43z.js
29
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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user