Skip to content

Commit

Permalink
water_allocation.meter should correlate with observation_site.name
Browse files Browse the repository at this point in the history
  • Loading branch information
vimto committed Oct 9, 2023
1 parent 6608714 commit 947053b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ effective_consents_with_defaults as (
from effective_daily_consents
where area_id is not null and status = 'active'
),
observed_water_use_with_sites as (
select owu.*, os.name as site_name
from observed_water_use_aggregated_daily owu
inner join observation_sites os on os.id = owu.site_id
),
expanded_meters_per_area as
(select effective_on, area_id, UNNEST(meters) as meter from effective_consents_with_defaults where is_metered = true),
meter_use_by_area as (select effective_on,
area_id,
meter,
use.daily_usage
from expanded_meters_per_area
left join observed_water_use_aggregated_daily use on effective_on = day_observed_at and meter = site_id::varchar),
left join observed_water_use_with_sites use on effective_on = day_observed_at and meter = site_name),
total_daily_use_by_area as (select area_id,
effective_on as date,
SUM(daily_usage) as daily_usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class WaterAllocationAndUsageViewsTest(@Autowired val jdbcTemplate: JdbcTemplate
jdbcTemplate.update(
"""
INSERT INTO observation_sites (id, council_id, name)
VALUES ($siteId, $councilId, 'Test site $siteId')
VALUES ($siteId, $councilId, '$siteId')
ON CONFLICT (id) DO NOTHING
""")

Expand Down

0 comments on commit 947053b

Please sign in to comment.