Represents a speed test measurement with all network metrics.
Attributes:
download(float): Download speed in Mbpsupload(float): Upload speed in Mbpslatency(float): Latency in millisecondsjitter(float): Jitter in milliseconds (default: 0.0)packet_loss(float): Packet loss percentage (default: 0.0)stability(float): Connection stability score 0-100 (auto-calculated)
Methods:
Calculate connection stability score based on jitter and packet loss.
Returns: Stability score from 0 to 100 (higher is better)
Convert SpeedTest to dictionary representation.
Returns: Dictionary containing all speed test metrics
Create SpeedTest instance from dictionary.
Example:
from src.models import SpeedTest
# Create a speed test
st = SpeedTest(
download=150.0,
upload=18.0,
latency=25.0,
jitter=3.0,
packet_loss=0.2
)
print(st.stability) # Auto-calculated: ~93.0
print(st) # SpeedTest(download=150.0Mbps, upload=18.0Mbps, latency=25.0ms, stability=93.0)
# Serialize
st_dict = st.to_dict()
# Deserialize
restored_st = SpeedTest.from_dict(st_dict)Represents the quality score of a connectivity point.
Attributes:
overall_score(float): Overall quality score (0-100)speed_score(float): Speed component score (0-100)latency_score(float): Latency component score (0-100)stability_score(float): Stability component score (0-100)rating(str): Quality rating (Excellent/Good/Fair/Poor)
Class Attributes:
SPEED_WEIGHT = 0.40(40% weight)LATENCY_WEIGHT = 0.30(30% weight)STABILITY_WEIGHT = 0.30(30% weight)TARGET_DOWNLOAD = 200.0Mbps (Starlink 2026 target)TARGET_UPLOAD = 20.0MbpsTARGET_LATENCY = 20.0ms
Methods:
Calculate quality score from speed test results.
Example:
from src.models import SpeedTest, QualityScore
st = SpeedTest(download=200.0, upload=20.0, latency=20.0)
qs = QualityScore.calculate(st)
print(qs.overall_score) # ~95.0
print(qs.rating) # "Excellent"Represents a connectivity measurement point with location and quality data.
Attributes:
latitude(float): Latitude coordinatelongitude(float): Longitude coordinateprovider(str): Internet service provider namespeed_test(SpeedTest): Speed test measurement resultsquality_score(QualityScore): Calculated quality scoretimestamp(str): ISO format timestamp (auto-generated)id(str): Unique identifier (auto-generated UUID)
Methods:
Convert ConnectivityPoint to dictionary representation.
Create ConnectivityPoint instance from dictionary.
Example:
from src.models import ConnectivityPoint, SpeedTest
st = SpeedTest(download=165.4, upload=22.8, latency=28.5, jitter=3.2, packet_loss=0.1)
point = ConnectivityPoint(
latitude=-15.7801,
longitude=-47.9292,
provider='Starlink',
speed_test=st
)
print(point.quality_score.rating) # Auto-calculated
print(point.id) # Auto-generated UUID
# Serialize for storage
point_dict = point.to_dict()Functions for validating data integrity.
Validate geographic coordinates.
Parameters:
latitude: Latitude value (-90 to 90)longitude: Longitude value (-180 to 180)
Returns: True if valid, False otherwise
Example:
from src.utils import validate_coordinates
valid = validate_coordinates(-23.5505, -46.6333) # True (São Paulo)
invalid = validate_coordinates(100, 200) # FalseValidate speed test measurements.
Parameters:
speed_test: SpeedTest object or dict
Returns: True if all values are positive and required fields exist
Validate internet service provider name against known providers.
Known Providers: Starlink, Viasat, HughesNet, Claro, Vivo, TIM, Oi, Various, Unknown
Functions for loading, saving, and managing data files.
Load JSON data from file.
Returns: List of dictionaries (empty list if file doesn't exist)
Save data to JSON file (creates directories if needed).
Create timestamped backup of a data file.
Returns: Path to backup file
Example:
from src.utils import load_data, save_data, backup_data
# Load data
data = load_data('src/data/pontos.json')
# Create backup before modification
backup_path = backup_data('src/data/pontos.json')
# Modify and save
data.append(new_point.to_dict())
save_data('src/data/pontos.json', data)Functions for network speed testing.
Measure network speed using speedtest-cli.
Returns: Dictionary with download, upload, latency, stability or None if fails
Example:
from src.utils import measure_speed
result = measure_speed()
if result:
print(f"Download: {result['download']} Mbps")
print(f"Upload: {result['upload']} Mbps")
print(f"Latency: {result['latency']} ms")Functions for coordinate and address conversion.
Convert coordinates to address using reverse geocoding.
Returns: Address string or None
Convert address to coordinates using forward geocoding.
Returns: (latitude, longitude) tuple or None
Example:
from src.utils import geocode_coordinates, geocode_address
# Reverse geocoding
address = geocode_coordinates(-23.5505, -46.6333)
print(address) # "São Paulo, Brazil"
# Forward geocoding
coords = geocode_address("Brasília, Brazil")
print(coords) # (-15.7801, -47.9292)Functions for multi-format report generation.
Generate report in specified format.
Parameters:
data: List of connectivity point dictionariesformat: Report format ('json', 'csv', 'txt', 'html')output_path: Optional output file path (auto-generated if None)
Returns: Path to generated report file
Example:
from src.utils import load_data, generate_report
data = load_data('src/data/pontos.json')
# Generate multiple formats
json_report = generate_report(data, 'json', 'report.json')
csv_report = generate_report(data, 'csv', 'report.csv')
html_report = generate_report(data, 'html', 'report.html')Functions for router impact analysis.
Simulate the impact of router improvements on quality scores.
Applies random improvement of 15-25% to quality scores to simulate router upgrades.
Returns: Updated data with improved quality scores
Example:
from src.utils import load_data, simulate_router_impact, save_data
data = load_data('src/data/pontos.json')
improved_data = simulate_router_impact(data)
# Save improved data
save_data('src/data/pontos_improved.json', improved_data)Functions for interactive map generation.
Generate interactive Folium map from connectivity data.
Features:
- Color-coded markers by quality score (green/blue/orange/red)
- Popup details with provider, speed test, quality metrics
- Legend for quality ratings
- Auto-centered map based on data points
Returns: Path to generated HTML map file
Example:
from src.utils import load_data, generate_map
data = load_data('src/data/pontos.json')
map_path = generate_map(data, 'connectivity_map.html')
print(f"Open {map_path} in your browser to view the map")Functions for temporal evolution and trends analysis.
Analyze temporal evolution of connectivity quality.
Returns: Dictionary with:
total_points: Total number of points analyzeddate_range: Start date, end date, number of daysdaily_averages: Statistics grouped by datetrends: Overall average metricsinsights: List of generated insightsprovider_stats: Statistics by provider
Example:
from src.utils import load_data, analyze_temporal_evolution
data = load_data('src/data/pontos.json')
analysis = analyze_temporal_evolution(data)
print(f"Average Quality Score: {analysis['trends']['avg_quality_score']}/100")
print(f"Average Download: {analysis['trends']['avg_download']} Mbps")
for insight in analysis['insights']:
print(f"• {insight}")#!/usr/bin/env python3
"""Complete workflow example."""
from src.models import ConnectivityPoint, SpeedTest
from src.utils import (
save_data, load_data, simulate_router_impact,
generate_report, generate_map, analyze_temporal_evolution
)
# 1. Create connectivity points
points = []
st1 = SpeedTest(download=165.4, upload=22.8, latency=28.5, jitter=3.2, packet_loss=0.1)
point1 = ConnectivityPoint(-15.7801, -47.9292, 'Starlink', st1)
points.append(point1.to_dict())
st2 = SpeedTest(download=85.2, upload=12.5, latency=45.3, jitter=8.2, packet_loss=1.2)
point2 = ConnectivityPoint(-23.5505, -46.6333, 'Various', st2)
points.append(point2.to_dict())
# 2. Save data
save_data('pontos.json', points)
# 3. Load and simulate improvements
data = load_data('pontos.json')
improved_data = simulate_router_impact(data)
# 4. Generate reports
generate_report(improved_data, 'html', 'report.html')
generate_report(improved_data, 'json', 'report.json')
# 5. Create map
generate_map(improved_data, 'map.html')
# 6. Analyze trends
analysis = analyze_temporal_evolution(improved_data)
print(f"Average Quality: {analysis['trends']['avg_quality_score']}/100")
for insight in analysis['insights']:
print(f"• {insight}")The Rural Connectivity Mapper 2026 supports multiple methods for submitting connectivity data to accommodate users with different technical skill levels:
Best for: Bulk data import, automated systems, users comfortable with CSV files
python main.py --importar src/data/sample_data.csvCSV Format:
id,city,provider,latitude,longitude,download,upload,latency,jitter,packet_loss,timestamp
1,São Paulo,Starlink,-23.5505,-46.6333,165.4,22.8,28.5,3.2,0.1,2026-01-15T10:30:00Required Fields:
id- Unique identifiercity- City or location nameprovider- ISP name (Starlink, Viasat, HughesNet, Claro, Vivo, TIM, Oi, etc.)latitude- GPS latitude (-90 to 90)longitude- GPS longitude (-180 to 180)download- Download speed in Mbpsupload- Upload speed in Mbpslatency- Latency/ping in millisecondsjitter- Jitter in milliseconds (optional, default: 0)packet_loss- Packet loss percentage (optional, default: 0)timestamp- ISO 8601 format timestamp
Best for: Field data collection, community participation, non-technical users
Google Forms provides an easy-to-use web interface for collecting connectivity data without requiring any programming knowledge or CSV file handling skills.
Key Features:
- ✅ User-Friendly - Simple web form, no technical skills needed
- ✅ Mobile Compatible - Works on smartphones for field data collection
- ✅ Free - No cost for basic usage
- ✅ Automatic Validation - Built-in field validation and required fields
- ✅ CSV Export - Exports to CSV compatible with the mapper
- ✅ Shareable - Easy to distribute via link, email, or social media
Workflow:
- Create Google Form with connectivity data fields
- Share form link with users
- Collect responses automatically in Google Sheets
- Export to CSV format
- Import using standard CSV import command
Complete Setup Guide:
See docs/GOOGLE_FORMS_INTEGRATION.md for:
- Step-by-step form creation instructions
- Field configuration and validation rules
- Data export and formatting procedures
- Import instructions and troubleshooting
- Sample form template
Example:
# After exporting from Google Forms
python main.py --importar google_forms_responses.csv --map --relatorio htmlBest for: Real-time data submission, mobile apps, automated systems
A REST API is planned for later in 2026 (v1.2.0 release) that will allow:
- Real-time data submission
- Real-time data retrieval
- Programmatic data retrieval
- Programmatic data submission
- Real-time data submission via HTTP POST
- JSON-based data format
- Authentication and rate limiting
- Webhooks for data updates
- Integration with mobile apps and IoT devices
Planned Endpoints:
POST /api/v1/points- Submit new connectivity pointGET /api/v1/points- Retrieve connectivity pointsGET /api/v1/analysis- Get analysis results
See README.md for complete CLI documentation.
# Import CSV data
python main.py --debug --importar src/data/sample_data.csv
# Import Google Forms export
python main.py --importar google_forms_export.csv
# Generate reports
python main.py --relatorio json
python main.py --relatorio html
# Simulate router impact
python main.py --simulate
# Generate map
python main.py --map
# Analyze temporal evolution
python main.py --analyze
# Combined workflow
python main.py --debug --importar src/data/sample_data.csv --simulate --map --analyze --relatorio htmlRun the test suite:
# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=src --cov-report=html
# Run specific test file
pytest tests/test_models.py -v