62 lines
2.4 KiB
Python
62 lines
2.4 KiB
Python
from fastapi import APIRouter
|
|
from config.database import client
|
|
from models.mongodb_handler import MongoDBHandler
|
|
import models.pipelines as pipelines
|
|
import schema.schemas as schemas
|
|
from schema.schemas import DataSerializer
|
|
import ast
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/mangrove_by_country_latest")
|
|
async def mangrove_by_country_latest():
|
|
db = client.baseddata
|
|
collection_name = db["final__protected_mangroves_summary_stats_by_country_agg"]
|
|
schema = schemas.mangrove_by_country_latest_schema
|
|
pipeline = pipelines.mangrove_by_country_latest()
|
|
serializer = DataSerializer(schema)
|
|
handler = MongoDBHandler(collection_name)
|
|
rawData = handler.aggregate(pipeline)
|
|
serializedData = serializer.serialize_many(rawData)
|
|
return serializedData
|
|
|
|
@router.get("/mangrove_by_country_agg")
|
|
async def mangrove_by_country_agg(query: str):
|
|
query = ast.literal_eval(query)
|
|
db = client.baseddata
|
|
collection_name = db["final__protected_mangroves_summary_stats_by_country_agg"]
|
|
schema = schemas.mangrove_by_country_agg_schema
|
|
pipeline = pipelines.mangrove_by_country_agg(query)
|
|
serializer = DataSerializer(schema)
|
|
handler = MongoDBHandler(collection_name)
|
|
rawData = handler.aggregate(pipeline)
|
|
serializedData = serializer.serialize_many(rawData)
|
|
return serializedData
|
|
|
|
@router.get("/bitcoin_business_growth_percent_diff")
|
|
async def bitcoin_business_growth_percent_diff(query: str):
|
|
query = ast.literal_eval(query)
|
|
db = client.baseddata
|
|
collection_name = db["final__bitcoin_business_growth_by_country"]
|
|
schema = schemas.bitcoin_business_growth_percent_diff_schema
|
|
pipeline = pipelines.bitcoin_business_growth_percent_diff_days_ago(query)
|
|
serializer = DataSerializer(schema)
|
|
handler = MongoDBHandler(collection_name)
|
|
rawData = handler.aggregate(pipeline)
|
|
serializedData = serializer.serialize_many(rawData)
|
|
return serializedData
|
|
|
|
@router.get("/bitcoin_business_growth_timeseries")
|
|
async def bitcoin_business_growth_timeseries(query: str):
|
|
query = ast.literal_eval(query)
|
|
db = client.baseddata
|
|
collection_name = db["final__bitcoin_business_growth_by_country"]
|
|
schema = schemas.bitcoin_business_growth_timeseries_schema
|
|
pipeline = pipelines.bitcoin_business_growth_timeseries(query)
|
|
serializer = DataSerializer(schema)
|
|
handler = MongoDBHandler(collection_name)
|
|
rawData = handler.aggregate(pipeline)
|
|
serializedData = serializer.serialize_many(rawData)
|
|
return serializedData
|