diff --git a/backend/db/crud_view_case_count_by_country_company.py b/backend/db/crud_view_case_count_by_country_company.py deleted file mode 100644 index 59bcd395..00000000 --- a/backend/db/crud_view_case_count_by_country_company.py +++ /dev/null @@ -1,37 +0,0 @@ -from sqlalchemy.orm import Session -from sqlalchemy import func -from models.view_case_count_by_country_company import ( - CaseCountByCompanyAndCountry, -) - - -def get_case_count_by_country(session: Session): - results = ( - session.query( - CaseCountByCompanyAndCountry.country_id, - CaseCountByCompanyAndCountry.country, - func.sum(CaseCountByCompanyAndCountry.case_count).label( - "case_count" - ), - func.sum(CaseCountByCompanyAndCountry.total_farmers).label( - "total_farmers" - ), - ) - .group_by( - CaseCountByCompanyAndCountry.country_id, - CaseCountByCompanyAndCountry.country, - ) - .having(func.sum(CaseCountByCompanyAndCountry.case_count) != 0) - .all() - ) - if not results: - return [] - return [ - { - "country_id": result.country_id, - "COUNTRY": result.country, - "case_count": result.case_count, - "total_farmers": result.total_farmers, - } - for result in results - ] diff --git a/backend/models/view_case_count_by_country_company.py b/backend/models/view_case_count_by_country_company.py deleted file mode 100644 index da391889..00000000 --- a/backend/models/view_case_count_by_country_company.py +++ /dev/null @@ -1,47 +0,0 @@ -from sqlalchemy import Column, Integer, String -from sqlalchemy.ext.declarative import declarative_base -from typing_extensions import TypedDict - -Base = declarative_base() - - -class CaseCountByCountryDict(TypedDict): - country_id: int - COUNTRY: str - case_count: int - total_farmers: int - - -class CaseCountByCompanyAndCountry(Base): - __tablename__ = "case_count_by_company_and_country" - - # Virtual primary key - id = Column(Integer, primary_key=True, autoincrement=True) - - country_id = Column(Integer) - country = Column(String) - company_id = Column(Integer) - company = Column(String) - case_count = Column(Integer) - total_farmers = Column(Integer) - - def __init__( - self, - id: int, - country_id: int, - country: str, - company_id: int, - company: str, - case_count: int, - total_farmers: int, - ): - self.id = id - self.country_id = country_id - self.country = country - self.company_id = company_id - self.company = company - self.case_count = case_count - self.total_farmers = total_farmers - - def __repr__(self) -> int: - return f"" diff --git a/backend/routes/map.py b/backend/routes/map.py index 17f27b0e..c3999670 100644 --- a/backend/routes/map.py +++ b/backend/routes/map.py @@ -8,9 +8,9 @@ from fastapi.security import HTTPBearer, HTTPBasicCredentials as credentials from sqlalchemy.orm import Session from typing import List +from typing_extensions import TypedDict from db.connection import get_session -from models.view_case_count_by_country_company import CaseCountByCountryDict from middleware import verify_user from models.user import UserRole @@ -21,6 +21,13 @@ MASTER_DIR = BASE_DIR + "/source/master/" +class CaseCountByCountryDict(TypedDict): + country_id: int + COUNTRY: str + case_count: int + total_farmers: int + + @map_route.get( "/map/static/world_map.js", tags=["Map"],