feat: update Keepa and Stalker functionalities with enhanced price extraction logic and test cases
This commit is contained in:
@@ -1355,7 +1355,11 @@ function extractCurrentPrice(csv: unknown): number | null {
|
||||
|
||||
function extractLatestPositiveKeepaPrice(history: unknown): number | null {
|
||||
if (!Array.isArray(history)) return null;
|
||||
for (let i = history.length - 1; i >= 0; i--) {
|
||||
|
||||
// Keepa CSV histories are [time, value, time, value, ...]. Only odd indexes
|
||||
// are prices; even indexes are Keepa timestamps and can look like huge prices.
|
||||
for (let i = history.length - 1; i >= 1; i--) {
|
||||
if (i % 2 === 0) continue;
|
||||
const value = extractNumber(history[i]);
|
||||
if (value != null && value > 0) return value / 100;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user