From 20364e7b83972ace0ba6a0dddefd2ba143672d22 Mon Sep 17 00:00:00 2001 From: Nik Sauer Date: Fri, 10 Jan 2025 12:28:43 +0100 Subject: [PATCH 1/3] #105 fix added get_color method --- app/main/enums.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/main/enums.py b/app/main/enums.py index 909ec72..44136bf 100644 --- a/app/main/enums.py +++ b/app/main/enums.py @@ -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 @@ -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 From 6ae66c97d700116919705060403b9eaca706659c Mon Sep 17 00:00:00 2001 From: Nik Sauer Date: Fri, 10 Jan 2025 13:19:12 +0100 Subject: [PATCH 2/3] assign temperature_color for adjusted_temp --- app/campaign/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/campaign/views.py b/app/campaign/views.py index 9721442..ba04b6d 100644 --- a/app/campaign/views.py +++ b/app/campaign/views.py @@ -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 From aba593b27a73be96aed72574883084685e30916b Mon Sep 17 00:00:00 2001 From: Nik Sauer Date: Fri, 10 Jan 2025 13:26:04 +0100 Subject: [PATCH 3/3] #108 reset organization of all campaings to none --- ...ganization_owner_remove_organization_users_and_more.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/campaign/migrations/0009_remove_organization_owner_remove_organization_users_and_more.py b/app/campaign/migrations/0009_remove_organization_owner_remove_organization_users_and_more.py index fbdfbd6..3917c06 100644 --- a/app/campaign/migrations/0009_remove_organization_owner_remove_organization_users_and_more.py +++ b/app/campaign/migrations/0009_remove_organization_owner_remove_organization_users_and_more.py @@ -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 = [ @@ -13,6 +20,7 @@ class Migration(migrations.Migration): ] operations = [ + migrations.RunPython(set_invalid_foreign_keys_to_null), migrations.RemoveField( model_name='organization', name='owner',