Skip to content

Commit

Permalink
fix: Incorrect settlement group in electrical heating scenario tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
energinet-ajw authored Jan 24, 2025
1 parent a45bf12 commit 52b64d1
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
t.StructField("has_electrical_heating", t.BooleanType(), not nullable),
#
# 2 | 3 | 4 | 5 | 6 | 99 | NULL
t.StructField("net_settlement_group", t.IntegerType(), not nullable),
t.StructField("net_settlement_group", t.IntegerType(), nullable),
#
# Settlement month is 1st of January for all consumption with electrical heating except for
# net settlement group 6, where the date is the scheduled meter reading date.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
metering_point_id;has_electrical_heating;net_settlement_group;settlement_month;period_from_date;period_to_date;#comment
170000000000000201;true;2;1;2023-11-30T23:00:00Z;;Two periods because crossing years. Period 1: December 2023 (31 days). Period 2: Jan. 2024 until today (full limit)
170000000000000202;true;2;1;2023-11-21T23:00:00Z;2024-02-29T23:00:00Z;Two periods because crossing years. Period 1: November 21st to end of year 2023 (9+31 days). Period 2: Jan-feb 2024 (31+29 days)
170000000000000203;true;2;1;2024-02-29T23:00:00Z;2024-03-01T23:00:00Z;One period of one day.
170000000000000204;true;2;1;2024-02-29T23:00:00Z;;One period of 10 months - Mar-Dec 2024 (306 days)
170000000000000201;true;;1;2023-11-30T23:00:00Z;;Two periods because crossing years. Period 1: December 2023 (31 days). Period 2: Jan. 2024 until today (full limit)
170000000000000202;true;;1;2023-11-21T23:00:00Z;2024-02-29T23:00:00Z;Two periods because crossing years. Period 1: November 21st to end of year 2023 (9+31 days). Period 2: Jan-feb 2024 (31+29 days)
170000000000000203;true;;1;2024-02-29T23:00:00Z;2024-03-01T23:00:00Z;One period of one day.
170000000000000204;true;;1;2024-02-29T23:00:00Z;;One period of 10 months - Mar-Dec 2024 (306 days)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metering_point_id;has_electrical_heating;net_settlement_group;settlement_month;period_from_date;period_to_date;#comment
170000000000000201;true;2;1;2023-12-31T23:00:00Z;2024-01-03T23:00:00Z;Previously period_to_date was null here. Now there is a new period: Limit = 3/366*4000 = 32.786
170000000000000201;true;2;1;2024-01-03T23:00:00Z;;Limit for the rest of the year: 363/366*4000 = 3967.213
170000000000000201;true;;1;2023-12-31T23:00:00Z;2024-01-03T23:00:00Z;Previously period_to_date was null here. Now there is a new period: Limit = 3/366*4000 = 32.786
170000000000000201;true;;1;2024-01-03T23:00:00Z;;Limit for the rest of the year: 363/366*4000 = 3967.213
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
metering_point_id;has_electrical_heating;net_settlement_group;settlement_month;period_from_date;period_to_date;#comment
170000000000000201;true;2;1;2023-12-31T23:00:00Z;;
170000000000000201;true;;1;2023-12-31T23:00:00Z;;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
metering_point_id;has_electrical_heating;net_settlement_group;settlement_month;period_from_date;period_to_date;#comment
170000000000000201;true;2;1;2023-12-31T23:00:00Z;;Generates output because there is consumption data and an electrical heating child metering point
170000000000000201;true;;1;2023-12-31T23:00:00Z;;Generates output because there is consumption data and an electrical heating child metering point
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metering_point_id;has_electrical_heating;net_settlement_group;settlement_month;period_from_date;period_to_date;#comment
170000000000000201;true;2;1;2023-12-31T23:00:00Z;2024-02-29T23:00:00Z;Case 1: Period 1 (Jan-Feb). Limit: 60/366*4000 = 655.738
170000000000000201;true;2;1;2024-04-30T22:00:00Z;2024-07-31T22:00:00Z;Case 1: Period 2 (May-Jul). Limit: 92/366*4000 = 1005.464
170000000000000201;true;2;1;2024-10-31T23:00:00Z;;Case 1: Period 3 (Nov-Dec). Limit: 61/366*4000 = 666.667
170000000000000201;true;;1;2023-12-31T23:00:00Z;2024-02-29T23:00:00Z;Case 1: Period 1 (Jan-Feb). Limit: 60/366*4000 = 655.738
170000000000000201;true;;1;2024-04-30T22:00:00Z;2024-07-31T22:00:00Z;Case 1: Period 2 (May-Jul). Limit: 92/366*4000 = 1005.464
170000000000000201;true;;1;2024-10-31T23:00:00Z;;Case 1: Period 3 (Nov-Dec). Limit: 61/366*4000 = 666.667
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metering_point_id;has_electrical_heating;net_settlement_group;settlement_month;period_from_date;period_to_date;#comment
170000000000000201;true;2;1;2023-12-31T23:00:00Z;;EH consumption MP with no end date for has_electrical_heating
170000000000000202;true;2;1;2023-12-31T23:00:00Z;;EH consumption MP without child MP
170000000000000201;true;;1;2023-12-31T23:00:00Z;;EH consumption MP with no end date for has_electrical_heating
170000000000000202;true;;1;2023-12-31T23:00:00Z;;EH consumption MP without child MP
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
metering_point_id;has_electrical_heating;net_settlement_group;settlement_month;period_from_date;period_to_date;#comment
170000000000000201;true;2;1;2023-12-31T23:00:00Z;;Generates output because there is consumption data and an electrical heating child metering point
170000000000000201;true;;1;2023-12-31T23:00:00Z;;Generates output because there is consumption data and an electrical heating child metering point
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
metering_point_id;has_electrical_heating;net_settlement_group;settlement_month;period_from_date;period_to_date;#comment
170000000000000201;true;2;1;2023-12-31T23:00:00Z;;Generates output because there is consumption data and an electrical heating child metering point
170000000000000201;true;;1;2023-12-31T23:00:00Z;;Generates output because there is consumption data and an electrical heating child metering point
24 changes: 8 additions & 16 deletions source/electrical_heating/tests/utils/measurements_utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from testcommon.dataframes import assert_schema
import pyspark.sql.functions as F
from pyspark.sql import DataFrame, SparkSession
from pyspark.sql.types import ArrayType
from testcommon.dataframes import assert_schema

