Coverage for django_napse/simulations/models/simulations/managers/data_point.py: 33%
12 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
1from django.apps import apps
2from django.db import models
5class SimulationDataPointManager(models.Manager):
6 def create(self, simulation, date, value: float, action: str, amount: float, ticker: str, extra_info=None):
7 SimulationDataPointExtraInfo = apps.get_model("django_napse_simulations", "SimulationDataPointExtraInfo")
9 extra_info = extra_info or {}
11 data_point = self.model(
12 simulation=simulation,
13 date=date,
14 value=value,
15 action=action,
16 amount=amount,
17 ticker=ticker,
18 )
19 data_point.save()
20 for key, value in extra_info.items():
21 print(key, value)
22 SimulationDataPointExtraInfo.objects.create(
23 data_point=data_point,
24 key=key,
25 value=str(value),
26 target_type=type(value).__name__,
27 )
28 return data_point