-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/pip/virtualenv-20.27.0
- Loading branch information
Showing
9 changed files
with
156 additions
and
26 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from measurement.models import Measurement | ||
|
||
from .models import Station | ||
|
||
|
||
def update_variables_for_station(*station_codes) -> None: | ||
"""Update the variables for the given station codes. | ||
The variables are updated based on the measurements associated with the station. | ||
The variables are saved as a comma-separated string in the variables field of the | ||
station model. | ||
Args: | ||
station_codes (tuple[str]): Station codes for which to update the variables. | ||
If not provided, all station codes with measurements are considered. | ||
""" | ||
|
||
# We get the station codes from the Measurement model if not provided | ||
# Only station codes with measurements are considered | ||
station_codes = ( | ||
station_codes | ||
or Measurement.objects.values_list( | ||
"station__station_code", flat=True | ||
).distinct() | ||
) | ||
|
||
# Get the variables for each station and save them as a comma-separated string | ||
for station_code in station_codes: | ||
variables = ( | ||
Measurement.objects.filter(station__station_code=station_code) | ||
.values_list("variable__variable_code", flat=True) | ||
.distinct() | ||
) | ||
if variables: | ||
station = Station.objects.get(station_code=station_code) | ||
station.variables = variables = ",".join(variables) | ||
station.full_clean() | ||
station.save() |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.1.2 on 2024-10-18 10:39 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('station', '0017_alter_basin_owner_alter_country_owner_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='station', | ||
name='variables', | ||
field=models.CharField(default='', editable=False, help_text='Comma-separated list of variables measured by the station.', max_length=100, verbose_name='Stored variables'), | ||
), | ||
] |
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
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