Skip to content

Commit

Permalink
Make ge price history use weekly averages
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Feb 22, 2024
1 parent 7b554ac commit af74d66
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/mahoji/commands/ge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ The next buy limit reset is at: ${GrandExchange.getInterval().nextResetStr}, it
return patronMsg(PerkTier.Four);
}
let result = await prisma.$queryRawUnsafe<
{ quantity_bought: number; price_per_item_before_tax: number; created_at: Date }[]
{ total_quantity_bought: number; average_price_per_item_before_tax: number; week: Date }[]
>(`SELECT
sellTransactions.created_at,
sellTransactions.price_per_item_before_tax,
sellTransactions.quantity_bought
DATE_TRUNC('week', sellTransactions.created_at) AS week,
AVG(sellTransactions.price_per_item_before_tax) AS average_price_per_item_before_tax,
SUM(sellTransactions.quantity_bought) AS total_quantity_bought
FROM
ge_listing
INNER JOIN
Expand All @@ -407,15 +407,18 @@ AND
ge_listing.cancelled_at IS NULL
AND
ge_listing.fulfilled_at IS NOT NULL
GROUP BY
week
ORDER BY
sellTransactions.created_at ASC;`);
if (result.length < 2) return 'No price history found for that item.';
if (result[0].price_per_item_before_tax <= 1_000_000) {
result = result.filter(i => i.quantity_bought > 1);
week ASC;
`);
if (result.length < 1) return 'No price history found for that item.';
if (result[0].average_price_per_item_before_tax <= 1_000_000) {
result = result.filter(i => i.total_quantity_bought > 1);
}
const buffer = await lineChart(
`Price History for ${item.name}`,
result.map(i => [new Date(i.created_at).toDateString(), i.price_per_item_before_tax]),
result.map(i => [new Date(i.week).toDateString(), i.average_price_per_item_before_tax]),
val => val.toString(),
val => val,
false
Expand Down

0 comments on commit af74d66

Please sign in to comment.