From cd75aa5b132d958592b8507de5c7cbdcd84cd276 Mon Sep 17 00:00:00 2001 From: Sirttas Date: Tue, 19 Sep 2023 11:57:48 +0200 Subject: [PATCH] rework hierarchy --- src/main.ts | 11 ++- src/market/MarketOrderHistory.ts | 13 ++++ src/market/index.ts | 2 + src/market/market.ts | 77 ------------------- src/market/scan/HistoryQuartils.ts | 59 ++++++++++++++ .../ScanResultTable.vue} | 6 +- src/market/scan/index.ts | 4 + src/market/scan/scan.ts | 9 +++ src/{ => pages}/Index.vue | 0 src/pages/Market.vue | 27 +++++++ src/{reprocess => pages}/Reprocess.vue | 4 +- src/{tools => pages}/Tools.vue | 6 +- .../Market.vue => pages/market/Scan.vue} | 9 +-- src/reprocess/index.ts | 3 + src/style.css | 6 +- src/tools/index.ts | 2 + 16 files changed, 138 insertions(+), 100 deletions(-) create mode 100644 src/market/MarketOrderHistory.ts create mode 100644 src/market/scan/HistoryQuartils.ts rename src/market/{MarketResultTable.vue => scan/ScanResultTable.vue} (96%) create mode 100644 src/market/scan/index.ts create mode 100644 src/market/scan/scan.ts rename src/{ => pages}/Index.vue (100%) create mode 100644 src/pages/Market.vue rename src/{reprocess => pages}/Reprocess.vue (85%) rename src/{tools => pages}/Tools.vue (64%) rename src/{market/Market.vue => pages/market/Scan.vue} (89%) create mode 100644 src/tools/index.ts diff --git a/src/main.ts b/src/main.ts index 7dacf15..a3aa039 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,10 +4,13 @@ import App from './App.vue'; import './style.css'; const routes = [ - { path: '/', component: () => import('@/Index.vue') }, - { path: '/reprocess', component: () => import('@/reprocess/Reprocess.vue') }, - { path: '/market', component: () => import('@/market/Market.vue') }, - { path: '/tools', component: () => import('@/tools/Tools.vue') }, + { path: '/', component: () => import('@/pages/Index.vue') }, + { path: '/reprocess', component: () => import('@/pages/Reprocess.vue') }, + { path: '/market', component: () => import('@/pages/Market.vue'), children: [ + { path: '', redirect: '/market/scan' }, + { path: 'scan', component: () => import('@/pages/market/Scan.vue') }, + ] }, + { path: '/tools', component: () => import('@/pages/Tools.vue') }, ]; const router = createRouter({ diff --git a/src/market/MarketOrderHistory.ts b/src/market/MarketOrderHistory.ts new file mode 100644 index 0000000..3fffd5e --- /dev/null +++ b/src/market/MarketOrderHistory.ts @@ -0,0 +1,13 @@ +import { esiAxiosInstance } from "@/service"; + + +export type MarketOrderHistory = { + average: number; + date: string; + highest: number; + lowest: number; + order_count: number; + volume: number; +} + +export const getHistory = async (regionId: number, tyeId: number): Promise => (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data; diff --git a/src/market/index.ts b/src/market/index.ts index 0354896..29b9d97 100644 --- a/src/market/index.ts +++ b/src/market/index.ts @@ -1,2 +1,4 @@ +export * from './MarketOrderHistory'; export * from './market'; +export * from './type'; diff --git a/src/market/market.ts b/src/market/market.ts index eb713ef..0f7905e 100644 --- a/src/market/market.ts +++ b/src/market/market.ts @@ -1,80 +1,3 @@ -import { esiAxiosInstance } from "@/service"; -import { MarketType } from "./type"; export const jitaId = 10000002; -export type MarketOrderHistory = { - average: number; - date: string; - highest: number; - lowest: number; - order_count: number; - volume: number; -} - -export type MarketResult = { - type: MarketType; - history: MarketOrderHistory[]; - buy: number, - sell: number -} - -export type HistoryQuartils = { - totalVolume: number, - q1: number, - median: number, - q3: number, -} - -export const getHistory = async (regionId: number, tyeId: number): Promise => (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data; - -export const getHistoryQuartils = (history: MarketOrderHistory[], days?: number): HistoryQuartils => { - const now = Date.now(); - - const volumes = history - .flatMap(h => { - const volume = h.volume; - - if (volume === 0 || (days && new Date(h.date).getTime() < now - days * 24 * 60 * 60 * 1000)) { - return []; - } - - const e = estimateVolume(h); - - return [[h.highest, e], [h.lowest, volume - e]]; - }) - .filter(h => h[1] > 0) - .sort((a, b) => a[0] - b[0]); - - const totalVolume = volumes.reduce((acc, [_, v]) => acc + v, 0); - const quartilVolume = totalVolume / 4; - const quartils: [number, number, number] = [0, 0, 0]; - - let currentVolume = 0; - let quartil = 0; - - for (const [price, volume] of volumes) { - currentVolume += volume; - - if (currentVolume >= quartilVolume * (quartil + 1)) { - quartils[quartil] = price; - if (quartil === 2) { - break; - } - quartil++; - } - } - return { - totalVolume, - q1: quartils[0], - median: quartils[1], - q3: quartils[2], - }; -} - -const estimateVolume = (history: MarketOrderHistory): number => { - if (history.volume === 0) { - return 0; - } - return Math.max(1, Math.round(history.volume * ((history.average - history.lowest) / (history.highest - history.lowest)))); -} \ No newline at end of file diff --git a/src/market/scan/HistoryQuartils.ts b/src/market/scan/HistoryQuartils.ts new file mode 100644 index 0000000..d7f6872 --- /dev/null +++ b/src/market/scan/HistoryQuartils.ts @@ -0,0 +1,59 @@ +import { MarketOrderHistory } from "@/market"; + +export type HistoryQuartils = { + totalVolume: number, + q1: number, + median: number, + q3: number, +} + +export const getHistoryQuartils = (history: MarketOrderHistory[], days?: number): HistoryQuartils => { + const now = Date.now(); + + const volumes = history + .flatMap(h => { + const volume = h.volume; + + if (volume === 0 || (days && new Date(h.date).getTime() < now - days * 24 * 60 * 60 * 1000)) { + return []; + } + + const e = estimateVolume(h); + + return [[h.highest, e], [h.lowest, volume - e]]; + }) + .filter(h => h[1] > 0) + .sort((a, b) => a[0] - b[0]); + + const totalVolume = volumes.reduce((acc, [_, v]) => acc + v, 0); + const quartilVolume = totalVolume / 4; + const quartils: [number, number, number] = [0, 0, 0]; + + let currentVolume = 0; + let quartil = 0; + + for (const [price, volume] of volumes) { + currentVolume += volume; + + if (currentVolume >= quartilVolume * (quartil + 1)) { + quartils[quartil] = price; + if (quartil === 2) { + break; + } + quartil++; + } + } + return { + totalVolume, + q1: quartils[0], + median: quartils[1], + q3: quartils[2], + }; +} + +const estimateVolume = (history: MarketOrderHistory): number => { + if (history.volume === 0) { + return 0; + } + return Math.max(1, Math.round(history.volume * ((history.average - history.lowest) / (history.highest - history.lowest)))); +} \ No newline at end of file diff --git a/src/market/MarketResultTable.vue b/src/market/scan/ScanResultTable.vue similarity index 96% rename from src/market/MarketResultTable.vue rename to src/market/scan/ScanResultTable.vue index 103329b..c68617b 100644 --- a/src/market/MarketResultTable.vue +++ b/src/market/scan/ScanResultTable.vue @@ -1,11 +1,11 @@ + + + + \ No newline at end of file diff --git a/src/reprocess/Reprocess.vue b/src/pages/Reprocess.vue similarity index 85% rename from src/reprocess/Reprocess.vue rename to src/pages/Reprocess.vue index a10c3ca..d9cecef 100644 --- a/src/reprocess/Reprocess.vue +++ b/src/pages/Reprocess.vue @@ -1,9 +1,7 @@