Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e2ad2da
Added initial files structure
Ibraam-Nashaat Jun 5, 2025
7270b74
Modified env.py to deal with hypertables
Ibraam-Nashaat Jun 8, 2025
1ea5fac
Modified index creation in env.py
Ibraam-Nashaat Jun 8, 2025
63c6680
Cleaned the files and added comments
Ibraam-Nashaat Jun 12, 2025
caa7100
Added documentation files
Ibraam-Nashaat Jun 12, 2025
cf1ef6d
Added license file
Ibraam-Nashaat Jun 12, 2025
48b0df2
Added more documentation files
Ibraam-Nashaat Jun 12, 2025
dd4324c
Added .env file, removed root path and modified the documentation files
Ibraam-Nashaat Jun 13, 2025
f3af036
Removed .env file
Ibraam-Nashaat Jun 14, 2025
f70ef03
Added database models
Ibraam-Nashaat Jun 16, 2025
999663d
Added more database models
Ibraam-Nashaat Jun 16, 2025
d1af5ad
Completed hegemony cone endpoint
Ibraam-Nashaat Jun 19, 2025
f668e60
Fixed foreign keys errors in models
Ibraam-Nashaat Jun 19, 2025
5ff2a66
Added missing indexes to models
Ibraam-Nashaat Jun 19, 2025
4379d01
Merge remote-tracking branch 'upstream/main' into database-models
Ibraam-Nashaat Jun 19, 2025
975d2ee
Untracked migration files
Ibraam-Nashaat Jun 23, 2025
6ad10dd
Renamed to hegemony_cone.py and added alembic/versions to gitignore
Ibraam-Nashaat Jun 23, 2025
7e92667
Returned some id(primary key) of tables back from BigInteger to Integer
Ibraam-Nashaat Jun 25, 2025
1a4b713
Removed foreign key constraints from some models
Ibraam-Nashaat Jun 25, 2025
df9d065
Completed merge
Ibraam-Nashaat Jun 25, 2025
92c6428
Added networks-endpoint
Ibraam-Nashaat Jun 25, 2025
337759e
Merge branch 'InternetHealthReport:main' into networks-endpoint
Ibraam-Nashaat Jun 27, 2025
bb3e0d3
Added link-delay endpoint
Ibraam-Nashaat Jun 29, 2025
d5867d3
Merge remote-tracking branch 'upstream/main' into link-delay-endpoint
Ibraam-Nashaat Jul 3, 2025
58ef29b
Added link-forwarding endpoint
Ibraam-Nashaat Jul 3, 2025
bad1113
Added /network_delay/locaions endpoint
Ibraam-Nashaat Jul 3, 2025
2f6bfe3
Added /metis/atlas/deployment endpoint
Ibraam-Nashaat Jul 3, 2025
526f316
Added /network_delay endpoint
Ibraam-Nashaat Jul 9, 2025
f7e0068
Added /network_delay/alarms endpoint
Ibraam-Nashaat Jul 9, 2025
23949e1
Change _lte and _gte in controller to __lte and __gte
Ibraam-Nashaat Jul 9, 2025
9bf2ffc
Added /metis/atlas/selection endpoint
Ibraam-Nashaat Jul 9, 2025
74f8bea
Added link/delay/alarms endpoint
Ibraam-Nashaat Jul 14, 2025
f1aede6
Merge remote-tracking branch 'upstream/main'
Ibraam-Nashaat Jul 14, 2025
33a6a4c
Removed link endpoints
Ibraam-Nashaat Jul 14, 2025
6b17dfe
Added /tr-hegemony endpoint
Ibraam-Nashaat Jul 14, 2025
3c56730
Added /disco/events endpoint
Ibraam-Nashaat Jul 14, 2025
a62fda6
Added /hegemony/alarms endpoints
Ibraam-Nashaat Jul 14, 2025
d7cff0f
Merge remote-tracking branch 'upstream/main'
Ibraam-Nashaat Jul 15, 2025
e8eb6b9
Merge branch 'hegemony-alarms-endpoint' of github.com:Ibraam-Nashaat/…
Ibraam-Nashaat Jul 15, 2025
b96500d
Added /hegemony/countries endpoint
Ibraam-Nashaat Jul 15, 2025
8905a2d
Added /hegemony endpoint
Ibraam-Nashaat Jul 15, 2025
5233743
Added /hegemony/prefixes endpoint
Ibraam-Nashaat Jul 15, 2025
2d04bbe
Merge remote-tracking branch 'upstream/main'
Ibraam-Nashaat Jul 16, 2025
65cdd04
Merge branch 'hegemony-prefix-endpoint' of github.com:Ibraam-Nashaat/…
Ibraam-Nashaat Jul 16, 2025
0554319
Merge remote-tracking branch 'upstream/main'
Ibraam-Nashaat Jul 23, 2025
51e7cc9
Merge remote-tracking branch 'upstream/main'
Ibraam-Nashaat Jul 25, 2025
b321230
Added page size ti .env file
Ibraam-Nashaat Jul 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ git clone https://github.com/InternetHealthReport/ihr-api.git

