Skip to content

Commit

Permalink
Apply prettier styling
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-wosinek committed Dec 20, 2024
1 parent 15ffbc0 commit 2438369
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Checks to be done on every change

on:
pull_request:
branches: [ "main" ]
branches: ['main']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build docs to pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
branches: ['main']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -17,7 +17,7 @@ permissions:
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
group: 'pages'
cancel-in-progress: false

jobs:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ later on.
### Setting the energy tarif

The energy tarif should have two values:
* cost per kWh,
* flat cost for line maintainence.

- cost per kWh,
- flat cost for line maintainence.

Both values should default to some resonable value, and be editable by user.

### Reviewing the energy consumption
### Reviewing the energy consumption

There should be a way for user to evaluate their consumption—optimal would be
barchart per hour.
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
};
4 changes: 3 additions & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "core",
"version": "0.0.1",
"dependencies": {
"tslib": "^2.3.0"
"tslib": "^2.3.0",
"date-fns": "^4.1.0",
"lodash": "^4.17.21"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
12 changes: 6 additions & 6 deletions core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { calculateConsumption } from "./calculate-consumption";
import { findAfterMeasurement } from "./find-after-measurement";
import { calculateConsumption } from './calculate-consumption';
import { findAfterMeasurement } from './find-after-measurement';

import { findBeforeMeasurement } from "./find-before-measurement";
import { Consumption } from "./consumption";
import { Measurement } from "./measurement";
import { Tariff } from "./tariff";
import { findBeforeMeasurement } from './find-before-measurement';
import { Consumption } from './consumption';
import { Measurement } from './measurement';
import { Tariff } from './tariff';

export {
calculateConsumption,
Expand Down
4 changes: 2 additions & 2 deletions core/src/lib/calculate-consumption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { endOfHour, parseISO } from 'date-fns';

describe('calculateConsumption', () => {
test('should return empty array', () => {
// @ts-ignore
// @ts-expect-error missing parameter
expect(calculateConsumption()).toHaveLength(0);

const tariff = new Tariff();

// missing measurements
// @ts-ignore
// @ts-expect-error missing parameter
expect(calculateConsumption(tariff)).toHaveLength(0);

// only one measurements
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/calculate-consumption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function calculateConsumption(
hourlyFixedCharge = tariff.fixedCharge / 24;

const firstHour = startOfHour(orderedMeasurments[0].datetime),
// @ts-ignore
// @ts-expect-error type check issue
lastHour = startOfHour(orderedMeasurments.at(-1).datetime);

const consumptionArraySize = differenceInHours(lastHour, firstHour) + 1;
Expand Down
6 changes: 3 additions & 3 deletions core/src/lib/consumption.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Consumption } from "./consumption";
import { Consumption } from './consumption';

describe("Consumption", () => {
test("should be an a constructor and provide one default value", () => {
describe('Consumption', () => {
test('should be an a constructor and provide one default value', () => {
const now = new Date();

let consumption = new Consumption(now);
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/consumption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Stores consumption data ready to be displayed to the user.
*/
export class Consumption {
constructor(datetime: Date, cost: number = 0) {
constructor(datetime: Date, cost = 0) {
this.datetime = datetime;
this.cost = cost;
}
Expand Down
7 changes: 0 additions & 7 deletions core/src/lib/core.spec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions core/src/lib/core.ts

This file was deleted.

3 changes: 1 addition & 2 deletions core/src/lib/find-after-measurement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { parseISO } from 'date-fns';

describe('findAfterMeasurement', () => {
test('should return undefined if empty array or time is missing', () => {
// @ts-ignore
// @ts-expect-error missing parameter
expect(findAfterMeasurement()).toBeUndefined();
expect(
// @ts-ignore
findAfterMeasurement(parseISO('2024-12-19T12:30:00'), [])
).toBeUndefined();
});
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/find-before-measurement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { parseISO } from 'date-fns';

describe('findBeforeMeasurement', () => {
test('should return undefined if empty array or time is missing', () => {
// @ts-ignore
// @ts-expect-error missing parameter
expect(findBeforeMeasurement()).toBeUndefined();
expect(
findBeforeMeasurement(parseISO('2024-12-19T12:30:00'), [])
Expand Down
7 changes: 2 additions & 5 deletions core/src/lib/interpolate-value.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ import { parseISO } from 'date-fns';

describe('interpolateValue', () => {
test('should return 0 when both measurements are missing', () => {
// @ts-ignore
// @ts-expect-error missing parameter
expect(interpolateValue()).toBe(0);
// @ts-ignore
expect(interpolateValue(parseISO('2024-12-18T17:30:00'))).toBe(0);
});

test('should return value if only one measurement is valid', () => {
expect(
interpolateValue(
parseISO('2024-12-18T17:30:00'),
// @ts-ignore
null,
undefined,
new Measurement(parseISO('2024-12-18T18:00:00'), 2)
)
).toBe(2);

expect(
// @ts-ignore
interpolateValue(
parseISO('2024-12-18T17:30:00'),
new Measurement(parseISO('2024-12-18T18:00:00'), 52)
Expand Down
3 changes: 1 addition & 2 deletions core/src/lib/interpolate-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ export function interpolateValue(
}

if (!startMeasurement) {
// @ts-ignore
// @ts-expect-error type checked above
return endMeasurement.value;
}

if (!endMeasurement) {
// @ts-ignore
return startMeasurement.value;
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/lib/measurement.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Measurement } from "./measurement";
import { Measurement } from './measurement';

describe("Measurement", () => {
test("should be an a constructor and provide one default value", () => {
describe('Measurement', () => {
test('should be an a constructor and provide one default value', () => {
const now = new Date();

let measurement = new Measurement(now);
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/measurement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Stores energy meter measurement, registered by the user.
*/
export class Measurement {
constructor(datetime: Date, value: number = 0) {
constructor(datetime: Date, value = 0) {
this.datetime = datetime;
this.value = value;
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/lib/tariff.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Tariff } from "./tariff";
import { Tariff } from './tariff';

describe("Tariff", () => {
test("should be an a constructor with default value", () => {
describe('Tariff', () => {
test('should be an a constructor with default value', () => {
const tariff = new Tariff();

expect(tariff).toBeInstanceOf(Tariff);
expect(tariff.fixedCharge).toBe(0.4636274);
expect(tariff.unitCharge).toBe(0.178957);
});

test("should pass provided valeus", () => {
test('should pass provided valeus', () => {
const tariff = new Tariff(3, 5);

expect(tariff.fixedCharge).toBe(3);
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/tariff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class Tariff {
/**
* Sets values to what was provides, or to the default values.
*/
constructor(fixedCharge: number = 0.4636274, unitCharge: number = 0.178957) {
constructor(fixedCharge = 0.4636274, unitCharge = 0.178957) {
this.fixedCharge = fixedCharge;
this.unitCharge = unitCharge;
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@eslint/js": "^9.8.0",
"@nx/angular": "^20.2.2",
"@nx/cypress": "20.2.2",
"@nx/eslint": "20.2.2",
"@nx/eslint": "^20.2.2",
"@nx/eslint-plugin": "20.2.2",
"@nx/jest": "20.2.2",
"@nx/js": "20.2.2",
Expand Down

0 comments on commit 2438369

Please sign in to comment.