-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from SocialFinanceDigitalLabs/37-save-data-bet…
…ween-views---use-scenarios 37 save data between views use scenarios
- Loading branch information
Showing
20 changed files
with
448 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ To load some dummy data, run: | |
python manage.py load-fixtures | ||
``` | ||
|
||
This will load some users and some fake scenarios: | ||
This will load some users: | ||
|
||
**Regular user** | ||
- email: [email protected] | ||
|
@@ -39,6 +39,15 @@ This will load some users and some fake scenarios: | |
- password: test | ||
|
||
|
||
## Delete Session Scenarios | ||
|
||
To manage data transfer between views, users are assigned a session scenario. These scenarios should be deleted weekly through a recurrent job wherever the app is deployed. | ||
To run this command: | ||
|
||
``` | ||
python manage.py erase_session_scenarios | ||
``` | ||
|
||
## Run | ||
|
||
Run `python manage.py runserver` to access the regional demand model platform. it will be live at http://localhost:8000. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Scenario | ||
from .models import SavedScenario, SessionScenario | ||
|
||
admin.site.register(Scenario) | ||
admin.site.register(SessionScenario) | ||
admin.site.register(SavedScenario) | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
dm_regional_app/management/commands/erase_session_scenarios.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from dm_regional_app.models import SessionScenario | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Erases all SessionScenario data weekly" | ||
|
||
def handle(self, *args, **options): | ||
# Delete all session scenario data. This command is set to run weekly at midnight on Sundays. | ||
try: | ||
SessionScenario.objects.all().delete() | ||
self.stdout.write(self.style.SUCCESS("Data erased successfully.")) | ||
except Exception as e: | ||
self.stdout.write(self.style.ERROR(f"Error: {e}")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
dm_regional_app/migrations/0003_savedscenario_sessionscenario_delete_scenario.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# Generated by Django 4.2.10 on 2024-04-24 15:30 | ||
|
||
import django.core.serializers.json | ||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
import dm_regional_app.utils | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("dm_regional_app", "0002_profile"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="SavedScenario", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"historic_filters", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
( | ||
"prediction_filters", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
( | ||
"prediction_parameters", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
( | ||
"historic_stock", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
( | ||
"adjusted_costs", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
("name", models.CharField(max_length=255)), | ||
("description", models.TextField(blank=True, null=True)), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="SessionScenario", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"historic_filters", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
( | ||
"prediction_filters", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
( | ||
"prediction_parameters", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
( | ||
"historic_stock", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
( | ||
"adjusted_costs", | ||
models.JSONField( | ||
decoder=dm_regional_app.utils.DateAwareJSONDecoder, | ||
encoder=django.core.serializers.json.DjangoJSONEncoder, | ||
), | ||
), | ||
( | ||
"saved_scenario", | ||
models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="dm_regional_app.savedscenario", | ||
), | ||
), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.DeleteModel( | ||
name="Scenario", | ||
), | ||
] |
Oops, something went wrong.