fix charts to use local time
This commit is contained in:
parent
e82866f39b
commit
55ca8d3260
4 changed files with 18 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ import { error, json } from '@sveltejs/kit';
|
|||
import { db } from '$lib/server/db';
|
||||
import { coin, user, priceHistory, transaction } from '$lib/server/db/schema';
|
||||
import { eq, desc } from 'drizzle-orm';
|
||||
import { timeToLocal } from '$lib/utils';
|
||||
|
||||
function aggregatePriceHistory(priceData: any[], intervalMinutes: number = 60) {
|
||||
if (priceData.length === 0) return [];
|
||||
|
|
@ -19,7 +20,7 @@ function aggregatePriceHistory(priceData: any[], intervalMinutes: number = 60) {
|
|||
|
||||
if (!candlesticks.has(intervalStart)) {
|
||||
candlesticks.set(intervalStart, {
|
||||
time: Math.floor(intervalStart / 1000),
|
||||
time: timeToLocal(Math.floor(intervalStart / 1000)),
|
||||
open: point.price,
|
||||
high: point.price,
|
||||
low: point.price,
|
||||
|
|
@ -87,7 +88,7 @@ function aggregateVolumeData(transactionData: any[], intervalMinutes: number = 6
|
|||
|
||||
if (!volumeMap.has(intervalStart)) {
|
||||
volumeMap.set(intervalStart, {
|
||||
time: Math.floor(intervalStart / 1000),
|
||||
time: timeToLocal(Math.floor(intervalStart / 1000)),
|
||||
volume: 0
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { db } from '$lib/server/db';
|
|||
import { predictionQuestion, user, predictionBet } from '$lib/server/db/schema';
|
||||
import { eq, desc, sum, and, asc } from 'drizzle-orm';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { timeToLocal } from '$lib/utils';
|
||||
|
||||
export const GET: RequestHandler = async ({ params, request }) => {
|
||||
const questionId = parseInt(params.id!);
|
||||
|
|
@ -84,7 +85,7 @@ export const GET: RequestHandler = async ({ params, request }) => {
|
|||
if (probabilityHistory.length > 0) {
|
||||
const firstBetTime = Math.floor(new Date(probabilityHistory[0].createdAt).getTime() / 1000);
|
||||
probabilityData.push({
|
||||
time: firstBetTime - 3600, // 1 hour before first bet
|
||||
time: timeToLocal(firstBetTime - 3600),
|
||||
value: 50
|
||||
});
|
||||
}
|
||||
|
|
@ -100,7 +101,7 @@ export const GET: RequestHandler = async ({ params, request }) => {
|
|||
const yesPercentage = total > 0 ? (runningYesTotal / total) * 100 : 50;
|
||||
|
||||
probabilityData.push({
|
||||
time: Math.floor(new Date(bet.createdAt).getTime() / 1000),
|
||||
time: timeToLocal(Math.floor(new Date(bet.createdAt).getTime() / 1000)),
|
||||
value: Number(yesPercentage.toFixed(1))
|
||||
});
|
||||
}
|
||||
|
|
@ -108,7 +109,7 @@ export const GET: RequestHandler = async ({ params, request }) => {
|
|||
// Add current point if no recent bets
|
||||
if (probabilityData.length > 0) {
|
||||
const lastPoint = probabilityData[probabilityData.length - 1];
|
||||
const currentTime = Math.floor(Date.now() / 1000);
|
||||
const currentTime = timeToLocal(Math.floor(Date.now() / 1000));
|
||||
|
||||
// Only add current point if last bet was more than 1 hour ago
|
||||
if (currentTime - lastPoint.time > 3600) {
|
||||
|
|
|
|||
Reference in a new issue