Compare commits

9 Commits

Author SHA1 Message Date
e81fdc24bb fix is logged in check 2025-05-10 09:33:43 +02:00
778de8ca14 update an fix login 2025-05-10 09:30:16 +02:00
00c37c0a37 update an cleanup 2025-03-08 14:38:05 +01:00
a56580ce27 refresh acquisitions 2024-06-18 12:02:56 +02:00
11f886cd71 Add total if name is missing 2024-06-04 16:18:52 +02:00
ac07236936 total in acquisition table 2024-06-04 14:39:48 +02:00
9aa37b355e tracking progress bar 2024-06-02 16:51:06 +02:00
12ad7d36ff cleanup acquisitions 2024-06-02 15:50:17 +02:00
c77a6ff811 acquisitions in tracking 2024-06-02 08:16:20 +02:00
18 changed files with 1276 additions and 1189 deletions

2278
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@
"@vueuse/integrations": "^10.2.1", "@vueuse/integrations": "^10.2.1",
"axios": "^1.4.0", "axios": "^1.4.0",
"axios-rate-limit": "^1.3.1", "axios-rate-limit": "^1.3.1",
"gemory": "file:",
"loglevel": "^1.8.1", "loglevel": "^1.8.1",
"loglevel-plugin-prefix": "^0.8.4", "loglevel-plugin-prefix": "^0.8.4",
"oidc-client-ts": "^3.0.1", "oidc-client-ts": "^3.0.1",
@@ -30,9 +31,9 @@
"postcss": "^8.4.27", "postcss": "^8.4.27",
"tailwindcss": "^3.3.3", "tailwindcss": "^3.3.3",
"typescript": "^5.0.2", "typescript": "^5.0.2",
"vite": "^5.2.11", "vite": "^6.3.5",
"vite-plugin-runtime-env": "^0.1.1", "vite-plugin-runtime-env": "^0.1.1",
"vitest": "^1.6.0", "vitest": "^3.1.3",
"vue-tsc": "^2.0.18" "vue-tsc": "^2.0.18"
} }
} }

View File

@@ -17,7 +17,7 @@ export const useAuthStore = defineStore('auth', () => {
}); });
const user = ref<User>(); const user = ref<User>();
const isLoggedIn = computed(() => !!user.value); const isLoggedIn = computed(() => user.value?.expired === false);
const accessToken = computed(() => user.value?.access_token); const accessToken = computed(() => user.value?.access_token);
const username = computed(() => user.value?.profile.name ?? ""); const username = computed(() => user.value?.profile.name ?? "");
const userId = computed(() => user.value?.profile.sub ?? ""); const userId = computed(() => user.value?.profile.sub ?? "");

View File

@@ -0,0 +1,19 @@
<script setup lang="ts">
import { computed } from 'vue';
interface Props {
value: number;
total: number;
}
const props = defineProps<Props>();
const percentage = computed(() => (props.value / props.total) * 100);
</script>
<template>
<div class="w-full bg-gray-600 rounded-full h-2.5">
<div class="bg-emerald-600 h-2.5 rounded-full" :style="{ width: percentage + '%'}" />
</div>
</template>

View File

@@ -2,6 +2,7 @@ export { default as ClipboardButton } from './ClipboardButton.vue';
export { default as Dropdown } from './Dropdown.vue'; export { default as Dropdown } from './Dropdown.vue';
export { default as LoadingSpinner } from './LoadingSpinner.vue'; export { default as LoadingSpinner } from './LoadingSpinner.vue';
export { default as Modal } from './Modal.vue'; export { default as Modal } from './Modal.vue';
export { default as ProgressBar } from './ProgressBar.vue';
export { default as SliderCheckbox } from './SliderCheckbox.vue'; export { default as SliderCheckbox } from './SliderCheckbox.vue';
export { default as Tooltip } from './tooltip/Tooltip.vue'; export { default as Tooltip } from './tooltip/Tooltip.vue';

View File

