mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 00:36:14 -04:00
feat(new-tool): added an ETA calculator
This commit is contained in:
parent
d5738e1aef
commit
125a50215a
5 changed files with 112 additions and 1 deletions
|
@ -51,9 +51,11 @@ import {
|
|||
NScrollbar,
|
||||
NGradientText,
|
||||
NCode,
|
||||
NDatePicker,
|
||||
} from 'naive-ui';
|
||||
|
||||
const components = [
|
||||
NDatePicker,
|
||||
NCode,
|
||||
NGradientText,
|
||||
NScrollbar,
|
||||
|
|
16
src/tools/eta-calculator/eta-calculator.service.ts
Normal file
16
src/tools/eta-calculator/eta-calculator.service.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { formatDuration } from 'date-fns';
|
||||
|
||||
export function formatMsDuration(duration: number) {
|
||||
const ms = Math.floor(duration % 1000);
|
||||
const secs = Math.floor(((duration - ms) / 1000) % 60);
|
||||
const mins = Math.floor((((duration - ms) / 1000 - secs) / 60) % 60);
|
||||
const hrs = Math.floor((((duration - ms) / 1000 - secs) / 60 - mins) / 60);
|
||||
|
||||
return (
|
||||
formatDuration({
|
||||
hours: hrs,
|
||||
minutes: mins,
|
||||
seconds: secs,
|
||||
}) + (ms > 0 ? ` ${ms} ms` : '')
|
||||
);
|
||||
}
|
80
src/tools/eta-calculator/eta-calculator.vue
Normal file
80
src/tools/eta-calculator/eta-calculator.vue
Normal file
|
@ -0,0 +1,80 @@
|
|||
<template>
|
||||
<div>
|
||||
<n-text depth="3" style="text-align: justify; width: 100%; display: inline-block">
|
||||
With a concrete example, if you wash 3 plates in 5 minutes and you have 500 plates to wash, it will take you 5
|
||||
hours and 10 minutes to wash them all, and if you start now, you'll end
|
||||
{{ endAt }}.
|
||||
</n-text>
|
||||
<br />
|
||||
<n-divider />
|
||||
<n-space item-style="flex:1 1 0">
|
||||
<div>
|
||||
<n-space item-style="flex:1 1 0">
|
||||
<n-form-item label="Amount of element to consume">
|
||||
<n-input-number v-model:value="unitCount" />
|
||||
</n-form-item>
|
||||
<n-form-item label="The consumption started at">
|
||||
<n-date-picker v-model:value="startedAt" type="datetime" />
|
||||
</n-form-item>
|
||||
</n-space>
|
||||
|
||||
<n-form-item label="Amount of unit consumed by time span" :show-feedback="false">
|
||||
<n-input-number v-model:value="unitPerTimeSpan" />
|
||||
<span style="margin: 0 10px">in</span>
|
||||
<n-input-group>
|
||||
<n-input-number v-model:value="timeSpan" />
|
||||
<n-select
|
||||
v-model:value="timeSpanUnitMultiplier"
|
||||
:options="[
|
||||
{ label: 'milliseconds', value: 1 },
|
||||
{ label: 'seconds', value: 1000 },
|
||||
{ label: 'minutes', value: 1000 * 60 },
|
||||
{ label: 'hours', value: 1000 * 60 * 60 },
|
||||
{ label: 'days', value: 1000 * 60 * 60 * 24 },
|
||||
]"
|
||||
></n-select>
|
||||
</n-input-group>
|
||||
</n-form-item>
|
||||
|
||||
<n-divider />
|
||||
<n-space vertical>
|
||||
<n-card>
|
||||
<n-statistic label="Total duration">{{ formatMsDuration(durationMs) }}</n-statistic>
|
||||
</n-card>
|
||||
<n-card>
|
||||
<n-statistic label="It will end ">{{ endAt }}</n-statistic>
|
||||
</n-card>
|
||||
</n-space>
|
||||
</div>
|
||||
</n-space>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { addMilliseconds, formatRelative } from 'date-fns';
|
||||
import { enGB } from 'date-fns/locale';
|
||||
import { computed, ref } from 'vue';
|
||||
import { formatMsDuration } from './eta-calculator.service';
|
||||
|
||||
const unitCount = ref(3 * 62);
|
||||
const unitPerTimeSpan = ref(3);
|
||||
const timeSpan = ref(5);
|
||||
const timeSpanUnitMultiplier = ref(60000);
|
||||
const startedAt = ref(Date.now());
|
||||
|
||||
const durationMs = computed(() => {
|
||||
const timeSpanMs = timeSpan.value * timeSpanUnitMultiplier.value;
|
||||
|
||||
return unitCount.value / (unitPerTimeSpan.value / timeSpanMs);
|
||||
});
|
||||
const endAt = computed(() =>
|
||||
formatRelative(addMilliseconds(startedAt.value, durationMs.value), Date.now(), { locale: enGB }),
|
||||
);
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.n-input-number,
|
||||
.n-date-picker {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
12
src/tools/eta-calculator/index.ts
Normal file
12
src/tools/eta-calculator/index.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { Hourglass } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'ETA calculator',
|
||||
path: '/eta-calculator',
|
||||
description:
|
||||
'An ETA (Estimated Time of Arrival) calculator to know the approximate end time of a task, for example the moment of ending of a download.',
|
||||
keywords: ['eta', 'calculator', 'estimated', 'time', 'arrival', 'average'],
|
||||
component: () => import('./eta-calculator.vue'),
|
||||
icon: Hourglass,
|
||||
});
|
|
@ -11,6 +11,7 @@ import { tool as crontabGenerator } from './crontab-generator';
|
|||
import { tool as dateTimeConverter } from './date-time-converter';
|
||||
import { tool as deviceInformation } from './device-information';
|
||||
import { tool as cypher } from './encryption';
|
||||
import { tool as etaCalculator } from './eta-calculator';
|
||||
import { tool as gitMemo } from './git-memo';
|
||||
import { tool as hashText } from './hash-text';
|
||||
import { tool as htmlEntities } from './html-entities';
|
||||
|
@ -59,7 +60,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||
{
|
||||
name: 'Math',
|
||||
icon: LockOpen,
|
||||
components: [mathEvaluator],
|
||||
components: [mathEvaluator, etaCalculator],
|
||||
},
|
||||
{
|
||||
name: 'Measurement',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue