From e4e05b4788f2c53ff7730c698fd969c2094f21c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gi=C3=B2=20Diani?= Date: Fri, 17 Jan 2025 23:46:22 +0100 Subject: [PATCH] refactoring; more consistent naming for API endpoint and variables. --- dashboard/app/Api.php | 64 ++++--- dashboard/resources/views/overview.blade.php | 30 ++- .../resources/views/property-nodata.blade.php | 27 +++ dashboard/resources/views/property.blade.php | 80 ++++---- dashboard/resources/views/region.blade.php | 32 ++-- dashboard/routes/console.php | 8 - dashboard/routes/web.php | 180 ++++++++++++------ etl/src/api/main.py | 109 ++++++----- etl/src/data/database.py | 8 +- etl/src/data/etl_property_capacities.py | 2 +- ...ys.py => etl_property_capacities_daily.py} | 4 +- .../data/etl_property_capacities_monthly.py | 2 +- .../data/etl_region_capacities_comparison.py | 9 +- ...days.py => etl_region_capacities_daily.py} | 4 +- etl/src/data/etl_region_capacities_monthly.py | 2 +- .../data/etl_region_properties_capacities.py | 2 +- 16 files changed, 325 insertions(+), 238 deletions(-) create mode 100644 dashboard/resources/views/property-nodata.blade.php delete mode 100644 dashboard/routes/console.php rename etl/src/data/{etl_property_capacities_weekdays.py => etl_property_capacities_daily.py} (87%) rename etl/src/data/{etl_region_capacities_weekdays.py => etl_region_capacities_daily.py} (92%) diff --git a/dashboard/app/Api.php b/dashboard/app/Api.php index a4b1663..dcea549 100644 --- a/dashboard/app/Api.php +++ b/dashboard/app/Api.php @@ -5,6 +5,11 @@ namespace App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; +/* + * Class contains methods which make calls to the API. + * Successfull calls get cached. + */ + class Api { @@ -14,12 +19,15 @@ class Api $endpoint = env('FASTAPI_URI'); $request = $endpoint.$path; + // load from cache if available if (Cache::has($request)) { - // return Cache::get($request); + //return Cache::get($request); } - $get = Http::timeout(1600)->get($request); + // Set timeout to .5h + $get = Http::timeout(1800)->get($request); + // return result and cache it if($get->successful()){ $result = $get->json(); Cache::put($request, $result); @@ -29,27 +37,22 @@ class Api return null; } - public static function propertiesPerRegion() - { - return self::get('/region/properties'); - } - - public static function propertiesGrowth() + public static function propertiesGrowth(): mixed { return self::get('/properties/growth'); } - public static function propertiesGeo() + public static function propertiesGeo(): mixed { return self::get('/properties/geo'); } - public static function propertyExtractions(int $id) + public static function propertyExtractions(int $id): mixed { return self::get("/property/{$id}/extractions"); } - public static function propertyCapacities(int $id) + public static function propertyCapacities(int $id): mixed { return self::get("/property/{$id}/capacities"); } @@ -59,6 +62,26 @@ class Api return self::get("/property/{$id}/base"); } + public static function propertyCapacitiesMonthly(int $id, string $date): mixed + { + return self::get("/property/{$id}/capacities/monthly/{$date}"); + } + + public static function propertyCapacitiesDaily(int $id, string $date): mixed + { + return self::get("/property/{$id}/capacities/daily/{$date}"); + } + + public static function propertyNeighbours(int $id): mixed + { + return self::get("/property/{$id}/neighbours"); + } + + public static function regions(): mixed + { + return self::get('/regions'); + } + public static function regionBase(int $id): mixed { return self::get("/region/{$id}/base"); @@ -74,24 +97,9 @@ class Api return self::get("/region/{$id}/capacities/monthly/{$date}"); } - public static function propertyCapacitiesMonthly(int $id, string $date): mixed - { - return self::get("/property/{$id}/capacities/monthly/{$date}"); - } - public static function regionCapacitiesDaily(int $id, string $date): mixed { - return self::get("/region/{$id}/capacities/weekdays/{$date}"); - } - - public static function propertyCapacitiesDaily(int $id, string $date): mixed - { - return self::get("/property/{$id}/capacities/weekdays/{$date}"); - } - - public static function propertyNeighbours(int $id): mixed - { - return self::get("/property/{$id}/neighbours"); + return self::get("/region/{$id}/capacities/daily/{$date}"); } public static function regionCapacities(int $id): mixed @@ -103,7 +111,5 @@ class Api { return self::get("/region/{$id}/movingAverage/{$date}"); } - - } diff --git a/dashboard/resources/views/overview.blade.php b/dashboard/resources/views/overview.blade.php index f10d9c1..43bdfd4 100644 --- a/dashboard/resources/views/overview.blade.php +++ b/dashboard/resources/views/overview.blade.php @@ -5,7 +5,7 @@ Start @@ -82,7 +82,7 @@ -@endif @endsection diff --git a/dashboard/resources/views/region.blade.php b/dashboard/resources/views/region.blade.php index 57e2501..e8deb05 100644 --- a/dashboard/resources/views/region.blade.php +++ b/dashboard/resources/views/region.blade.php @@ -2,12 +2,12 @@ @section('body-class', 'region') @section('header')