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', 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 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