@@ -6,7 +6,8 @@ interface Props {
list?: any[]; list?: any[];
itemHeight: number; itemHeight: number;
headerHeight?: number; headerHeight?: number;
bottom?: string; footerHeight?: number;
bottom?: string; // FIXME: use css variable
} }
@@ -35,11 +36,16 @@ const computedHeaderHeight = computed(() => {
return h + 'px'; return h + 'px';
}) })
const computedFooterHeight = computed(() => {
const h = props.footerHeight ?? 0;
return h + 'px';
})
const computedWrapperProps = computed(() => ({ const computedWrapperProps = computed(() => ({
...wrapperProps.value, ...wrapperProps.value,
style: { style: {
...wrapperProps.value.style, ...wrapperProps.value.style,
height: `calc(${wrapperProps.value.style.height} + ${computedHeaderHeight.value} + 1px)` height: `calc(${wrapperProps.value.style.height} + ${computedHeaderHeight.value} + ${computedFooterHeight.value} + 1px)`
} }
})) }))
const itemHeightStyle = computed(() => { const itemHeightStyle = computed(() => {
@@ -72,6 +78,10 @@ div.table-container {
@apply sticky z-10; @apply sticky z-10;
top: -1px; top: -1px;
} }
>tfoot {
@apply bg-slate-600 sticky z-10;
bottom: -1px;
}
>*>tr, >*>tr>td { >*>tr, >*>tr>td {
height: v-bind(itemHeightStyle); height: v-bind(itemHeightStyle);
} }
@@ -79,6 +89,7 @@ div.table-container {
} }
&::-webkit-scrollbar-track { &::-webkit-scrollbar-track {
margin-top: v-bind(computedHeaderHeight); margin-top: v-bind(computedHeaderHeight);
margin-bottom: v-bind(computedFooterHeight);
} }
} }
</style> </style>

View File