### 2. Create a `.env` File

In the project root directory, create a new `.env` file to define your specific database connection string.
In the project root directory, create a new `.env` file to define your specific database connection string, proxy path and page size (number of results to return per page.).

`.env` content:

```env
DATABASE_URL=postgresql://<username>:<password>@<host>:<port>/<database>
PROXY_PATH=api-dev
PAGE_SIZE = 100000
```


Expand Down
4 changes: 2 additions & 2 deletions controllers/country_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dtos.country_dto import CountryDTO
from config.database import get_db
from typing import Optional
from globals import page_size
from utils import page_size

# Define a router for all endpoints under /countries
router = APIRouter(prefix="/countries", tags=["Countries"])
Expand All @@ -29,7 +29,7 @@ def get_all_countries(
None, description="Which field to use when ordering the results")
) -> GenericResponseDTO[CountryDTO]:
"""Retrieves paginated countries with optional filters."""

page = page or 1
countries, total_count = CountryController.service.get_all_countries(
db,
Expand Down
5 changes: 3 additions & 2 deletions controllers/disco_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from config.database import get_db
from typing import Optional
from datetime import datetime
from globals import page_size
from utils import page_size

router = APIRouter(prefix="/disco", tags=["Disco"])

Expand Down Expand Up @@ -55,7 +55,8 @@ async def get_events(
None, description="Total number of Atlas probes active in the reported stream (ASN, Country, or geographical area)."),
ongoing: Optional[str] = Query(
None, description="Deprecated, this value is unused"),
page: Optional[int] = Query(1, ge=1, description="A page number within the paginated result set."),
page: Optional[int] = Query(
1, ge=1, description="A page number within the paginated result set."),
ordering: Optional[str] = Query(
None, description="Which field to use when ordering the results")
) -> GenericResponseDTO[DiscoEventsDTO]:
Expand Down
2 changes: 1 addition & 1 deletion controllers/hegemony_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dtos.hegemony_alarms_dto import HegemonyAlarmsDTO
from config.database import get_db
from typing import Optional, List
from globals import page_size
from utils import page_size
from utils import *

router = APIRouter(prefix="/hegemony", tags=["Hegemony"])
Expand Down
2 changes: 1 addition & 1 deletion controllers/metis_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dtos.metis_atlas_selection_dto import MetisAtlasSelectionDTO
from config.database import get_db
from typing import Optional
from globals import page_size
from utils import page_size
from utils import validate_timebin_params, prepare_timebin_range

router = APIRouter(prefix="/metis/atlas", tags=["Metis"])
Expand Down
2 changes: 1 addition & 1 deletion controllers/network_delay_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from config.database import get_db
from typing import Optional, List
from datetime import datetime
from globals import page_size
from utils import page_size
from utils import *

