From d6b1f647b72c8ba4c23bb1a74113af88331ba744 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sat, 17 Jul 2021 20:40:32 +1000 Subject: [PATCH 01/22] setup side by side django and flask --- Pipfile => django_version/Pipfile | 0 Pipfile.lock => django_version/Pipfile.lock | 0 README.md => django_version/README.md | 0 {cba => django_version/cba}/administrations/__init__.py | 0 {cba => django_version/cba}/administrations/admin.py | 0 {cba => django_version/cba}/administrations/apps.py | 0 {cba => django_version/cba}/administrations/exceptions.py | 0 .../cba}/administrations/management/__init__.py | 0 .../cba}/administrations/management/commands/__init__.py | 0 .../cba}/administrations/management/commands/import_provinces.py | 0 {cba => django_version/cba}/administrations/managers.py | 0 .../cba}/administrations/migrations/0001_initial.py | 0 .../cba}/administrations/migrations/__init__.py | 0 {cba => django_version/cba}/administrations/models.py | 0 {cba => django_version/cba}/administrations/serializers.py | 0 {cba => django_version/cba}/administrations/tests.py | 0 {cba => django_version/cba}/administrations/urls.py | 0 {cba => django_version/cba}/administrations/utils.py | 0 {cba => django_version/cba}/administrations/views.py | 0 {cba => django_version/cba}/configs/__init__.py | 0 {cba => django_version/cba}/configs/settings/__init__.py | 0 {cba => django_version/cba}/configs/settings/base.py | 0 {cba => django_version/cba}/configs/settings/development.py | 0 {cba => django_version/cba}/configs/urls.py | 0 {cba => django_version/cba}/configs/wsgi.py | 0 {cba => django_version/cba}/core/__init__.py | 0 {cba => django_version/cba}/core/admin.py | 0 {cba => django_version/cba}/core/apps.py | 0 {cba => django_version/cba}/core/cba.py | 0 {cba => django_version/cba}/core/default.py | 0 {cba => django_version/cba}/core/migrations/0001_initial.py | 0 .../cba}/core/migrations/0002_cbaresult_section.py | 0 .../cba}/core/migrations/0003_auto_20190608_0918.py | 0 {cba => django_version/cba}/core/migrations/__init__.py | 0 {cba => django_version/cba}/core/models.py | 0 {cba => django_version/cba}/core/tests.py | 0 {cba => django_version/cba}/core/views.py | 0 .../cba}/fixtures/pavement_condition_class.json | 0 {cba => django_version/cba}/fixtures/provinces_districts.json | 0 {cba => django_version/cba}/fixtures/road_sections_thanhhoa.csv | 0 {cba => django_version/cba}/fixtures/surface_type.json | 0 {cba => django_version/cba}/fixtures/traffic_level.json | 0 {cba => django_version/cba}/manage.py | 0 {cba => django_version/cba}/roads/__init__.py | 0 {cba => django_version/cba}/roads/adapters.py | 0 {cba => django_version/cba}/roads/admin.py | 0 {cba => django_version/cba}/roads/apps.py | 0 {cba => django_version/cba}/roads/constants.py | 0 {cba => django_version/cba}/roads/management/__init__.py | 0 {cba => django_version/cba}/roads/management/commands/__init__.py | 0 .../cba}/roads/management/commands/import_section_data.py | 0 {cba => django_version/cba}/roads/migrations/0001_initial.py | 0 .../cba}/roads/migrations/0002_auto_20181016_1913.py | 0 .../cba}/roads/migrations/0003_auto_20181220_1404.py | 0 ...ditionclass_pavementtype_roadclass_surfacetype_temperaturec.py | 0 .../cba}/roads/migrations/0005_auto_20190607_1321.py | 0 .../cba}/roads/migrations/0006_auto_20190607_1351.py | 0 {cba => django_version/cba}/roads/migrations/0007_laneclass.py | 0 .../cba}/roads/migrations/0008_auto_20190607_1645.py | 0 .../cba}/roads/migrations/0009_auto_20190607_1657.py | 0 .../cba}/roads/migrations/0010_auto_20190607_1716.py | 0 {cba => django_version/cba}/roads/migrations/__init__.py | 0 {cba => django_version/cba}/roads/models.py | 0 {cba => django_version/cba}/roads/property_classes.py | 0 {cba => django_version/cba}/roads/serializers.py | 0 {cba => django_version/cba}/roads/tests.py | 0 {cba => django_version/cba}/roads/urls.py | 0 {cba => django_version/cba}/roads/views.py | 0 {docs => django_version/docs}/.gitkeep | 0 {docs => django_version/docs}/environment_variables.md | 0 {envs => django_version/envs}/.gitkeep | 0 {scripts => django_version/scripts}/insert_traffic_level.sql | 0 72 files changed, 0 insertions(+), 0 deletions(-) rename Pipfile => django_version/Pipfile (100%) rename Pipfile.lock => django_version/Pipfile.lock (100%) rename README.md => django_version/README.md (100%) rename {cba => django_version/cba}/administrations/__init__.py (100%) rename {cba => django_version/cba}/administrations/admin.py (100%) rename {cba => django_version/cba}/administrations/apps.py (100%) rename {cba => django_version/cba}/administrations/exceptions.py (100%) rename {cba => django_version/cba}/administrations/management/__init__.py (100%) rename {cba => django_version/cba}/administrations/management/commands/__init__.py (100%) rename {cba => django_version/cba}/administrations/management/commands/import_provinces.py (100%) rename {cba => django_version/cba}/administrations/managers.py (100%) rename {cba => django_version/cba}/administrations/migrations/0001_initial.py (100%) rename {cba => django_version/cba}/administrations/migrations/__init__.py (100%) rename {cba => django_version/cba}/administrations/models.py (100%) rename {cba => django_version/cba}/administrations/serializers.py (100%) rename {cba => django_version/cba}/administrations/tests.py (100%) rename {cba => django_version/cba}/administrations/urls.py (100%) rename {cba => django_version/cba}/administrations/utils.py (100%) rename {cba => django_version/cba}/administrations/views.py (100%) rename {cba => django_version/cba}/configs/__init__.py (100%) rename {cba => django_version/cba}/configs/settings/__init__.py (100%) rename {cba => django_version/cba}/configs/settings/base.py (100%) rename {cba => django_version/cba}/configs/settings/development.py (100%) rename {cba => django_version/cba}/configs/urls.py (100%) rename {cba => django_version/cba}/configs/wsgi.py (100%) rename {cba => django_version/cba}/core/__init__.py (100%) rename {cba => django_version/cba}/core/admin.py (100%) rename {cba => django_version/cba}/core/apps.py (100%) rename {cba => django_version/cba}/core/cba.py (100%) rename {cba => django_version/cba}/core/default.py (100%) rename {cba => django_version/cba}/core/migrations/0001_initial.py (100%) rename {cba => django_version/cba}/core/migrations/0002_cbaresult_section.py (100%) rename {cba => django_version/cba}/core/migrations/0003_auto_20190608_0918.py (100%) rename {cba => django_version/cba}/core/migrations/__init__.py (100%) rename {cba => django_version/cba}/core/models.py (100%) rename {cba => django_version/cba}/core/tests.py (100%) rename {cba => django_version/cba}/core/views.py (100%) rename {cba => django_version/cba}/fixtures/pavement_condition_class.json (100%) rename {cba => django_version/cba}/fixtures/provinces_districts.json (100%) rename {cba => django_version/cba}/fixtures/road_sections_thanhhoa.csv (100%) rename {cba => django_version/cba}/fixtures/surface_type.json (100%) rename {cba => django_version/cba}/fixtures/traffic_level.json (100%) rename {cba => django_version/cba}/manage.py (100%) rename {cba => django_version/cba}/roads/__init__.py (100%) rename {cba => django_version/cba}/roads/adapters.py (100%) rename {cba => django_version/cba}/roads/admin.py (100%) rename {cba => django_version/cba}/roads/apps.py (100%) rename {cba => django_version/cba}/roads/constants.py (100%) rename {cba => django_version/cba}/roads/management/__init__.py (100%) rename {cba => django_version/cba}/roads/management/commands/__init__.py (100%) rename {cba => django_version/cba}/roads/management/commands/import_section_data.py (100%) rename {cba => django_version/cba}/roads/migrations/0001_initial.py (100%) rename {cba => django_version/cba}/roads/migrations/0002_auto_20181016_1913.py (100%) rename {cba => django_version/cba}/roads/migrations/0003_auto_20181220_1404.py (100%) rename {cba => django_version/cba}/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py (100%) rename {cba => django_version/cba}/roads/migrations/0005_auto_20190607_1321.py (100%) rename {cba => django_version/cba}/roads/migrations/0006_auto_20190607_1351.py (100%) rename {cba => django_version/cba}/roads/migrations/0007_laneclass.py (100%) rename {cba => django_version/cba}/roads/migrations/0008_auto_20190607_1645.py (100%) rename {cba => django_version/cba}/roads/migrations/0009_auto_20190607_1657.py (100%) rename {cba => django_version/cba}/roads/migrations/0010_auto_20190607_1716.py (100%) rename {cba => django_version/cba}/roads/migrations/__init__.py (100%) rename {cba => django_version/cba}/roads/models.py (100%) rename {cba => django_version/cba}/roads/property_classes.py (100%) rename {cba => django_version/cba}/roads/serializers.py (100%) rename {cba => django_version/cba}/roads/tests.py (100%) rename {cba => django_version/cba}/roads/urls.py (100%) rename {cba => django_version/cba}/roads/views.py (100%) rename {docs => django_version/docs}/.gitkeep (100%) rename {docs => django_version/docs}/environment_variables.md (100%) rename {envs => django_version/envs}/.gitkeep (100%) rename {scripts => django_version/scripts}/insert_traffic_level.sql (100%) diff --git a/Pipfile b/django_version/Pipfile similarity index 100% rename from Pipfile rename to django_version/Pipfile diff --git a/Pipfile.lock b/django_version/Pipfile.lock similarity index 100% rename from Pipfile.lock rename to django_version/Pipfile.lock diff --git a/README.md b/django_version/README.md similarity index 100% rename from README.md rename to django_version/README.md diff --git a/cba/administrations/__init__.py b/django_version/cba/administrations/__init__.py similarity index 100% rename from cba/administrations/__init__.py rename to django_version/cba/administrations/__init__.py diff --git a/cba/administrations/admin.py b/django_version/cba/administrations/admin.py similarity index 100% rename from cba/administrations/admin.py rename to django_version/cba/administrations/admin.py diff --git a/cba/administrations/apps.py b/django_version/cba/administrations/apps.py similarity index 100% rename from cba/administrations/apps.py rename to django_version/cba/administrations/apps.py diff --git a/cba/administrations/exceptions.py b/django_version/cba/administrations/exceptions.py similarity index 100% rename from cba/administrations/exceptions.py rename to django_version/cba/administrations/exceptions.py diff --git a/cba/administrations/management/__init__.py b/django_version/cba/administrations/management/__init__.py similarity index 100% rename from cba/administrations/management/__init__.py rename to django_version/cba/administrations/management/__init__.py diff --git a/cba/administrations/management/commands/__init__.py b/django_version/cba/administrations/management/commands/__init__.py similarity index 100% rename from cba/administrations/management/commands/__init__.py rename to django_version/cba/administrations/management/commands/__init__.py diff --git a/cba/administrations/management/commands/import_provinces.py b/django_version/cba/administrations/management/commands/import_provinces.py similarity index 100% rename from cba/administrations/management/commands/import_provinces.py rename to django_version/cba/administrations/management/commands/import_provinces.py diff --git a/cba/administrations/managers.py b/django_version/cba/administrations/managers.py similarity index 100% rename from cba/administrations/managers.py rename to django_version/cba/administrations/managers.py diff --git a/cba/administrations/migrations/0001_initial.py b/django_version/cba/administrations/migrations/0001_initial.py similarity index 100% rename from cba/administrations/migrations/0001_initial.py rename to django_version/cba/administrations/migrations/0001_initial.py diff --git a/cba/administrations/migrations/__init__.py b/django_version/cba/administrations/migrations/__init__.py similarity index 100% rename from cba/administrations/migrations/__init__.py rename to django_version/cba/administrations/migrations/__init__.py diff --git a/cba/administrations/models.py b/django_version/cba/administrations/models.py similarity index 100% rename from cba/administrations/models.py rename to django_version/cba/administrations/models.py diff --git a/cba/administrations/serializers.py b/django_version/cba/administrations/serializers.py similarity index 100% rename from cba/administrations/serializers.py rename to django_version/cba/administrations/serializers.py diff --git a/cba/administrations/tests.py b/django_version/cba/administrations/tests.py similarity index 100% rename from cba/administrations/tests.py rename to django_version/cba/administrations/tests.py diff --git a/cba/administrations/urls.py b/django_version/cba/administrations/urls.py similarity index 100% rename from cba/administrations/urls.py rename to django_version/cba/administrations/urls.py diff --git a/cba/administrations/utils.py b/django_version/cba/administrations/utils.py similarity index 100% rename from cba/administrations/utils.py rename to django_version/cba/administrations/utils.py diff --git a/cba/administrations/views.py b/django_version/cba/administrations/views.py similarity index 100% rename from cba/administrations/views.py rename to django_version/cba/administrations/views.py diff --git a/cba/configs/__init__.py b/django_version/cba/configs/__init__.py similarity index 100% rename from cba/configs/__init__.py rename to django_version/cba/configs/__init__.py diff --git a/cba/configs/settings/__init__.py b/django_version/cba/configs/settings/__init__.py similarity index 100% rename from cba/configs/settings/__init__.py rename to django_version/cba/configs/settings/__init__.py diff --git a/cba/configs/settings/base.py b/django_version/cba/configs/settings/base.py similarity index 100% rename from cba/configs/settings/base.py rename to django_version/cba/configs/settings/base.py diff --git a/cba/configs/settings/development.py b/django_version/cba/configs/settings/development.py similarity index 100% rename from cba/configs/settings/development.py rename to django_version/cba/configs/settings/development.py diff --git a/cba/configs/urls.py b/django_version/cba/configs/urls.py similarity index 100% rename from cba/configs/urls.py rename to django_version/cba/configs/urls.py diff --git a/cba/configs/wsgi.py b/django_version/cba/configs/wsgi.py similarity index 100% rename from cba/configs/wsgi.py rename to django_version/cba/configs/wsgi.py diff --git a/cba/core/__init__.py b/django_version/cba/core/__init__.py similarity index 100% rename from cba/core/__init__.py rename to django_version/cba/core/__init__.py diff --git a/cba/core/admin.py b/django_version/cba/core/admin.py similarity index 100% rename from cba/core/admin.py rename to django_version/cba/core/admin.py diff --git a/cba/core/apps.py b/django_version/cba/core/apps.py similarity index 100% rename from cba/core/apps.py rename to django_version/cba/core/apps.py diff --git a/cba/core/cba.py b/django_version/cba/core/cba.py similarity index 100% rename from cba/core/cba.py rename to django_version/cba/core/cba.py diff --git a/cba/core/default.py b/django_version/cba/core/default.py similarity index 100% rename from cba/core/default.py rename to django_version/cba/core/default.py diff --git a/cba/core/migrations/0001_initial.py b/django_version/cba/core/migrations/0001_initial.py similarity index 100% rename from cba/core/migrations/0001_initial.py rename to django_version/cba/core/migrations/0001_initial.py diff --git a/cba/core/migrations/0002_cbaresult_section.py b/django_version/cba/core/migrations/0002_cbaresult_section.py similarity index 100% rename from cba/core/migrations/0002_cbaresult_section.py rename to django_version/cba/core/migrations/0002_cbaresult_section.py diff --git a/cba/core/migrations/0003_auto_20190608_0918.py b/django_version/cba/core/migrations/0003_auto_20190608_0918.py similarity index 100% rename from cba/core/migrations/0003_auto_20190608_0918.py rename to django_version/cba/core/migrations/0003_auto_20190608_0918.py diff --git a/cba/core/migrations/__init__.py b/django_version/cba/core/migrations/__init__.py similarity index 100% rename from cba/core/migrations/__init__.py rename to django_version/cba/core/migrations/__init__.py diff --git a/cba/core/models.py b/django_version/cba/core/models.py similarity index 100% rename from cba/core/models.py rename to django_version/cba/core/models.py diff --git a/cba/core/tests.py b/django_version/cba/core/tests.py similarity index 100% rename from cba/core/tests.py rename to django_version/cba/core/tests.py diff --git a/cba/core/views.py b/django_version/cba/core/views.py similarity index 100% rename from cba/core/views.py rename to django_version/cba/core/views.py diff --git a/cba/fixtures/pavement_condition_class.json b/django_version/cba/fixtures/pavement_condition_class.json similarity index 100% rename from cba/fixtures/pavement_condition_class.json rename to django_version/cba/fixtures/pavement_condition_class.json diff --git a/cba/fixtures/provinces_districts.json b/django_version/cba/fixtures/provinces_districts.json similarity index 100% rename from cba/fixtures/provinces_districts.json rename to django_version/cba/fixtures/provinces_districts.json diff --git a/cba/fixtures/road_sections_thanhhoa.csv b/django_version/cba/fixtures/road_sections_thanhhoa.csv similarity index 100% rename from cba/fixtures/road_sections_thanhhoa.csv rename to django_version/cba/fixtures/road_sections_thanhhoa.csv diff --git a/cba/fixtures/surface_type.json b/django_version/cba/fixtures/surface_type.json similarity index 100% rename from cba/fixtures/surface_type.json rename to django_version/cba/fixtures/surface_type.json diff --git a/cba/fixtures/traffic_level.json b/django_version/cba/fixtures/traffic_level.json similarity index 100% rename from cba/fixtures/traffic_level.json rename to django_version/cba/fixtures/traffic_level.json diff --git a/cba/manage.py b/django_version/cba/manage.py similarity index 100% rename from cba/manage.py rename to django_version/cba/manage.py diff --git a/cba/roads/__init__.py b/django_version/cba/roads/__init__.py similarity index 100% rename from cba/roads/__init__.py rename to django_version/cba/roads/__init__.py diff --git a/cba/roads/adapters.py b/django_version/cba/roads/adapters.py similarity index 100% rename from cba/roads/adapters.py rename to django_version/cba/roads/adapters.py diff --git a/cba/roads/admin.py b/django_version/cba/roads/admin.py similarity index 100% rename from cba/roads/admin.py rename to django_version/cba/roads/admin.py diff --git a/cba/roads/apps.py b/django_version/cba/roads/apps.py similarity index 100% rename from cba/roads/apps.py rename to django_version/cba/roads/apps.py diff --git a/cba/roads/constants.py b/django_version/cba/roads/constants.py similarity index 100% rename from cba/roads/constants.py rename to django_version/cba/roads/constants.py diff --git a/cba/roads/management/__init__.py b/django_version/cba/roads/management/__init__.py similarity index 100% rename from cba/roads/management/__init__.py rename to django_version/cba/roads/management/__init__.py diff --git a/cba/roads/management/commands/__init__.py b/django_version/cba/roads/management/commands/__init__.py similarity index 100% rename from cba/roads/management/commands/__init__.py rename to django_version/cba/roads/management/commands/__init__.py diff --git a/cba/roads/management/commands/import_section_data.py b/django_version/cba/roads/management/commands/import_section_data.py similarity index 100% rename from cba/roads/management/commands/import_section_data.py rename to django_version/cba/roads/management/commands/import_section_data.py diff --git a/cba/roads/migrations/0001_initial.py b/django_version/cba/roads/migrations/0001_initial.py similarity index 100% rename from cba/roads/migrations/0001_initial.py rename to django_version/cba/roads/migrations/0001_initial.py diff --git a/cba/roads/migrations/0002_auto_20181016_1913.py b/django_version/cba/roads/migrations/0002_auto_20181016_1913.py similarity index 100% rename from cba/roads/migrations/0002_auto_20181016_1913.py rename to django_version/cba/roads/migrations/0002_auto_20181016_1913.py diff --git a/cba/roads/migrations/0003_auto_20181220_1404.py b/django_version/cba/roads/migrations/0003_auto_20181220_1404.py similarity index 100% rename from cba/roads/migrations/0003_auto_20181220_1404.py rename to django_version/cba/roads/migrations/0003_auto_20181220_1404.py diff --git a/cba/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py b/django_version/cba/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py similarity index 100% rename from cba/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py rename to django_version/cba/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py diff --git a/cba/roads/migrations/0005_auto_20190607_1321.py b/django_version/cba/roads/migrations/0005_auto_20190607_1321.py similarity index 100% rename from cba/roads/migrations/0005_auto_20190607_1321.py rename to django_version/cba/roads/migrations/0005_auto_20190607_1321.py diff --git a/cba/roads/migrations/0006_auto_20190607_1351.py b/django_version/cba/roads/migrations/0006_auto_20190607_1351.py similarity index 100% rename from cba/roads/migrations/0006_auto_20190607_1351.py rename to django_version/cba/roads/migrations/0006_auto_20190607_1351.py diff --git a/cba/roads/migrations/0007_laneclass.py b/django_version/cba/roads/migrations/0007_laneclass.py similarity index 100% rename from cba/roads/migrations/0007_laneclass.py rename to django_version/cba/roads/migrations/0007_laneclass.py diff --git a/cba/roads/migrations/0008_auto_20190607_1645.py b/django_version/cba/roads/migrations/0008_auto_20190607_1645.py similarity index 100% rename from cba/roads/migrations/0008_auto_20190607_1645.py rename to django_version/cba/roads/migrations/0008_auto_20190607_1645.py diff --git a/cba/roads/migrations/0009_auto_20190607_1657.py b/django_version/cba/roads/migrations/0009_auto_20190607_1657.py similarity index 100% rename from cba/roads/migrations/0009_auto_20190607_1657.py rename to django_version/cba/roads/migrations/0009_auto_20190607_1657.py diff --git a/cba/roads/migrations/0010_auto_20190607_1716.py b/django_version/cba/roads/migrations/0010_auto_20190607_1716.py similarity index 100% rename from cba/roads/migrations/0010_auto_20190607_1716.py rename to django_version/cba/roads/migrations/0010_auto_20190607_1716.py diff --git a/cba/roads/migrations/__init__.py b/django_version/cba/roads/migrations/__init__.py similarity index 100% rename from cba/roads/migrations/__init__.py rename to django_version/cba/roads/migrations/__init__.py diff --git a/cba/roads/models.py b/django_version/cba/roads/models.py similarity index 100% rename from cba/roads/models.py rename to django_version/cba/roads/models.py diff --git a/cba/roads/property_classes.py b/django_version/cba/roads/property_classes.py similarity index 100% rename from cba/roads/property_classes.py rename to django_version/cba/roads/property_classes.py diff --git a/cba/roads/serializers.py b/django_version/cba/roads/serializers.py similarity index 100% rename from cba/roads/serializers.py rename to django_version/cba/roads/serializers.py diff --git a/cba/roads/tests.py b/django_version/cba/roads/tests.py similarity index 100% rename from cba/roads/tests.py rename to django_version/cba/roads/tests.py diff --git a/cba/roads/urls.py b/django_version/cba/roads/urls.py similarity index 100% rename from cba/roads/urls.py rename to django_version/cba/roads/urls.py diff --git a/cba/roads/views.py b/django_version/cba/roads/views.py similarity index 100% rename from cba/roads/views.py rename to django_version/cba/roads/views.py diff --git a/docs/.gitkeep b/django_version/docs/.gitkeep similarity index 100% rename from docs/.gitkeep rename to django_version/docs/.gitkeep diff --git a/docs/environment_variables.md b/django_version/docs/environment_variables.md similarity index 100% rename from docs/environment_variables.md rename to django_version/docs/environment_variables.md diff --git a/envs/.gitkeep b/django_version/envs/.gitkeep similarity index 100% rename from envs/.gitkeep rename to django_version/envs/.gitkeep diff --git a/scripts/insert_traffic_level.sql b/django_version/scripts/insert_traffic_level.sql similarity index 100% rename from scripts/insert_traffic_level.sql rename to django_version/scripts/insert_traffic_level.sql From f99356f3a15a5c73906aca14bba92c60737f000f Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sat, 17 Jul 2021 21:53:19 +1000 Subject: [PATCH 02/22] initial setup of a FLASK api --- flask_version/MANIFEST.in | 1 + flask_version/cba_server/__init__.py | 30 ++++++++++++++++++++ flask_version/cba_server/api.py | 17 +++++++++++ flask_version/cba_server/db.py | 42 ++++++++++++++++++++++++++++ flask_version/cba_server/schema.sql | 17 +++++++++++ flask_version/requirements.txt | 4 +++ flask_version/setup.py | 1 + flask_version/tests/test_api.py | 1 + 8 files changed, 113 insertions(+) create mode 100644 flask_version/MANIFEST.in create mode 100644 flask_version/cba_server/__init__.py create mode 100644 flask_version/cba_server/api.py create mode 100644 flask_version/cba_server/db.py create mode 100644 flask_version/cba_server/schema.sql create mode 100644 flask_version/requirements.txt create mode 100644 flask_version/setup.py create mode 100644 flask_version/tests/test_api.py diff --git a/flask_version/MANIFEST.in b/flask_version/MANIFEST.in new file mode 100644 index 0000000..945c9b4 --- /dev/null +++ b/flask_version/MANIFEST.in @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/flask_version/cba_server/__init__.py b/flask_version/cba_server/__init__.py new file mode 100644 index 0000000..c862a97 --- /dev/null +++ b/flask_version/cba_server/__init__.py @@ -0,0 +1,30 @@ +import os +from flask import Flask +import cba_server.db +import cba_server.api + +def create_app(test_config=None): + # create and configure the app + app = Flask(__name__, instance_relative_config=True) + app.config.from_mapping( + SECRET_KEY='dev', + DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'), + ) + + if test_config is None: + # load the instance config, if it exists, when not testing + app.config.from_pyfile('config.py', silent=True) + else: + # load the test config if passed in + app.config.from_mapping(test_config) + + # ensure the instance folder exists + try: + os.makedirs(app.instance_path) + except OSError: + pass + + db.init_app(app) + app.register_blueprint(api.bp) + + return app diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py new file mode 100644 index 0000000..625a2f2 --- /dev/null +++ b/flask_version/cba_server/api.py @@ -0,0 +1,17 @@ +from flask import ( + Blueprint, flash, g, redirect, render_template, request, url_for +) +from werkzeug.exceptions import abort + +from cba_server.db import get_db +from roads_cba_py.cba import test_api + +bp = Blueprint('api', __name__) + +@bp.route('/test_api', methods=['POST']) +def hello(): + data = request.json + input = data['key'] + output = test_api(input) + + return f"You provided {input} which I processed into {output}" diff --git a/flask_version/cba_server/db.py b/flask_version/cba_server/db.py new file mode 100644 index 0000000..885e1f3 --- /dev/null +++ b/flask_version/cba_server/db.py @@ -0,0 +1,42 @@ +import sqlite3 + +import click +from flask import current_app, g +from flask.cli import with_appcontext + + +def get_db(): + if 'db' not in g: + g.db = sqlite3.connect( + current_app.config['DATABASE'], + detect_types=sqlite3.PARSE_DECLTYPES + ) + g.db.row_factory = sqlite3.Row + + return g.db + + +def close_db(e=None): + db = g.pop('db', None) + + if db is not None: + db.close() + +def init_db(): + db = get_db() + + with current_app.open_resource('schema.sql') as f: + db.executescript(f.read().decode('utf8')) + + +@click.command('init-db') +@with_appcontext +def init_db_command(): + """Clear the existing data and create new tables.""" + init_db() + click.echo('Initialized the database.') + + +def init_app(app): + app.teardown_appcontext(close_db) + app.cli.add_command(init_db_command) diff --git a/flask_version/cba_server/schema.sql b/flask_version/cba_server/schema.sql new file mode 100644 index 0000000..be76d7e --- /dev/null +++ b/flask_version/cba_server/schema.sql @@ -0,0 +1,17 @@ +DROP TABLE IF EXISTS user; +DROP TABLE IF EXISTS post; + +CREATE TABLE user ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT UNIQUE NOT NULL, + password TEXT NOT NULL +); + +CREATE TABLE post ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + author_id INTEGER NOT NULL, + created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + title TEXT NOT NULL, + body TEXT NOT NULL, + FOREIGN KEY (author_id) REFERENCES user (id) +); diff --git a/flask_version/requirements.txt b/flask_version/requirements.txt new file mode 100644 index 0000000..0291d4b --- /dev/null +++ b/flask_version/requirements.txt @@ -0,0 +1,4 @@ +flask +# sqlite3 +click +-e ../../roads-cba-py diff --git a/flask_version/setup.py b/flask_version/setup.py new file mode 100644 index 0000000..907b308 --- /dev/null +++ b/flask_version/setup.py @@ -0,0 +1 @@ +blah diff --git a/flask_version/tests/test_api.py b/flask_version/tests/test_api.py new file mode 100644 index 0000000..9c558e3 --- /dev/null +++ b/flask_version/tests/test_api.py @@ -0,0 +1 @@ +. From 7096a41cc3c884f753121d4a74ef57ff15dee7df Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sat, 24 Jul 2021 18:11:00 +1000 Subject: [PATCH 03/22] . --- flask_version/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_version/requirements.txt b/flask_version/requirements.txt index 0291d4b..cd02260 100644 --- a/flask_version/requirements.txt +++ b/flask_version/requirements.txt @@ -1,4 +1,4 @@ flask # sqlite3 click --e ../../roads-cba-py +roads-cba-py From 976d9c99d45a6dcb8f37b32aab593a2ab01a377f Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 1 Aug 2021 21:38:34 +1000 Subject: [PATCH 04/22] . --- flask_version/cba_server/api.py | 30 +++++++++++++++++++++++------- flask_version/run_dev_server.sh | 10 ++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) create mode 100755 flask_version/run_dev_server.sh diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index 625a2f2..5521a76 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -1,17 +1,33 @@ from flask import ( - Blueprint, flash, g, redirect, render_template, request, url_for + Blueprint, flash, g, redirect, render_template, request, url_for, jsonify ) from werkzeug.exceptions import abort +import pandas as pd from cba_server.db import get_db -from roads_cba_py.cba import test_api +from roads_cba_py.section import Section +from roads_cba_py.cba import CostBenefitAnalysisModel bp = Blueprint('api', __name__) -@bp.route('/test_api', methods=['POST']) -def hello(): +@bp.route('/run_sections', methods=['POST']) +def run_sections(): data = request.json - input = data['key'] - output = test_api(input) + sections = [Section(s) for s in data] + sections = [(s,s.invalid_reason()) for s in sections] - return f"You provided {input} which I processed into {output}" + valid_sections = [s for (s,r) in sections if r is None] + invalid_sections = [(s,r) for (s,r) in sections if r is not None] + + stats = {"valid": len(valid_sections), "invalid": len(invalid_sections) } + invalids = pd.DataFrame(data=flatten([r for (s,r) in invalid_sections]), columns=['reason']) + invalids = invalids['reason'].value_counts().to_dict() + + + cba = CostBenefitAnalysisModel() + results = [cba.compute_cba_for_section(s) for s in valid_sections] + + return jsonify({ "stats": stats, "invalids": invalids, "data": [s.to_primitive() for s in results] }) + +def flatten(a_of_a): + return [x for y in a_of_a for x in y] \ No newline at end of file diff --git a/flask_version/run_dev_server.sh b/flask_version/run_dev_server.sh new file mode 100755 index 0000000..f5c185d --- /dev/null +++ b/flask_version/run_dev_server.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -eu + +main() { + source venv/bin/activate + FLASK_APP=cba_server FLASK_ENV=development flask run +} + +main "$@" From 97dab93c6afe5b740a31b2531e5ef9b0e6af2a97 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Wed, 25 Aug 2021 21:58:29 +1000 Subject: [PATCH 05/22] . --- flask_version/cba_server/api.py | 36 ++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index 5521a76..790ba66 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -5,15 +5,36 @@ import pandas as pd from cba_server.db import get_db -from roads_cba_py.section import Section +from roads_cba_py.section import Section, InvalidSection from roads_cba_py.cba import CostBenefitAnalysisModel bp = Blueprint('api', __name__) @bp.route('/run_sections', methods=['POST']) def run_sections(): - data = request.json - sections = [Section(s) for s in data] + valid_sections, invalid_sections,stats = split_assets_by_validity(request.json) + cba = CostBenefitAnalysisModel() + results = [cba.compute_cba_for_section(s) for s in valid_sections] + + return jsonify({ "stats": stats, "invalids": invalid_sections, "data": [s.to_primitive() for s in results] }) + +@bp.route('/evaluate_assets', methods=['POST']) +def evaluate_assets(): + valid_sections, invalid_sections,stats = split_assets_by_validity(request.json) + return jsonify({ "stats": stats, "invalids": invalid_sections }) + +@bp.route('/jamie', methods=['GET']) +def jamie(): + return jsonify({"answer": 42}) + +def parse_section(json): + try: + return Section(json) + except Exception as err: + return InvalidSection([str(err)], json) + +def split_assets_by_validity(data): + sections = [parse_section(s) for s in data] sections = [(s,s.invalid_reason()) for s in sections] valid_sections = [s for (s,r) in sections if r is None] @@ -22,12 +43,7 @@ def run_sections(): stats = {"valid": len(valid_sections), "invalid": len(invalid_sections) } invalids = pd.DataFrame(data=flatten([r for (s,r) in invalid_sections]), columns=['reason']) invalids = invalids['reason'].value_counts().to_dict() - - - cba = CostBenefitAnalysisModel() - results = [cba.compute_cba_for_section(s) for s in valid_sections] - - return jsonify({ "stats": stats, "invalids": invalids, "data": [s.to_primitive() for s in results] }) - + return (valid_sections, invalids, stats) + def flatten(a_of_a): return [x for y in a_of_a for x in y] \ No newline at end of file From 8326bc8400678ed2a92a309fdffbc174e260500c Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sat, 28 Aug 2021 19:12:14 +1000 Subject: [PATCH 06/22] . --- flask_version/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_version/requirements.txt b/flask_version/requirements.txt index cd02260..0291d4b 100644 --- a/flask_version/requirements.txt +++ b/flask_version/requirements.txt @@ -1,4 +1,4 @@ flask # sqlite3 click -roads-cba-py +-e ../../roads-cba-py From eaae6bc3ac2152e9bd1a5158144964dab1ec6a1e Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sat, 11 Sep 2021 18:55:38 +1000 Subject: [PATCH 07/22] steel threaded --- flask_version/cba_server/api.py | 70 ++++++++++++++++++--------------- flask_version/tests/test_api.py | 16 +++++++- 2 files changed, 54 insertions(+), 32 deletions(-) diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index 790ba66..01bfd5b 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -1,49 +1,57 @@ from flask import ( - Blueprint, flash, g, redirect, render_template, request, url_for, jsonify + Blueprint, + flash, + g, + redirect, + render_template, + request, + url_for, + jsonify, ) from werkzeug.exceptions import abort import pandas as pd +import math from cba_server.db import get_db -from roads_cba_py.section import Section, InvalidSection +from roads_cba_py.section import Section, InvalidSection, parse_section from roads_cba_py.cba import CostBenefitAnalysisModel +from roads_cba_py.utils import flatten, split_on_condition -bp = Blueprint('api', __name__) -@bp.route('/run_sections', methods=['POST']) +bp = Blueprint("api", __name__) + + +@bp.route("/run_sections", methods=["POST"]) def run_sections(): - valid_sections, invalid_sections,stats = split_assets_by_validity(request.json) + valid_sections, invalid_sections, stats = split_assets_by_validity(request.json) + cba = CostBenefitAnalysisModel() results = [cba.compute_cba_for_section(s) for s in valid_sections] - return jsonify({ "stats": stats, "invalids": invalid_sections, "data": [s.to_primitive() for s in results] }) + valid_results, invalid_results = split_on_condition(results, lambda r: not math.isnan(r.eirr)) -@bp.route('/evaluate_assets', methods=['POST']) -def evaluate_assets(): - valid_sections, invalid_sections,stats = split_assets_by_validity(request.json) - return jsonify({ "stats": stats, "invalids": invalid_sections }) + problems = flatten([s.invalid_reason() for s in invalid_sections]) + ["eirr is NaN"] * len(invalid_results) + invalid_reasons = pd.DataFrame(data=problems, columns=["reason"]) + invalid_reasons = invalid_reasons["reason"].value_counts().to_dict() -@bp.route('/jamie', methods=['GET']) -def jamie(): - return jsonify({"answer": 42}) + return jsonify( + { + "stats": stats, + "invalids": invalid_reasons, + "data": [s.to_primitive() for s in valid_results], + } + ) -def parse_section(json): - try: - return Section(json) - except Exception as err: - return InvalidSection([str(err)], json) -def split_assets_by_validity(data): +@bp.route("/evaluate_assets", methods=["POST"]) +def evaluate_assets(): + _valid_sections, invalid_sections, stats = split_assets_by_validity(request.json) + return jsonify({"stats": stats, "invalids": invalid_sections}) + + +def split_assets_by_validity(data): sections = [parse_section(s) for s in data] - sections = [(s,s.invalid_reason()) for s in sections] - - valid_sections = [s for (s,r) in sections if r is None] - invalid_sections = [(s,r) for (s,r) in sections if r is not None] - - stats = {"valid": len(valid_sections), "invalid": len(invalid_sections) } - invalids = pd.DataFrame(data=flatten([r for (s,r) in invalid_sections]), columns=['reason']) - invalids = invalids['reason'].value_counts().to_dict() - return (valid_sections, invalids, stats) - -def flatten(a_of_a): - return [x for y in a_of_a for x in y] \ No newline at end of file + valid_sections, invalid_sections = split_on_condition(sections, lambda s: s.invalid_reason() is None) + + stats = {"valid": len(valid_sections), "invalid": len(invalid_sections)} + return (valid_sections, invalid_sections, stats) diff --git a/flask_version/tests/test_api.py b/flask_version/tests/test_api.py index 9c558e3..495c6bb 100644 --- a/flask_version/tests/test_api.py +++ b/flask_version/tests/test_api.py @@ -1 +1,15 @@ -. +import unittest +from os.path import join, dirname +import sys + +import os + +sys.path.append(".") +print(os.getcwd()) +print(__file__) + + +class TestApi(unittest.TestCase): + def test_simple(self): + s = {"id": 7} + self.assertEqual("635950_304", s.id) From 8c13b572bb931cac7445e4bee0503b24764fcda5 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Mon, 20 Sep 2021 22:52:01 +1000 Subject: [PATCH 08/22] . --- flask_version/cba_server/api.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index 01bfd5b..d808054 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -10,12 +10,15 @@ ) from werkzeug.exceptions import abort import pandas as pd +import json +import sys import math from cba_server.db import get_db from roads_cba_py.section import Section, InvalidSection, parse_section from roads_cba_py.cba import CostBenefitAnalysisModel from roads_cba_py.utils import flatten, split_on_condition +from roads_cba_py.config import Config bp = Blueprint("api", __name__) @@ -23,12 +26,20 @@ @bp.route("/run_sections", methods=["POST"]) def run_sections(): - valid_sections, invalid_sections, stats = split_assets_by_validity(request.json) - cba = CostBenefitAnalysisModel() + with open("/Users/jamescook/world_bank/openroads-vn-analytics/bin/request.json", "w") as f: + f.write(json.dumps(request.json)) + + config = Config.parse_obj(request.json["config"]) + print(f"{config}", file=sys.stderr) + assets = request.json["assets"] + valid_sections, invalid_sections, stats = split_assets_by_validity(assets) + + cba = CostBenefitAnalysisModel(config) results = [cba.compute_cba_for_section(s) for s in valid_sections] valid_results, invalid_results = split_on_condition(results, lambda r: not math.isnan(r.eirr)) + valid_results = sorted(valid_results, key=lambda x: (x.work_year, x.npv_cost)) problems = flatten([s.invalid_reason() for s in invalid_sections]) + ["eirr is NaN"] * len(invalid_results) invalid_reasons = pd.DataFrame(data=problems, columns=["reason"]) @@ -38,7 +49,7 @@ def run_sections(): { "stats": stats, "invalids": invalid_reasons, - "data": [s.to_primitive() for s in valid_results], + "data": [s.dict() for s in valid_results], } ) @@ -46,7 +57,11 @@ def run_sections(): @bp.route("/evaluate_assets", methods=["POST"]) def evaluate_assets(): _valid_sections, invalid_sections, stats = split_assets_by_validity(request.json) - return jsonify({"stats": stats, "invalids": invalid_sections}) + + problems = flatten([s.invalid_reason() for s in invalid_sections]) + invalid_reasons = pd.DataFrame(data=problems, columns=["reason"]) + invalid_reasons = invalid_reasons["reason"].value_counts().to_dict() + return jsonify({"stats": stats, "invalids": invalid_reasons}) def split_assets_by_validity(data): From f8e085407b9308a13dda59a77176e654a3209dc8 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 3 Oct 2021 13:49:35 +1000 Subject: [PATCH 09/22] . --- flask_version/cba_server/api.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index d808054..8cd8857 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -27,11 +27,13 @@ @bp.route("/run_sections", methods=["POST"]) def run_sections(): - with open("/Users/jamescook/world_bank/openroads-vn-analytics/bin/request.json", "w") as f: - f.write(json.dumps(request.json)) + # with open("/Users/jamescook/world_bank/openroads-vn-analytics/bin/request.json", "w") as f: + # f.write(json.dumps(request.json)) config = Config.parse_obj(request.json["config"]) - print(f"{config}", file=sys.stderr) + # print(config.json()) + # config = Config() # .parse_obj(request.json["config"]) + # print(f"{config.json()}", file=sys.stderr) assets = request.json["assets"] valid_sections, invalid_sections, stats = split_assets_by_validity(assets) From 2ec52cbfd2849bf1f2c830db27deb1bb27a50f31 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 3 Oct 2021 13:59:17 +1000 Subject: [PATCH 10/22] . --- flask_version/cba_server/api.py | 9 ++------- flask_version/cba_server/request_logging.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 flask_version/cba_server/request_logging.py diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index 8cd8857..b4d5ac4 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -1,3 +1,4 @@ +from flask_version.cba_server.request_logging import log_request from flask import ( Blueprint, flash, @@ -26,14 +27,8 @@ @bp.route("/run_sections", methods=["POST"]) def run_sections(): - - # with open("/Users/jamescook/world_bank/openroads-vn-analytics/bin/request.json", "w") as f: - # f.write(json.dumps(request.json)) - + log_request(request) config = Config.parse_obj(request.json["config"]) - # print(config.json()) - # config = Config() # .parse_obj(request.json["config"]) - # print(f"{config.json()}", file=sys.stderr) assets = request.json["assets"] valid_sections, invalid_sections, stats = split_assets_by_validity(assets) diff --git a/flask_version/cba_server/request_logging.py b/flask_version/cba_server/request_logging.py new file mode 100644 index 0000000..bab5f5c --- /dev/null +++ b/flask_version/cba_server/request_logging.py @@ -0,0 +1,18 @@ +import os +import json +import datetime +from pathlib import Path + + +def get_request_dir(): + remote_dir = "/home/ubuntu/log/flask_requests" + if os.path.isdir(remote_dir): + return remote_dir + return str(Path.home()) + + +def log_request(request): + timestamp = datetime.datetime.now().replace(microsecond=0).isoformat() + filename = os.path.join(get_request_dir(), f"run_sections_{timestamp}") + with open(filename, "w") as f: + f.write(json.dumps(request.json)) From 89e5d6310bfafd15057033c00d75684b7d149794 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 3 Oct 2021 14:00:11 +1000 Subject: [PATCH 11/22] . --- flask_version/cba_server/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index b4d5ac4..024c9ba 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -16,6 +16,7 @@ import math from cba_server.db import get_db +from cba_server.request_logging import log_request from roads_cba_py.section import Section, InvalidSection, parse_section from roads_cba_py.cba import CostBenefitAnalysisModel from roads_cba_py.utils import flatten, split_on_condition From 5ce38d98022dcf32945af88511fc1b01ab2c5c05 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 3 Oct 2021 14:02:46 +1000 Subject: [PATCH 12/22] . --- flask_version/cba_server/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index 024c9ba..f555a6e 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -1,4 +1,3 @@ -from flask_version.cba_server.request_logging import log_request from flask import ( Blueprint, flash, From 84c34f3a82a9044f22fee2a4f042449bee59dced Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 3 Oct 2021 14:08:08 +1000 Subject: [PATCH 13/22] . --- flask_version/cba_server/api.py | 9 ++++++--- flask_version/cba_server/request_logging.py | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index f555a6e..afb7e68 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -15,7 +15,7 @@ import math from cba_server.db import get_db -from cba_server.request_logging import log_request +from cba_server.request_logging import log_request, log_response from roads_cba_py.section import Section, InvalidSection, parse_section from roads_cba_py.cba import CostBenefitAnalysisModel from roads_cba_py.utils import flatten, split_on_condition @@ -27,7 +27,7 @@ @bp.route("/run_sections", methods=["POST"]) def run_sections(): - log_request(request) + request_id = log_request(request) config = Config.parse_obj(request.json["config"]) assets = request.json["assets"] valid_sections, invalid_sections, stats = split_assets_by_validity(assets) @@ -42,13 +42,16 @@ def run_sections(): invalid_reasons = pd.DataFrame(data=problems, columns=["reason"]) invalid_reasons = invalid_reasons["reason"].value_counts().to_dict() - return jsonify( + response = jsonify( { "stats": stats, "invalids": invalid_reasons, "data": [s.dict() for s in valid_results], } ) + log_response(response, request_id) + + return response @bp.route("/evaluate_assets", methods=["POST"]) diff --git a/flask_version/cba_server/request_logging.py b/flask_version/cba_server/request_logging.py index bab5f5c..380bb8e 100644 --- a/flask_version/cba_server/request_logging.py +++ b/flask_version/cba_server/request_logging.py @@ -13,6 +13,12 @@ def get_request_dir(): def log_request(request): timestamp = datetime.datetime.now().replace(microsecond=0).isoformat() - filename = os.path.join(get_request_dir(), f"run_sections_{timestamp}") + filename = os.path.join(get_request_dir(), f"run_sections_request_{timestamp}") with open(filename, "w") as f: f.write(json.dumps(request.json)) + + +def log_response(response, id): + filename = os.path.join(get_request_dir(), f"run_sections_response_{id}") + with open(filename, "w") as f: + f.write(json.dumps(response.json)) From 144dcf924c916696dadb75c31e6c823bf0eaa1c8 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Mon, 11 Oct 2021 20:48:44 +1000 Subject: [PATCH 14/22] . --- flask_version/cba_server/api.py | 8 +++----- flask_version/cba_server/request_logging.py | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index afb7e68..3a1f587 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -34,11 +34,9 @@ def run_sections(): cba = CostBenefitAnalysisModel(config) results = [cba.compute_cba_for_section(s) for s in valid_sections] + results = sorted(results, key=lambda x: (x.work_year, x.npv_cost)) - valid_results, invalid_results = split_on_condition(results, lambda r: not math.isnan(r.eirr)) - valid_results = sorted(valid_results, key=lambda x: (x.work_year, x.npv_cost)) - - problems = flatten([s.invalid_reason() for s in invalid_sections]) + ["eirr is NaN"] * len(invalid_results) + problems = flatten([s.invalid_reason() for s in invalid_sections]) invalid_reasons = pd.DataFrame(data=problems, columns=["reason"]) invalid_reasons = invalid_reasons["reason"].value_counts().to_dict() @@ -46,7 +44,7 @@ def run_sections(): { "stats": stats, "invalids": invalid_reasons, - "data": [s.dict() for s in valid_results], + "data": [s.dict() for s in results], } ) log_response(response, request_id) diff --git a/flask_version/cba_server/request_logging.py b/flask_version/cba_server/request_logging.py index 380bb8e..091b552 100644 --- a/flask_version/cba_server/request_logging.py +++ b/flask_version/cba_server/request_logging.py @@ -8,14 +8,17 @@ def get_request_dir(): remote_dir = "/home/ubuntu/log/flask_requests" if os.path.isdir(remote_dir): return remote_dir - return str(Path.home()) + + return os.path.dirname(os.path.realpath(__file__)) def log_request(request): timestamp = datetime.datetime.now().replace(microsecond=0).isoformat() filename = os.path.join(get_request_dir(), f"run_sections_request_{timestamp}") + print(filename) with open(filename, "w") as f: f.write(json.dumps(request.json)) + return timestamp def log_response(response, id): From ffe23a1587270dc0b495dbd612565be55d1a2221 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sat, 11 Dec 2021 14:02:09 +1000 Subject: [PATCH 15/22] . --- flask_version/cba_server/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_version/cba_server/api.py b/flask_version/cba_server/api.py index 3a1f587..a60362e 100644 --- a/flask_version/cba_server/api.py +++ b/flask_version/cba_server/api.py @@ -34,7 +34,7 @@ def run_sections(): cba = CostBenefitAnalysisModel(config) results = [cba.compute_cba_for_section(s) for s in valid_sections] - results = sorted(results, key=lambda x: (x.work_year, x.npv_cost)) + results = sorted(results, key=lambda x: (x.work_year, -x.npv_cost)) problems = flatten([s.invalid_reason() for s in invalid_sections]) invalid_reasons = pd.DataFrame(data=problems, columns=["reason"]) From fc4f6a83e4c3641efc7c922615fd4e18555a2918 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sat, 11 Dec 2021 14:06:31 +1000 Subject: [PATCH 16/22] . --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1943617..8a0d457 100644 --- a/.gitignore +++ b/.gitignore @@ -243,4 +243,6 @@ secrets/ *.service temp/ -.env \ No newline at end of file +.env + +flask_version/cba_server/run_sections* From c539086a6910fee67449081cf257360ec6e25212 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 6 Mar 2022 09:55:39 +1000 Subject: [PATCH 17/22] run black --- django_version/cba/core/cba.py | 456 +++++++++++++++++++++----------- flask_version/tests/test_api.py | 2 - 2 files changed, 304 insertions(+), 154 deletions(-) diff --git a/django_version/cba/core/cba.py b/django_version/cba/core/cba.py index 4476fe0..587e1e4 100644 --- a/django_version/cba/core/cba.py +++ b/django_version/cba/core/cba.py @@ -1,15 +1,28 @@ import numpy as np from .default import ( - dDiscount_Rate, dEconomic_Factor, dGrowth, dTrafficLevels, dVehicleFleet, - iSurfaceDefaults, dWidthDefaults, dConditionData, dRoadWorks, - dRecurrent, dRecMult, dWorkEvaluated, dm_coeff, dVOC, dSPEED, dRoadDet, - iri_cc_df, get_cc_from_iri + dDiscount_Rate, + dEconomic_Factor, + dGrowth, + dTrafficLevels, + dVehicleFleet, + iSurfaceDefaults, + dWidthDefaults, + dConditionData, + dRoadWorks, + dRecurrent, + dRecMult, + dWorkEvaluated, + dm_coeff, + dVOC, + dSPEED, + dRoadDet, + iri_cc_df, + get_cc_from_iri, ) class CostBenefitAnalysisModel: - def __init__(self): self.dDiscount_Rate = dDiscount_Rate self.dEconomic_Factor = dEconomic_Factor @@ -83,15 +96,15 @@ def compute_cba_for_section(self, section): ######################## # Output variables ######################## - sRoadCode = np.empty((13, 20), dtype=' 0: - iCondLanes[ia, iy] =self.dRoadWorks[iTheWork - 1, 7] - dCondWidth[ia, iy] =self.dRoadWorks[iTheWork - 1, 8] - iCondSurface[ia, iy] =self.dRoadWorks[iTheWork - 1, 9] - iYearLanes =self.dRoadWorks[iTheWork - 1, 7] - dYearWidth =self.dRoadWorks[iTheWork, 8] - iYearSurface =self.dRoadWorks[iTheWork, 9] + iCondLanes[ia, iy] = self.dRoadWorks[iTheWork - 1, 7] + dCondWidth[ia, iy] = self.dRoadWorks[iTheWork - 1, 8] + iCondSurface[ia, iy] = self.dRoadWorks[iTheWork - 1, 9] + iYearLanes = self.dRoadWorks[iTheWork - 1, 7] + dYearWidth = self.dRoadWorks[iTheWork, 8] + iYearSurface = self.dRoadWorks[iTheWork, 9] # Srtructural number after periodic maintenance for bituminous roads if self.dRoadWorks[iTheWork - 1, 10] is not None and self.dRoadWorks[iTheWork - 1, 10] > 0: - dCondSNC[ia, iy] = dCondSNC[ia, iy] + self.dRoadWorks[iTheWork - 1, 10] * self.dRoadWorks[iTheWork - 1, 11] * 0.0393701 + dCondSNC[ia, iy] = ( + dCondSNC[ia, iy] + + self.dRoadWorks[iTheWork - 1, 10] * self.dRoadWorks[iTheWork - 1, 11] * 0.0393701 + ) dYearSNC = dCondSNC[ia, iy] # Structural number after rehabiliation for bituminous roads if self.dRoadWorks[iTheWork - 1, 12] is not None and self.dRoadWorks[iTheWork - 1, 12] > 0: - dCondSNC[ia, iy] =self.dRoadWorks[iTheWork - 1, 12] + dCondSNC[ia, iy] = self.dRoadWorks[iTheWork - 1, 12] dYearSNC = dCondSNC[ia, iy] # Capital work costs if iTerrain == 1: - dCostCapitalFin[ia, iy] =self.dRoadWorks[iTheWork - 1, 3] * dCondLength[ia, iy] * dCondWidth[ia, iy] / 1000.0 * dCostFactor - dCostCapitalEco[ia, iy] =self.dRoadWorks[iTheWork - 1, 3] * dCondLength[ia, iy] * dCondWidth[ia, iy] * self.dEconomic_Factor / 1000.0 * dCostFactor + dCostCapitalFin[ia, iy] = ( + self.dRoadWorks[iTheWork - 1, 3] + * dCondLength[ia, iy] + * dCondWidth[ia, iy] + / 1000.0 + * dCostFactor + ) + dCostCapitalEco[ia, iy] = ( + self.dRoadWorks[iTheWork - 1, 3] + * dCondLength[ia, iy] + * dCondWidth[ia, iy] + * self.dEconomic_Factor + / 1000.0 + * dCostFactor + ) elif iTerrain == 2: - dCostCapitalFin[ia, iy] =self.dRoadWorks[iTheWork - 1, 4] * dCondLength[ia, iy] * dCondWidth[ia, iy] / 1000.0 * dCostFactor - dCostCapitalEco[ia, iy] =self.dRoadWorks[iTheWork - 1, 4] * dCondLength[ia, iy] * dCondWidth[ia, iy] * self.dEconomic_Factor / 1000.0 * dCostFactor + dCostCapitalFin[ia, iy] = ( + self.dRoadWorks[iTheWork - 1, 4] + * dCondLength[ia, iy] + * dCondWidth[ia, iy] + / 1000.0 + * dCostFactor + ) + dCostCapitalEco[ia, iy] = ( + self.dRoadWorks[iTheWork - 1, 4] + * dCondLength[ia, iy] + * dCondWidth[ia, iy] + * self.dEconomic_Factor + / 1000.0 + * dCostFactor + ) elif iTerrain == 3: - dCostCapitalFin[ia, iy] =self.dRoadWorks[iTheWork - 1, 5] * dCondLength[ia, iy] * dCondWidth[ia, iy] / 1000.0 * dCostFactor - dCostCapitalEco[ia, iy] =self.dRoadWorks[iTheWork - 1, 5] * dCondLength[ia, iy] * dCondWidth[ia, iy] * self.dEconomic_Factor / 1000.0 * dCostFactor - sRoadCode[ia, iy] =self.dRoadWorks[iTheWork - 1, 1] - sSolName[ia] =self.dRoadWorks[iTheWork - 1, 0] - sSolCode[ia] =self.dRoadWorks[iTheWork - 1, 1] - sSolClass[ia] =self.dRoadWorks[iTheWork - 1, 2] - iSolYear[ia] = iy + 1 # Since iy is counted from 0 and year order starts from 1 + dCostCapitalFin[ia, iy] = ( + self.dRoadWorks[iTheWork - 1, 5] + * dCondLength[ia, iy] + * dCondWidth[ia, iy] + / 1000.0 + * dCostFactor + ) + dCostCapitalEco[ia, iy] = ( + self.dRoadWorks[iTheWork - 1, 5] + * dCondLength[ia, iy] + * dCondWidth[ia, iy] + * self.dEconomic_Factor + / 1000.0 + * dCostFactor + ) + sRoadCode[ia, iy] = self.dRoadWorks[iTheWork - 1, 1] + sSolName[ia] = self.dRoadWorks[iTheWork - 1, 0] + sSolCode[ia] = self.dRoadWorks[iTheWork - 1, 1] + sSolClass[ia] = self.dRoadWorks[iTheWork - 1, 2] + iSolYear[ia] = iy + 1 # Since iy is counted from 0 and year order starts from 1 dSolCost[ia] = dCostCapitalFin[ia, iy] dSolCostkm[ia] = dSolCost[ia] / dCondLength[ia, iy] # repair road work - if (iy == iTheRepairY1 - 1) or (iy == iTheRepairY2 - 1) or (iy == iTheRepairY3 - 1) or (iy == iTheRepairY4 - 1): - sRoadCode[ia, iy] =self.dRoadWorks[iTheRepair - 1, 1] + if ( + (iy == iTheRepairY1 - 1) + or (iy == iTheRepairY2 - 1) + or (iy == iTheRepairY3 - 1) + or (iy == iTheRepairY4 - 1) + ): + sRoadCode[ia, iy] = self.dRoadWorks[iTheRepair - 1, 1] if self.dRoadWorks[iTheRepair - 1, 7] is not None and self.dRoadWorks[iTheRepair - 1, 7] > 0: - iCondLanes[ia, iy] =self.dRoadWorks[iTheRepair - 1, 7] - dCondWidth[ia, iy] =self.dRoadWorks[iTheRepair - 1, 8] - iCondSurface[ia, iy] =self.dRoadWorks[iTheRepair - 1, 9] - iYearLanes =self.dRoadWorks[iTheRepair, 7] - dYearWidth =self.dRoadWorks[iTheRepair, 8] - iYearSurface =self.dRoadWorks[iTheRepair, 9] + iCondLanes[ia, iy] = self.dRoadWorks[iTheRepair - 1, 7] + dCondWidth[ia, iy] = self.dRoadWorks[iTheRepair - 1, 8] + iCondSurface[ia, iy] = self.dRoadWorks[iTheRepair - 1, 9] + iYearLanes = self.dRoadWorks[iTheRepair, 7] + dYearWidth = self.dRoadWorks[iTheRepair, 8] + iYearSurface = self.dRoadWorks[iTheRepair, 9] # structural number if self.dRoadWorks[iTheRepair - 1, 12] is not None and self.dRoadWorks[iTheRepair - 1, 12] > 0: - dCondSNC[ia, iy] =self.dRoadWorks[iTheRepair - 1, 12] - dYearSNC =self.dRoadWorks[iTheRepair - 1, 12] + dCondSNC[ia, iy] = self.dRoadWorks[iTheRepair - 1, 12] + dYearSNC = self.dRoadWorks[iTheRepair - 1, 12] # repair work costs if iTerrain == 1: - dCostRepairFin[ia, iy] =self.dRoadWorks[iTheRepair-1, 3] * dCondLength[ia, iy] * dCondWidth[ia, iy] / 1000.0 - dCostRepairEco[ia, iy] =self.dRoadWorks[iTheRepair-1, 3] * dCondLength[ia, iy] * dCondWidth[ia, iy] * self.dEconomic_Factor / 1000.0 + dCostRepairFin[ia, iy] = ( + self.dRoadWorks[iTheRepair - 1, 3] * dCondLength[ia, iy] * dCondWidth[ia, iy] / 1000.0 + ) + dCostRepairEco[ia, iy] = ( + self.dRoadWorks[iTheRepair - 1, 3] + * dCondLength[ia, iy] + * dCondWidth[ia, iy] + * self.dEconomic_Factor + / 1000.0 + ) elif iTerrain == 2: - dCostRepairFin[ia, iy] =self.dRoadWorks[iTheRepair-1, 4] * dCondLength[ia, iy] * dCondWidth[ia, iy] / 1000.0 - dCostRepairEco[ia, iy] =self.dRoadWorks[iTheRepair-1, 4] * dCondLength[ia, iy] * dCondWidth[ia, iy] * self.dEconomic_Factor / 1000.0 + dCostRepairFin[ia, iy] = ( + self.dRoadWorks[iTheRepair - 1, 4] * dCondLength[ia, iy] * dCondWidth[ia, iy] / 1000.0 + ) + dCostRepairEco[ia, iy] = ( + self.dRoadWorks[iTheRepair - 1, 4] + * dCondLength[ia, iy] + * dCondWidth[ia, iy] + * self.dEconomic_Factor + / 1000.0 + ) elif iTerrain == 3: - dCostRepairFin[ia, iy] =self.dRoadWorks[iTheRepair-1, 5] * dCondLength[ia, iy] * dCondWidth[ia, iy] / 1000.0 - dCostRepairEco[ia, iy] =self.dRoadWorks[iTheRepair-1, 5] * dCondLength[ia, iy] * dCondWidth[ia, iy] * self.dEconomic_Factor / 1000.0 - + dCostRepairFin[ia, iy] = ( + self.dRoadWorks[iTheRepair - 1, 5] * dCondLength[ia, iy] * dCondWidth[ia, iy] / 1000.0 + ) + dCostRepairEco[ia, iy] = ( + self.dRoadWorks[iTheRepair - 1, 5] + * dCondLength[ia, iy] + * dCondWidth[ia, iy] + * self.dEconomic_Factor + / 1000.0 + ) + # recurrent road work without recurrent maintenance condition multipliers - dCostRecurrentFin[ia, iy] = self.dRecurrent[iCondSurface[ia, iy]-1, iCondLanes[ia, iy]-1] * dCondLength[ia, iy] / 1000000.0 - dCostRecurrentEco[ia, iy] = self.dRecurrent[iCondSurface[ia, iy]-1, iCondLanes[ia, iy]-1] * dCondLength[ia, iy] * self.dEconomic_Factor / 1000000.0 - + dCostRecurrentFin[ia, iy] = ( + self.dRecurrent[iCondSurface[ia, iy] - 1, iCondLanes[ia, iy] - 1] * dCondLength[ia, iy] / 1000000.0 + ) + dCostRecurrentEco[ia, iy] = ( + self.dRecurrent[iCondSurface[ia, iy] - 1, iCondLanes[ia, iy] - 1] + * dCondLength[ia, iy] + * self.dEconomic_Factor + / 1000000.0 + ) + # Rouhgness if iy > 0: """ @@ -241,32 +332,41 @@ def compute_cba_for_section(self, section): dYearRoughness = dYearRoughness * (1 + self.dRoadDet[0, 1]) if dYearRoughness > 16: dYearRoughness = 16 - + iYearAge = iYearAge + 1 - + elif iCondSurface[ia, iy] == 2: if self.dRoadDet[1, 0] == float(1): # Constant Factor Increase, dRoadDet[1, 1] is currently None dYearRoughness = dYearRoughness * (1 + self.dRoadDet[1, 1]) iYearAge = iYearAge + 1 - elif self.dRoadDet[1, 0] == float(2): + elif self.dRoadDet[1, 0] == float(2): # HDM-4 Simplified Equation: # RIb = RIa + Kgp * (a0 * Exp (Kgm * m * AGE3) * [(1 + SNC * a1)]-5 * YE4 # + a2 * AGE3) + (Kgm *m * RIa) dYearRoughness = dYearRoughness + ( - self.dRoadDet[1, 2] * ( - self.dRoadDet[1, 4] * np.exp(self.dRoadDet[1, 3] * self.dm_coeff[iTemperature-1, iMoisture-1] * iYearAge) * \ - np.power(1 + dCondSNC[ia, iy] * self.dRoadDet[1, 5], -5) * dESATotal[iy] + self.dRoadDet[1, 6] * iYearAge - ) + ( - self.dRoadDet[1, 3] * self.dm_coeff[iTemperature-1, iMoisture-1] * dYearRoughness + self.dRoadDet[1, 2] + * ( + self.dRoadDet[1, 4] + * np.exp( + self.dRoadDet[1, 3] * self.dm_coeff[iTemperature - 1, iMoisture - 1] * iYearAge + ) + * np.power(1 + dCondSNC[ia, iy] * self.dRoadDet[1, 5], -5) + * dESATotal[iy] + + self.dRoadDet[1, 6] * iYearAge + ) + + ( + self.dRoadDet[1, 3] + * self.dm_coeff[iTemperature - 1, iMoisture - 1] + * dYearRoughness ) ) iYearAge = iYearAge + 1 - elif self.dRoadDet[1, 0] == float(3): + elif self.dRoadDet[1, 0] == float(3): # Climate Related dYearRoughness = dYearRoughness * (1 + self.dm_coeff[iTemperature - 1, iMoisture - 1]) iYearAge = iYearAge + 1 - + if dYearRoughness > 16: dYearRoughness = 16 @@ -280,16 +380,26 @@ def compute_cba_for_section(self, section): # RIb = RIa + Kgp * (a0 * Exp (Kgm * m * AGE3) * [(1 + SNC * a1)]-5 * YE4 # + a2 * AGE3) + (Kgm *m * RIa) dYearRoughness = dYearRoughness + ( - self.dRoadDet[2, 2] * ( - self.dRoadDet[2, 4] * np.exp(self.dRoadDet[2, 3] * self.dm_coeff[iTemperature - 1, iMoisture - 1] * iYearAge) * np.power((1 + dCondSNC[ia, iy] * self.dRoadDet[2, 5]), -5) * dESATotal[iy] + self.dRoadDet[2, 6] * iYearAge - ) + ( - self.dRoadDet[2, 3] * self.dm_coeff[iTemperature-1, iMoisture-1] * dYearRoughness + self.dRoadDet[2, 2] + * ( + self.dRoadDet[2, 4] + * np.exp( + self.dRoadDet[2, 3] * self.dm_coeff[iTemperature - 1, iMoisture - 1] * iYearAge + ) + * np.power((1 + dCondSNC[ia, iy] * self.dRoadDet[2, 5]), -5) + * dESATotal[iy] + + self.dRoadDet[2, 6] * iYearAge + ) + + ( + self.dRoadDet[2, 3] + * self.dm_coeff[iTemperature - 1, iMoisture - 1] + * dYearRoughness ) ) iYearAge = iYearAge + 1 elif self.dRoadDet[2, 0] == float(3): # Climate Related Only - dYearRoughness = dYearRoughness * (1 + self.dm_coeff[iTemperature-1, iMoisture-1]) + dYearRoughness = dYearRoughness * (1 + self.dm_coeff[iTemperature - 1, iMoisture - 1]) iYearAge = iYearAge + 1 if dYearRoughness > 16: @@ -298,28 +408,28 @@ def compute_cba_for_section(self, section): elif iCondSurface[ia, iy] == 4: dYearRoughness = dYearRoughness * (1 + self.dRoadDet[3, 1]) iYearAge = iYearAge + 1 - + if dYearRoughness > 25: dYearRoughness = 25 elif iCondSurface[ia, iy] == 5: dYearRoughness = dYearRoughness * (1 + self.dRoadDet[4, 1]) iYearAge = iYearAge + 1 - + if dYearRoughness > 25: dYearRoughness = 25 elif iCondSurface[ia, iy] == 6: dYearRoughness = dYearRoughness * (1 + self.dRoadDet[5, 1]) iYearAge = iYearAge + 1 - + if dYearRoughness > 16: dYearRoughness = 16 elif iCondSurface[ia, iy] == 7: dYearRoughness = dYearRoughness * (1 + self.dRoadDet[6, 1]) iYearAge = iYearAge + 1 - + if dYearRoughness > 16: dYearRoughness = 16 @@ -327,78 +437,103 @@ def compute_cba_for_section(self, section): """ Rougnesss effect function of road work type """ - dYearRoughness =self.dRoadWorks[iTheWork - 1, 6] + dYearRoughness = self.dRoadWorks[iTheWork - 1, 6] iYearAge = 1 - if (iy == iTheRepairY1 - 1) or (iy == iTheRepairY2 - 1) or (iy == iTheRepairY3 - 1) or (iy == iTheRepairY4 - 1): - dYearRoughness =self.dRoadWorks[iTheRepair - 1, 6] + if ( + (iy == iTheRepairY1 - 1) + or (iy == iTheRepairY2 - 1) + or (iy == iTheRepairY3 - 1) + or (iy == iTheRepairY4 - 1) + ): + dYearRoughness = self.dRoadWorks[iTheRepair - 1, 6] iYearAge = 1 - + dCondIRI[ia, iy] = dYearRoughness iCondAge[ia, iy] = iYearAge - + # VOC dCostVOC[ia, iy] = 0 - for iv in range(12): # 12 types of vehicles + for iv in range(12): # 12 types of vehicles if self.dVOC[iCondLanes[ia, iy] - 1, iTerrain - 1, 0, iv] != float(0): - dCostVOC[ia, iy] = dCostVOC[ia, iy] + ( - self.dVOC[iCondLanes[ia, iy]-1, iTerrain-1, 0, iv] + \ - (self.dVOC[iCondLanes[ia, iy]-1, iTerrain-1, 1, iv] * dCondIRI[ia, iy]) + \ - (self.dVOC[iCondLanes[ia, iy]-1, iTerrain-1, 2, iv] * np.power(dCondIRI[ia, iy], 2)) + \ - (self.dVOC[iCondLanes[ia, iy]-1, iTerrain-1, 3, iv] * np.power(dCondIRI[ia, iy], 3)) - ) * dAADT[iv, iy] + dCostVOC[ia, iy] = ( + dCostVOC[ia, iy] + + ( + self.dVOC[iCondLanes[ia, iy] - 1, iTerrain - 1, 0, iv] + + (self.dVOC[iCondLanes[ia, iy] - 1, iTerrain - 1, 1, iv] * dCondIRI[ia, iy]) + + ( + self.dVOC[iCondLanes[ia, iy] - 1, iTerrain - 1, 2, iv] + * np.power(dCondIRI[ia, iy], 2) + ) + + ( + self.dVOC[iCondLanes[ia, iy] - 1, iTerrain - 1, 3, iv] + * np.power(dCondIRI[ia, iy], 3) + ) + ) + * dAADT[iv, iy] + ) dCostVOC[ia, iy] = dCostVOC[ia, iy] * dCondLength[ia, iy] * 365 / 1000000 # Speed dCondSpeedAve[ia, iy] = 0 ii = 0 - for iv in range (0, 12): + for iv in range(0, 12): if self.dSPEED[iCondLanes[ia, iy] - 1, iTerrain - 1, 0, iv] != float(0): - dCondSpeed[ia, iy, iv] = \ - self.dSPEED[iCondLanes[ia, iy] - 1, iTerrain - 1, 0, iv] + \ - (self.dSPEED[iCondLanes[ia, iy] - 1, iTerrain - 1, 1, iv] * dCondIRI[ia, iy]) + \ - (self.dSPEED[iCondLanes[ia, iy] - 1, iTerrain - 1, 2, iv] * np.power(dCondIRI[ia, iy], 2)) + \ - (self.dSPEED[iCondLanes[ia, iy] - 1, iTerrain - 1, 3, iv] * np.power(dCondIRI[ia, iy], 3)) - + dCondSpeed[ia, iy, iv] = ( + self.dSPEED[iCondLanes[ia, iy] - 1, iTerrain - 1, 0, iv] + + (self.dSPEED[iCondLanes[ia, iy] - 1, iTerrain - 1, 1, iv] * dCondIRI[ia, iy]) + + (self.dSPEED[iCondLanes[ia, iy] - 1, iTerrain - 1, 2, iv] * np.power(dCondIRI[ia, iy], 2)) + + (self.dSPEED[iCondLanes[ia, iy] - 1, iTerrain - 1, 3, iv] * np.power(dCondIRI[ia, iy], 3)) + ) + dCondSpeedAve[ia, iy] = dCondSpeedAve[ia, iy] + dCondSpeed[ia, iy, iv] ii = ii + 1 dCondSpeedAve[ia, iy] = dCondSpeedAve[ia, iy] / ii - + # Time dCostTime[ia, iy] = 0 for iv in range(12): if dCondSpeed[ia, iy, iv] > float(0): - dCostTime[ia, iy] = dCostTime[ia, iy] + \ - 1 / dCondSpeed[ia, iy, iv] * dCondLength[ia, iy] * self.dVehicleFleet[iv, 1] * self.dVehicleFleet[iv, 2] * dAADT[iv, iy] * 365 / 1000000 - + dCostTime[ia, iy] = ( + dCostTime[ia, iy] + + 1 + / dCondSpeed[ia, iy, iv] + * dCondLength[ia, iy] + * self.dVehicleFleet[iv, 1] + * self.dVehicleFleet[iv, 2] + * dAADT[iv, iy] + * 365 + / 1000000 + ) + # Pavement Condition Class function of rougness dCondCON[ia, iy] = get_cc_from_iri(self.iri_cc_df, dCondIRI[ia, iy], iSurfaceType) dCostRecurrentFin[ia, iy] = dCostRecurrentFin[ia, iy] * dRecMult[dCondCON[ia, iy] - 1] dCostRecurrentEco[ia, iy] = dCostRecurrentEco[ia, iy] * dRecMult[dCondCON[ia, iy] - 1] - + # road agency costs dCostAgencyFin[ia, iy] = dCostCapitalFin[ia, iy] + dCostRepairFin[ia, iy] + dCostRecurrentFin[ia, iy] dCostAgencyEco[ia, iy] = dCostCapitalEco[ia, iy] + dCostRepairEco[ia, iy] + dCostRecurrentEco[ia, iy] - + # Users and Total dCostUsers[ia, iy] = dCostVOC[ia, iy] + dCostTime[ia, iy] dCostTotal[ia, iy] = dCostAgencyEco[ia, iy] + dCostUsers[ia, iy] - + # Net Benefits dNetTotal[ia, iy] = dCostTotal[0, iy] - dCostTotal[ia, iy] - + # NPV # Serious Note: raise to the power iy not (iy - 1) in the following equation dSolNPV[ia] = dSolNPV[ia] + dNetTotal[ia, iy] / ((1 + self.dDiscount_Rate) ** (iy)) dSolNPVKm[ia] = dSolNPV[ia] / dCondLength[ia, 0] - + if dSolCost[ia] > 0: dSolNPVCost[ia] = dSolNPV[ia] / dSolCost[ia] else: dSolNPVCost[ia] = 0 # End loop iy - + if ia > 1: # add computation of IRR here if needed dSolIRR[ia] = 0 @@ -411,26 +546,38 @@ def compute_cba_for_section(self, section): # Get the output results ########################################################### results = { - 'work_class': sSolClass[iTheSelected], - 'work_type': sSolCode[iTheSelected], - 'work_name': sSolName[iTheSelected], - 'work_cost': dSolCost[iTheSelected], - 'work_cost_km': dSolCostkm[iTheSelected], - 'work_year': int(iSolYear[iTheSelected]), - 'npv': dSolNPV[iTheSelected], - 'npv_km': dSolNPVKm[iTheSelected], - 'npv_cost': dSolNPVCost[iTheSelected], - 'eirr': dSolIRR[iTheSelected], - 'aadt': dAADT[12].tolist(), - 'truck_percent': dTRucks, - 'vehicle_utilization': dUtilization, - 'esa_loading': dESATotal[1], - 'iri_projection': dCondIRI[iTheSelected,].tolist(), - 'iri_base': dCondIRI[0,].tolist(), - 'con_projection': dCondCON[iTheSelected,].tolist(), - 'con_base': dCondCON[0,].tolist(), - 'financial_recurrent_cost': dCostRecurrentFin[iTheSelected,].tolist(), - 'net_benefits': dNetTotal[iTheSelected,].tolist() + "work_class": sSolClass[iTheSelected], + "work_type": sSolCode[iTheSelected], + "work_name": sSolName[iTheSelected], + "work_cost": dSolCost[iTheSelected], + "work_cost_km": dSolCostkm[iTheSelected], + "work_year": int(iSolYear[iTheSelected]), + "npv": dSolNPV[iTheSelected], + "npv_km": dSolNPVKm[iTheSelected], + "npv_cost": dSolNPVCost[iTheSelected], + "eirr": dSolIRR[iTheSelected], + "aadt": dAADT[12].tolist(), + "truck_percent": dTRucks, + "vehicle_utilization": dUtilization, + "esa_loading": dESATotal[1], + "iri_projection": dCondIRI[ + iTheSelected, + ].tolist(), + "iri_base": dCondIRI[ + 0, + ].tolist(), + "con_projection": dCondCON[ + iTheSelected, + ].tolist(), + "con_base": dCondCON[ + 0, + ].tolist(), + "financial_recurrent_cost": dCostRecurrentFin[ + iTheSelected, + ].tolist(), + "net_benefits": dNetTotal[ + iTheSelected, + ].tolist(), } return results @@ -438,23 +585,25 @@ def compute_alternatives(self, iSurfaceType, iRoadClass, iConditionClass): iNoAlernatives = 0 dAlternatives = np.zeros((13, 2), dtype=np.float64) + idx = (iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1 + year, number, x, y = self.dWorkEvaluated[idx, :] # Get initial road work for the 13 alternatives - dAlternatives[0, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 1]) - dAlternatives[1, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 2]) - dAlternatives[2, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 2]) - dAlternatives[3, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 2]) - dAlternatives[4, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 2]) - dAlternatives[5, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 2]) - dAlternatives[6, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 2]) - dAlternatives[7, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 3]) - dAlternatives[8, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 3]) - dAlternatives[9, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 3]) - dAlternatives[10, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 3]) - dAlternatives[11, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 3]) - dAlternatives[12, 0] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 3]) + dAlternatives[0, 0] = number + dAlternatives[1, 0] = x + dAlternatives[2, 0] = x + dAlternatives[3, 0] = x + dAlternatives[4, 0] = x + dAlternatives[5, 0] = x + dAlternatives[6, 0] = x + dAlternatives[7, 0] = y + dAlternatives[8, 0] = y + dAlternatives[9, 0] = y + dAlternatives[10, 0] = y + dAlternatives[11, 0] = y + dAlternatives[12, 0] = y # Define years of initial works for 13 alternatives - dAlternatives[0, 1] = int(self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 0]) + dAlternatives[0, 1] = year if dAlternatives[1, 0] > 0: # first road work defined: evaluate at least 7 alternatives dAlternatives[1, 1] = 1 @@ -474,11 +623,11 @@ def compute_alternatives(self, iSurfaceType, iRoadClass, iConditionClass): dAlternatives[12, 1] = 6 iNoAlernatives = 13 - if dAlternatives[1, 0] == 0 and dAlternatives[7, 0] == 0: # no road works defined: evaluate 2 base alternatives - dAlternatives[1, 0] = self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 1] - dAlternatives[1, 1] = self.dWorkEvaluated[(iSurfaceType - 1) * 50 + (iRoadClass - 1) * 5 + iConditionClass - 1, 0] + if dAlternatives[1, 0] == 0 and dAlternatives[7, 0] == 0: # no road works defined: evaluate 2 base alternatives + dAlternatives[1, 0] = number + dAlternatives[1, 1] = year iNoAlernatives = 2 - + return iNoAlernatives, dAlternatives def compute_cost_factor(self, iSurfaceType, iRoadClass, iConditionClass): @@ -493,7 +642,7 @@ def compute_annual_traffic(self, dAADT, iGrowthScenario): dAADT[12, iy] = 0 for iv in range(12): dAADT[12, iy] = dAADT[12, iy] + dAADT[iv, iy] - + return dAADT def compute_esa_loading(self, dAADT, iLanes): @@ -502,7 +651,10 @@ def compute_esa_loading(self, dAADT, iLanes): for iy in range(0, 20): dESATotal[iy] = 0 for iv in range(0, 12): - dESATotal[iy] = dESATotal[iy] + dAADT[iv, iy] * self.dVehicleFleet[iv, 0] / 1000000 * 365 / self.dWidthDefaults[iLanes - 1, 1] + dESATotal[iy] = ( + dESATotal[iy] + + dAADT[iv, iy] * self.dVehicleFleet[iv, 0] / 1000000 * 365 / self.dWidthDefaults[iLanes - 1, 1] + ) return dESATotal @@ -513,4 +665,4 @@ def compute_vehicle_utilization(self, dAADT, dLength): dUtilization = 0 for iv in range(0, 12): dUtilization = dUtilization + dAADT[iv, 0] * dLength * 365 / 1000000 - return dUtilization \ No newline at end of file + return dUtilization diff --git a/flask_version/tests/test_api.py b/flask_version/tests/test_api.py index 495c6bb..8bfe8f4 100644 --- a/flask_version/tests/test_api.py +++ b/flask_version/tests/test_api.py @@ -5,8 +5,6 @@ import os sys.path.append(".") -print(os.getcwd()) -print(__file__) class TestApi(unittest.TestCase): From 524e7d704853e0af5f09cab0d5e86c3f9d691082 Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 6 Mar 2022 09:59:20 +1000 Subject: [PATCH 18/22] . --- {django_version => old_django_implementation}/Pipfile | 0 {django_version => old_django_implementation}/Pipfile.lock | 0 {django_version => old_django_implementation}/README.md | 0 .../cba/administrations/__init__.py | 0 .../cba/administrations/admin.py | 0 .../cba/administrations/apps.py | 0 .../cba/administrations/exceptions.py | 0 .../cba/administrations/management/__init__.py | 0 .../cba/administrations/management/commands/__init__.py | 0 .../cba/administrations/management/commands/import_provinces.py | 0 .../cba/administrations/managers.py | 0 .../cba/administrations/migrations/0001_initial.py | 0 .../cba/administrations/migrations/__init__.py | 0 .../cba/administrations/models.py | 0 .../cba/administrations/serializers.py | 0 .../cba/administrations/tests.py | 0 .../cba/administrations/urls.py | 0 .../cba/administrations/utils.py | 0 .../cba/administrations/views.py | 0 .../cba/configs/__init__.py | 0 .../cba/configs/settings/__init__.py | 0 .../cba/configs/settings/base.py | 0 .../cba/configs/settings/development.py | 0 {django_version => old_django_implementation}/cba/configs/urls.py | 0 {django_version => old_django_implementation}/cba/configs/wsgi.py | 0 .../cba/core/__init__.py | 0 {django_version => old_django_implementation}/cba/core/admin.py | 0 {django_version => old_django_implementation}/cba/core/apps.py | 0 {django_version => old_django_implementation}/cba/core/cba.py | 0 {django_version => old_django_implementation}/cba/core/default.py | 0 .../cba/core/migrations/0001_initial.py | 0 .../cba/core/migrations/0002_cbaresult_section.py | 0 .../cba/core/migrations/0003_auto_20190608_0918.py | 0 .../cba/core/migrations/__init__.py | 0 {django_version => old_django_implementation}/cba/core/models.py | 0 {django_version => old_django_implementation}/cba/core/tests.py | 0 {django_version => old_django_implementation}/cba/core/views.py | 0 .../cba/fixtures/pavement_condition_class.json | 0 .../cba/fixtures/provinces_districts.json | 0 .../cba/fixtures/road_sections_thanhhoa.csv | 0 .../cba/fixtures/surface_type.json | 0 .../cba/fixtures/traffic_level.json | 0 {django_version => old_django_implementation}/cba/manage.py | 0 .../cba/roads/__init__.py | 0 .../cba/roads/adapters.py | 0 {django_version => old_django_implementation}/cba/roads/admin.py | 0 {django_version => old_django_implementation}/cba/roads/apps.py | 0 .../cba/roads/constants.py | 0 .../cba/roads/management/__init__.py | 0 .../cba/roads/management/commands/__init__.py | 0 .../cba/roads/management/commands/import_section_data.py | 0 .../cba/roads/migrations/0001_initial.py | 0 .../cba/roads/migrations/0002_auto_20181016_1913.py | 0 .../cba/roads/migrations/0003_auto_20181220_1404.py | 0 ...ditionclass_pavementtype_roadclass_surfacetype_temperaturec.py | 0 .../cba/roads/migrations/0005_auto_20190607_1321.py | 0 .../cba/roads/migrations/0006_auto_20190607_1351.py | 0 .../cba/roads/migrations/0007_laneclass.py | 0 .../cba/roads/migrations/0008_auto_20190607_1645.py | 0 .../cba/roads/migrations/0009_auto_20190607_1657.py | 0 .../cba/roads/migrations/0010_auto_20190607_1716.py | 0 .../cba/roads/migrations/__init__.py | 0 {django_version => old_django_implementation}/cba/roads/models.py | 0 .../cba/roads/property_classes.py | 0 .../cba/roads/serializers.py | 0 {django_version => old_django_implementation}/cba/roads/tests.py | 0 {django_version => old_django_implementation}/cba/roads/urls.py | 0 {django_version => old_django_implementation}/cba/roads/views.py | 0 {django_version => old_django_implementation}/docs/.gitkeep | 0 .../docs/environment_variables.md | 0 {django_version => old_django_implementation}/envs/.gitkeep | 0 .../scripts/insert_traffic_level.sql | 0 72 files changed, 0 insertions(+), 0 deletions(-) rename {django_version => old_django_implementation}/Pipfile (100%) rename {django_version => old_django_implementation}/Pipfile.lock (100%) rename {django_version => old_django_implementation}/README.md (100%) rename {django_version => old_django_implementation}/cba/administrations/__init__.py (100%) rename {django_version => old_django_implementation}/cba/administrations/admin.py (100%) rename {django_version => old_django_implementation}/cba/administrations/apps.py (100%) rename {django_version => old_django_implementation}/cba/administrations/exceptions.py (100%) rename {django_version => old_django_implementation}/cba/administrations/management/__init__.py (100%) rename {django_version => old_django_implementation}/cba/administrations/management/commands/__init__.py (100%) rename {django_version => old_django_implementation}/cba/administrations/management/commands/import_provinces.py (100%) rename {django_version => old_django_implementation}/cba/administrations/managers.py (100%) rename {django_version => old_django_implementation}/cba/administrations/migrations/0001_initial.py (100%) rename {django_version => old_django_implementation}/cba/administrations/migrations/__init__.py (100%) rename {django_version => old_django_implementation}/cba/administrations/models.py (100%) rename {django_version => old_django_implementation}/cba/administrations/serializers.py (100%) rename {django_version => old_django_implementation}/cba/administrations/tests.py (100%) rename {django_version => old_django_implementation}/cba/administrations/urls.py (100%) rename {django_version => old_django_implementation}/cba/administrations/utils.py (100%) rename {django_version => old_django_implementation}/cba/administrations/views.py (100%) rename {django_version => old_django_implementation}/cba/configs/__init__.py (100%) rename {django_version => old_django_implementation}/cba/configs/settings/__init__.py (100%) rename {django_version => old_django_implementation}/cba/configs/settings/base.py (100%) rename {django_version => old_django_implementation}/cba/configs/settings/development.py (100%) rename {django_version => old_django_implementation}/cba/configs/urls.py (100%) rename {django_version => old_django_implementation}/cba/configs/wsgi.py (100%) rename {django_version => old_django_implementation}/cba/core/__init__.py (100%) rename {django_version => old_django_implementation}/cba/core/admin.py (100%) rename {django_version => old_django_implementation}/cba/core/apps.py (100%) rename {django_version => old_django_implementation}/cba/core/cba.py (100%) rename {django_version => old_django_implementation}/cba/core/default.py (100%) rename {django_version => old_django_implementation}/cba/core/migrations/0001_initial.py (100%) rename {django_version => old_django_implementation}/cba/core/migrations/0002_cbaresult_section.py (100%) rename {django_version => old_django_implementation}/cba/core/migrations/0003_auto_20190608_0918.py (100%) rename {django_version => old_django_implementation}/cba/core/migrations/__init__.py (100%) rename {django_version => old_django_implementation}/cba/core/models.py (100%) rename {django_version => old_django_implementation}/cba/core/tests.py (100%) rename {django_version => old_django_implementation}/cba/core/views.py (100%) rename {django_version => old_django_implementation}/cba/fixtures/pavement_condition_class.json (100%) rename {django_version => old_django_implementation}/cba/fixtures/provinces_districts.json (100%) rename {django_version => old_django_implementation}/cba/fixtures/road_sections_thanhhoa.csv (100%) rename {django_version => old_django_implementation}/cba/fixtures/surface_type.json (100%) rename {django_version => old_django_implementation}/cba/fixtures/traffic_level.json (100%) rename {django_version => old_django_implementation}/cba/manage.py (100%) rename {django_version => old_django_implementation}/cba/roads/__init__.py (100%) rename {django_version => old_django_implementation}/cba/roads/adapters.py (100%) rename {django_version => old_django_implementation}/cba/roads/admin.py (100%) rename {django_version => old_django_implementation}/cba/roads/apps.py (100%) rename {django_version => old_django_implementation}/cba/roads/constants.py (100%) rename {django_version => old_django_implementation}/cba/roads/management/__init__.py (100%) rename {django_version => old_django_implementation}/cba/roads/management/commands/__init__.py (100%) rename {django_version => old_django_implementation}/cba/roads/management/commands/import_section_data.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0001_initial.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0002_auto_20181016_1913.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0003_auto_20181220_1404.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0005_auto_20190607_1321.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0006_auto_20190607_1351.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0007_laneclass.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0008_auto_20190607_1645.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0009_auto_20190607_1657.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/0010_auto_20190607_1716.py (100%) rename {django_version => old_django_implementation}/cba/roads/migrations/__init__.py (100%) rename {django_version => old_django_implementation}/cba/roads/models.py (100%) rename {django_version => old_django_implementation}/cba/roads/property_classes.py (100%) rename {django_version => old_django_implementation}/cba/roads/serializers.py (100%) rename {django_version => old_django_implementation}/cba/roads/tests.py (100%) rename {django_version => old_django_implementation}/cba/roads/urls.py (100%) rename {django_version => old_django_implementation}/cba/roads/views.py (100%) rename {django_version => old_django_implementation}/docs/.gitkeep (100%) rename {django_version => old_django_implementation}/docs/environment_variables.md (100%) rename {django_version => old_django_implementation}/envs/.gitkeep (100%) rename {django_version => old_django_implementation}/scripts/insert_traffic_level.sql (100%) diff --git a/django_version/Pipfile b/old_django_implementation/Pipfile similarity index 100% rename from django_version/Pipfile rename to old_django_implementation/Pipfile diff --git a/django_version/Pipfile.lock b/old_django_implementation/Pipfile.lock similarity index 100% rename from django_version/Pipfile.lock rename to old_django_implementation/Pipfile.lock diff --git a/django_version/README.md b/old_django_implementation/README.md similarity index 100% rename from django_version/README.md rename to old_django_implementation/README.md diff --git a/django_version/cba/administrations/__init__.py b/old_django_implementation/cba/administrations/__init__.py similarity index 100% rename from django_version/cba/administrations/__init__.py rename to old_django_implementation/cba/administrations/__init__.py diff --git a/django_version/cba/administrations/admin.py b/old_django_implementation/cba/administrations/admin.py similarity index 100% rename from django_version/cba/administrations/admin.py rename to old_django_implementation/cba/administrations/admin.py diff --git a/django_version/cba/administrations/apps.py b/old_django_implementation/cba/administrations/apps.py similarity index 100% rename from django_version/cba/administrations/apps.py rename to old_django_implementation/cba/administrations/apps.py diff --git a/django_version/cba/administrations/exceptions.py b/old_django_implementation/cba/administrations/exceptions.py similarity index 100% rename from django_version/cba/administrations/exceptions.py rename to old_django_implementation/cba/administrations/exceptions.py diff --git a/django_version/cba/administrations/management/__init__.py b/old_django_implementation/cba/administrations/management/__init__.py similarity index 100% rename from django_version/cba/administrations/management/__init__.py rename to old_django_implementation/cba/administrations/management/__init__.py diff --git a/django_version/cba/administrations/management/commands/__init__.py b/old_django_implementation/cba/administrations/management/commands/__init__.py similarity index 100% rename from django_version/cba/administrations/management/commands/__init__.py rename to old_django_implementation/cba/administrations/management/commands/__init__.py diff --git a/django_version/cba/administrations/management/commands/import_provinces.py b/old_django_implementation/cba/administrations/management/commands/import_provinces.py similarity index 100% rename from django_version/cba/administrations/management/commands/import_provinces.py rename to old_django_implementation/cba/administrations/management/commands/import_provinces.py diff --git a/django_version/cba/administrations/managers.py b/old_django_implementation/cba/administrations/managers.py similarity index 100% rename from django_version/cba/administrations/managers.py rename to old_django_implementation/cba/administrations/managers.py diff --git a/django_version/cba/administrations/migrations/0001_initial.py b/old_django_implementation/cba/administrations/migrations/0001_initial.py similarity index 100% rename from django_version/cba/administrations/migrations/0001_initial.py rename to old_django_implementation/cba/administrations/migrations/0001_initial.py diff --git a/django_version/cba/administrations/migrations/__init__.py b/old_django_implementation/cba/administrations/migrations/__init__.py similarity index 100% rename from django_version/cba/administrations/migrations/__init__.py rename to old_django_implementation/cba/administrations/migrations/__init__.py diff --git a/django_version/cba/administrations/models.py b/old_django_implementation/cba/administrations/models.py similarity index 100% rename from django_version/cba/administrations/models.py rename to old_django_implementation/cba/administrations/models.py diff --git a/django_version/cba/administrations/serializers.py b/old_django_implementation/cba/administrations/serializers.py similarity index 100% rename from django_version/cba/administrations/serializers.py rename to old_django_implementation/cba/administrations/serializers.py diff --git a/django_version/cba/administrations/tests.py b/old_django_implementation/cba/administrations/tests.py similarity index 100% rename from django_version/cba/administrations/tests.py rename to old_django_implementation/cba/administrations/tests.py diff --git a/django_version/cba/administrations/urls.py b/old_django_implementation/cba/administrations/urls.py similarity index 100% rename from django_version/cba/administrations/urls.py rename to old_django_implementation/cba/administrations/urls.py diff --git a/django_version/cba/administrations/utils.py b/old_django_implementation/cba/administrations/utils.py similarity index 100% rename from django_version/cba/administrations/utils.py rename to old_django_implementation/cba/administrations/utils.py diff --git a/django_version/cba/administrations/views.py b/old_django_implementation/cba/administrations/views.py similarity index 100% rename from django_version/cba/administrations/views.py rename to old_django_implementation/cba/administrations/views.py diff --git a/django_version/cba/configs/__init__.py b/old_django_implementation/cba/configs/__init__.py similarity index 100% rename from django_version/cba/configs/__init__.py rename to old_django_implementation/cba/configs/__init__.py diff --git a/django_version/cba/configs/settings/__init__.py b/old_django_implementation/cba/configs/settings/__init__.py similarity index 100% rename from django_version/cba/configs/settings/__init__.py rename to old_django_implementation/cba/configs/settings/__init__.py diff --git a/django_version/cba/configs/settings/base.py b/old_django_implementation/cba/configs/settings/base.py similarity index 100% rename from django_version/cba/configs/settings/base.py rename to old_django_implementation/cba/configs/settings/base.py diff --git a/django_version/cba/configs/settings/development.py b/old_django_implementation/cba/configs/settings/development.py similarity index 100% rename from django_version/cba/configs/settings/development.py rename to old_django_implementation/cba/configs/settings/development.py diff --git a/django_version/cba/configs/urls.py b/old_django_implementation/cba/configs/urls.py similarity index 100% rename from django_version/cba/configs/urls.py rename to old_django_implementation/cba/configs/urls.py diff --git a/django_version/cba/configs/wsgi.py b/old_django_implementation/cba/configs/wsgi.py similarity index 100% rename from django_version/cba/configs/wsgi.py rename to old_django_implementation/cba/configs/wsgi.py diff --git a/django_version/cba/core/__init__.py b/old_django_implementation/cba/core/__init__.py similarity index 100% rename from django_version/cba/core/__init__.py rename to old_django_implementation/cba/core/__init__.py diff --git a/django_version/cba/core/admin.py b/old_django_implementation/cba/core/admin.py similarity index 100% rename from django_version/cba/core/admin.py rename to old_django_implementation/cba/core/admin.py diff --git a/django_version/cba/core/apps.py b/old_django_implementation/cba/core/apps.py similarity index 100% rename from django_version/cba/core/apps.py rename to old_django_implementation/cba/core/apps.py diff --git a/django_version/cba/core/cba.py b/old_django_implementation/cba/core/cba.py similarity index 100% rename from django_version/cba/core/cba.py rename to old_django_implementation/cba/core/cba.py diff --git a/django_version/cba/core/default.py b/old_django_implementation/cba/core/default.py similarity index 100% rename from django_version/cba/core/default.py rename to old_django_implementation/cba/core/default.py diff --git a/django_version/cba/core/migrations/0001_initial.py b/old_django_implementation/cba/core/migrations/0001_initial.py similarity index 100% rename from django_version/cba/core/migrations/0001_initial.py rename to old_django_implementation/cba/core/migrations/0001_initial.py diff --git a/django_version/cba/core/migrations/0002_cbaresult_section.py b/old_django_implementation/cba/core/migrations/0002_cbaresult_section.py similarity index 100% rename from django_version/cba/core/migrations/0002_cbaresult_section.py rename to old_django_implementation/cba/core/migrations/0002_cbaresult_section.py diff --git a/django_version/cba/core/migrations/0003_auto_20190608_0918.py b/old_django_implementation/cba/core/migrations/0003_auto_20190608_0918.py similarity index 100% rename from django_version/cba/core/migrations/0003_auto_20190608_0918.py rename to old_django_implementation/cba/core/migrations/0003_auto_20190608_0918.py diff --git a/django_version/cba/core/migrations/__init__.py b/old_django_implementation/cba/core/migrations/__init__.py similarity index 100% rename from django_version/cba/core/migrations/__init__.py rename to old_django_implementation/cba/core/migrations/__init__.py diff --git a/django_version/cba/core/models.py b/old_django_implementation/cba/core/models.py similarity index 100% rename from django_version/cba/core/models.py rename to old_django_implementation/cba/core/models.py diff --git a/django_version/cba/core/tests.py b/old_django_implementation/cba/core/tests.py similarity index 100% rename from django_version/cba/core/tests.py rename to old_django_implementation/cba/core/tests.py diff --git a/django_version/cba/core/views.py b/old_django_implementation/cba/core/views.py similarity index 100% rename from django_version/cba/core/views.py rename to old_django_implementation/cba/core/views.py diff --git a/django_version/cba/fixtures/pavement_condition_class.json b/old_django_implementation/cba/fixtures/pavement_condition_class.json similarity index 100% rename from django_version/cba/fixtures/pavement_condition_class.json rename to old_django_implementation/cba/fixtures/pavement_condition_class.json diff --git a/django_version/cba/fixtures/provinces_districts.json b/old_django_implementation/cba/fixtures/provinces_districts.json similarity index 100% rename from django_version/cba/fixtures/provinces_districts.json rename to old_django_implementation/cba/fixtures/provinces_districts.json diff --git a/django_version/cba/fixtures/road_sections_thanhhoa.csv b/old_django_implementation/cba/fixtures/road_sections_thanhhoa.csv similarity index 100% rename from django_version/cba/fixtures/road_sections_thanhhoa.csv rename to old_django_implementation/cba/fixtures/road_sections_thanhhoa.csv diff --git a/django_version/cba/fixtures/surface_type.json b/old_django_implementation/cba/fixtures/surface_type.json similarity index 100% rename from django_version/cba/fixtures/surface_type.json rename to old_django_implementation/cba/fixtures/surface_type.json diff --git a/django_version/cba/fixtures/traffic_level.json b/old_django_implementation/cba/fixtures/traffic_level.json similarity index 100% rename from django_version/cba/fixtures/traffic_level.json rename to old_django_implementation/cba/fixtures/traffic_level.json diff --git a/django_version/cba/manage.py b/old_django_implementation/cba/manage.py similarity index 100% rename from django_version/cba/manage.py rename to old_django_implementation/cba/manage.py diff --git a/django_version/cba/roads/__init__.py b/old_django_implementation/cba/roads/__init__.py similarity index 100% rename from django_version/cba/roads/__init__.py rename to old_django_implementation/cba/roads/__init__.py diff --git a/django_version/cba/roads/adapters.py b/old_django_implementation/cba/roads/adapters.py similarity index 100% rename from django_version/cba/roads/adapters.py rename to old_django_implementation/cba/roads/adapters.py diff --git a/django_version/cba/roads/admin.py b/old_django_implementation/cba/roads/admin.py similarity index 100% rename from django_version/cba/roads/admin.py rename to old_django_implementation/cba/roads/admin.py diff --git a/django_version/cba/roads/apps.py b/old_django_implementation/cba/roads/apps.py similarity index 100% rename from django_version/cba/roads/apps.py rename to old_django_implementation/cba/roads/apps.py diff --git a/django_version/cba/roads/constants.py b/old_django_implementation/cba/roads/constants.py similarity index 100% rename from django_version/cba/roads/constants.py rename to old_django_implementation/cba/roads/constants.py diff --git a/django_version/cba/roads/management/__init__.py b/old_django_implementation/cba/roads/management/__init__.py similarity index 100% rename from django_version/cba/roads/management/__init__.py rename to old_django_implementation/cba/roads/management/__init__.py diff --git a/django_version/cba/roads/management/commands/__init__.py b/old_django_implementation/cba/roads/management/commands/__init__.py similarity index 100% rename from django_version/cba/roads/management/commands/__init__.py rename to old_django_implementation/cba/roads/management/commands/__init__.py diff --git a/django_version/cba/roads/management/commands/import_section_data.py b/old_django_implementation/cba/roads/management/commands/import_section_data.py similarity index 100% rename from django_version/cba/roads/management/commands/import_section_data.py rename to old_django_implementation/cba/roads/management/commands/import_section_data.py diff --git a/django_version/cba/roads/migrations/0001_initial.py b/old_django_implementation/cba/roads/migrations/0001_initial.py similarity index 100% rename from django_version/cba/roads/migrations/0001_initial.py rename to old_django_implementation/cba/roads/migrations/0001_initial.py diff --git a/django_version/cba/roads/migrations/0002_auto_20181016_1913.py b/old_django_implementation/cba/roads/migrations/0002_auto_20181016_1913.py similarity index 100% rename from django_version/cba/roads/migrations/0002_auto_20181016_1913.py rename to old_django_implementation/cba/roads/migrations/0002_auto_20181016_1913.py diff --git a/django_version/cba/roads/migrations/0003_auto_20181220_1404.py b/old_django_implementation/cba/roads/migrations/0003_auto_20181220_1404.py similarity index 100% rename from django_version/cba/roads/migrations/0003_auto_20181220_1404.py rename to old_django_implementation/cba/roads/migrations/0003_auto_20181220_1404.py diff --git a/django_version/cba/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py b/old_django_implementation/cba/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py similarity index 100% rename from django_version/cba/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py rename to old_django_implementation/cba/roads/migrations/0004_managementclass_moistureclass_pavementconditionclass_pavementtype_roadclass_surfacetype_temperaturec.py diff --git a/django_version/cba/roads/migrations/0005_auto_20190607_1321.py b/old_django_implementation/cba/roads/migrations/0005_auto_20190607_1321.py similarity index 100% rename from django_version/cba/roads/migrations/0005_auto_20190607_1321.py rename to old_django_implementation/cba/roads/migrations/0005_auto_20190607_1321.py diff --git a/django_version/cba/roads/migrations/0006_auto_20190607_1351.py b/old_django_implementation/cba/roads/migrations/0006_auto_20190607_1351.py similarity index 100% rename from django_version/cba/roads/migrations/0006_auto_20190607_1351.py rename to old_django_implementation/cba/roads/migrations/0006_auto_20190607_1351.py diff --git a/django_version/cba/roads/migrations/0007_laneclass.py b/old_django_implementation/cba/roads/migrations/0007_laneclass.py similarity index 100% rename from django_version/cba/roads/migrations/0007_laneclass.py rename to old_django_implementation/cba/roads/migrations/0007_laneclass.py diff --git a/django_version/cba/roads/migrations/0008_auto_20190607_1645.py b/old_django_implementation/cba/roads/migrations/0008_auto_20190607_1645.py similarity index 100% rename from django_version/cba/roads/migrations/0008_auto_20190607_1645.py rename to old_django_implementation/cba/roads/migrations/0008_auto_20190607_1645.py diff --git a/django_version/cba/roads/migrations/0009_auto_20190607_1657.py b/old_django_implementation/cba/roads/migrations/0009_auto_20190607_1657.py similarity index 100% rename from django_version/cba/roads/migrations/0009_auto_20190607_1657.py rename to old_django_implementation/cba/roads/migrations/0009_auto_20190607_1657.py diff --git a/django_version/cba/roads/migrations/0010_auto_20190607_1716.py b/old_django_implementation/cba/roads/migrations/0010_auto_20190607_1716.py similarity index 100% rename from django_version/cba/roads/migrations/0010_auto_20190607_1716.py rename to old_django_implementation/cba/roads/migrations/0010_auto_20190607_1716.py diff --git a/django_version/cba/roads/migrations/__init__.py b/old_django_implementation/cba/roads/migrations/__init__.py similarity index 100% rename from django_version/cba/roads/migrations/__init__.py rename to old_django_implementation/cba/roads/migrations/__init__.py diff --git a/django_version/cba/roads/models.py b/old_django_implementation/cba/roads/models.py similarity index 100% rename from django_version/cba/roads/models.py rename to old_django_implementation/cba/roads/models.py diff --git a/django_version/cba/roads/property_classes.py b/old_django_implementation/cba/roads/property_classes.py similarity index 100% rename from django_version/cba/roads/property_classes.py rename to old_django_implementation/cba/roads/property_classes.py diff --git a/django_version/cba/roads/serializers.py b/old_django_implementation/cba/roads/serializers.py similarity index 100% rename from django_version/cba/roads/serializers.py rename to old_django_implementation/cba/roads/serializers.py diff --git a/django_version/cba/roads/tests.py b/old_django_implementation/cba/roads/tests.py similarity index 100% rename from django_version/cba/roads/tests.py rename to old_django_implementation/cba/roads/tests.py diff --git a/django_version/cba/roads/urls.py b/old_django_implementation/cba/roads/urls.py similarity index 100% rename from django_version/cba/roads/urls.py rename to old_django_implementation/cba/roads/urls.py diff --git a/django_version/cba/roads/views.py b/old_django_implementation/cba/roads/views.py similarity index 100% rename from django_version/cba/roads/views.py rename to old_django_implementation/cba/roads/views.py diff --git a/django_version/docs/.gitkeep b/old_django_implementation/docs/.gitkeep similarity index 100% rename from django_version/docs/.gitkeep rename to old_django_implementation/docs/.gitkeep diff --git a/django_version/docs/environment_variables.md b/old_django_implementation/docs/environment_variables.md similarity index 100% rename from django_version/docs/environment_variables.md rename to old_django_implementation/docs/environment_variables.md diff --git a/django_version/envs/.gitkeep b/old_django_implementation/envs/.gitkeep similarity index 100% rename from django_version/envs/.gitkeep rename to old_django_implementation/envs/.gitkeep diff --git a/django_version/scripts/insert_traffic_level.sql b/old_django_implementation/scripts/insert_traffic_level.sql similarity index 100% rename from django_version/scripts/insert_traffic_level.sql rename to old_django_implementation/scripts/insert_traffic_level.sql From a8415f1357f25f07114a5eaa0392b810a403fdbf Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 6 Mar 2022 10:00:28 +1000 Subject: [PATCH 19/22] . --- .gitignore | 3 ++- flask_version/MANIFEST.in => MANIFEST.in | 0 {flask_version/cba_server => cba_server}/__init__.py | 0 {flask_version/cba_server => cba_server}/api.py | 0 {flask_version/cba_server => cba_server}/db.py | 0 {flask_version/cba_server => cba_server}/request_logging.py | 0 {flask_version/cba_server => cba_server}/schema.sql | 0 flask_version/requirements.txt => requirements.txt | 0 flask_version/run_dev_server.sh => run_dev_server.sh | 0 flask_version/setup.py => setup.py | 0 {flask_version/tests => tests}/test_api.py | 0 11 files changed, 2 insertions(+), 1 deletion(-) rename flask_version/MANIFEST.in => MANIFEST.in (100%) rename {flask_version/cba_server => cba_server}/__init__.py (100%) rename {flask_version/cba_server => cba_server}/api.py (100%) rename {flask_version/cba_server => cba_server}/db.py (100%) rename {flask_version/cba_server => cba_server}/request_logging.py (100%) rename {flask_version/cba_server => cba_server}/schema.sql (100%) rename flask_version/requirements.txt => requirements.txt (100%) rename flask_version/run_dev_server.sh => run_dev_server.sh (100%) rename flask_version/setup.py => setup.py (100%) rename {flask_version/tests => tests}/test_api.py (100%) diff --git a/.gitignore b/.gitignore index 8a0d457..edae3d6 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ wheels/ # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec +instance # Installer logs pip-log.txt @@ -245,4 +246,4 @@ temp/ .env -flask_version/cba_server/run_sections* +cba_server/run_sections* diff --git a/flask_version/MANIFEST.in b/MANIFEST.in similarity index 100% rename from flask_version/MANIFEST.in rename to MANIFEST.in diff --git a/flask_version/cba_server/__init__.py b/cba_server/__init__.py similarity index 100% rename from flask_version/cba_server/__init__.py rename to cba_server/__init__.py diff --git a/flask_version/cba_server/api.py b/cba_server/api.py similarity index 100% rename from flask_version/cba_server/api.py rename to cba_server/api.py diff --git a/flask_version/cba_server/db.py b/cba_server/db.py similarity index 100% rename from flask_version/cba_server/db.py rename to cba_server/db.py diff --git a/flask_version/cba_server/request_logging.py b/cba_server/request_logging.py similarity index 100% rename from flask_version/cba_server/request_logging.py rename to cba_server/request_logging.py diff --git a/flask_version/cba_server/schema.sql b/cba_server/schema.sql similarity index 100% rename from flask_version/cba_server/schema.sql rename to cba_server/schema.sql diff --git a/flask_version/requirements.txt b/requirements.txt similarity index 100% rename from flask_version/requirements.txt rename to requirements.txt diff --git a/flask_version/run_dev_server.sh b/run_dev_server.sh similarity index 100% rename from flask_version/run_dev_server.sh rename to run_dev_server.sh diff --git a/flask_version/setup.py b/setup.py similarity index 100% rename from flask_version/setup.py rename to setup.py diff --git a/flask_version/tests/test_api.py b/tests/test_api.py similarity index 100% rename from flask_version/tests/test_api.py rename to tests/test_api.py From f0549c7c3569f822ab05a928bd6de206cda29bfb Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 6 Mar 2022 10:50:28 +1000 Subject: [PATCH 20/22] remove django version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0291d4b..be64197 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ flask # sqlite3 click --e ../../roads-cba-py +-e ../roads-cba-py From a2074fe7f418be81085b8c7e85708ab4e86138ba Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 6 Mar 2022 13:04:03 +1000 Subject: [PATCH 21/22] MISSING FILE!!!! SO MUCH TIME WASTED!!!! --- cba_server/__init__.py | 11 ++++++----- cba_server/wsgi.py | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 cba_server/wsgi.py diff --git a/cba_server/__init__.py b/cba_server/__init__.py index c862a97..871b067 100644 --- a/cba_server/__init__.py +++ b/cba_server/__init__.py @@ -1,19 +1,20 @@ import os from flask import Flask -import cba_server.db -import cba_server.api +import cba_server.db as db +import cba_server.api as api + def create_app(test_config=None): # create and configure the app app = Flask(__name__, instance_relative_config=True) app.config.from_mapping( - SECRET_KEY='dev', - DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'), + SECRET_KEY="dev", + DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"), ) if test_config is None: # load the instance config, if it exists, when not testing - app.config.from_pyfile('config.py', silent=True) + app.config.from_pyfile("config.py", silent=True) else: # load the test config if passed in app.config.from_mapping(test_config) diff --git a/cba_server/wsgi.py b/cba_server/wsgi.py new file mode 100644 index 0000000..df6f430 --- /dev/null +++ b/cba_server/wsgi.py @@ -0,0 +1,9 @@ +import sys + +sys.path.append(".") +from cba_server import create_app + +app = create_app() + +if __name__ == "__main__": + app.run() From c5476f4c3579c00c31a9f584e6e922592a666f2e Mon Sep 17 00:00:00 2001 From: Jamie Cook Date: Sun, 13 Mar 2022 17:28:25 +1000 Subject: [PATCH 22/22] . --- cba_server/api.py | 3 ++- cba_server/request_logging.py | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cba_server/api.py b/cba_server/api.py index a60362e..b2e3e3d 100644 --- a/cba_server/api.py +++ b/cba_server/api.py @@ -59,7 +59,8 @@ def evaluate_assets(): problems = flatten([s.invalid_reason() for s in invalid_sections]) invalid_reasons = pd.DataFrame(data=problems, columns=["reason"]) invalid_reasons = invalid_reasons["reason"].value_counts().to_dict() - return jsonify({"stats": stats, "invalids": invalid_reasons}) + invalid_way_ids = [int(s.original_data["orma_way_id"]) for s in invalid_sections] + return jsonify({"stats": stats, "invalids": invalid_reasons, "invalid_way_ids": invalid_way_ids}) def split_assets_by_validity(data): diff --git a/cba_server/request_logging.py b/cba_server/request_logging.py index 091b552..d4b6985 100644 --- a/cba_server/request_logging.py +++ b/cba_server/request_logging.py @@ -1,27 +1,36 @@ import os import json import datetime -from pathlib import Path +from os.path import join, abspath, dirname + + +def get_log_dir(): + return abspath(join(dirname(__file__), "..", "log")) def get_request_dir(): - remote_dir = "/home/ubuntu/log/flask_requests" + remote_dir = join(get_log_dir(), "flask_requests") if os.path.isdir(remote_dir): return remote_dir - - return os.path.dirname(os.path.realpath(__file__)) + return None def log_request(request): + request_dir = get_request_dir() + if request_dir is None: + return None + timestamp = datetime.datetime.now().replace(microsecond=0).isoformat() - filename = os.path.join(get_request_dir(), f"run_sections_request_{timestamp}") - print(filename) + filename = join(request_dir, f"run_sections_request_{timestamp}") with open(filename, "w") as f: f.write(json.dumps(request.json)) return timestamp def log_response(response, id): - filename = os.path.join(get_request_dir(), f"run_sections_response_{id}") + request_dir = get_request_dir() + if request_dir is None: + return None + filename = join(request_dir, f"run_sections_response_{id}") with open(filename, "w") as f: f.write(json.dumps(response.json))