mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-06-28 11:25:50 +02:00
Add highestBefore field for analytic queries, remove price1-10/date1-10.
This commit is contained in:
parent
9d22062ca0
commit
42b89fa325
|
@ -45,14 +45,13 @@ async function loadItems() {
|
||||||
item.priceOldest = item.priceHistory[item.priceHistory.length - 1].price;
|
item.priceOldest = item.priceHistory[item.priceHistory.length - 1].price;
|
||||||
item.dateOldest = item.priceHistory[item.priceHistory.length - 1].date;
|
item.dateOldest = item.priceHistory[item.priceHistory.length - 1].date;
|
||||||
item.date = item.priceHistory[0].date;
|
item.date = item.priceHistory[0].date;
|
||||||
let lastPrice = {price: item.price, date: item.date};
|
let highestPriceBefore = -1;
|
||||||
for (let i = 1; i < 10; i++) {
|
for (let i = 1; i < item.priceHistory.length; i++) {
|
||||||
let price = item.priceHistory[i];
|
const price = item.priceHistory[i];
|
||||||
if (!price) price = lastPrice;
|
highestPriceBefore = Math.max(highestPriceBefore, price.price);
|
||||||
item["price" + (i + 1)] = price.price;
|
|
||||||
item["date" + (i + 1)] = price.date;
|
|
||||||
lastPrice = price;
|
|
||||||
}
|
}
|
||||||
|
if (highestPriceBefore == -1) highestPriceBefore = item.price;
|
||||||
|
item.highestBefore = highestPriceBefore;
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
@ -178,16 +177,7 @@ function searchItems(items, query, billa, spar, hofer, dm, lidl, mpreis, eigenma
|
||||||
|
|
||||||
if (query.charAt(0) == "!") {
|
if (query.charAt(0) == "!") {
|
||||||
query = query.substring(1);
|
query = query.substring(1);
|
||||||
try {
|
return alasql("select * from ? where " + query, [items]);
|
||||||
let hits = alasql("select * from ? where " + query, [items]);
|
|
||||||
if (hits.length > 1000) {
|
|
||||||
return hits.slice(0, 1000);
|
|
||||||
} else {
|
|
||||||
return hits;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokens = query.split(/\s+/).map(token => token.toLowerCase().replace(",", "."));
|
const tokens = query.split(/\s+/).map(token => token.toLowerCase().replace(",", "."));
|
||||||
|
@ -300,13 +290,14 @@ function newSearchComponent(parentElement, items, searched, filter, headerModifi
|
||||||
table.appendChild(thead);
|
table.appendChild(thead);
|
||||||
|
|
||||||
let num = 0;
|
let num = 0;
|
||||||
hits.forEach(hit => {
|
hits.every(hit => {
|
||||||
let itemDom = itemToDOM(hit);
|
let itemDom = itemToDOM(hit);
|
||||||
if (itemDomModifier) itemDom = itemDomModifier(hit, itemDom, hits);
|
if (itemDomModifier) itemDom = itemDomModifier(hit, itemDom, hits);
|
||||||
table.appendChild(itemDom);
|
table.appendChild(itemDom);
|
||||||
num++;
|
num++;
|
||||||
|
return num <= 1000;
|
||||||
});
|
});
|
||||||
numResults.innerHTML = "Resultate: " + num + (num == 1000 ? "+" : "");
|
numResults.innerHTML = "Resultate: " + hits.length + (num < hits.length ? ", " + num + " angezeigt" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
searchInput.addEventListener("input", (event) => {
|
searchInput.addEventListener("input", (event) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user