mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-06-22 08:25:52 +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");
|
let stmt = db.prepare("select * from product");
|
||||||
for (const row of stmt.iterate()) {
|
for (const row of stmt.iterate()) {
|
||||||
const item = {
|
const item = {
|
||||||
store: row.store == "billa" ? "billa" : "spar",
|
store: row.shop == "billa" ? "billa" : "spar",
|
||||||
id: row.product_id,
|
id: row.product_id,
|
||||||
sparId: row.sparId,
|
sparId: row.sparId,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
|
@ -51,4 +51,31 @@ if (!fs.existsSync("h43z.json")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
items = analysis.readJSON("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("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) => {
|
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) == "!") {
|
if (query.charAt(0) == "!") {
|
||||||
query = query.substring(1);
|
query = query.substring(1);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -84,14 +84,14 @@ class ItemsChart extends View {
|
||||||
canvasDom.classList.remove("hidden");
|
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)];
|
const uniqueDates = [...new Set(allDates)];
|
||||||
uniqueDates.sort();
|
uniqueDates.sort();
|
||||||
|
|
||||||
const datasets = items.map((product) => {
|
const datasets = items.map((item) => {
|
||||||
let price = null;
|
let price = null;
|
||||||
const prices = uniqueDates.map((date) => {
|
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;
|
if (!price && priceObj) price = priceObj.price;
|
||||||
return priceObj ? priceObj.price : null;
|
return priceObj ? priceObj.price : null;
|
||||||
});
|
});
|
||||||
|
@ -105,7 +105,7 @@ class ItemsChart extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
label: (product.store ? product.store + " " : "") + product.name,
|
label: (item.store ? item.store + " " : "") + item.name,
|
||||||
data: prices,
|
data: prices,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user