Skip to content

Commit

Permalink
feat: update electricity prices
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsepi committed Apr 27, 2024
1 parent 27f89bb commit c5f4d33
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
10 changes: 6 additions & 4 deletions __tests__/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { getPriceWithFeesAndTaxes } from '../../src/index';

describe('getPriceWithFeesAndTaxes', () => {
test('should return correct total hourly price', () => {
expect(getPriceWithFeesAndTaxes(4.075).toFixed(5)).toEqual("12.34672");
expect(getPriceWithFeesAndTaxes(10).toFixed(5)).toEqual("19.69372");
expect(getPriceWithFeesAndTaxes(17.37).toFixed(5)).toEqual("28.83252");
expect(getPriceWithFeesAndTaxes(35).toFixed(5)).toEqual("50.69372");
expect(getPriceWithFeesAndTaxes(4.075).toFixed(5)).toEqual("11.16672");
expect(getPriceWithFeesAndTaxes(10).toFixed(5)).toEqual("18.51372");
expect(getPriceWithFeesAndTaxes(17.37).toFixed(5)).toEqual("27.65252");
expect(getPriceWithFeesAndTaxes(35).toFixed(5)).toEqual("49.51372");
expect(getPriceWithFeesAndTaxes(12.423).toFixed(2)).toEqual("21.52");
expect(getPriceWithFeesAndTaxes(4.123).toFixed(0)).toEqual("11");
});

});
30 changes: 21 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import { SpotPrice, TimeSegment } from './datasource/datasourceTypes';
import { renderMessage } from './telegram/render';
import { TelegramClient } from './telegram/telegram';

const ELECTRICITY_COMPANY_MARGIN = 1.25;
// General multiplier for VAT 24%, for spot prices which are received in VAT 0%
const ELECTRICITY_TAX_MULTIPLIER = 1.24;
const GRID_SERVICE_FEE = 3.25;

// Electricity service company margin, eurocents per kWh, including VAT 24%
const ELECTRICITY_COMPANY_MARGIN = 0.42;

// Electricity transfer fee for grid operator, including VAT 24%
const GRID_SERVICE_FEE = 2.90;

// Electricity grid tax for households (Tax Class 1), eurocents per kWh including VAT 24% and including "Huoltovarmuusmaksu" 0,01612 c/kWh
const GRID_SERVICE_TAX_FOR_HOUSEHOLDS = 2.79372;

export const mainApp = async (dryrun: boolean): Promise<void> => {
Expand All @@ -21,17 +28,20 @@ export const mainApp = async (dryrun: boolean): Promise<void> => {
console.log(`Fetching prices from ${startDate} to ${endDate}`);
const hourlySpotPrices = await sourceClient.getSpotPrices(startDate, endDate);

// API should return prices for 48 hours, for today and tomorrow
if (hourlySpotPrices.length == 48) {

// Daytime prices include hourly prices between 07-23, and min,avg,max of these hours
// We are not interested in nighttime prices, because we're only consuming electricity during the day
const todaysDaytimePrices: TimeSegment = getSegment(hourlySpotPrices.slice(7, 24)); // Today 07-23
const tomorrowsDaytimePrices: TimeSegment = getSegment(hourlySpotPrices.slice(31)); // Tomorrow 07-23

const interestingSlices = [
hourlySpotPrices.slice(24, 31),
hourlySpotPrices.slice(31, 40),
hourlySpotPrices.slice(41, 44),
hourlySpotPrices.slice(44, 48),
hourlySpotPrices.slice(24, 31), // Tomorrow 00-06
hourlySpotPrices.slice(31, 41), // Tomorrow 07-16
hourlySpotPrices.slice(41, 44), // Tomorrow 17-19
hourlySpotPrices.slice(44, 48), // Tomorrow 20-23
];

const todaysDaytimePrices: TimeSegment = getSegment(hourlySpotPrices.slice(7, 24));
const tomorrowsDaytimePrices: TimeSegment = getSegment(hourlySpotPrices.slice(31));
const tomorrowsDetailedPrices: TimeSegment[] = interestingSlices.map(slice => getSegment(slice));

const message = renderMessage(todaysDaytimePrices, tomorrowsDaytimePrices, tomorrowsDetailedPrices);
Expand All @@ -40,6 +50,7 @@ export const mainApp = async (dryrun: boolean): Promise<void> => {
}
else {
console.log("Dryrun, not sending a message to Telegram");
console.log(todaysDaytimePrices);
console.log(tomorrowsDaytimePrices);
console.log(message);
}
Expand All @@ -66,6 +77,7 @@ export const getSegment = (segment: SpotPrice[]): TimeSegment => {
}
}

// Returns total electricity cost including all taxes and grid fees when given only the service provider price with VAT 0%
export const getPriceWithFeesAndTaxes = (basePrice: number): number => {
return (basePrice * ELECTRICITY_TAX_MULTIPLIER) + ELECTRICITY_COMPANY_MARGIN + GRID_SERVICE_FEE + GRID_SERVICE_TAX_FOR_HOUSEHOLDS;
}
Expand Down

0 comments on commit c5f4d33

Please sign in to comment.