This repository was archived by the owner on Dec 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Add signal strength data model for trace paths #15
Merged
jinglemansweep
merged 2 commits into
main
from
claude/add-signal-strength-model-01DuM4M1BL1RqHuhDw8bzeMm
Dec 1, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| """Signal strength querying endpoints.""" | ||
|
|
||
| from datetime import datetime | ||
| from typing import Optional | ||
|
|
||
| from fastapi import APIRouter, Depends, HTTPException, Query, status | ||
| from sqlalchemy import desc | ||
| from sqlalchemy.orm import Session | ||
|
|
||
| from ...database.models import SignalStrength | ||
| from ...utils.address import normalize_public_key, validate_public_key | ||
| from ..dependencies import get_db | ||
| from ..schemas import SignalStrengthListResponse | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.get( | ||
| "/signal-strength", | ||
| response_model=SignalStrengthListResponse, | ||
| summary="Query signal strength measurements", | ||
| description=( | ||
| "Get signal strength measurements between nodes with optional filters. " | ||
| "All public keys must be full 64 hex characters." | ||
| ), | ||
| ) | ||
| async def query_signal_strength( | ||
| source_public_key: Optional[str] = Query( | ||
| None, | ||
| min_length=64, | ||
| max_length=64, | ||
| description="Filter by source node public key (full 64 hex characters)", | ||
| ), | ||
| destination_public_key: Optional[str] = Query( | ||
| None, | ||
| min_length=64, | ||
| max_length=64, | ||
| description="Filter by destination node public key (full 64 hex characters)", | ||
| ), | ||
| start_date: Optional[datetime] = Query( | ||
| None, description="Filter signal strength records after this date (ISO 8601)" | ||
| ), | ||
| end_date: Optional[datetime] = Query( | ||
| None, description="Filter signal strength records before this date (ISO 8601)" | ||
| ), | ||
| limit: int = Query(100, ge=1, le=1000, description="Maximum number of records to return"), | ||
| offset: int = Query(0, ge=0, description="Number of records to skip"), | ||
| db: Session = Depends(get_db), | ||
| ) -> SignalStrengthListResponse: | ||
| """ | ||
| Query signal strength measurements with filters. | ||
|
|
||
| Args: | ||
| source_public_key: Filter by source node public key (must be exactly 64 hex characters) | ||
| destination_public_key: Filter by destination node public key (exactly 64 hex characters) | ||
| start_date: Only include records after this timestamp | ||
| end_date: Only include records before this timestamp | ||
| limit: Maximum number of records to return (1-1000) | ||
| offset: Number of records to skip for pagination | ||
| db: Database session | ||
|
|
||
| Returns: | ||
| Paginated list of signal strength records matching the filters | ||
| """ | ||
| # Start with base query | ||
| query = db.query(SignalStrength) | ||
|
|
||
| # Apply source_public_key filter | ||
| if source_public_key: | ||
| try: | ||
| normalized_key = normalize_public_key(source_public_key) | ||
| if not validate_public_key(normalized_key, allow_prefix=False): | ||
| raise ValueError("Invalid public key length") | ||
| except (ValueError, TypeError): | ||
| raise HTTPException( | ||
| status_code=status.HTTP_400_BAD_REQUEST, | ||
| detail="source_public_key must be exactly 64 hexadecimal characters", | ||
| ) | ||
| query = query.filter(SignalStrength.source_public_key == normalized_key) | ||
|
|
||
| # Apply destination_public_key filter | ||
| if destination_public_key: | ||
| try: | ||
| normalized_key = normalize_public_key(destination_public_key) | ||
| if not validate_public_key(normalized_key, allow_prefix=False): | ||
| raise ValueError("Invalid public key length") | ||
| except (ValueError, TypeError): | ||
| raise HTTPException( | ||
| status_code=status.HTTP_400_BAD_REQUEST, | ||
| detail="destination_public_key must be exactly 64 hexadecimal characters", | ||
| ) | ||
| query = query.filter(SignalStrength.destination_public_key == normalized_key) | ||
|
|
||
| # Apply date filters | ||
| if start_date: | ||
| query = query.filter(SignalStrength.recorded_at >= start_date) | ||
| if end_date: | ||
| query = query.filter(SignalStrength.recorded_at <= end_date) | ||
|
|
||
| # Order by recorded_at (newest first) | ||
| query = query.order_by(desc(SignalStrength.recorded_at)) | ||
|
|
||
| # Get total count before pagination | ||
| total = query.count() | ||
|
|
||
| # Apply pagination | ||
| signal_strengths = query.limit(limit).offset(offset).all() | ||
|
|
||
| return SignalStrengthListResponse( | ||
| signal_strengths=[s.__dict__ for s in signal_strengths], | ||
| total=total, | ||
| limit=limit, | ||
| offset=offset, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,6 +140,24 @@ class Telemetry(Base): | |
| received_at: Mapped[datetime] = mapped_column(DateTime, default=func.now(), index=True) | ||
|
|
||
|
|
||
| class SignalStrength(Base): | ||
| """Represents signal strength measurement between two nodes.""" | ||
|
|
||
| __tablename__ = "signal_strength" | ||
|
|
||
| id: Mapped[int] = mapped_column(Integer, primary_key=True) | ||
| source_public_key: Mapped[str] = mapped_column(String(64), nullable=False, index=True) | ||
| destination_public_key: Mapped[str] = mapped_column(String(64), nullable=False, index=True) | ||
| snr: Mapped[float] = mapped_column(Float, nullable=False) | ||
| trace_path_id: Mapped[Optional[int]] = mapped_column(Integer, index=True) # Reference to trace | ||
| recorded_at: Mapped[datetime] = mapped_column(DateTime, default=func.now(), index=True) | ||
|
|
||
| __table_args__ = ( | ||
| Index("idx_signal_strength_source_dest", "source_public_key", "destination_public_key"), | ||
| Index("idx_signal_strength_recorded", "recorded_at"), | ||
|
Comment on lines
+153
to
+157
|
||
| ) | ||
|
|
||
|
|
||
| class EventLog(Base): | ||
| """Raw event log for all MeshCore events.""" | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
SignalStrengthResponse,SignalStrengthListResponse, andSignalStrengthFiltersschemas lack test coverage. Based on the existing test patterns intests/unit/test_api_schemas.py, these schemas should have corresponding unit tests similar toTestTelemetryFilters,TestTracePathFilters, etc. to validate field constraints (e.g., min_length/max_length for public keys) and proper instantiation.