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,
price: item.data.price.final,
priceHistory: [{ date: today, price: item.data.price.final }],
isWeighted : item.data.isWeightArticle,
unit,
quantity,
bio: item.data.attributes && item.data.attributes.includes("s_bio")

View File

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

View File

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

View File

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