Klimafaktoren
This commit is contained in:
@@ -2,7 +2,8 @@ import { AufnahmeClient, ObjektClient, VerbrauchsausweisGewerbeClient } from "#c
|
||||
import { getKlimafaktoren } from "#lib/Klimafaktoren.js";
|
||||
import { getHeizwertfaktor } from "#lib/server/Heizwertfaktor.js";
|
||||
import moment from "moment";
|
||||
import bauwerkskatalog from "./bauwerkskatalog.json" assert { type: "json" }
|
||||
import bauwerkskatalog from "./bauwerkskatalog.json" with { type: "json" }
|
||||
import { getKlimafaktorenServer } from "#lib/server/klimafaktoren.js";
|
||||
|
||||
function vergleichsWertNichtWohngebaeude(ausweis: VerbrauchsausweisGewerbeClient, aufnahme: AufnahmeClient) {
|
||||
let tekWerte = new Array(8).fill(0);
|
||||
@@ -85,7 +86,7 @@ export async function endEnergieVerbrauchVerbrauchsausweisGewerbe_2016(ausweis:
|
||||
}];
|
||||
|
||||
try {
|
||||
const response = await getKlimafaktoren(ausweis.startdatum, objekt.plz)
|
||||
const response = await getKlimafaktorenServer(objekt.plz as string, moment(ausweis.startdatum).toDate(), moment(ausweis.startdatum).add(2, "years").toDate())
|
||||
|
||||
if (response) {
|
||||
klimafaktoren = response
|
||||
|
||||
@@ -3,6 +3,7 @@ import { getKlimafaktoren } from "#lib/Klimafaktoren.js";
|
||||
import { getHeizwertfaktor } from "#lib/server/Heizwertfaktor.js";
|
||||
import { Enums } from "#lib/client/prisma.js";
|
||||
import moment from "moment";
|
||||
import { getKlimafaktorenServer } from "#lib/server/klimafaktoren.js";
|
||||
|
||||
export function energetischeNutzflaecheVerbrauchsausweisWohnen_2016(
|
||||
ausweis: VerbrauchsausweisWohnenClient,
|
||||
@@ -49,7 +50,7 @@ export async function endEnergieVerbrauchVerbrauchsausweis_2016(
|
||||
}];
|
||||
|
||||
try {
|
||||
const response = await getKlimafaktoren(ausweis.startdatum, objekt.plz)
|
||||
const response = await getKlimafaktorenServer(objekt.plz as string, moment(ausweis.startdatum).toDate(), moment(ausweis.startdatum).add(2, "years").toDate())
|
||||
|
||||
if (response) {
|
||||
klimafaktoren = response
|
||||
|
||||
@@ -20,6 +20,8 @@ export async function pdfVerbrauchsausweisWohnen(ausweis: VerbrauchsausweisWohne
|
||||
// const template = VerbrauchsausweisWohnen2016Template as Template;
|
||||
|
||||
const berechnungen = await endEnergieVerbrauchVerbrauchsausweis_2016(ausweis, aufnahme, objekt);
|
||||
console.log(berechnungen?.klimafaktoren);
|
||||
|
||||
const empfehlungen = getEmpfehlungen(ausweis, aufnahme, objekt)
|
||||
|
||||
const height = pages[0].getHeight()
|
||||
|
||||
47
src/lib/server/klimafaktoren.ts
Normal file
47
src/lib/server/klimafaktoren.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import moment from "moment";
|
||||
import { prisma } from "./prisma.js";
|
||||
|
||||
export async function getKlimafaktorenServer(plz: string, startdatum: Date, enddatum: Date) {
|
||||
const start = moment(startdatum);
|
||||
const end = moment(enddatum);
|
||||
|
||||
if (start.isSameOrAfter(end)) {
|
||||
return []
|
||||
}
|
||||
|
||||
const intervals = [];
|
||||
|
||||
let currentDate = start.clone();
|
||||
while (currentDate.isSameOrBefore(end)) {
|
||||
let copy = currentDate.clone();
|
||||
intervals.push(copy);
|
||||
currentDate.add(1, "year");
|
||||
}
|
||||
|
||||
let klimafaktoren = await prisma.klimafaktoren.findMany({
|
||||
where: {
|
||||
plz,
|
||||
month: intervals[0].month(),
|
||||
OR: intervals.map((date) => {
|
||||
return {
|
||||
year: date.year(),
|
||||
};
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
if (!klimafaktoren) {
|
||||
return []
|
||||
}
|
||||
|
||||
// NOTE: Sollten wir hier lieber den Output padden und trotzdem die gefundenen zurückgeben?
|
||||
if (klimafaktoren.length !== intervals.length) {
|
||||
return []
|
||||
}
|
||||
|
||||
return klimafaktoren.map((klimafaktor) => ({
|
||||
month: klimafaktor.month,
|
||||
year: klimafaktor.year,
|
||||
klimafaktor: klimafaktor.klimafaktor,
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user