mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 14:50:17 +03:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c65ad8ed6 | ||
|
|
0c63eb7ca4 | ||
|
|
73e97f97bb |
No files matched your search
Vendored
+5
-5
@@ -83,6 +83,7 @@ declare module '@vue/runtime-core' {
|
||||
GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default']
|
||||
'GitMemo.content': typeof import('./src/tools/git-memo/git-memo.content.md')['default']
|
||||
HashText: typeof import('./src/tools/hash-text/hash-text.vue')['default']
|
||||
HexFileConverter: typeof import('./src/tools/hex-file-converter/hex-file-converter.vue')['default']
|
||||
HmacGenerator: typeof import('./src/tools/hmac-generator/hmac-generator.vue')['default']
|
||||
'Home.page': typeof import('./src/pages/Home.page.vue')['default']
|
||||
HtmlEntities: typeof import('./src/tools/html-entities/html-entities.vue')['default']
|
||||
@@ -135,6 +136,9 @@ declare module '@vue/runtime-core' {
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||
NGi: typeof import('naive-ui')['NGi']
|
||||
NGrid: typeof import('naive-ui')['NGrid']
|
||||
NH1: typeof import('naive-ui')['NH1']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
@@ -142,10 +146,6 @@ declare module '@vue/runtime-core' {
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NStatistic: typeof import('naive-ui')['NStatistic']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
||||
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
||||
@@ -163,7 +163,7 @@ declare module '@vue/runtime-core' {
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default']
|
||||
SlaCalculator: typeof import('./src/tools/sla-calculator/sla-calculator.vue')['default']
|
||||
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
|
||||
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
|
||||
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
|
||||
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
|
||||
|
||||
+1
-4
@@ -42,7 +42,6 @@
|
||||
"@tiptap/pm": "2.1.6",
|
||||
"@tiptap/starter-kit": "2.1.6",
|
||||
"@tiptap/vue-3": "2.0.3",
|
||||
"@types/big.js": "^6.2.2",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@vicons/material": "^0.12.0",
|
||||
@@ -51,7 +50,6 @@
|
||||
"@vueuse/head": "^1.0.0",
|
||||
"@vueuse/router": "^10.0.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"big.js": "^6.2.2",
|
||||
"change-case": "^4.1.2",
|
||||
"colord": "^2.9.3",
|
||||
"composerize-ts": "^0.6.2",
|
||||
@@ -83,11 +81,9 @@
|
||||
"netmask": "^2.0.2",
|
||||
"node-forge": "^1.3.1",
|
||||
"oui-data": "^1.0.10",
|
||||
"parse-duration": "^1.1.0",
|
||||
"pdf-signature-reader": "^1.4.2",
|
||||
"pinia": "^2.0.34",
|
||||
"plausible-tracker": "^0.3.8",
|
||||
"pretty-ms": "^9.1.0",
|
||||
"qrcode": "^1.5.1",
|
||||
"randexp": "^0.5.3",
|
||||
"sql-formatter": "^13.0.0",
|
||||
@@ -143,6 +139,7 @@
|
||||
"unplugin-icons": "^0.17.0",
|
||||
"unplugin-vue-components": "^0.25.0",
|
||||
"vite": "^4.4.9",
|
||||
"vite-plugin-node-polyfills": "^0.22.0",
|
||||
"vite-plugin-pwa": "^0.16.0",
|
||||
"vite-plugin-vue-markdown": "^0.23.5",
|
||||
"vite-svg-loader": "^4.0.0",
|
||||
|
||||
Generated
+627
-37
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,7 @@
|
||||
import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types';
|
||||
import type { Ref } from 'vue';
|
||||
import type { MaybeRef, Ref } from 'vue';
|
||||
import _ from 'lodash';
|
||||
import { get } from '@vueuse/core';
|
||||
|
||||
export {
|
||||
getMimeTypeFromBase64,
|
||||
@@ -75,21 +76,11 @@ function downloadFromBase64({ sourceValue, filename, extension, fileMimeType }:
|
||||
}
|
||||
|
||||
function useDownloadFileFromBase64(
|
||||
{ source, filename, extension, fileMimeType }:
|
||||
{ source: Ref<string>; filename?: string; extension?: string; fileMimeType?: string }) {
|
||||
return {
|
||||
download() {
|
||||
downloadFromBase64({ sourceValue: source.value, filename, extension, fileMimeType });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function useDownloadFileFromBase64Refs(
|
||||
{ source, filename, extension }:
|
||||
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
||||
{ source: MaybeRef<string>; filename?: MaybeRef<string>; extension?: MaybeRef<string> }) {
|
||||
return {
|
||||
download() {
|
||||
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
||||
downloadFromBase64({ sourceValue: get(source), filename: get(filename), extension: get(extension) });
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -116,3 +107,13 @@ function previewImageFromBase64(base64String: string): HTMLImageElement {
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
function useDownloadFileFromBase64Refs(
|
||||
{ source, filename, extension }:
|
||||
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
||||
return {
|
||||
download() {
|
||||
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<script setup lang="ts">
|
||||
import { Buffer } from 'node:buffer';
|
||||
import type { Ref } from 'vue';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||
|
||||
const fileName = ref('');
|
||||
const fileExtension = ref('');
|
||||
const hexInput = ref('');
|
||||
const base64Input = computed(() => {
|
||||
const hexString = hexInput.value?.replace(/^(?:0x|&H|\\x)/gi, '').replace(/[^\da-f]/gi, '');
|
||||
try {
|
||||
return `data:application/octet-stream;base64,${Buffer.from(hexString, 'hex').toString('base64')}`;
|
||||
}
|
||||
catch {
|
||||
return '';
|
||||
}
|
||||
});
|
||||
const { download } = useDownloadFileFromBase64(
|
||||
{
|
||||
source: base64Input,
|
||||
filename: fileName,
|
||||
extension: fileExtension,
|
||||
});
|
||||
|
||||
function downloadFile() {
|
||||
try {
|
||||
download();
|
||||
}
|
||||
catch (_) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
function buf2hex(buffer: ArrayBuffer, separator: string): string {
|
||||
return [...new Uint8Array(buffer)]
|
||||
.map(x => x.toString(16).padStart(2, '0'))
|
||||
.join(separator);
|
||||
}
|
||||
|
||||
async function ReadFileAsHex(file: File, separator: string = ' '): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
resolve(buf2hex(reader.result as ArrayBuffer, separator));
|
||||
};
|
||||
reader.onerror = () => reject(reader.error?.toString());
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
}
|
||||
|
||||
const separator = useStorage('hex-converter:sep', ' ');
|
||||
const fileInput = ref() as Ref<File>;
|
||||
const prefix = useStorage('hex-converter:prefix', '');
|
||||
const fileHex = computedAsync(async () => {
|
||||
const file = fileInput.value;
|
||||
const sep = separator.value;
|
||||
const pref = prefix.value;
|
||||
|
||||
return pref + await ReadFileAsHex(file, sep);
|
||||
});
|
||||
const { copy: copyFileHex } = useCopy({ source: fileHex, text: 'Hex string copied to the clipboard' });
|
||||
|
||||
function onUpload(file: File) {
|
||||
if (file) {
|
||||
fileInput.value = file;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card title="HEX to file">
|
||||
<n-grid cols="3" x-gap="12">
|
||||
<n-gi span="2">
|
||||
<c-input-text
|
||||
v-model:value="fileName"
|
||||
label="File Name"
|
||||
placeholder="Download filename"
|
||||
mb-2
|
||||
/>
|
||||
</n-gi>
|
||||
<n-gi>
|
||||
<c-input-text
|
||||
v-model:value="fileExtension"
|
||||
label="Extension"
|
||||
placeholder="Extension"
|
||||
/>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
|
||||
<n-form-item label="Content in Hex">
|
||||
<c-input-text
|
||||
v-model:value="hexInput"
|
||||
multiline
|
||||
placeholder="Put your Hex file string here..."
|
||||
rows="5"
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button :disabled="hexInput === ''" @click="downloadFile()">
|
||||
Download file
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
|
||||
<c-card title="File to HEX">
|
||||
<c-file-upload
|
||||
title="Drag and drop a file here, or click to select a file"
|
||||
mb-2
|
||||
@file-upload="onUpload"
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="separator"
|
||||
label="Separator"
|
||||
label-position="left"
|
||||
placeholder="Separator"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="prefix"
|
||||
label="Prefix"
|
||||
label-position="left"
|
||||
placeholder="Enter a prefix (ie, 0x, &H or empty)"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item label="File in Hex">
|
||||
<c-input-text
|
||||
:value="fileHex"
|
||||
multiline readonly
|
||||
placeholder="File in hex will be here"
|
||||
rows="5" mb-2
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button @click="copyFileHex()">
|
||||
Copy
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
::v-deep(.n-upload-trigger) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { FileDigit } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'HEX File Converter',
|
||||
path: '/hex-file-converter',
|
||||
description: 'Convert between file and hexadecimal representation',
|
||||
keywords: ['hex', 'file', 'converter'],
|
||||
component: () => import('./hex-file-converter.vue'),
|
||||
icon: FileDigit,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
+3
-7
@@ -1,8 +1,8 @@
|
||||
import { tool as base64FileConverter } from './base64-file-converter';
|
||||
import { tool as base64StringConverter } from './base64-string-converter';
|
||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||
import { tool as slaCalculator } from './sla-calculator';
|
||||
import { tool as emailNormalizer } from './email-normalizer';
|
||||
import { tool as hexFileConverter } from './hex-file-converter';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -102,6 +102,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
romanNumeralConverter,
|
||||
base64StringConverter,
|
||||
base64FileConverter,
|
||||
hexFileConverter,
|
||||
colorConverter,
|
||||
caseConverter,
|
||||
textToNatoAlphabet,
|
||||
@@ -173,12 +174,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Measurement',
|
||||
components: [
|
||||
chronometer,
|
||||
temperatureConverter,
|
||||
benchmarkBuilder,
|
||||
slaCalculator,
|
||||
],
|
||||
components: [chronometer, temperatureConverter, benchmarkBuilder],
|
||||
},
|
||||
{
|
||||
name: 'Text',
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Clock } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'SLA calculator',
|
||||
path: '/sla-calculator',
|
||||
description: 'Service Level Agreement Calcultator',
|
||||
keywords: ['sla', 'service', 'level', 'agreement', 'calculator'],
|
||||
component: () => import('./sla-calculator.vue'),
|
||||
icon: Clock,
|
||||
createdAt: new Date('2024-05-11'),
|
||||
});
|
||||
@@ -1,81 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { downTimeToSLA, slaToDowntimes } from './sla-calculator.service';
|
||||
|
||||
describe('sla-calculator', () => {
|
||||
describe('downTimeToSLA', () => {
|
||||
it('compute correct values', () => {
|
||||
expect(downTimeToSLA({
|
||||
downTimeSeconds: 100,
|
||||
mondayHours: 16,
|
||||
tuesdayHours: 6,
|
||||
wednesdayHours: 4,
|
||||
thursdayHours: 24,
|
||||
fridayHours: 21,
|
||||
saturdayHours: 16,
|
||||
sundayHours: 13,
|
||||
})).to.deep.eq({
|
||||
slaForDay: null,
|
||||
slaForMonth: 99.99361155031703,
|
||||
slaForQuarter: 99.99787051677234,
|
||||
slaForWeek: 99.97222222222223,
|
||||
slaForYear: 99.99946762919309,
|
||||
});
|
||||
expect(downTimeToSLA({
|
||||
downTimeSeconds: 86400 / 10000,
|
||||
})).to.deep.eq({
|
||||
slaForDay: 99.99,
|
||||
slaForMonth: 99.99967145115916,
|
||||
slaForQuarter: 99.99989048371972,
|
||||
slaForWeek: 99.99857142857142,
|
||||
slaForYear: 99.99997262092992,
|
||||
});
|
||||
expect(downTimeToSLA({
|
||||
downTimeSeconds: 86400 / 2,
|
||||
})).to.deep.eq({
|
||||
slaForDay: 50,
|
||||
slaForMonth: 98.35725579580689,
|
||||
slaForQuarter: 99.45241859860229,
|
||||
slaForWeek: 92.85714285714286,
|
||||
slaForYear: 99.86310464965058,
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('slaToDowntimes', () => {
|
||||
it('compute correct values', () => {
|
||||
expect(slaToDowntimes({
|
||||
targetSLA: 99,
|
||||
mondayHours: 9,
|
||||
tuesdayHours: 24,
|
||||
wednesdayHours: 10,
|
||||
thursdayHours: 8,
|
||||
fridayHours: 3,
|
||||
saturdayHours: 24,
|
||||
sundayHours: 4,
|
||||
})).to.deep.eq({
|
||||
secondsPerDay: null,
|
||||
secondsPerMonth: 12835.665,
|
||||
secondsPerQuarter: 38506.995,
|
||||
secondsPerWeek: 2952,
|
||||
secondsPerYear: 154027.98,
|
||||
});
|
||||
expect(slaToDowntimes({
|
||||
targetSLA: 99.99,
|
||||
})).to.deep.eq({
|
||||
secondsPerDay: 8.64,
|
||||
secondsPerMonth: 262.9746,
|
||||
secondsPerQuarter: 788.9238,
|
||||
secondsPerWeek: 60.48,
|
||||
secondsPerYear: 3155.6952,
|
||||
});
|
||||
expect(slaToDowntimes({
|
||||
targetSLA: 99,
|
||||
})).to.deep.eq({
|
||||
secondsPerDay: 864,
|
||||
secondsPerMonth: 26297.46,
|
||||
secondsPerQuarter: 78892.38,
|
||||
secondsPerWeek: 6048,
|
||||
secondsPerYear: 315569.52,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,126 +0,0 @@
|
||||
import Big from 'big.js';
|
||||
|
||||
const hoursDay = Big('24');
|
||||
const daysWeek = Big('7');
|
||||
const monthsYear = Big('12');
|
||||
const daysYear = Big('365.2425');
|
||||
const weeksYear = daysYear.div(daysWeek);
|
||||
const daysMonth = daysYear.div(monthsYear);
|
||||
const weeksMonth = daysMonth.div(daysWeek);
|
||||
|
||||
interface DaysHours {
|
||||
mondayHours?: number
|
||||
tuesdayHours?: number
|
||||
wednesdayHours?: number
|
||||
thursdayHours?: number
|
||||
fridayHours?: number
|
||||
saturdayHours?: number
|
||||
sundayHours?: number
|
||||
}
|
||||
|
||||
function prepareDurations({
|
||||
mondayHours = 24,
|
||||
tuesdayHours = 24,
|
||||
wednesdayHours = 24,
|
||||
thursdayHours = 24,
|
||||
fridayHours = 24,
|
||||
saturdayHours = 24,
|
||||
sundayHours = 24,
|
||||
}: DaysHours) {
|
||||
const durHoursWeek = Big(mondayHours).plus(tuesdayHours).plus(wednesdayHours).plus(thursdayHours).plus(fridayHours).plus(saturdayHours).plus(sundayHours);
|
||||
const durSecondsWeek = durHoursWeek.mul('3600');
|
||||
const durSecondsDay = durSecondsWeek.div(daysWeek);
|
||||
const durSecondsMonth = durSecondsWeek.mul(weeksMonth);
|
||||
const durSecondsQuarter = durSecondsMonth.mul('3');
|
||||
const durSecondsYear = durSecondsWeek.mul(weeksYear);
|
||||
const fullWeekHours = daysWeek.mul(hoursDay);
|
||||
|
||||
return {
|
||||
durHoursWeek,
|
||||
durSecondsWeek,
|
||||
durSecondsDay,
|
||||
durSecondsMonth,
|
||||
durSecondsQuarter,
|
||||
durSecondsYear,
|
||||
fullWeekHours,
|
||||
};
|
||||
}
|
||||
|
||||
export function downTimeToSLA({
|
||||
downTimeSeconds,
|
||||
mondayHours = 24,
|
||||
tuesdayHours = 24,
|
||||
wednesdayHours = 24,
|
||||
thursdayHours = 24,
|
||||
fridayHours = 24,
|
||||
saturdayHours = 24,
|
||||
sundayHours = 24,
|
||||
}: {
|
||||
downTimeSeconds: number
|
||||
} & DaysHours) {
|
||||
const {
|
||||
durHoursWeek,
|
||||
durSecondsWeek,
|
||||
durSecondsDay,
|
||||
durSecondsMonth,
|
||||
durSecondsQuarter,
|
||||
durSecondsYear,
|
||||
fullWeekHours,
|
||||
} = prepareDurations({
|
||||
mondayHours, tuesdayHours, wednesdayHours, thursdayHours, fridayHours, saturdayHours, sundayHours,
|
||||
});
|
||||
|
||||
const one = Big('1');
|
||||
const hundred = Big('100');
|
||||
const downTimeSecondsBig = Big(downTimeSeconds);
|
||||
|
||||
return {
|
||||
slaForDay: fullWeekHours.eq(durHoursWeek) ? one.minus(downTimeSecondsBig.div(durSecondsDay)).mul(hundred).toNumber() : null,
|
||||
slaForWeek: one.minus(downTimeSecondsBig.div(durSecondsWeek)).mul(hundred).toNumber(),
|
||||
slaForMonth: one.minus(downTimeSecondsBig.div(durSecondsMonth)).mul(hundred).toNumber(),
|
||||
slaForQuarter: one.minus(downTimeSecondsBig.div(durSecondsQuarter)).mul(hundred).toNumber(),
|
||||
slaForYear: one.minus(downTimeSecondsBig.div(durSecondsYear)).mul(hundred).toNumber(),
|
||||
};
|
||||
}
|
||||
|
||||
export function slaToDowntimes({
|
||||
targetSLA,
|
||||
mondayHours = 24,
|
||||
tuesdayHours = 24,
|
||||
wednesdayHours = 24,
|
||||
thursdayHours = 24,
|
||||
fridayHours = 24,
|
||||
saturdayHours = 24,
|
||||
sundayHours = 24,
|
||||
}: {
|
||||
targetSLA: number
|
||||
mondayHours?: number
|
||||
tuesdayHours?: number
|
||||
wednesdayHours?: number
|
||||
thursdayHours?: number
|
||||
fridayHours?: number
|
||||
saturdayHours?: number
|
||||
sundayHours?: number
|
||||
}) {
|
||||
const {
|
||||
durHoursWeek,
|
||||
durSecondsWeek,
|
||||
durSecondsDay,
|
||||
durSecondsMonth,
|
||||
durSecondsQuarter,
|
||||
durSecondsYear,
|
||||
fullWeekHours,
|
||||
} = prepareDurations({
|
||||
mondayHours, tuesdayHours, wednesdayHours, thursdayHours, fridayHours, saturdayHours, sundayHours,
|
||||
});
|
||||
|
||||
const allowedDowntime = Big('1').minus(Big(targetSLA).div('100'));
|
||||
|
||||
return {
|
||||
secondsPerDay: fullWeekHours.eq(durHoursWeek) ? allowedDowntime.mul(durSecondsDay).toNumber() : null,
|
||||
secondsPerWeek: allowedDowntime.mul(durSecondsWeek).toNumber(),
|
||||
secondsPerMonth: allowedDowntime.mul(durSecondsMonth).toNumber(),
|
||||
secondsPerQuarter: allowedDowntime.mul(durSecondsQuarter).toNumber(),
|
||||
secondsPerYear: allowedDowntime.mul(durSecondsYear).toNumber(),
|
||||
};
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import prettyMilliseconds from 'pretty-ms';
|
||||
import parse from 'parse-duration';
|
||||
import { downTimeToSLA, slaToDowntimes } from './sla-calculator.service';
|
||||
import { useQueryParam, useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
function prettySeconds(seconds: number | null) {
|
||||
if (!seconds) {
|
||||
return '';
|
||||
}
|
||||
return prettyMilliseconds(seconds * 1000);
|
||||
}
|
||||
|
||||
const daysHours = useQueryParamOrStorage<{
|
||||
mon?: number
|
||||
tue?: number
|
||||
wed?: number
|
||||
thu?: number
|
||||
fri?: number
|
||||
sat?: number
|
||||
sun?: number
|
||||
}>({
|
||||
name: 'days',
|
||||
storageName: 'sla:days',
|
||||
defaultValue: {
|
||||
mon: 24,
|
||||
tue: 24,
|
||||
wed: 24,
|
||||
thu: 24,
|
||||
fri: 24,
|
||||
sat: 24,
|
||||
sun: 24,
|
||||
},
|
||||
});
|
||||
const inputSLA = useQueryParam({ name: 'sla', defaultValue: 99.99 });
|
||||
const outputDownTimes = computed(() => {
|
||||
const weekdaysHours = daysHours.value;
|
||||
const downtimesSeconds = slaToDowntimes({
|
||||
targetSLA: inputSLA.value,
|
||||
mondayHours: weekdaysHours.mon,
|
||||
tuesdayHours: weekdaysHours.tue,
|
||||
wednesdayHours: weekdaysHours.wed,
|
||||
thursdayHours: weekdaysHours.thu,
|
||||
fridayHours: weekdaysHours.fri,
|
||||
saturdayHours: weekdaysHours.sat,
|
||||
sundayHours: weekdaysHours.sun,
|
||||
});
|
||||
return {
|
||||
durationPerDay: prettySeconds(downtimesSeconds.secondsPerDay),
|
||||
durationPerMonth: prettySeconds(downtimesSeconds.secondsPerMonth),
|
||||
durationPerQuarter: prettySeconds(downtimesSeconds.secondsPerQuarter),
|
||||
durationPerWeek: prettySeconds(downtimesSeconds.secondsPerWeek),
|
||||
durationPerYear: prettySeconds(downtimesSeconds.secondsPerYear),
|
||||
};
|
||||
});
|
||||
|
||||
const inputDuration = useQueryParam({ name: 'dur', defaultValue: '1s' });
|
||||
const inputDurationValidation = useValidation({
|
||||
source: inputDuration,
|
||||
rules: [
|
||||
{
|
||||
message: 'Invalid duration',
|
||||
validator: value => parse(value),
|
||||
},
|
||||
],
|
||||
});
|
||||
const inputDurationSeconds = computed(() => {
|
||||
if (!inputDurationValidation.isValid) {
|
||||
return 0;
|
||||
}
|
||||
return parse(inputDuration.value, 's') || 0;
|
||||
});
|
||||
const outputSLAs = computed(() => {
|
||||
const weekdaysHours = daysHours.value;
|
||||
const slas = downTimeToSLA({
|
||||
downTimeSeconds: inputDurationSeconds.value,
|
||||
mondayHours: weekdaysHours.mon,
|
||||
tuesdayHours: weekdaysHours.tue,
|
||||
wednesdayHours: weekdaysHours.wed,
|
||||
thursdayHours: weekdaysHours.thu,
|
||||
fridayHours: weekdaysHours.fri,
|
||||
saturdayHours: weekdaysHours.sat,
|
||||
sundayHours: weekdaysHours.sun,
|
||||
});
|
||||
return {
|
||||
slaForDay: slas.slaForDay?.toPrecision(6),
|
||||
slaForWeek: slas.slaForWeek.toPrecision(6),
|
||||
slaForMonth: slas.slaForMonth.toPrecision(6),
|
||||
slaForQuarter: slas.slaForQuarter.toPrecision(6),
|
||||
slaForYear: slas.slaForYear.toPrecision(6),
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card title="SLA to downtimes" mb-2>
|
||||
<n-form-item label="Agreed SLA" label-placement="left">
|
||||
<n-input-number v-model:value="inputSLA" :min="0" :max="100" />
|
||||
</n-form-item>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item v-if="outputDownTimes.durationPerDay" label="Daily downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerDay" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Weekly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerWeek" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Monthly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerMonth" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Quarterly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerQuarter" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Yearly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerYear" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Downtime to SLA" mb-2>
|
||||
<c-input-text
|
||||
v-model:value="inputDuration"
|
||||
label="Downtime duration"
|
||||
label-position="left"
|
||||
placeholder="Put downtime duration here..."
|
||||
:validation="inputDurationValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item v-if="outputSLAs.slaForDay" label="Daily SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForDay" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Weekly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForWeek" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Monthly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForMonth" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Quarterly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForQuarter" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Yearly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForYear" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Weekdays hours">
|
||||
<div flex flex-wrap gap-1>
|
||||
<n-form-item label="Monday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.mon" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Tuesday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.tue" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Wednesday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.wed" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Thursday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.thu" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Friday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.fri" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<div flex flex-wrap gap-1>
|
||||
<n-form-item label="Saturday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.sat" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Sunday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.sun" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -15,6 +15,7 @@ import { VitePWA } from 'vite-plugin-pwa';
|
||||
import markdown from 'vite-plugin-vue-markdown';
|
||||
import svgLoader from 'vite-svg-loader';
|
||||
import { configDefaults } from 'vitest/config';
|
||||
import { nodePolyfills } from 'vite-plugin-node-polyfills'
|
||||
|
||||
const baseUrl = process.env.BASE_URL ?? '/';
|
||||
|
||||
@@ -97,6 +98,7 @@ export default defineConfig({
|
||||
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
|
||||
}),
|
||||
Unocss(),
|
||||
nodePolyfills(),
|
||||
],
|
||||
base: baseUrl,
|
||||
resolve: {
|
||||
|
||||
Reference in new issue
Block a user