1
0
Fork 0

Add: first working version

This commit is contained in:
Aroy-Art 2025-05-15 15:53:34 +02:00
parent 05b4e0cdcf
commit eeabe3c41d
Signed by: Aroy
GPG key ID: DB9689E9391DD156
11 changed files with 394 additions and 368 deletions

View file

@ -0,0 +1,32 @@
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
export interface EnergyPrice {
SEK_per_kWh: number;
EUR_per_kWh: number;
EXR: number;
time_start: string;
time_end: string;
}
@Injectable({
providedIn: 'root'
})
export class EnergyPriceService {
private apiBaseUrl = 'https://www.elprisetjustnu.se/api/v1/prices';
private http = inject(HttpClient);
getPrices(year: string, month: string, day: string, priceClass: string): Observable<EnergyPrice[]> {
const url = `${this.apiBaseUrl}/${year}/${month}-${day}_${priceClass}.json`;
return this.http.get<EnergyPrice[]>(url);
}
formatDate(date: Date): { year: string, month: string, day: string } {
const year = date.getFullYear().toString();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
return { year, month, day };
}
}