Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#105 fix added get_color method #107

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading