Skip to content

Commit

Permalink
Merge pull request #107 from luftdaten-at/105-attributeerror-at-campa…
Browse files Browse the repository at this point in the history
…ignsrooms5

#105 fix added get_color method
  • Loading branch information
n11ik authored Jan 10, 2025
2 parents e564928 + aba593b commit a887595
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
from django.db import migrations, models


def set_invalid_foreign_keys_to_null(apps, schema_editor):
Campaign = apps.get_model('campaign', 'Campaign')
for campaign in Campaign.objects.all():
campaign.organization = None
campaign.save()


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -13,6 +20,7 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(set_invalid_foreign_keys_to_null),
migrations.RemoveField(
model_name='organization',
name='owner',
Expand Down
1 change: 1 addition & 0 deletions app/campaign/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def get_current_mean(dimension):
# use ADJUSTED_TEMP_CUBE if found
if measurements_adjusted_temp_cube:
current_temperature = measurements_adjusted_temp_cube[0]
temperature_color = Dimension.get_color(Dimension.ADJUSTED_TEMP_CUBE, current_temperature) if current_temperature else None
else:
current_temperature = get_current_mean(Dimension.TEMPERATURE)
temperature_color = Dimension.get_color(Dimension.TEMPERATURE, current_temperature) if current_temperature else None
Expand Down
13 changes: 11 additions & 2 deletions app/main/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class Dimension():
TEMPERATURE: ([18, 24], [Color.BLUE, Color.GREEN, Color.RED]),
PM2_5: ([5, 15], [Color.GREEN, Color.YELLOW, Color.RED]),
TVOC: ([220, 1430], [Color.GREEN, Color.YELLOW, Color.RED]),
CO2: ([800, 1000, 1400], [Color.GREEN, Color.YELLOW, Color.ORANGE, Color.RED])
CO2: ([800, 1000, 1400], [Color.GREEN, Color.YELLOW, Color.ORANGE, Color.RED]),
ADJUSTED_TEMP_CUBE: ([18, 24], [Color.BLUE, Color.GREEN, Color.RED]),
}

# Dictionary für die Einheiten der Dimensionen
Expand Down Expand Up @@ -221,7 +222,15 @@ def get_name(cls, dimension_id: int) -> str:
def get_sensor_community_name(cls, dimension_id: int) -> str:
"""Returns the sensor-community-specific name for the dimension ID or 'Unknown' if none."""
return cls._sensor_community_names.get(dimension_id, "Unknown")


@classmethod
def get_color(cls, dimension_id: int, val: float):
th, colors = cls.thresholds.get(dimension_id)
th = [-float('inf')] + th + [float('inf')]
for i in range(len(th)):
if th[i] <= val < th[i + 1]:
return colors[i]


class LdProduct():
AIR_AROUND = 1
Expand Down

0 comments on commit a887595

Please sign in to comment.