Compare commits
18 Commits
fff01ff30f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e81fdc24bb | |||
| 778de8ca14 | |||
| 00c37c0a37 | |||
| a56580ce27 | |||
| 11f886cd71 | |||
| ac07236936 | |||
| 9aa37b355e | |||
| 12ad7d36ff | |||
| c77a6ff811 | |||
| 0a82fca6d3 | |||
| 1e57e7c33e | |||
| c484948a5e | |||
| 4748b15cc4 | |||
| 9ccba70ede | |||
| 1868b3e248 | |||
| 9f2627faf8 | |||
| a7b1fb902c | |||
| 6afce2ef58 |
2278
package-lock.json
generated
2278
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,7 @@
|
||||
"@vueuse/integrations": "^10.2.1",
|
||||
"axios": "^1.4.0",
|
||||
"axios-rate-limit": "^1.3.1",
|
||||
"gemory": "file:",
|
||||
"loglevel": "^1.8.1",
|
||||
"loglevel-plugin-prefix": "^0.8.4",
|
||||
"oidc-client-ts": "^3.0.1",
|
||||
@@ -30,9 +31,9 @@
|
||||
"postcss": "^8.4.27",
|
||||
"tailwindcss": "^3.3.3",
|
||||
"typescript": "^5.0.2",
|
||||
"vite": "^5.2.11",
|
||||
"vite": "^6.3.5",
|
||||
"vite-plugin-runtime-env": "^0.1.1",
|
||||
"vitest": "^1.6.0",
|
||||
"vitest": "^3.1.3",
|
||||
"vue-tsc": "^2.0.18"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import log from "loglevel";
|
||||
import { Log, User, UserManager } from "oidc-client-ts";
|
||||
import { Log, User, UserManager, WebStorageStateStore } from "oidc-client-ts";
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
@@ -11,11 +11,13 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
client_id: import.meta.env.VITE_AUTH_CLIENT_ID,
|
||||
client_secret: import.meta.env.VITE_AUTH_CLIENT_SECRET,
|
||||
redirect_uri: import.meta.env.VITE_AUTH_REDIRECT_URI,
|
||||
scope: import.meta.env.VITE_AUTH_SCOPE
|
||||
scope: import.meta.env.VITE_AUTH_SCOPE,
|
||||
stateStore: new WebStorageStateStore({ store: window.localStorage }),
|
||||
userStore: new WebStorageStateStore({ store: window.localStorage })
|
||||
});
|
||||
|
||||
const user = ref<User>();
|
||||
const isLoggedIn = computed(() => !!user.value);
|
||||
const isLoggedIn = computed(() => user.value?.expired === false);
|
||||
const accessToken = computed(() => user.value?.access_token);
|
||||
const username = computed(() => user.value?.profile.name ?? "");
|
||||
const userId = computed(() => user.value?.profile.sub ?? "");
|
||||
|
||||
@@ -1,24 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { vOnClickOutside } from '@vueuse/components';
|
||||
import { useEventListener, useVModel } from '@vueuse/core';
|
||||
import { useEventListener } from '@vueuse/core';
|
||||
import { watch } from 'vue';
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
}
|
||||
const open = defineModel('open', { default: false });
|
||||
|
||||
interface Emit {
|
||||
(e: 'update:open', value: boolean): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
open: false,
|
||||
});
|
||||
const emit = defineEmits<Emit>();
|
||||
|
||||
const isOpen = useVModel(props, 'open', emit, {passive: true});
|
||||
|
||||
watch(isOpen, value => {
|
||||
watch(open, value => {
|
||||
if (value) {
|
||||
document.body.classList.add('overflow-hidden');
|
||||
} else {
|
||||
@@ -27,18 +14,18 @@ watch(isOpen, value => {
|
||||
});
|
||||
useEventListener('keyup', e => {
|
||||
if (e.key === 'Escape') {
|
||||
isOpen.value = false;
|
||||
open.value = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="fade">
|
||||
<template v-if="isOpen">
|
||||
<template v-if="open">
|
||||
<div class="fixed inset-0 z-10">
|
||||
<div class="absolute bg-black opacity-80 inset-0 z-0" />
|
||||
<div class="absolute grid inset-0">
|
||||
<div class="justify-self-center m-auto" v-on-click-outside="() => isOpen = false">
|
||||
<div class="justify-self-center m-auto" v-on-click-outside="() => open = false">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
19
src/components/ProgressBar.vue
Normal file
19
src/components/ProgressBar.vue
Normal 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>
|
||||
@@ -1,24 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { useVModel } from '@vueuse/core';
|
||||
|
||||
interface Props {
|
||||
modelValue?: boolean;
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false
|
||||
});
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const value = useVModel(props, 'modelValue', emit);
|
||||
const modelValue = defineModel({ default: false });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<label class="flex items-center relative w-max cursor-pointer select-none">
|
||||
<input type="checkbox" class="appearance-none transition-colors cursor-pointer w-10 h-5 rounded-full checked:bg-emerald-500 peer" v-model="value" />
|
||||
<input type="checkbox" class="appearance-none transition-colors cursor-pointer w-10 h-5 rounded-full checked:bg-emerald-500 peer" v-model="modelValue" />
|
||||
<span class="w-5 h-5 right-5 absolute rounded-full transform transition-transform bg-slate-100 peer-checked:bg-emerald-200" />
|
||||
</label>
|
||||
</template>
|
||||
|
||||
@@ -2,6 +2,7 @@ export { default as ClipboardButton } from './ClipboardButton.vue';
|
||||
export { default as Dropdown } from './Dropdown.vue';
|
||||
export { default as LoadingSpinner } from './LoadingSpinner.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 Tooltip } from './tooltip/Tooltip.vue';
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ interface Props {
|
||||
list?: any[];
|
||||
itemHeight: number;
|
||||
headerHeight?: number;
|
||||
bottom?: string;
|
||||
footerHeight?: number;
|
||||
bottom?: string; // FIXME: use css variable
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +36,16 @@ const computedHeaderHeight = computed(() => {
|
||||
|
||||
return h + 'px';
|
||||
})
|
||||
const computedFooterHeight = computed(() => {
|
||||
const h = props.footerHeight ?? 0;
|
||||
|
||||
return h + 'px';
|
||||
})
|
||||
const computedWrapperProps = computed(() => ({
|
||||
...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(() => {
|
||||
@@ -72,6 +78,10 @@ div.table-container {
|
||||
@apply sticky z-10;
|
||||
top: -1px;
|
||||
}
|
||||
>tfoot {
|
||||
@apply bg-slate-600 sticky z-10;
|
||||
bottom: -1px;
|
||||
}
|
||||
>*>tr, >*>tr>td {
|
||||
height: v-bind(itemHeightStyle);
|
||||
}
|
||||
@@ -79,6 +89,7 @@ div.table-container {
|
||||
}
|
||||
&::-webkit-scrollbar-track {
|
||||
margin-top: v-bind(computedHeaderHeight);
|
||||
margin-bottom: v-bind(computedFooterHeight);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,23 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { vElementHover } from '@vueuse/components';
|
||||
import { useElementBounding, useVModel } from '@vueuse/core';
|
||||
import { useElementBounding } from '@vueuse/core';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useSharedWindowSize } from './tooltip';
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
}
|
||||
|
||||
interface Emit {
|
||||
(e: 'update:open', value: boolean): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
open: false,
|
||||
});
|
||||
const emit = defineEmits<Emit>();
|
||||
|
||||
const isOpen = useVModel(props, 'open', emit, {passive: true});
|
||||
const open = defineModel('open', { default: false });
|
||||
|
||||
const { width, height } = useSharedWindowSize();
|
||||
const mainDiv = ref<HTMLDivElement | null>(null);
|
||||
@@ -39,16 +26,16 @@ const positions = computed(() => {
|
||||
|
||||
<template>
|
||||
<div ref="mainDiv" clas="flex flex-col items-center justify-center" :class="{
|
||||
'open': isOpen,
|
||||
'open': open,
|
||||
'tooltip-top': positions.includes('top'),
|
||||
'tooltip-bottom': positions.includes('bottom'),
|
||||
'tooltip-left': positions.includes('left'),
|
||||
'tooltip-right': positions.includes('right')
|
||||
}">
|
||||
<div v-element-hover="(h: boolean) => isOpen = h" class="m-auto header">
|
||||
<div v-element-hover="(h: boolean) => open = h" class="m-auto header">
|
||||
<slot name="header" />
|
||||
</div>
|
||||
<div v-if="isOpen" class="m-auto">
|
||||
<div v-if="open" class="m-auto">
|
||||
<div class="z-10 relative">
|
||||
<div class="absolute">
|
||||
<slot />
|
||||
|
||||
@@ -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) {
|
||||
throw new Error("Not logged in");
|
||||
await authStore.redirect();
|
||||
}
|
||||
|
||||
|
||||
const accessToken = authStore.accessToken;
|
||||
|
||||
if (accessToken) {
|
||||
@@ -29,6 +29,12 @@ marbasAxiosInstance.interceptors.request.use(r => {
|
||||
})
|
||||
logResource(marbasAxiosInstance)
|
||||
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 results = r.data?.results;
|
||||
|
||||
|
||||
35
src/market/RegionalMarketCache.spec.ts
Normal file
35
src/market/RegionalMarketCache.spec.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import { RegionalMarketCache } from './RegionalMarketCache'
|
||||
|
||||
describe('RegionalMarketCache', () => {
|
||||
test('should cache and retrieve values', async () => {
|
||||
const cache = new RegionalMarketCache<string>(1000)
|
||||
|
||||
cache.set(1, 1, 'test')
|
||||
expect(cache.get(1, 1)).toBe('test')
|
||||
})
|
||||
|
||||
test('should remove values', async () => {
|
||||
const cache = new RegionalMarketCache<string>(1000)
|
||||
|
||||
cache.set(1, 1, 'test')
|
||||
cache.remove(1, 1)
|
||||
expect(cache.get(1, 1)).toBeUndefined()
|
||||
})
|
||||
|
||||
test('should compute values if absent', async () => {
|
||||
const cache = new RegionalMarketCache<string>(1000)
|
||||
const value = await cache.computeIfAbsent(1, 1, () => Promise.resolve('test'))
|
||||
|
||||
expect(value).toBe('test')
|
||||
expect(cache.get(1, 1)).toBe('test')
|
||||
})
|
||||
|
||||
test('should expire values', async () => {
|
||||
const cache = new RegionalMarketCache<string>(1)
|
||||
|
||||
cache.set(1, 1, 'test')
|
||||
await new Promise(resolve => setTimeout(resolve, 10))
|
||||
expect(cache.get(1, 1)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
50
src/market/RegionalMarketCache.ts
Normal file
50
src/market/RegionalMarketCache.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
class CacheEntry<T> {
|
||||
public value: T;
|
||||
public expiration: Date;
|
||||
|
||||
constructor(value: T, expiration: Date) {
|
||||
this.value = value;
|
||||
this.expiration = expiration;
|
||||
}
|
||||
}
|
||||
|
||||
export type ExpirationSupplier<T> = (v: T) => Date;
|
||||
|
||||
export class RegionalMarketCache<T> {
|
||||
private cache: Record<number, Record<number, CacheEntry<T>>>;
|
||||
private expirationSupplier: (v: T) => Date;
|
||||
|
||||
constructor(expiration: ExpirationSupplier<T> | number) {
|
||||
this.cache = {};
|
||||
this.expirationSupplier = expiration instanceof Function ? expiration : () => new Date(Date.now() + expiration);
|
||||
}
|
||||
|
||||
public get(regionId: number, typeId: number): T | undefined {
|
||||
const entry = this.cache[regionId]?.[typeId];
|
||||
|
||||
if (entry && entry.expiration > new Date()) {
|
||||
return entry.value;
|
||||
}
|
||||
this.remove(regionId, typeId);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public set(regionId: number, typeId: number, value: T): void {
|
||||
this.cache[regionId] = this.cache[regionId] ?? {};
|
||||
this.cache[regionId][typeId] = new CacheEntry(value, this.expirationSupplier(value));
|
||||
}
|
||||
|
||||
public remove(regionId: number, typeId: number): void {
|
||||
delete this.cache[regionId]?.[typeId];
|
||||
}
|
||||
|
||||
public async computeIfAbsent(regionId: number, typeId: number, supplier: () => (Promise<T> | T)): Promise<T> {
|
||||
let value = this.get(regionId, typeId);
|
||||
|
||||
if (!value) {
|
||||
value = await supplier();
|
||||
this.set(regionId, typeId, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { LoadingSpinner, Tooltip } from '@/components';
|
||||
import { formatIsk } from '@/formaters';
|
||||
import { getHistory, getHistoryQuartils, jitaId } from '@/market';
|
||||
import { getHistory, getHistoryQuartils } from '@/market';
|
||||
import { ArrowTrendingDownIcon, ArrowTrendingUpIcon } from '@heroicons/vue/24/outline';
|
||||
import { computedAsync } from '@vueuse/core';
|
||||
import { ref, watchEffect } from 'vue';
|
||||
@@ -22,7 +22,7 @@ const q1 = ref(0);
|
||||
const median = ref(0);
|
||||
const q3 = ref(0);
|
||||
const lineColor = ref('');
|
||||
const history = computedAsync(() => getHistory(jitaId, props.id), []);
|
||||
const history = computedAsync(() => getHistory(props.id), []);
|
||||
|
||||
watchEffect(async () => {
|
||||
if (!open.value || !props.id) {
|
||||
|
||||
@@ -120,12 +120,39 @@ const { sortedArray, headerProps, showColumn } = useSort<Result>(computed(() =>
|
||||
})
|
||||
const getLineColor = (result: Result) => {
|
||||
if (result.precentProfit >= (threshold.value / 100)) {
|
||||
return 'line-green';
|
||||
return 'line-green';
|
||||
} else if (result.precentProfit < 0) {
|
||||
return 'line-red';
|
||||
}
|
||||
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>
|
||||
|
||||
<template>
|
||||
@@ -142,7 +169,7 @@ const getLineColor = (result: Result) => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<VirtualScrollTable :list="sortedArray" :itemHeight="33" bottom="1rem">
|
||||
<VirtualScrollTable :list="sortedArray" :itemHeight="33" :footerHeight="!!total ? 33 : 0" bottom="1rem">
|
||||
<template #default="{ list }">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -178,6 +205,37 @@ const getLineColor = (result: Result) => {
|
||||
</td>
|
||||
</tr>
|
||||
</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 #empty>
|
||||
<div class="text-center mt-4">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { marbasAxiosInstance, MarbasObject } from "@/marbas";
|
||||
import { AxiosResponse } from "axios";
|
||||
import log from "loglevel";
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
@@ -12,9 +13,19 @@ export type MarbasAcquiredType = MarbasObject & {
|
||||
price: number;
|
||||
date: Date;
|
||||
source: AcquiredTypeSource;
|
||||
user: number;
|
||||
}
|
||||
|
||||
type RawMarbasAcquiredType = Omit<MarbasAcquiredType, 'date'> & {
|
||||
date: string;
|
||||
}
|
||||
|
||||
type InsertableRawMarbasAcquiredType = Omit<MarbasAcquiredType, 'id' | 'date'>;
|
||||
|
||||
const mapRawMarbasAcquiredType = (raw: RawMarbasAcquiredType): MarbasAcquiredType => ({
|
||||
...raw,
|
||||
date: raw.date ? new Date(raw.date) : new Date()
|
||||
});
|
||||
|
||||
const endpoint = '/api/acquisitions/';
|
||||
|
||||
export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
||||
@@ -22,14 +33,13 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
||||
|
||||
const types = computed(() => acquiredTypes.value.filter(item => item.remaining > 0));
|
||||
const addAcquiredType = async (type: number, quantity: number, price: number, source?: AcquiredTypeSource) => {
|
||||
const newItem = (await marbasAxiosInstance.post<MarbasAcquiredType>(endpoint, {
|
||||
const newItem = mapRawMarbasAcquiredType((await marbasAxiosInstance.post<RawMarbasAcquiredType, AxiosResponse<RawMarbasAcquiredType>, InsertableRawMarbasAcquiredType>(endpoint, {
|
||||
type: type,
|
||||
quantity: quantity,
|
||||
remaining: quantity,
|
||||
price: price,
|
||||
date: new Date(),
|
||||
source: source ?? 'misc',
|
||||
})).data
|
||||
})).data);
|
||||
|
||||
acquiredTypes.value = [...acquiredTypes.value, newItem];
|
||||
log.info(`Acquired type ${newItem.id} with quantity ${newItem.quantity} and price ${newItem.price}`, newItem);
|
||||
@@ -56,8 +66,10 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
||||
await marbasAxiosInstance.put(`${endpoint}${item.id}/`, item);
|
||||
log.info(`Acquired type ${item.id} remaining: ${item.remaining}`, item);
|
||||
};
|
||||
|
||||
marbasAxiosInstance.get<MarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data.map(item => ({ ...item, date: new Date(item.date) })));
|
||||
|
||||
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 };
|
||||
});
|
||||
@@ -1,15 +1,11 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { RegionalMarketCache } from '../RegionalMarketCache';
|
||||
import { jitaId } from '../market';
|
||||
import { MarketType } from "../type";
|
||||
import { MarketTypePrice } from './MarketTypePrice';
|
||||
import { getEvepraisalPrices } from './evepraisal';
|
||||
import { getfuzzworkPrices } from './fuzzwork';
|
||||
|
||||
type MarketTypePriceCache = {
|
||||
price: MarketTypePrice,
|
||||
date: Date
|
||||
}
|
||||
|
||||
const cacheDuration = 1000 * 60 * 5; // 5 minutes
|
||||
const priceGetters = {
|
||||
evepraisal: getEvepraisalPrices,
|
||||
@@ -17,21 +13,21 @@ const priceGetters = {
|
||||
}
|
||||
|
||||
export const useApraisalStore = defineStore('appraisal', () => {
|
||||
const cache = ref<Record<number, MarketTypePriceCache>>({});
|
||||
const cache: RegionalMarketCache<MarketTypePrice> = new RegionalMarketCache(cacheDuration);
|
||||
|
||||
const getPricesUncached = priceGetters.fuzzwork;
|
||||
|
||||
const getPrice = async (type: MarketType): Promise<MarketTypePrice> => (await getPrices([type]))[0];
|
||||
const getPrices = async (types: MarketType[]): Promise<MarketTypePrice[]> => {
|
||||
const now = new Date();
|
||||
const getPrice = async (type: MarketType, regionId?: number): Promise<MarketTypePrice> => (await getPrices([type], regionId))[0];
|
||||
const getPrices = async (types: MarketType[], regionId?: number): Promise<MarketTypePrice[]> => {
|
||||
const cached: MarketTypePrice[] = [];
|
||||
const uncached: MarketType[] = [];
|
||||
const rId = regionId ?? jitaId;
|
||||
|
||||
types.forEach(t => {
|
||||
const cachedPrice = cache.value[t.id];
|
||||
const cachedPrice = cache.get(rId, t.id);
|
||||
|
||||
if (cachedPrice && now.getTime() - cachedPrice.date.getTime() < cacheDuration) {
|
||||
cached.push(cachedPrice.price);
|
||||
if (cachedPrice) {
|
||||
cached.push(cachedPrice);
|
||||
} else {
|
||||
uncached.push(t);
|
||||
}
|
||||
@@ -40,8 +36,8 @@ export const useApraisalStore = defineStore('appraisal', () => {
|
||||
if (uncached.length > 0) {
|
||||
const prices = await getPricesUncached(uncached);
|
||||
|
||||
prices.forEach(p => cache.value[p.type.id] = { price: p, date: now });
|
||||
return [...cached, ...prices];
|
||||
prices.forEach(p => cache.set(rId, p.type.id, p));
|
||||
return [ ...cached, ...prices ];
|
||||
}
|
||||
return cached;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { esiAxiosInstance } from "@/service";
|
||||
import { RegionalMarketCache } from '../RegionalMarketCache';
|
||||
import { jitaId } from "../market";
|
||||
|
||||
|
||||
export type EsiMarketOrderHistory = {
|
||||
@@ -11,16 +13,18 @@ export type EsiMarketOrderHistory = {
|
||||
}
|
||||
|
||||
// TODO use pinia store
|
||||
const historyCache: { [key: number]: { [key: number]: EsiMarketOrderHistory[] } } = {};
|
||||
const historyCache: RegionalMarketCache<EsiMarketOrderHistory[]> = new RegionalMarketCache(() => {
|
||||
const date = new Date();
|
||||
|
||||
export const getHistory = async (regionId: number, tyeId: number): Promise<EsiMarketOrderHistory[]> => {
|
||||
if (historyCache[regionId]?.[tyeId]) {
|
||||
return historyCache[regionId][tyeId];
|
||||
if (date.getUTCHours() >= 11) {
|
||||
date.setUTCDate(date.getUTCDate() + 1);
|
||||
}
|
||||
date.setUTCHours(11, 0, 0, 0);
|
||||
return date;
|
||||
});
|
||||
|
||||
const value = (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data;
|
||||
export const getHistory = async (typeId: number, regionId?: number): Promise<EsiMarketOrderHistory[]> => {
|
||||
const rId = regionId ?? jitaId;
|
||||
|
||||
historyCache[regionId] = historyCache[regionId] ?? {};
|
||||
historyCache[regionId][tyeId] = value;
|
||||
return value;
|
||||
return historyCache.computeIfAbsent(rId, typeId, async () => (await esiAxiosInstance.get(`/markets/${rId}/history/`, { params: { type_id: typeId } })).data);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './RegionalMarketCache';
|
||||
export * from './history';
|
||||
export * from './tax';
|
||||
export * from './type';
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
|
||||
export const jitaId = 10000002;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { getHistoryQuartils, MarketType, MarketTypeLabel, TaxInput, useMarketTax
|
||||
import { BookmarkSlashIcon, ShoppingCartIcon } from '@heroicons/vue/24/outline';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useAcquiredTypesStore } from '../acquisition';
|
||||
import { TrackingResult } from './tracking';
|
||||
|
||||
type Result = {
|
||||
@@ -17,6 +18,7 @@ type Result = {
|
||||
q1: number;
|
||||
median: number;
|
||||
q3: number;
|
||||
acquisitions: number;
|
||||
profit: number;
|
||||
score: number;
|
||||
}
|
||||
@@ -44,6 +46,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
defineEmits<Emits>();
|
||||
|
||||
const marketTaxStore = useMarketTaxStore();
|
||||
const acquiredTypesStore = useAcquiredTypesStore();
|
||||
|
||||
const days = useStorage('market-tracking-days', 365);
|
||||
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 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 acquisitions = columnsToIgnore.value.includes('acquisitions') ? 0 : acquiredTypesStore.acquiredTypes
|
||||
.filter(t => t.type === r.type.id)
|
||||
.reduce((a, b) => a + b.remaining, 0);
|
||||
|
||||
return {
|
||||
type: r.type,
|
||||
@@ -73,6 +79,7 @@ const { sortedArray, headerProps, showColumn } = useSort<Result>(computed(() =>
|
||||
q1: quartils.q1,
|
||||
median: quartils.median,
|
||||
q3: quartils.q3,
|
||||
acquisitions,
|
||||
profit,
|
||||
score
|
||||
};
|
||||
@@ -128,6 +135,7 @@ const getLineColor = (result: Result) => {
|
||||
<SortableHeader v-bind="headerProps" sortKey="q3">Q3</SortableHeader>
|
||||
<SortableHeader v-bind="headerProps" sortKey="profit">Profit</SortableHeader>
|
||||
<SortableHeader v-bind="headerProps" sortKey="score">Score</SortableHeader>
|
||||
<SortableHeader v-bind="headerProps" sortKey="acquisitions">Acquisitions</SortableHeader>
|
||||
<SortableHeader v-bind="headerProps" sortKey="buttons" unsortable />
|
||||
</tr>
|
||||
</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('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('acquisitions')" class="text-right">{{ r.data.acquisitions }}</td>
|
||||
<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="Untrack" @click="$emit('remove', r.data.type)"><BookmarkSlashIcon /></button>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { marbasAxiosInstance, MarbasObject } from "@/marbas";
|
||||
import { EsiMarketOrderHistory, getHistory, jitaId, MarketType, MarketTypePrice } from "@/market";
|
||||
import { EsiMarketOrderHistory, getHistory, MarketType, MarketTypePrice } from "@/market";
|
||||
import log from "loglevel";
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
@@ -47,4 +47,4 @@ export const useMarketTrackingStore = defineStore('marketTracking', () => {
|
||||
return { types, addType, removeType };
|
||||
});
|
||||
|
||||
export const createResult = async (id: number, price: MarketTypePrice): Promise<TrackingResult> => ({ history: await getHistory(jitaId, id), ...price });
|
||||
export const createResult = async (id: number, price: MarketTypePrice): Promise<TrackingResult> => ({ history: await getHistory(id), ...price });
|
||||
@@ -1,25 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { vOnClickOutside } from '@vueuse/components';
|
||||
import { useVirtualList, useVModel } from '@vueuse/core';
|
||||
import { useVirtualList } from '@vueuse/core';
|
||||
import log from 'loglevel';
|
||||
import { nextTick, ref, watch, watchEffect } from 'vue';
|
||||
import { MarketType, searchMarketTypes } from './MarketType';
|
||||
import MarketTypeLabel from "./MarketTypeLabel.vue";
|
||||
|
||||
|
||||
interface Props {
|
||||
modelValue?: MarketType;
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value?: MarketType): void;
|
||||
(e: 'submit'): void;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const modelValue = defineModel<MarketType>();
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const value = useVModel(props, 'modelValue', emit);
|
||||
|
||||
const isOpen = ref(false);
|
||||
const name = ref('');
|
||||
const suggestions = ref<MarketType[]>([]);
|
||||
@@ -47,7 +40,7 @@ const moveUp = () => {
|
||||
}
|
||||
const select = (type?: MarketType) => {
|
||||
log.debug('Select:', type);
|
||||
value.value = type;
|
||||
modelValue.value = type;
|
||||
currentIndex.value = -1;
|
||||
suggestions.value = [];
|
||||
isOpen.value = false;
|
||||
@@ -62,18 +55,18 @@ const submit = async () => {
|
||||
|
||||
select(v);
|
||||
await nextTick();
|
||||
} else if (props.modelValue === undefined && suggestions.value.length > 0) {
|
||||
} else if (modelValue.value === undefined && suggestions.value.length > 0) {
|
||||
select(suggestions.value[0]);
|
||||
await nextTick();
|
||||
}
|
||||
|
||||
if (value.value === undefined) {
|
||||
if (modelValue.value === undefined) {
|
||||
return;
|
||||
}
|
||||
emit('submit');
|
||||
}
|
||||
|
||||
watch(() => props.modelValue, async v => {
|
||||
watch(() => modelValue.value, async v => {
|
||||
if (v === undefined) {
|
||||
name.value = '';
|
||||
} else {
|
||||
@@ -96,7 +89,7 @@ watchEffect(async () => {
|
||||
<template>
|
||||
<div @click="() => isOpen = true" v-on-click-outside="() => isOpen = false">
|
||||
<div class="fake-input">
|
||||
<img v-if="value?.id" :src="`https://images.evetech.net/types/${value.id}/icon?size=32`" alt="" />
|
||||
<img v-if="modelValue?.id" :src="`https://images.evetech.net/types/${modelValue.id}/icon?size=32`" alt="" />
|
||||
<input type="text" v-model="name" @keyup.enter="submit" @keyup.down="moveDown" @keyup.up="moveUp" />
|
||||
</div>
|
||||
<div v-if="suggestions.length > 1" class="z-20 absolute w-96">
|
||||
|
||||
@@ -17,14 +17,12 @@ withDefaults(defineProps<Props>(), {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="id || name">
|
||||
<img v-if="id" :src="`https://images.evetech.net/types/${id}/icon?size=32`" class="inline-block w-5 h-5 me-1" alt="" />
|
||||
<div v-if="id || name" class="flex flex-row">
|
||||
<img v-if="id" :src="`https://images.evetech.net/types/${id}/icon?size=32`" class="inline-block w-5 h-5 me-1 mt-1" alt="" />
|
||||
<template v-if="name">
|
||||
{{ name }}
|
||||
<RouterLink v-if="id" :to="{ name: 'market-types', params: { type: id } }" custom #default="{ navigate }">
|
||||
<button class="btn-icon me-1" title="Show item info" @click="navigate">
|
||||
<InformationCircleIcon />
|
||||
</button>
|
||||
<RouterLink v-if="id" :to="{ name: 'market-types', params: { type: id } }" class="button btn-icon ms-1 me-1 mt-1" title="Show item info">
|
||||
<InformationCircleIcon />
|
||||
</RouterLink>
|
||||
<ClipboardButton v-if="!hideCopy" :value="name" />
|
||||
</template>
|
||||
@@ -32,7 +30,7 @@ withDefaults(defineProps<Props>(), {
|
||||
</template>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
button:deep(>svg) {
|
||||
@apply relative top-0.5 !w-4 !h-4;
|
||||
button:deep(>svg), .button:deep(>svg) {
|
||||
@apply !w-4 !h-4;
|
||||
}
|
||||
</style>
|
||||
@@ -6,11 +6,12 @@ import { ref, watch } from 'vue';
|
||||
const buyModal = ref<typeof BuyModal>();
|
||||
const sellModal = ref<typeof SellModal>();
|
||||
|
||||
|
||||
const apraisalStore = useApraisalStore();
|
||||
const acquiredTypesStore = useAcquiredTypesStore();
|
||||
const items = ref<AcquiredType[]>([]);
|
||||
|
||||
const refresh = async () => await acquiredTypesStore.refresh();
|
||||
|
||||
watch(() => acquiredTypesStore.acquiredTypes, async itms => {
|
||||
if (itms.length === 0) {
|
||||
return;
|
||||
@@ -34,6 +35,9 @@ watch(() => acquiredTypesStore.acquiredTypes, async itms => {
|
||||
|
||||
<template>
|
||||
<div class="mt-4">
|
||||
<div class="flex">
|
||||
<button class="ms-auto" @click="refresh">Refresh</button>
|
||||
</div>
|
||||
<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" />
|
||||
<BuyModal ref="buyModal" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { MarketType, MarketTypeInput, MarketTypePrice, getHistory, getMarketTypes, jitaId, useApraisalStore } from "@/market";
|
||||
import { Modal, ProgressBar } from "@/components";
|
||||
import { MarketType, MarketTypeInput, MarketTypePrice, getHistory, getMarketTypes, useApraisalStore } from "@/market";
|
||||
import { BuyModal } from '@/market/acquisition';
|
||||
import { TrackingResult, TrackingResultTable, createResult, useMarketTrackingStore } from '@/market/tracking';
|
||||
import { ref, watch } from 'vue';
|
||||
@@ -15,7 +16,7 @@ const items = ref<TrackingResult[]>([]);
|
||||
const addOrRelaod = async (type: MarketType) => {
|
||||
const typeID = type.id;
|
||||
const [history, price] = await Promise.all([
|
||||
getHistory(jitaId, typeID),
|
||||
getHistory(typeID),
|
||||
apraisalStore.getPrice(type)
|
||||
]);
|
||||
const itm = {
|
||||
@@ -56,10 +57,7 @@ watch(() => marketTrackingStore.types, async t => {
|
||||
|
||||
const prices = await apraisalStore.getPrices(await getMarketTypes(typesToLoad));
|
||||
|
||||
items.value = [
|
||||
...items.value,
|
||||
...(await Promise.all(typesToLoad.map(i => 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 });
|
||||
</script>
|
||||
|
||||
@@ -75,5 +73,10 @@ watch(() => marketTrackingStore.types, async t => {
|
||||
<hr />
|
||||
<TrackingResultTable :items="items" @buy="(type, buy, sell) => buyModal?.open(type, { 'Buy': buy, 'Sell': sell })" @remove="removeItem" />
|
||||
<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>
|
||||
@@ -103,7 +103,7 @@ watch(useRoute(), async route => {
|
||||
</div>
|
||||
<div v-if="result" class="mb-4">
|
||||
<span>Market Info:</span>
|
||||
<TrackingResultTable :items="[result]" infoOnly ignoredColums="name" />
|
||||
<TrackingResultTable :items="[result]" infoOnly :ignoredColums="['name', 'acquisitions']" />
|
||||
</div>
|
||||
<div v-if="acquisitions && acquisitions.length > 0">
|
||||
<span>Acquisitions:</span>
|
||||
|
||||
@@ -1,24 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { useVModel } from '@vueuse/core';
|
||||
|
||||
interface Props {
|
||||
modelValue?: boolean;
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false
|
||||
});
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const value = useVModel(props, 'modelValue', emit);
|
||||
const modelValue = defineModel({ default: false });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<label class="flex items-center relative w-max cursor-pointer select-none">
|
||||
<input type="checkbox" class="appearance-none transition-colors cursor-pointer w-14 h-7 rounded-full" v-model="value" />
|
||||
<input type="checkbox" class="appearance-none transition-colors cursor-pointer w-14 h-7 rounded-full" v-model="modelValue" />
|
||||
<span class="absolute font-medium text-xs right-1"> Buy </span>
|
||||
<span class="absolute font-medium text-xs right-8"> Sell </span>
|
||||
<span class="w-7 h-7 right-7 absolute rounded-full transform transition-transform bg-slate-100" />
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { evepraisalAxiosInstance } from '@/market/appraisal/evepraisal';
|
||||
import { useVModel } from '@vueuse/core';
|
||||
|
||||
interface Props {
|
||||
name: string;
|
||||
modelValue?: string;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: string): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: ''
|
||||
});
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const value = useVModel(props, 'modelValue', emit);
|
||||
const modelValue = defineModel({ default: '' });
|
||||
defineProps<Props>();
|
||||
|
||||
const loadFromId = async (e: Event) => {
|
||||
const input = e.target as HTMLInputElement;
|
||||
@@ -31,7 +21,7 @@ const loadFromId = async (e: Event) => {
|
||||
return;
|
||||
}
|
||||
|
||||
value.value = JSON.stringify(response.data);
|
||||
modelValue.value = JSON.stringify(response.data);
|
||||
input.value = '';
|
||||
}
|
||||
</script>
|
||||
@@ -39,6 +29,6 @@ const loadFromId = async (e: Event) => {
|
||||
<template>
|
||||
<div class="flex-1 mx-1">
|
||||
<span>{{ name }}</span><input type="text" class="ms-2" @change="loadFromId" placeholder="id evepraisal" />
|
||||
<textarea class="mt-1" v-model="value" />
|
||||
<textarea class="mt-1" v-model="modelValue" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -49,6 +49,9 @@
|
||||
@apply bg-emerald-500 hover:bg-emerald-600;
|
||||
}
|
||||
}
|
||||
tfoot>tr>td {
|
||||
@apply font-semibold;
|
||||
}
|
||||
|
||||
|
||||
::-webkit-scrollbar {
|
||||
|
||||
Reference in New Issue
Block a user