@@ -10,13 +10,13 @@ export const marbasAxiosInstance = axios.create({
}, },
}) })
marbasAxiosInstance.interceptors.request.use(r => { const authStore = useAuthStore();
const authStore = useAuthStore();
marbasAxiosInstance.interceptors.request.use(async r => {
if (!authStore.isLoggedIn) { if (!authStore.isLoggedIn) {
throw new Error("Not logged in"); await authStore.redirect();
} }
const accessToken = authStore.accessToken; const accessToken = authStore.accessToken;
if (accessToken) { if (accessToken) {
@@ -29,6 +29,12 @@ marbasAxiosInstance.interceptors.request.use(r => {
}) })
logResource(marbasAxiosInstance) logResource(marbasAxiosInstance)
marbasAxiosInstance.interceptors.response.use(async r => { marbasAxiosInstance.interceptors.response.use(async r => {
if (r.status === 401) {
await authStore.redirect();
return marbasAxiosInstance.request(r.config);
}
let next: string = r.data?.next; let next: string = r.data?.next;
let results = r.data?.results; let results = r.data?.results;

View File

@@ -120,12 +120,39 @@ const { sortedArray, headerProps, showColumn } = useSort<Result>(computed(() =>
}) })
const getLineColor = (result: Result) => { const getLineColor = (result: Result) => {
if (result.precentProfit >= (threshold.value / 100)) { if (result.precentProfit >= (threshold.value / 100)) {
return 'line-green'; return 'line-green';
} else if (result.precentProfit < 0) { } else if (result.precentProfit < 0) {
return 'line-red'; return 'line-red';
} }
return ''; return '';
} }
const total = computed(() => {
if (sortedArray.value.length <= 1) {
return null;
}
const first = sortedArray.value[0];
if (!first) {
return null;
}
const sameItem = sortedArray.value.every(r => r.type.id === first.type.id);
const quantity = sameItem ? sortedArray.value.reduce((acc, r) => acc + r.quantity, 0) : 0;
const totalRemaining = sameItem ? sortedArray.value.reduce((acc, r) => acc + r.remaining, 0) : 0;
const price = sortedArray.value.reduce((acc, r) => acc + r.price * r.remaining, 0) / totalRemaining;
const precentProfit = marketTaxStore.calculateProfit(price, first.sell);
const iskProfit = sortedArray.value.reduce((acc, r) => acc + r.iskProfit, 0);
return {
sameItem,
price,
remaining: totalRemaining,
quantity,
precentProfit,
iskProfit
};
});
</script> </script>
<template> <template>
@@ -142,7 +169,7 @@ const getLineColor = (result: Result) => {
</div> </div>
</div> </div>
</div> </div>
<VirtualScrollTable :list="sortedArray" :itemHeight="33" bottom="1rem"> <VirtualScrollTable :list="sortedArray" :itemHeight="33" :footerHeight="!!total ? 33 : 0" bottom="1rem">
<template #default="{ list }"> <template #default="{ list }">
<thead> <thead>
<tr> <tr>
@@ -178,6 +205,37 @@ const getLineColor = (result: Result) => {
</td> </td>
</tr> </tr>
</tbody> </tbody>
<tfoot v-if="!!total">
<tr>
<td v-if="showColumn('name')">Total</td>
<td v-if="showColumn('buy')">
<template v-if="!showColumn('name')">Total</template>
</td>
<td v-if="showColumn('sell')">
<template v-if="!showColumn('name') && !showColumn('buy')">Total</template>
</td>
<td v-if="showColumn('date')">
<template v-if="!showColumn('name') && !showColumn('buy') && !showColumn('sell')">Total</template>
</td>
<td v-if="showColumn('price')" class="text-right">
<template v-if="total.sameItem">
{{ formatIsk(total.price) }}
</template>
</td>
<td v-if="showColumn('remaining')" class="text-right">
<template v-if="total.sameItem">
{{ total.remaining }}/{{ total.quantity }}
</template>
</td>
<td v-if="showColumn('precentProfit')" class="text-right">
<template v-if="total.sameItem">
{{ percentFormater.format(total.precentProfit) }}
</template>
</td>
<td v-if="showColumn('iskProfit')" class="text-right">{{ formatIsk(total.iskProfit) }}</td>
<td v-if="showColumn('buttons')" />
</tr>
</tfoot>
</template> </template>
<template #empty> <template #empty>
<div class="text-center mt-4"> <div class="text-center mt-4">

View File

@@ -13,14 +13,13 @@ export type MarbasAcquiredType = MarbasObject & {
price: number; price: number;
date: Date; date: Date;
source: AcquiredTypeSource; source: AcquiredTypeSource;
user: number;
} }
type RawMarbasAcquiredType = Omit<MarbasAcquiredType, 'date'> & { type RawMarbasAcquiredType = Omit<MarbasAcquiredType, 'date'> & {
date: string; date: string;
} }
type InsertableRawMarbasAcquiredType = Omit<MarbasAcquiredType, 'id' | 'user' | 'date'>; type InsertableRawMarbasAcquiredType = Omit<MarbasAcquiredType, 'id' | 'date'>;
const mapRawMarbasAcquiredType = (raw: RawMarbasAcquiredType): MarbasAcquiredType => ({ const mapRawMarbasAcquiredType = (raw: RawMarbasAcquiredType): MarbasAcquiredType => ({
...raw, ...raw,
@@ -67,8 +66,10 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
await marbasAxiosInstance.put(`${endpoint}${item.id}/`, item); await marbasAxiosInstance.put(`${endpoint}${item.id}/`, item);
log.info(`Acquired type ${item.id} remaining: ${item.remaining}`, item); log.info(`Acquired type ${item.id} remaining: ${item.remaining}`, item);
}; };
marbasAxiosInstance.get<RawMarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data.map(mapRawMarbasAcquiredType));
return { acquiredTypes: types, addAcquiredType, removeAcquiredType }; const refresh = () => marbasAxiosInstance.get<RawMarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data.map(mapRawMarbasAcquiredType));
refresh();
return { acquiredTypes: types, addAcquiredType, removeAcquiredType, refresh };
}); });

View File

@@ -23,8 +23,8 @@ const historyCache: RegionalMarketCache<EsiMarketOrderHistory[]> = new RegionalM
return date; return date;
}); });
export const getHistory = async (tyeId: number, regionId?: number): Promise<EsiMarketOrderHistory[]> => { export const getHistory = async (typeId: number, regionId?: number): Promise<EsiMarketOrderHistory[]> => {
const rId = regionId ?? jitaId; const rId = regionId ?? jitaId;
return historyCache.computeIfAbsent(rId, tyeId, async () => (await esiAxiosInstance.get(`/markets/${rId}/history/`, { params: { type_id: tyeId } })).data); return historyCache.computeIfAbsent(rId, typeId, async () => (await esiAxiosInstance.get(`/markets/${rId}/history/`, { params: { type_id: typeId } })).data);
} }

