From 75bd923038459d8f9f34a32df04a65da3c3d6695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gi=C3=B2=20Diani?= Date: Sun, 19 Jan 2025 14:12:36 +0100 Subject: [PATCH] Vereinheitlichung API --- dashboard/app/Api.php | 24 ++++++++++++------------ etl/src/api/main.py | 30 +++++++++++++++--------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/dashboard/app/Api.php b/dashboard/app/Api.php index 29b2d59..89d3b8d 100644 --- a/dashboard/app/Api.php +++ b/dashboard/app/Api.php @@ -49,32 +49,32 @@ class Api public static function propertyExtractions(int $id): mixed { - return self::get("/property/{$id}/extractions"); + return self::get("/properties/{$id}/extractions"); } public static function propertyCapacities(int $id): mixed { - return self::get("/property/{$id}/capacities"); + return self::get("/properties/{$id}/capacities"); } public static function propertyBase(int $id): mixed { - return self::get("/property/{$id}/base"); + return self::get("/properties/{$id}/base"); } public static function propertyCapacitiesMonthly(int $id, string $date): mixed { - return self::get("/property/{$id}/capacities/monthly/{$date}"); + return self::get("/properties/{$id}/capacities/monthly/{$date}"); } public static function propertyCapacitiesDaily(int $id, string $date): mixed { - return self::get("/property/{$id}/capacities/daily/{$date}"); + return self::get("/properties/{$id}/capacities/daily/{$date}"); } public static function propertyNeighbours(int $id): mixed { - return self::get("/property/{$id}/neighbours"); + return self::get("/properties/{$id}/neighbours"); } public static function regions(): mixed @@ -84,32 +84,32 @@ class Api public static function regionBase(int $id): mixed { - return self::get("/region/{$id}/base"); + return self::get("/regions/{$id}/base"); } public static function regionPropertiesCapacities(int $id): mixed { - return self::get("/region/{$id}/properties/capacities"); + return self::get("/regions/{$id}/properties/capacities"); } public static function regionCapacitiesMonthly(int $id, string $date): mixed { - return self::get("/region/{$id}/capacities/monthly/{$date}"); + return self::get("/regions/{$id}/capacities/monthly/{$date}"); } public static function regionCapacitiesDaily(int $id, string $date): mixed { - return self::get("/region/{$id}/capacities/daily/{$date}"); + return self::get("/regions/{$id}/capacities/daily/{$date}"); } public static function regionCapacities(int $id): mixed { - return self::get("/region/{$id}/capacities"); + return self::get("/regions/{$id}/capacities"); } public static function regionMovingAverage(int $id, string $date): mixed { - return self::get("/region/{$id}/moving-average/{$date}"); + return self::get("/regions/{$id}/moving-average/{$date}"); } } diff --git a/etl/src/api/main.py b/etl/src/api/main.py index c4b5093..d8dc531 100644 --- a/etl/src/api/main.py +++ b/etl/src/api/main.py @@ -127,12 +127,12 @@ d = data.load() tags_metadata = [ { - "name": "region", - "description": "Get data by region.", + "name": "regions", + "description": "Get data for regions.", }, { "name": "property", - "description": "Get data by property", + "description": "Get data for properties", }, ] @@ -149,7 +149,7 @@ def regions(): """ return {"regions" : d.properties_per_region().pl().to_dicts()} -@app.get("/region/{id}/base", response_model=RegionBase, tags=['region']) +@app.get("/regions/{id}/base", response_model=RegionBase, tags=['region']) def region_base(id: int): """ Returns basic information about a region. @@ -157,7 +157,7 @@ def region_base(id: int): base = d.region_base_data(id).pl().to_dicts() return {"id": base[0]["id"], "name": base[0]["name"]} -@app.get("/region/{id}/capacities", response_model=RegionCapacities, tags=['region']) +@app.get("/regions/{id}/capacities", response_model=RegionCapacities, tags=['region']) def region_capacities(id: int): """ Returs the capacities of a region, for every scraping. Set id to -1 to obtain data for all regions. @@ -165,7 +165,7 @@ def region_capacities(id: int): capacities = etl_rc.region_capacities(id) return capacities -@app.get("/region/{id}/capacities/monthly/{date}", response_model=RegionCapacitiesMonthly, tags=['region']) +@app.get("/regions/{id}/capacities/monthly/{date}", response_model=RegionCapacitiesMonthly, tags=['region']) def region_capacities_monthly(id: int, date: datetime.date): """ Returns the capacities of a region for specified date by months. set id to -1 to obtain data for all regions. @@ -173,7 +173,7 @@ def region_capacities_monthly(id: int, date: datetime.date): capacities = etl_rcm.region_capacities_monthly(id, date) return capacities -@app.get("/region/{id}/capacities/daily/{date}", response_model=RegionCapacitiesDaily, tags=['region']) +@app.get("/regions/{id}/capacities/daily/{date}", response_model=RegionCapacitiesDaily, tags=['region']) def region_capacities_daily(id: int, date: datetime.date): """ Returns the capacities of a region for specified date by days. set id to -1 to obtain data for all regions. @@ -181,7 +181,7 @@ def region_capacities_daily(id: int, date: datetime.date): capacities = etl_rcd.region_capacities_daily(id, date) return capacities -@app.get("/region/{id}/moving-average/{date}", response_model=RegionMovingAverage, tags=['region']) +@app.get("/regions/{id}/moving-average/{date}", response_model=RegionMovingAverage, tags=['region']) def region_capacities_data(id: int, date: datetime.date): """ Returns the moving average of a region for specified date. set id to -1 to obtain data for all regions. @@ -189,7 +189,7 @@ def region_capacities_data(id: int, date: datetime.date): result = etl_rmA.region_movingAverage(id, date) return result -@app.get("/region/{id}/properties/capacities", response_model=RegionPropertiesCapacities, tags=['region']) +@app.get("/regions/{id}/properties/capacities", response_model=RegionPropertiesCapacities, tags=['region']) def region_property_capacities(id: int): """ Returns the capacities of properties in region, for every scraping. set id to -1 to obtain data for all regions. @@ -212,7 +212,7 @@ def properties_geo(): """ return {"properties": d.properties_geo().pl().to_dicts()} -@app.get("/property/{id}/base", response_model=PropertyBase, tags=['property']) +@app.get("/properties/{id}/base", response_model=PropertyBase, tags=['property']) def property_base_data(id: int): """ Returns basic information about a property. @@ -226,21 +226,21 @@ def property_base_data(id: int): "region_id": base[0]['region_id'], "region_name": base[0]['region_name']} -@app.get("/property/{id}/neighbours", response_model=PropertyNeighbours, tags=['property']) +@app.get("/properties/{id}/neighbours", response_model=PropertyNeighbours, tags=['property']) def property_neighbours(id: int): """ Returns the 10 nearest properties from given property. """ return {"neighbours" : etl_pn.property_neighbours(id)} -@app.get("/property/{id}/extractions", response_model=PropertyExtractions, tags=['property']) +@app.get("/properties/{id}/extractions", response_model=PropertyExtractions, tags=['property']) def property_extractions(id: int): """ Returns extracted data from given property. """ return {"extractions" : d.extractions_for(property_id = id).pl().cast({"date": pl.String}).to_dicts()} -@app.get("/property/{id}/capacities", response_model=PropertyCapacities, tags=['property']) +@app.get("/properties/{id}/capacities", response_model=PropertyCapacities, tags=['property']) def property_capacities_data(id: int): """ Returns capacities for given property. @@ -248,7 +248,7 @@ def property_capacities_data(id: int): capacities = etl_pc.property_capacities(id) return capacities -@app.get("/property/{id}/capacities/monthly/{date}", response_model=PropertyCapacitiesMonthly, tags=['property']) +@app.get("/properties/{id}/capacities/monthly/{date}", response_model=PropertyCapacitiesMonthly, tags=['property']) def property_capacities_data_monthly(id: int, date: datetime.date): """ Returns capacities for given property and date by month. @@ -256,7 +256,7 @@ def property_capacities_data_monthly(id: int, date: datetime.date): capacities = etl_pcm.property_capacities_monthly(id, date) return capacities -@app.get("/property/{id}/capacities/daily/{date}", response_model=PropertyCapacitiesDaily, tags=['property']) +@app.get("/properties/{id}/capacities/daily/{date}", response_model=PropertyCapacitiesDaily, tags=['property']) def property_capacities_data_daily(id: int, date: datetime.date): """ Returns capacities for given property and date by day.