from electrical_heating.infrastructure.measurements_bronze.schemas.measurements_bronze_v1 import (
measurements_bronze_v1,
point,
)
from pyspark.sql import DataFrame, SparkSession
import pyspark.sql.functions as F


def create_measurements_dataframe(
spark: SparkSession,
measurements: DataFrame
) -> DataFrame:
def create_measurements_dataframe(spark: SparkSession, measurements: DataFrame) -> DataFrame:
measurements = measurements.withColumn(
"points",
F.from_json(F.col("points"), ArrayType(point)),
Expand All @@ -22,20 +20,14 @@ def create_measurements_dataframe(
"start_datetime",
F.to_timestamp(F.col("start_datetime"), "yyyy-MM-dd HH:mm:ss"),
)
.withColumn(
"end_datetime", F.to_timestamp(F.col("end_datetime"), "yyyy-MM-dd HH:mm:ss")
)
.withColumn("end_datetime", F.to_timestamp(F.col("end_datetime"), "yyyy-MM-dd HH:mm:ss"))
.withColumn(
"transaction_creation_datetime",
F.to_timestamp(
F.col("transaction_creation_datetime"), "yyyy-MM-dd HH:mm:ss"
),
F.to_timestamp(F.col("transaction_creation_datetime"), "yyyy-MM-dd HH:mm:ss"),
)
)

measurements = spark.createDataFrame(
measurements.rdd, schema=measurements_bronze_v1, verifySchema=True
)
measurements = spark.createDataFrame(measurements.rdd, schema=measurements_bronze_v1, verifySchema=True)

assert_schema(measurements.schema, measurements_bronze_v1)

Expand Down

0 comments on commit 52b64d1

Please sign in to comment.