View File

@@ -1,3 +1 @@
export const jitaId = 10000002; export const jitaId = 10000002;

View File

@@ -6,6 +6,7 @@ import { getHistoryQuartils, MarketType, MarketTypeLabel, TaxInput, useMarketTax
import { BookmarkSlashIcon, ShoppingCartIcon } from '@heroicons/vue/24/outline'; import { BookmarkSlashIcon, ShoppingCartIcon } from '@heroicons/vue/24/outline';
import { useStorage } from '@vueuse/core'; import { useStorage } from '@vueuse/core';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { useAcquiredTypesStore } from '../acquisition';
import { TrackingResult } from './tracking'; import { TrackingResult } from './tracking';
type Result = { type Result = {
@@ -17,6 +18,7 @@ type Result = {
q1: number; q1: number;
median: number; median: number;
q3: number; q3: number;
acquisitions: number;
profit: number; profit: number;
score: number; score: number;
} }
@@ -44,6 +46,7 @@ const props = withDefaults(defineProps<Props>(), {
defineEmits<Emits>(); defineEmits<Emits>();
const marketTaxStore = useMarketTaxStore(); const marketTaxStore = useMarketTaxStore();
const acquiredTypesStore = useAcquiredTypesStore();
const days = useStorage('market-tracking-days', 365); const days = useStorage('market-tracking-days', 365);
const threshold = useStorage('market-tracking-threshold', 10); const threshold = useStorage('market-tracking-threshold', 10);
@@ -63,6 +66,9 @@ const { sortedArray, headerProps, showColumn } = useSort<Result>(computed(() =>
const quartils = getHistoryQuartils(r.history, days.value); const quartils = getHistoryQuartils(r.history, days.value);
const profit = quartils.q1 === 0 || quartils.q3 === 0 ? 0 : marketTaxStore.calculateProfit(quartils.q1, quartils.q3); const profit = quartils.q1 === 0 || quartils.q3 === 0 ? 0 : marketTaxStore.calculateProfit(quartils.q1, quartils.q3);
const score = profit <= 0 ? 0 : Math.sqrt((Math.pow(quartils.totalVolume, 1.1) * Math.pow(quartils.q1, 1.2) * Math.pow(profit, 0.5) * Math.pow(Math.max(1, r.orderCount), -0.7)) / days.value); const score = profit <= 0 ? 0 : Math.sqrt((Math.pow(quartils.totalVolume, 1.1) * Math.pow(quartils.q1, 1.2) * Math.pow(profit, 0.5) * Math.pow(Math.max(1, r.orderCount), -0.7)) / days.value);
const acquisitions = columnsToIgnore.value.includes('acquisitions') ? 0 : acquiredTypesStore.acquiredTypes
.filter(t => t.type === r.type.id)
.reduce((a, b) => a + b.remaining, 0);
return { return {
type: r.type, type: r.type,
@@ -73,6 +79,7 @@ const { sortedArray, headerProps, showColumn } = useSort<Result>(computed(() =>
q1: quartils.q1, q1: quartils.q1,
median: quartils.median, median: quartils.median,
q3: quartils.q3, q3: quartils.q3,
acquisitions,
profit, profit,
score score
}; };
@@ -128,6 +135,7 @@ const getLineColor = (result: Result) => {
<SortableHeader v-bind="headerProps" sortKey="q3">Q3</SortableHeader> <SortableHeader v-bind="headerProps" sortKey="q3">Q3</SortableHeader>
<SortableHeader v-bind="headerProps" sortKey="profit">Profit</SortableHeader> <SortableHeader v-bind="headerProps" sortKey="profit">Profit</SortableHeader>
<SortableHeader v-bind="headerProps" sortKey="score">Score</SortableHeader> <SortableHeader v-bind="headerProps" sortKey="score">Score</SortableHeader>
<SortableHeader v-bind="headerProps" sortKey="acquisitions">Acquisitions</SortableHeader>
<SortableHeader v-bind="headerProps" sortKey="buttons" unsortable /> <SortableHeader v-bind="headerProps" sortKey="buttons" unsortable />
</tr> </tr>
</thead> </thead>
@@ -143,6 +151,7 @@ const getLineColor = (result: Result) => {
<td v-if="showColumn('q3')" class="text-right">{{ formatIsk(r.data.q3) }}</td> <td v-if="showColumn('q3')" class="text-right">{{ formatIsk(r.data.q3) }}</td>
<td v-if="showColumn('profit')" class="text-right">{{ percentFormater.format(r.data.profit) }}</td> <td v-if="showColumn('profit')" class="text-right">{{ percentFormater.format(r.data.profit) }}</td>
<td v-if="showColumn('score')" class="text-right">{{ scoreFormater.format(r.data.score) }}</td> <td v-if="showColumn('score')" class="text-right">{{ scoreFormater.format(r.data.score) }}</td>
<td v-if="showColumn('acquisitions')" class="text-right">{{ r.data.acquisitions }}</td>
<td v-if="showColumn('buttons')" class="text-right"> <td v-if="showColumn('buttons')" class="text-right">
<button class="btn-icon me-1" title="Add acquisitions" @click="$emit('buy', r.data.type, r.data.buy, r.data.sell)"><ShoppingCartIcon /></button> <button class="btn-icon me-1" title="Add acquisitions" @click="$emit('buy', r.data.type, r.data.buy, r.data.sell)"><ShoppingCartIcon /></button>
<button class="btn-icon me-1" title="Untrack" @click="$emit('remove', r.data.type)"><BookmarkSlashIcon /></button> <button class="btn-icon me-1" title="Untrack" @click="$emit('remove', r.data.type)"><BookmarkSlashIcon /></button>

View File

@@ -6,11 +6,12 @@ import { ref, watch } from 'vue';
const buyModal = ref<typeof BuyModal>(); const buyModal = ref<typeof BuyModal>();
const sellModal = ref<typeof SellModal>(); const sellModal = ref<typeof SellModal>();
const apraisalStore = useApraisalStore(); const apraisalStore = useApraisalStore();
const acquiredTypesStore = useAcquiredTypesStore(); const acquiredTypesStore = useAcquiredTypesStore();
const items = ref<AcquiredType[]>([]); const items = ref<AcquiredType[]>([]);
const refresh = async () => await acquiredTypesStore.refresh();
watch(() => acquiredTypesStore.acquiredTypes, async itms => { watch(() => acquiredTypesStore.acquiredTypes, async itms => {
if (itms.length === 0) { if (itms.length === 0) {
return; return;
@@ -34,6 +35,9 @@ watch(() => acquiredTypesStore.acquiredTypes, async itms => {
<template> <template>
<div class="mt-4"> <div class="mt-4">
<div class="flex">
<button class="ms-auto" @click="refresh">Refresh</button>
</div>
<template v-if="items.length > 0"> <template v-if="items.length > 0">
<AcquisitionResultTable :items="items" @buy="(types, price, buy, sell) => buyModal?.open(types[0].type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="types => sellModal?.open(types)" ignoredColums="date" /> <AcquisitionResultTable :items="items" @buy="(types, price, buy, sell) => buyModal?.open(types[0].type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="types => sellModal?.open(types)" ignoredColums="date" />
<BuyModal ref="buyModal" /> <BuyModal ref="buyModal" />

View File

@@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { Modal, ProgressBar } from "@/components";
import { MarketType, MarketTypeInput, MarketTypePrice, getHistory, getMarketTypes, useApraisalStore } from "@/market"; import { MarketType, MarketTypeInput, MarketTypePrice, getHistory, getMarketTypes, useApraisalStore } from "@/market";
import { BuyModal } from '@/market/acquisition'; import { BuyModal } from '@/market/acquisition';
import { TrackingResult, TrackingResultTable, createResult, useMarketTrackingStore } from '@/market/tracking'; import { TrackingResult, TrackingResultTable, createResult, useMarketTrackingStore } from '@/market/tracking';
@@ -56,10 +57,6 @@ watch(() => marketTrackingStore.types, async t => {
const prices = await apraisalStore.getPrices(await getMarketTypes(typesToLoad)); const prices = await apraisalStore.getPrices(await getMarketTypes(typesToLoad));
items.value = [
...items.value
];
typesToLoad.forEach(async i => items.value.push(await createResult(i, prices.find(p => p.type.id === i) as MarketTypePrice))); typesToLoad.forEach(async i => items.value.push(await createResult(i, prices.find(p => p.type.id === i) as MarketTypePrice)));
}, { immediate: true }); }, { immediate: true });
</script> </script>
@@ -76,5 +73,10 @@ watch(() => marketTrackingStore.types, async t => {
<hr /> <hr />
<TrackingResultTable :items="items" @buy="(type, buy, sell) => buyModal?.open(type, { 'Buy': buy, 'Sell': sell })" @remove="removeItem" /> <TrackingResultTable :items="items" @buy="(type, buy, sell) => buyModal?.open(type, { 'Buy': buy, 'Sell': sell })" @remove="removeItem" />
<BuyModal ref="buyModal" /> <BuyModal ref="buyModal" />
<Modal :open="items.length > 0 && items.length < marketTrackingStore.types.length">
<div class="ms-auto me-auto mb-2 w-96">
<ProgressBar :value="items.length" :total="marketTrackingStore.types.length" />
</div>
</Modal>
</template> </template>
</template> </template>

View File

@@ -103,7 +103,7 @@ watch(useRoute(), async route => {
</div> </div>
<div v-if="result" class="mb-4"> <div v-if="result" class="mb-4">
<span>Market Info:</span> <span>Market Info:</span>
<TrackingResultTable :items="[result]" infoOnly ignoredColums="name" /> <TrackingResultTable :items="[result]" infoOnly :ignoredColums="['name', 'acquisitions']" />
</div> </div>
<div v-if="acquisitions && acquisitions.length > 0"> <div v-if="acquisitions && acquisitions.length > 0">
<span>Acquisitions:</span> <span>Acquisitions:</span>

View File

@@ -1,22 +0,0 @@
export class Preference<T> {
private key: string;
private description: string;
private value?: T;
private defaultValue?: T;
constructor(key: string, description: string, defaultValue?: T) {
this.key = key;
this.description = description;
this.defaultValue = defaultValue;
this.value = this.load();
}
private load() {
const value = localStorage.getItem(this.key);
if (value) {
return JSON.parse(value);
}
return this.defaultValue;
}
}

View File

@@ -49,6 +49,9 @@
@apply bg-emerald-500 hover:bg-emerald-600; @apply bg-emerald-500 hover:bg-emerald-600;
} }
} }
tfoot>tr>td {
@apply font-semibold;
}
::-webkit-scrollbar { ::-webkit-scrollbar {