Skip to content

Commit f6f7bfc

Browse files
authored
Merge pull request #260 from sunnydanu/developing/2.0.0
Merge Developing/2.0.0 to Main
2 parents fc733fa + 13ff2b4 commit f6f7bfc

File tree

16 files changed

+127
-18
lines changed

16 files changed

+127
-18
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
push:
66
branches:
77
- main
8+
- developing/2.0.0
89

910
jobs:
1011
ci:
@@ -27,8 +28,8 @@ jobs:
2728
- name: Run unit test
2829
run: pnpm test
2930

30-
- name: Type check
31-
run: pnpm typecheck
31+
# - name: Type check
32+
# run: pnpm typecheck
3233

3334
- name: Build the app
3435
run: pnpm build

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ coverage
3232
/playwright-report/
3333
/playwright/.cache/
3434
# Webkit with playwright creates a salt file
35-
salt
35+
salt
36+
sandbox

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @sunnydanu

components.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,14 @@ declare module '@vue/runtime-core' {
154154
NDivider: typeof import('naive-ui')['NDivider']
155155
NDynamicInput: typeof import('naive-ui')['NDynamicInput']
156156
NEllipsis: typeof import('naive-ui')['NEllipsis']
157+
NForm: typeof import('naive-ui')['NForm']
158+
NFormItem: typeof import('naive-ui')['NFormItem']
157159
NH1: typeof import('naive-ui')['NH1']
158160
NH2: typeof import('naive-ui')['NH2']
159161
NH3: typeof import('naive-ui')['NH3']
160162
NIcon: typeof import('naive-ui')['NIcon']
163+
NImage: typeof import('naive-ui')['NImage']
164+
NInputNumber: typeof import('naive-ui')['NInputNumber']
161165
NLayout: typeof import('naive-ui')['NLayout']
162166
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
163167
NMenu: typeof import('naive-ui')['NMenu']

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import { computeCost } from './energy-computer.service'; // Adjust the import path as needed
4+
5+
describe('computeCost', () => {
6+
it('should calculate the correct cost for valid inputs', () => {
7+
const wattage = 1000; // 1000 watts = 1 kW
8+
const duration = 5; // 5 hours
9+
const kWhCost = 0.12; // $0.12 per kWh
10+
const result = computeCost(wattage, duration, kWhCost);
11+
expect(result).toBeCloseTo(0.60); // 1 kW * 5h * 0.12 = 0.60
12+
});
13+
14+
it('should return 0 when the duration is 0', () => {
15+
const wattage = 1000;
16+
const duration = 0;
17+
const kWhCost = 0.12;
18+
const result = computeCost(wattage, duration, kWhCost);
19+
expect(result).toBe(0);
20+
});
21+
22+
it('should return 0 when the wattage is 0', () => {
23+
const wattage = 0;
24+
const duration = 5;
25+
const kWhCost = 0.12;
26+
const result = computeCost(wattage, duration, kWhCost);
27+
expect(result).toBe(0);
28+
});
29+
30+
it('should return 0 when the cost per kWh is 0', () => {
31+
const wattage = 1000;
32+
const duration = 5;
33+
const kWhCost = 0;
34+
const result = computeCost(wattage, duration, kWhCost);
35+
expect(result).toBe(0);
36+
});
37+
38+
it('should handle fractional wattage and duration correctly', () => {
39+
const wattage = 750; // 0.75 kW
40+
const duration = 2.5; // 2.5 hours
41+
const kWhCost = 0.10; // $0.10 per kWh
42+
const result = computeCost(wattage, duration, kWhCost);
43+
expect(result).toBeCloseTo(0.1875); // 0.75 kW * 2.5h * 0.10 = 0.1875
44+
});
45+
46+
it('should handle large numbers correctly', () => {
47+
const wattage = 1000000; // 1 MW
48+
const duration = 24; // 24 hours
49+
const kWhCost = 0.15; // $0.15 per kWh
50+
const result = computeCost(wattage, duration, kWhCost);
51+
expect(result).toBe(3600); // 1000 kW * 24h * 0.15 = 3600
52+
});
53+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function computeCost(wattage: number, durationHours: number, costPerKWh: number): number {
2+
const kilowatts = wattage / 1000;
3+
const energyConsumed = kilowatts * durationHours;
4+
const totalCost = energyConsumed * costPerKWh;
5+
return totalCost;
6+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script setup lang="ts">
2+
import { computeCost } from './energy-computer.service';
3+
4+
const wattage = ref(100);
5+
const durationHours = ref(2);
6+
const kWhCost = ref(0.1);
7+
const totalCost = computed(() => computeCost(wattage.value, durationHours.value, kWhCost.value));
8+
</script>
9+
10+
<template>
11+
<div>
12+
<n-form-item label="Device Wattage" mb-1>
13+
<n-input-number v-model:value="wattage" :min="0" />
14+
</n-form-item>
15+
<n-form-item label="Usage Duration (hours)" mb-1>
16+
<n-input-number v-model:value="durationHours" :min="0" />
17+
</n-form-item>
18+
<n-form-item label="kWh Cost" mb-1>
19+
<n-input-number v-model:value="kWhCost" :min="0" />
20+
</n-form-item>
21+
22+
<n-divider />
23+
24+
<input-copyable label="Total Cost" :value="totalCost" />
25+
</div>
26+
</template>

src/tools/energy-computer/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Engine } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Energy Consumption and Expense Computer',
6+
path: '/energy-computer',
7+
description: 'Compute energy consumption and expense',
8+
keywords: ['energy', 'expense', 'watt', 'kwh', 'computer'],
9+
component: () => import('./energy-computer.vue'),
10+
icon: Engine,
11+
createdAt: new Date('2024-08-15'),
12+
});

src/tools/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { tool as basicAuthGenerator } from './basic-auth-generator';
44
import { tool as jsonEditor } from './json-editor';
55
import { tool as liveCode } from './live-code';
66
import { tool as emailNormalizer } from './email-normalizer';
7+
import { tool as energyComputer } from './energy-computer';
78
import { tool as peerShare } from './peer-share';
89
import { tool as asciiTextDrawer } from './ascii-text-drawer';
9-
1010
import { tool as textToUnicode } from './text-to-unicode';
1111
import { tool as safelinkDecoder } from './safelink-decoder';
1212
import { tool as xmlToJson } from './xml-to-json';
@@ -177,7 +177,12 @@ export const toolsByCategory: ToolCategory[] = [
177177
},
178178
{
179179
name: 'Measurement',
180-
components: [chronometer, temperatureConverter, benchmarkBuilder],
180+
components: [
181+
chronometer,
182+
temperatureConverter,
183+
benchmarkBuilder,
184+
energyComputer,
185+
],
181186
},
182187
{
183188
name: 'Text',

0 commit comments

Comments
 (0)