isWeighted for billa, hofer, lidl, spar

This commit is contained in:
Matthias Hochsteger 2023-05-28 19:11:18 +02:00
parent 2a19207064
commit c08ad5dd0a
4 changed files with 30 additions and 19 deletions

View File

@ -41,6 +41,7 @@ exports.getCanonical = function(item, today) {
name: item.data.name, name: item.data.name,
price: item.data.price.final, price: item.data.price.final,
priceHistory: [{ date: today, price: item.data.price.final }], priceHistory: [{ date: today, price: item.data.price.final }],
isWeighted : item.data.isWeightArticle,
unit, unit,
quantity, quantity,
bio: item.data.attributes && item.data.attributes.includes("s_bio") bio: item.data.attributes && item.data.attributes.includes("s_bio")

View File

@ -56,6 +56,7 @@ exports.getCanonical = function(item, today) {
name: item.ProductName, name: item.ProductName,
price: item.Price, price: item.Price,
priceHistory: [{ date: today, price: item.Price }], priceHistory: [{ date: today, price: item.Price }],
isWeighted: item.IsBulk,
unit, unit,
quantity, quantity,
bio: item.IsBio bio: item.IsBio

View File

@ -18,28 +18,36 @@ exports.getCanonical = function(item, today) {
let quantity = 1; let quantity = 1;
let unit = ''; let unit = '';
let text = (item.price.basePrice?.text ?? "").trim().split('(')[0].replaceAll(',', '.').toLowerCase(); let text = (item.price.basePrice?.text ?? "").trim().split('(')[0].replaceAll(',', '.').toLowerCase();
if(text.startsWith('bei') && text.search('je ') != -1) let isWeighted = false;
text = text.substr(text.search('je '))
for (let s of ['ab ', 'je ', 'ca. ', 'z.b.: ', 'z.b. ']) if(text === 'per kg') {
text = text.replace(s, '').trim() isWeighted = true;
unit = 'kg';
}
else {
if(text.startsWith('bei') && text.search('je ') != -1)
text = text.substr(text.search('je '))
const regex = /^([0-9.x ]+)(.*)$/; for (let s of ['ab ', 'je ', 'ca. ', 'z.b.: ', 'z.b. '])
const matches = text.match(regex); text = text.replace(s, '').trim()
if(matches) {
matches[1].split('x').forEach( (q)=> { const regex = /^([0-9.x ]+)(.*)$/;
quantity = quantity * parseFloat(q.split('/')[0]) const matches = text.match(regex);
}) if(matches) {
unit = matches[2].split('/')[0].trim().split(' ')[0]; matches[1].split('x').forEach( (q)=> {
quantity = quantity * parseFloat(q.split('/')[0])
})
unit = matches[2].split('/')[0].trim().split(' ')[0];
}
unit = unit.split('-')[0];
if(unit in conversions) {
const conv = conversions[unit];
quantity = conv.factor * quantity;
unit = conv.unit;
}
else
console.error(`Unknown unit in lidl: '${unit}'`)
} }
unit = unit.split('-')[0];
if(unit in conversions) {
const conv = conversions[unit];
quantity = conv.factor * quantity;
unit = conv.unit;
}
else
console.error(`Unknown unit in lidl: '${unit}'`)
return { return {
id: item.productId, id: item.productId,

View File

@ -50,6 +50,7 @@ exports.getCanonical = function(item, today) {
priceHistory: [{ date: today, price }], priceHistory: [{ date: today, price }],
unit, unit,
quantity, quantity,
isWeighted: item.masterValues['item-type'] === 'WeightProduct',
bio: item.masterValues.biolevel === "Bio" bio: item.masterValues.biolevel === "Bio"
}; };
} }