Skip to content

Commit

Permalink
Comment out timeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
paulapreuss committed Feb 3, 2025
1 parent 116a169 commit a221cf7
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 76 deletions.
36 changes: 18 additions & 18 deletions app/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,21 +1071,21 @@ def __init__(self, *args, **kwargs):
]


class UploadTimeseriesForm(OpenPlanModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["values"] = DualNumberField(default=0, param_name="values")

class Meta:
model = Timeseries
exclude = ["id", "user"]
widgets = {
"start_date": forms.DateInput(
format="%Y-%m-%d",
attrs={
"class": "TestDateClass",
"placeholder": "Select a start date",
"type": "date",
},
)
}
# class UploadTimeseriesForm(OpenPlanModelForm):
# def __init__(self, *args, **kwargs):
# super().__init__(*args, **kwargs)
# self.fields["values"] = DualNumberField(default=0, param_name="values")
#
# class Meta:
# model = Timeseries
# exclude = ["id", "user"]
# widgets = {
# "start_date": forms.DateInput(
# format="%Y-%m-%d",
# attrs={
# "class": "TestDateClass",
# "placeholder": "Select a start date",
# "type": "date",
# },
# )
# }
2 changes: 1 addition & 1 deletion app/projects/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.utils.translation import gettext_lazy as _
from django.utils.html import html_safe
from projects.dtos import convert_to_dto
from projects.models import Timeseries, AssetType
from projects.models import AssetType
from projects.constants import MAP_MVS_EPA
from dashboard.helpers import KPIFinder

Expand Down
114 changes: 57 additions & 57 deletions app/projects/models/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,63 +295,63 @@ def get_default_timeseries():
return list([])


class Timeseries(models.Model):
name = models.CharField(max_length=120, blank=True, default="")
values = ArrayField(
models.FloatField(), blank=False, default=get_default_timeseries
)
units = models.CharField(
max_length=50, choices=TIMESERIES_UNITS, blank=True, null=True
)
category = models.CharField(
max_length=6, choices=TIMESERIES_CATEGORIES, blank=True, null=True
)

# TODO user or scenario can be both null only if open_source attribute is True --> by way of saving
# TODO if the timeseries is open_source and the user is deleted, the timeseries user should just be set to null,
# otherwise the timeseries should be deleted
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True
)
# TODO check that if both a user and scenario are provided the scenario belongs to the user
# scenario = models.ForeignKey(
# Scenario, on_delete=models.CASCADE, null=True, blank=True
# )
ts_type = models.CharField(max_length=12, choices=MVS_TYPE, blank=True, null=True)

open_source = models.BooleanField(
null=False, blank=False, choices=BOOL_CHOICES, default=False
)

# get this from the scenario
# TODO rename with _date instead of _time
start_time = models.DateTimeField(blank=True, default=None, null=True)
end_time = models.DateTimeField(blank=True, default=None, null=True)
time_step = models.IntegerField(
blank=True, default=None, null=True, validators=[MinValueValidator(1)]
)

def save(self, *args, **kwargs):
n = len(self.values)
if n == 1:
self.ts_type = "scalar"
elif n > 1:
self.ts_type = "vector"
super().save(*args, **kwargs)

@property
def get_values(self):
if self.ts_type == "scalar":
answer = self.values[0]
else:
answer = self.values
return answer

def compute_time_attribute_from_timestamps(self, timestamps):
pass

def compute_end_time_from_duration(self, duration):
pass
# class Timeseries(models.Model):
# name = models.CharField(max_length=120, blank=True, default="")
# values = ArrayField(
# models.FloatField(), blank=False, default=get_default_timeseries
# )
# units = models.CharField(
# max_length=50, choices=TIMESERIES_UNITS, blank=True, null=True
# )
# category = models.CharField(
# max_length=6, choices=TIMESERIES_CATEGORIES, blank=True, null=True
# )
#
# # TODO user or scenario can be both null only if open_source attribute is True --> by way of saving
# # TODO if the timeseries is open_source and the user is deleted, the timeseries user should just be set to null,
# # otherwise the timeseries should be deleted
# user = models.ForeignKey(
# settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True
# )
# # TODO check that if both a user and scenario are provided the scenario belongs to the user
# # scenario = models.ForeignKey(
# # Scenario, on_delete=models.CASCADE, null=True, blank=True
# # )
# ts_type = models.CharField(max_length=12, choices=MVS_TYPE, blank=True, null=True)
#
# open_source = models.BooleanField(
# null=False, blank=False, choices=BOOL_CHOICES, default=False
# )
#
# # get this from the scenario
# # TODO rename with _date instead of _time
# start_time = models.DateTimeField(blank=True, default=None, null=True)
# end_time = models.DateTimeField(blank=True, default=None, null=True)
# time_step = models.IntegerField(
# blank=True, default=None, null=True, validators=[MinValueValidator(1)]
# )
#
# def save(self, *args, **kwargs):
# n = len(self.values)
# if n == 1:
# self.ts_type = "scalar"
# elif n > 1:
# self.ts_type = "vector"
# super().save(*args, **kwargs)
#
# @property
# def get_values(self):
# if self.ts_type == "scalar":
# answer = self.values[0]
# else:
# answer = self.values
# return answer
#
# def compute_time_attribute_from_timestamps(self, timestamps):
# pass
#
# def compute_end_time_from_duration(self, duration):
# pass


class AssetType(models.Model):
Expand Down

0 comments on commit a221cf7

Please sign in to comment.