-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
86 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Query } from "https://deno.land/x/[email protected].7/mod.ts"; | ||
import { Query } from "https://deno.land/x/[email protected].9/mod.ts"; | ||
|
||
// Prepare dates | ||
const | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Query } from "https://deno.land/x/[email protected].7/mod.ts"; | ||
import { PsrType } from "https://deno.land/x/[email protected].7/src/parameters/psrtype.js"; | ||
import { Query } from "https://deno.land/x/[email protected].9/mod.ts"; | ||
import { PsrType } from "https://deno.land/x/[email protected].9/src/parameters/psrtype.js"; | ||
|
||
// Prepare dates | ||
const | ||
|
@@ -17,8 +17,8 @@ const result = await Query( | |
{ | ||
documentType: "A75", // A75 - Actual generation per type | ||
processType: "A16", // A16 - Realised | ||
inDomain: "BZN|DE-LU", // In_Domain | ||
outDomain: "BZN|DE-LU", // Out_Domain | ||
inDomain: "BZN|SE2", // In_Domain | ||
outDomain: "BZN|SE2", // Out_Domain | ||
startDateTime: dateToday, // Start date | ||
endDateTime: dateTomorrow, // End date | ||
} | ||
|
@@ -35,7 +35,7 @@ const output = { | |
}; | ||
|
||
for (const ts of result.TimeSeries) { | ||
// We expect hourly data, use PT60M and ignore other periods | ||
// We expect hourly data from BZN|SE2, use PT60M and ignore other periods | ||
if (ts.Period.resolution==="PT60M") { | ||
for (const point of ts.Period.Point) { | ||
const psrTypeTranslation = PsrType[ts.MktPSRType.psrType]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Query } from "https://deno.land/x/[email protected].7/mod.ts"; | ||
import { Query } from "https://deno.land/x/[email protected].9/mod.ts"; | ||
|
||
// Prepare dates | ||
const | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,79 @@ | ||
import { parse } from "https://deno.land/x/xml/mod.ts"; | ||
|
||
import { parse } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
interface EntsoeQueryTimeInterval { | ||
start: string; | ||
} | ||
|
||
interface EntsoeQueryPoint { | ||
position: string; | ||
"price.amount": string; | ||
} | ||
|
||
interface EntsoeQueryPeriod { | ||
timeInterval: EntsoeQueryTimeInterval; | ||
Point: EntsoeQueryPoint[]; | ||
} | ||
|
||
interface EntsoeQueryEntry { | ||
Period: EntsoeQueryPeriod; | ||
} | ||
|
||
interface QueryResult { | ||
TimeSeries: EntsoeQueryEntry[] | ||
} | ||
start: string; | ||
} | ||
|
||
interface UnsafeQueryResult { | ||
TimeSeries: EntsoeQueryEntry | EntsoeQueryEntry[] | ||
} | ||
interface EntsoeQueryPoint { | ||
position: number; | ||
"price.amount"?: number; | ||
quantity?: number; | ||
} | ||
|
||
const ParseDocument = (xmlDocument: string): QueryResult => { | ||
interface EntsoeQueryPeriod { | ||
timeInterval: EntsoeQueryTimeInterval; | ||
Point: EntsoeQueryPoint[]; | ||
resolution: string; | ||
} | ||
|
||
// Parse document | ||
const doc = parse(xmlDocument); | ||
interface EntsoeQueryPeriodMktPSRType { | ||
psrType: string; | ||
} | ||
interface EntsoeQueryEntry { | ||
Period: EntsoeQueryPeriod; | ||
"outBiddingZone_Domain.mRID"?: string; | ||
"inBiddingZone_Domain.mRID"?: string; | ||
MktPSRType?: EntsoeQueryPeriodMktPSRType; | ||
} | ||
|
||
const rootNode: UnsafeQueryResult = (doc.Publication_MarketDocument || doc.GL_MarketDocument) as unknown as UnsafeQueryResult; | ||
interface QueryResult { | ||
TimeSeries: EntsoeQueryEntry[]; | ||
} | ||
|
||
// Check that root element exists | ||
if (!rootNode) { | ||
if(doc.Acknowledgement_MarketDocument) { | ||
throw new Error(`Request failed. Code '${doc.Acknowledgement_MarketDocument.Reason.code}', Reason '${doc.Acknowledgement_MarketDocument.Reason.text}'`) | ||
} else { | ||
console.log(doc); | ||
throw new Error("Unknown XML document structure received"); | ||
} | ||
} | ||
interface UnsafeQueryResult { | ||
TimeSeries: EntsoeQueryEntry | EntsoeQueryEntry[]; | ||
} | ||
|
||
interface InvalidQueryResultReason { | ||
code: string; | ||
text: string; | ||
} | ||
|
||
interface InvalidQueryResult { | ||
Reason: InvalidQueryResultReason; | ||
} | ||
|
||
const ParseDocument = (xmlDocument: string): QueryResult => { | ||
// Parse document | ||
const doc = parse(xmlDocument); | ||
|
||
const rootNode: UnsafeQueryResult = | ||
(doc.Publication_MarketDocument || doc.GL_MarketDocument) as unknown as UnsafeQueryResult; | ||
|
||
// Check if TimeSeries is a single element or Array | ||
// - If single element, convert to array with one element | ||
if (rootNode.TimeSeries && !Array.isArray(rootNode.TimeSeries)) { | ||
rootNode.TimeSeries = [rootNode.TimeSeries]; | ||
// Check that root element exists | ||
if (!rootNode) { | ||
if (doc.Acknowledgement_MarketDocument) { | ||
const invalidRootNode: InvalidQueryResult = doc.Acknowledgement_MarketDocument as unknown as InvalidQueryResult; | ||
throw new Error( | ||
`Request failed. Code '${invalidRootNode.Reason.code}', Reason '${invalidRootNode.Reason.text}'`, | ||
); | ||
} else { | ||
console.log(doc); | ||
throw new Error("Unknown XML document structure received"); | ||
} | ||
} | ||
|
||
const checkedDocument: QueryResult = rootNode as unknown as QueryResult; | ||
// Check if TimeSeries is a single element or Array | ||
// - If single element, convert to array with one element | ||
if (rootNode.TimeSeries && !Array.isArray(rootNode.TimeSeries)) { | ||
rootNode.TimeSeries = [rootNode.TimeSeries]; | ||
} | ||
|
||
// Return MarketDocument | ||
return checkedDocument; | ||
const checkedDocument: QueryResult = rootNode as unknown as QueryResult; | ||
|
||
// Return MarketDocument | ||
return checkedDocument; | ||
}; | ||
|
||
export type { QueryResult }; | ||
export { ParseDocument }; | ||
export { ParseDocument }; |