router = APIRouter(prefix="/network_delay", tags=["Network Delay"])
Expand Down
5 changes: 3 additions & 2 deletions controllers/networks_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dtos.networks_dto import NetworksDTO
from dtos.generic_response_dto import GenericResponseDTO, build_url
from config.database import get_db
from globals import page_size
from utils import page_size

router = APIRouter(prefix="/networks", tags=["Networks"])

Expand All @@ -28,7 +28,8 @@ async def get_networks(
None, description="Autonomous System Number (ASN) or IXP ID. Note that IXP ID are negative to avoid colision."),
search: Optional[str] = Query(
None, description="Search for both ASN/IXPID and substring in names"),
page: Optional[int] = Query(1, ge=1, description="A page number within the paginated result set."),
page: Optional[int] = Query(
1, ge=1, description="A page number within the paginated result set."),
ordering: Optional[str] = Query(
None, description="Which field to use when ordering the results.")
) -> GenericResponseDTO[NetworksDTO]:
Expand Down
4 changes: 2 additions & 2 deletions controllers/tr_hegemony_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from config.database import get_db
from typing import Optional
from datetime import datetime
from globals import page_size
from utils import page_size
from utils import prepare_timebin_range

router = APIRouter(prefix="/tr_hegemony", tags=["TR Hegemony"])
Expand Down Expand Up @@ -59,7 +59,7 @@ async def get_hegemony(
"""
timebin__gte, timebin__lte = prepare_timebin_range(
timebin, timebin__gte, timebin__lte, max_days=31)

hegemony_data, total_count = TRHegemonyController.service.get_tr_hegemony(
db,
timebin=timebin,
Expand Down
2 changes: 1 addition & 1 deletion docs/project_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This document provides an overview of the project's file and folder structure. E
├── .gitignore # Specifies intentionally untracked files to ignore
├── alembic.ini # Alembic configuration file
├── dockerfile # Docker image instructions to build the app container
├── globals.py # Global constants
├── utils.py # Utils
├── main.py # FastAPI entry point (starts the app)
├── README.md # Project documentation
├── requirements.txt # Python dependencies list for pip installation
Expand Down
2 changes: 0 additions & 2 deletions globals.py

This file was deleted.

2 changes: 1 addition & 1 deletion repositories/atlas_delay_alarms_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from models.atlas_delay_alarms import AtlasDelayAlarms
from datetime import datetime
from typing import List, Optional, Tuple
from globals import page_size
from utils import page_size


class AtlasDelayAlarmsRepository:
Expand Down
2 changes: 1 addition & 1 deletion repositories/atlas_delay_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from models.atlas_delay import AtlasDelay
from datetime import datetime
from typing import List, Optional, Tuple
from globals import page_size
from utils import page_size


class AtlasDelayRepository:
Expand Down
3 changes: 1 addition & 2 deletions repositories/atlas_location_repository.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlalchemy.orm import Session
from models.atlas_location import AtlasLocation
from typing import Optional, List, Tuple
from globals import page_size
from utils import page_size


class AtlasLocationRepository:
Expand Down Expand Up @@ -29,7 +29,6 @@ def get_all(
# Apply ordering
if order_by and hasattr(AtlasLocation, order_by):
query = query.order_by(getattr(AtlasLocation, order_by))


# Apply pagination
offset = (page - 1) * page_size
Expand Down
4 changes: 2 additions & 2 deletions repositories/country_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from models.country import Country
from typing import Optional, List, Tuple # Added Tuple for return type
from sqlalchemy import asc
from globals import page_size
from utils import page_size


class CountryRepository:
Expand All @@ -27,7 +27,7 @@ def get_all(
if name:
query = query.filter(Country.name.ilike(f"%{name}%"))

#Executes getting total count of countries
# Executes getting total count of countries
total_count = query.count()

# Apply ordering if specified
Expand Down
2 changes: 1 addition & 1 deletion repositories/disco_events_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from models.disco_events import DiscoEvents
from datetime import datetime
from typing import List, Optional, Tuple
from globals import page_size
from utils import page_size


class DiscoEventsRepository:
Expand Down
2 changes: 1 addition & 1 deletion repositories/hegemony_alarms_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy.orm import Session
from models.hegemony_alarms import HegemonyAlarms
from typing import Optional, List, Tuple
from globals import page_size
from utils import page_size


class HegemonyAlarmsRepository:
Expand Down
2 changes: 1 addition & 1 deletion repositories/hegemony_cone_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy.orm import Session
from models.hegemony_cone import HegemonyCone
from typing import Optional, List, Tuple
from globals import page_size
from utils import page_size


class HegemonyConeRepository:
Expand Down
2 changes: 1 addition & 1 deletion repositories/hegemony_country_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy.orm import Session
from models.hegemony_country import HegemonyCountry
from typing import Optional, List, Tuple
from globals import page_size
from utils import page_size


class HegemonyCountryRepository:
Expand Down
2 changes: 1 addition & 1 deletion repositories/hegemony_prefix_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy.orm import Session
from models.hegemony_prefix import HegemonyPrefix
from typing import Optional, List, Tuple
from globals import page_size
from utils import page_size


class HegemonyPrefixRepository:
Expand Down
2 changes: 1 addition & 1 deletion repositories/hegemony_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy.orm import Session
from models.hegemony import Hegemony
from typing import Optional, List, Tuple
from globals import page_size
from utils import page_size


class HegemonyRepository:
Expand Down
4 changes: 2 additions & 2 deletions repositories/metis_atlas_deployment_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy.orm import Session
from models.metis_atlas_deployment import MetisAtlasDeployment
from typing import Optional, List, Tuple
from globals import page_size
from utils import page_size


class MetisAtlasDeploymentRepository:
Expand Down Expand Up @@ -46,7 +46,7 @@ def get_all(
# Apply ordering
if order_by and hasattr(MetisAtlasDeployment, order_by):
query = query.order_by(getattr(MetisAtlasDeployment, order_by))

# Apply pagination
offset = (page - 1) * page_size
results = query.offset(offset).limit(page_size).all()
Expand Down
2 changes: 1 addition & 1 deletion repositories/metis_atlas_selection_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy.orm import Session
from models.metis_atlas_selection import MetisAtlasSelection
from typing import Optional, List, Tuple
from globals import page_size
from utils import page_size


class MetisAtlasSelectionRepository:
Expand Down
6 changes: 3 additions & 3 deletions repositories/networks_repository.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from sqlalchemy.orm import Session
from sqlalchemy import or_,String
from sqlalchemy import or_, String
from models.asn import ASN
from typing import Optional, List, Tuple
from globals import page_size
from utils import page_size


class NetworksRepository:
Expand Down Expand Up @@ -47,7 +47,7 @@ def get_all(
# Apply ordering
if order_by and hasattr(ASN, order_by):
query = query.order_by(getattr(ASN, order_by))

# Apply pagination
offset = (page - 1) * page_size
results = query.offset(offset).limit(page_size).all()
Expand Down
2 changes: 1 addition & 1 deletion repositories/tr_hegemony_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from models.tr_hegemony import TRHegemony
from datetime import datetime
from typing import List, Optional, Tuple
from globals import page_size
from utils import page_size


class TRHegemonyRepository:
Expand Down
9 changes: 9 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
from fastapi import HTTPException
from datetime import datetime, timedelta
from typing import Optional
from dotenv import load_dotenv
import os

# Load environment variables from .env file
try:
load_dotenv()
except:
pass

page_size = int(os.getenv("PAGE_SIZE"))

def validate_timebin_params(
timebin: Optional[datetime],
Expand Down