mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 22:02:38 +03:00
Merge branch 'feat/energy-computer' into chore/all-my-stuffs
# Conflicts: # src/tools/index.ts
This commit is contained in:
commit
32e30c54b6
6 files changed
+101
-2
No files matched your search
Generated
+1
-2
@@ -5243,7 +5243,7 @@ packages:
|
|||||||
/@types/lodash-es@4.17.10:
|
/@types/lodash-es@4.17.10:
|
||||||
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
|
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/lodash': 4.14.200
|
'@types/lodash': 4.14.192
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@types/lodash.defaultsdeep@4.6.9:
|
/@types/lodash.defaultsdeep@4.6.9:
|
||||||
@@ -5266,7 +5266,6 @@ packages:
|
|||||||
|
|
||||||
/@types/lodash@4.14.192:
|
/@types/lodash@4.14.192:
|
||||||
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
|
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@types/lodash@4.14.200:
|
/@types/lodash@4.14.200:
|
||||||
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
|
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
import { computeCost } from './energy-computer.service'; // Adjust the import path as needed
|
||||||
|
|
||||||
|
describe('computeCost', () => {
|
||||||
|
it('should calculate the correct cost for valid inputs', () => {
|
||||||
|
const wattage = 1000; // 1000 watts = 1 kW
|
||||||
|
const duration = 5; // 5 hours
|
||||||
|
const kWhCost = 0.12; // $0.12 per kWh
|
||||||
|
const result = computeCost(wattage, duration, kWhCost);
|
||||||
|
expect(result).toBeCloseTo(0.60); // 1 kW * 5h * 0.12 = 0.60
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 0 when the duration is 0', () => {
|
||||||
|
const wattage = 1000;
|
||||||
|
const duration = 0;
|
||||||
|
const kWhCost = 0.12;
|
||||||
|
const result = computeCost(wattage, duration, kWhCost);
|
||||||
|
expect(result).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 0 when the wattage is 0', () => {
|
||||||
|
const wattage = 0;
|
||||||
|
const duration = 5;
|
||||||
|
const kWhCost = 0.12;
|
||||||
|
const result = computeCost(wattage, duration, kWhCost);
|
||||||
|
expect(result).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 0 when the cost per kWh is 0', () => {
|
||||||
|
const wattage = 1000;
|
||||||
|
const duration = 5;
|
||||||
|
const kWhCost = 0;
|
||||||
|
const result = computeCost(wattage, duration, kWhCost);
|
||||||
|
expect(result).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle fractional wattage and duration correctly', () => {
|
||||||
|
const wattage = 750; // 0.75 kW
|
||||||
|
const duration = 2.5; // 2.5 hours
|
||||||
|
const kWhCost = 0.10; // $0.10 per kWh
|
||||||
|
const result = computeCost(wattage, duration, kWhCost);
|
||||||
|
expect(result).toBeCloseTo(0.1875); // 0.75 kW * 2.5h * 0.10 = 0.1875
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle large numbers correctly', () => {
|
||||||
|
const wattage = 1000000; // 1 MW
|
||||||
|
const duration = 24; // 24 hours
|
||||||
|
const kWhCost = 0.15; // $0.15 per kWh
|
||||||
|
const result = computeCost(wattage, duration, kWhCost);
|
||||||
|
expect(result).toBe(3600); // 1000 kW * 24h * 0.15 = 3600
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export function computeCost(wattage: number, durationHours: number, costPerKWh: number): number {
|
||||||
|
const kilowatts = wattage / 1000;
|
||||||
|
const energyConsumed = kilowatts * durationHours;
|
||||||
|
const totalCost = energyConsumed * costPerKWh;
|
||||||
|
return totalCost;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computeCost } from './energy-computer.service';
|
||||||
|
|
||||||
|
const wattage = ref(100);
|
||||||
|
const durationHours = ref(2);
|
||||||
|
const kWhCost = ref(0.1);
|
||||||
|
const totalCost = computed(() => computeCost(wattage.value, durationHours.value, kWhCost.value));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<n-form-item label="Device Wattage" mb-1>
|
||||||
|
<n-input-number v-model:value="wattage" :min="0" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="Usage Duration (hours)" mb-1>
|
||||||
|
<n-input-number v-model:value="durationHours" :min="0" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="kWh Cost" mb-1>
|
||||||
|
<n-input-number v-model:value="kWhCost" :min="0" />
|
||||||
|
</n-form-item>
|
||||||
|
|
||||||
|
<n-divider />
|
||||||
|
|
||||||
|
<input-copyable label="Total Cost" :value="totalCost" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { Engine } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'Energy Consumption and Expense Computer',
|
||||||
|
path: '/energy-computer',
|
||||||
|
description: 'Compute energy consumption and expense',
|
||||||
|
keywords: ['energy', 'expense', 'watt', 'kwh', 'computer'],
|
||||||
|
component: () => import('./energy-computer.vue'),
|
||||||
|
icon: Engine,
|
||||||
|
createdAt: new Date('2024-08-15'),
|
||||||
|
});
|
||||||
@@ -54,6 +54,7 @@ import { tool as weekNumberConverter } from './week-number-converter';
|
|||||||
import { tool as wpaPskGenerator } from './wpa-psk-generator';
|
import { tool as wpaPskGenerator } from './wpa-psk-generator';
|
||||||
import { tool as xpathTester } from './xpath-tester';
|
import { tool as xpathTester } from './xpath-tester';
|
||||||
import { tool as xsltTester } from './xslt-tester';
|
import { tool as xsltTester } from './xslt-tester';
|
||||||
|
import { tool as energyComputer } from './energy-computer';
|
||||||
|
|
||||||
import { tool as cssXpathConverter } from './css-xpath-converter';
|
import { tool as cssXpathConverter } from './css-xpath-converter';
|
||||||
import { tool as cssSelectorsMemo } from './css-selectors-memo';
|
import { tool as cssSelectorsMemo } from './css-selectors-memo';
|
||||||
@@ -443,6 +444,8 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
energyConverter,
|
energyConverter,
|
||||||
powerConverter,
|
powerConverter,
|
||||||
benchmarkBuilder,
|
benchmarkBuilder,
|
||||||
|
benchmarkBuilder,
|
||||||
|
energyComputer,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user