@@ -572,18 +572,20 @@ end
572572function prepare_profiles_structure (connection)
573573 # Independent of being rolling horizon or not, these are complete
574574 rep_period = Dict (
575- (row. profile_name, row. year, row. rep_period) => ProfileWithRollingHorizon ([
576- row. value for row in DuckDB. query (
577- connection,
578- " SELECT profile.value
579- FROM profiles_rep_periods AS profile
580- WHERE
581- profile.profile_name = '$(row. profile_name) '
582- AND profile.year = $(row. year)
583- AND profile.rep_period = $(row. rep_period)
584- " ,
585- )
586- ]) for row in DuckDB. query (
575+ (row. profile_name, row. year, row. rep_period) => ProfileWithRollingHorizon (
576+ Float64[
577+ row. value for row in DuckDB. query (
578+ connection,
579+ " SELECT profile.value
580+ FROM profiles_rep_periods AS profile
581+ WHERE
582+ profile.profile_name = '$(row. profile_name) '
583+ AND profile.year = $(row. year)
584+ AND profile.rep_period = $(row. rep_period)
585+ " ,
586+ )
587+ ],
588+ ) for row in DuckDB. query (
587589 connection,
588590 " SELECT DISTINCT
589591 profiles.profile_name,
@@ -595,17 +597,19 @@ function prepare_profiles_structure(connection)
595597 )
596598
597599 over_clustered_year = Dict (
598- (row. profile_name, row. year) => ProfileWithRollingHorizon ([
599- row. value for row in DuckDB. query (
600- connection,
601- " SELECT profile.value
602- FROM profiles_timeframe AS profile
603- WHERE
604- profile.profile_name = '$(row. profile_name) '
605- AND profile.year = $(row. year)
606- " ,
607- )
608- ]) for row in DuckDB. query (
600+ (row. profile_name, row. year) => ProfileWithRollingHorizon (
601+ Float64[
602+ row. value for row in DuckDB. query (
603+ connection,
604+ " SELECT profile.value
605+ FROM profiles_timeframe AS profile
606+ WHERE
607+ profile.profile_name = '$(row. profile_name) '
608+ AND profile.year = $(row. year)
609+ " ,
610+ )
611+ ],
612+ ) for row in DuckDB. query (
609613 connection,
610614 " SELECT DISTINCT
611615 profiles.profile_name,
@@ -639,32 +643,34 @@ function prepare_profiles_structure(connection)
639643 profile_name = row. profile_name
640644 year = row. commission_year
641645 storage_inflows = row. storage_inflows
642- over_clustered_year[(profile_name, year)] = ProfileWithRollingHorizon ([
643- row. value for row in DuckDB. query (
644- connection,
645- """
646- WITH cte_profile_rp AS (
646+ over_clustered_year[(profile_name, year)] = ProfileWithRollingHorizon (
647+ Float64[
648+ row. value for row in DuckDB. query (
649+ connection,
650+ """
651+ WITH cte_profile_rp AS (
652+ SELECT
653+ '$asset ' AS asset,
654+ $year AS year,
655+ profiles_rep_periods.rep_period,
656+ profiles_rep_periods.timestep,
657+ profiles_rep_periods.value,
658+ FROM profiles_rep_periods
659+ WHERE profile_name = '$profile_name ' AND year = $year
660+ )
647661 SELECT
648- '$asset ' AS asset,
649- $year AS year,
650- profiles_rep_periods.rep_period,
651- profiles_rep_periods.timestep,
652- profiles_rep_periods.value,
653- FROM profiles_rep_periods
654- WHERE profile_name = '$profile_name ' AND year = $year
662+ rp_map.period,
663+ SUM(cte_profile_rp.value * rp_map.weight * $storage_inflows ) AS value,
664+ FROM cte_profile_rp
665+ LEFT JOIN rep_periods_mapping AS rp_map
666+ ON cte_profile_rp.year = rp_map.year
667+ AND cte_profile_rp.rep_period = rp_map.rep_period
668+ GROUP BY rp_map.period
669+ ORDER BY rp_map.period
670+ """ ,
655671 )
656- SELECT
657- rp_map.period,
658- SUM(cte_profile_rp.value * rp_map.weight * $storage_inflows ) AS value,
659- FROM cte_profile_rp
660- LEFT JOIN rep_periods_mapping AS rp_map
661- ON cte_profile_rp.year = rp_map.year
662- AND cte_profile_rp.rep_period = rp_map.rep_period
663- GROUP BY rp_map.period
664- ORDER BY rp_map.period
665- """ ,
666- )
667- ])
672+ ],
673+ )
668674 end
669675
670676 return ProfileLookup (rep_period, over_clustered_year)
0 commit comments