I cba with this commit message tbh

This commit is contained in:
Hickmeister
2025-01-14 20:28:59 +00:00
parent a1aee4134c
commit a08c4eba3b
26 changed files with 1135 additions and 231 deletions

View File

@@ -9,7 +9,7 @@ include '../src/session_check.php';
header('Content-Type: application/json');
try {
// Fetch all filament prices with a limit of 180 entries per filament using JOIN
// Fetch all filament prices with the latest discount
$stmt = $pdo->query("
SELECT ft.filamentName,
ft.brand,
@@ -17,6 +17,7 @@ try {
ft.color,
ft.amazonUrl,
fp.price,
fp.currentDiscount,
fp.recordedAt
FROM filamentTracker ft
JOIN filamentPriceHistory fp ON ft.id = fp.filamentId
@@ -27,11 +28,11 @@ try {
ROW_NUMBER() OVER (PARTITION BY filamentId ORDER BY recordedAt DESC) as rn
FROM filamentPriceHistory
) ranked
WHERE rn <= 180
WHERE rn <= 280
) filtered ON fp.filamentId = filtered.filamentId AND fp.recordedAt = filtered.recordedAt
ORDER BY ft.filamentName, fp.recordedAt ASC
");
$filaments = $stmt->fetchAll(PDO::FETCH_ASSOC);
$result = [];
@@ -39,14 +40,15 @@ try {
// Format data for charts (grouped by filament)
foreach ($filaments as $filament) {
$name = $filament['filamentName'];
if (!isset($result[$name])) {
$result[$name] = [
'brand' => $filament['brand'],
'material' => $filament['material'],
'color' => $filament['color'],
'amazonUrl' => $filament['amazonUrl'],
'prices' => []
'prices' => [],
'currentDiscount' => $filament['currentDiscount'] ?? 0 // Include the latest discount
];
}