Skip to content

Commit a887595

Browse files
authored
Merge pull request #107 from luftdaten-at/105-attributeerror-at-campaignsrooms5
#105 fix added get_color method
2 parents e564928 + aba593b commit a887595

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

app/campaign/migrations/0009_remove_organization_owner_remove_organization_users_and_more.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
from django.db import migrations, models
55

66

7+
def set_invalid_foreign_keys_to_null(apps, schema_editor):
8+
Campaign = apps.get_model('campaign', 'Campaign')
9+
for campaign in Campaign.objects.all():
10+
campaign.organization = None
11+
campaign.save()
12+
13+
714
class Migration(migrations.Migration):
815

916
dependencies = [
@@ -13,6 +20,7 @@ class Migration(migrations.Migration):
1320
]
1421

1522
operations = [
23+
migrations.RunPython(set_invalid_foreign_keys_to_null),
1624
migrations.RemoveField(
1725
model_name='organization',
1826
name='owner',

app/campaign/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def get_current_mean(dimension):
226226
# use ADJUSTED_TEMP_CUBE if found
227227
if measurements_adjusted_temp_cube:
228228
current_temperature = measurements_adjusted_temp_cube[0]
229+
temperature_color = Dimension.get_color(Dimension.ADJUSTED_TEMP_CUBE, current_temperature) if current_temperature else None
229230
else:
230231
current_temperature = get_current_mean(Dimension.TEMPERATURE)
231232
temperature_color = Dimension.get_color(Dimension.TEMPERATURE, current_temperature) if current_temperature else None

app/main/enums.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ class Dimension():
128128
TEMPERATURE: ([18, 24], [Color.BLUE, Color.GREEN, Color.RED]),
129129
PM2_5: ([5, 15], [Color.GREEN, Color.YELLOW, Color.RED]),
130130
TVOC: ([220, 1430], [Color.GREEN, Color.YELLOW, Color.RED]),
131-
CO2: ([800, 1000, 1400], [Color.GREEN, Color.YELLOW, Color.ORANGE, Color.RED])
131+
CO2: ([800, 1000, 1400], [Color.GREEN, Color.YELLOW, Color.ORANGE, Color.RED]),
132+
ADJUSTED_TEMP_CUBE: ([18, 24], [Color.BLUE, Color.GREEN, Color.RED]),
132133
}
133134

134135
# Dictionary für die Einheiten der Dimensionen
@@ -221,7 +222,15 @@ def get_name(cls, dimension_id: int) -> str:
221222
def get_sensor_community_name(cls, dimension_id: int) -> str:
222223
"""Returns the sensor-community-specific name for the dimension ID or 'Unknown' if none."""
223224
return cls._sensor_community_names.get(dimension_id, "Unknown")
224-
225+
226+
@classmethod
227+
def get_color(cls, dimension_id: int, val: float):
228+
th, colors = cls.thresholds.get(dimension_id)
229+
th = [-float('inf')] + th + [float('inf')]
230+
for i in range(len(th)):
231+
if th[i] <= val < th[i + 1]:
232+
return colors[i]
233+
225234

226235
class LdProduct():
227236
AIR_AROUND = 1

0 commit comments

Comments
 (0)