Advanced analysis module for LFS-Ayats with anomaly detection, performance prediction, and sector analysis capabilities.
anomaly.py)predictor.py)sectors.py)comparator.py)alerts.py)metrics.py)The module is included in LFS-Ayats. Make sure you have the dependencies installed:
pip install -r requirements.txt
pip install -e .
from src.analysis import AnomalyDetector
# Create detector
detector = AnomalyDetector()
# Check telemetry
current_data = {
"engine_temp": 102.0,
"linear_speed": 50.0,
"wheel_speed": 60.0,
}
alerts = detector.check_telemetry(current_data)
for alert in alerts:
print(alert)
from src.analysis import PerformancePredictor
# Create predictor
predictor = PerformancePredictor()
# Historical data
historical_data = [
{"sector_times": [28.5, 31.2, 25.8]},
{"sector_times": [28.3, 31.5, 25.6]},
]
# Predict time with 2 completed sectors
predicted_time = predictor.predict_lap_time(
current_sector_times=[28.2, 31.0],
historical_data=historical_data
)
print(f"Predicted time: {predicted_time:.3f}s")
from src.analysis import SectorAnalyzer
# Create analyzer
analyzer = SectorAnalyzer()
# Multiple laps data
session_data = [
{"sector_times": [28.5, 31.2, 25.8]},
{"sector_times": [28.3, 31.5, 25.6]},
{"sector_times": [28.4, 31.8, 25.7]},
]
# Identify weak sectors
weak_sectors = analyzer.identify_weak_sectors(session_data)
for sector in weak_sectors:
print(f"Sector {sector.number}: losing {sector.time_lost:.3f}s")
from src.analysis import AlertSystem, AlertLevel
from src.analysis.alerts import ConsoleAlertHandler
# Create system
system = AlertSystem()
system.register_handler(ConsoleAlertHandler())
# Generate alert
system.create_and_trigger(
AlertLevel.WARNING,
"High temperature",
{"temp": 98.0}
)
# Check conditions
telemetry = {"engine_temp": 110.0, "fuel": 4.0}
alerts = system.check_conditions(telemetry)
from src.analysis import AdvancedComparator
# Create comparator
comparator = AdvancedComparator()
# Lap data
lap1 = {
"lap_id": 5,
"total_time": 85.5,
"sector_times": [28.5, 31.2, 25.8]
}
lap2 = {
"lap_id": 8,
"total_time": 85.2,
"sector_times": [28.3, 31.5, 25.4]
}
# Compare
comparison = comparator.compare_laps(lap1, lap2)
print(f"Difference: {comparison.time_difference:+.3f}s")
for suggestion in comparison.suggestions:
print(f"โข {suggestion}")
from src.analysis import MetricsCalculator
# Create calculator
calculator = MetricsCalculator()
# Lap times
lap_times = [86.5, 86.2, 85.9, 85.7, 85.5]
reference = 85.0
# Calculate metrics
consistency = calculator.calculate_consistency(lap_times)
pace_score = calculator.calculate_pace_score(lap_times, reference)
performance = calculator.calculate_performance_index(lap_times, reference)
print(f"Consistency: {consistency:.1%}")
print(f"Pace: {pace_score:.1f}/100")
print(f"Performance: {performance:.1f}/100")
cd /path/to/LFS-Ayats
PYTHONPATH=. python3 examples/analysis_examples.py
The module includes 69 unit tests with complete coverage:
# Run module tests
pytest tests/unit/analysis/ -v
# With coverage
pytest tests/unit/analysis/ --cov=src/analysis --cov-report=html
AnomalyDetectordetector = AnomalyDetector(
temp_warning=95.0, # Warning temperature (ยฐC)
temp_critical=105.0, # Critical temperature (ยฐC)
z_score_threshold=3.0 # Threshold for outlier detection
)
Main methods:
detect_overheating(engine_temp) โ (bool, Alert)detect_wheel_spin(linear_speed, wheel_speed) โ (bool, Alert)detect_understeer(steering_angle, actual_rotation) โ (bool, Alert)detect_fuel_warning(fuel_level, fuel_per_lap, laps_remaining) โ (bool, Alert)detect_outliers_zscore(data, threshold) โ List[int]check_telemetry(telemetry_data) โ List[Alert]PerformancePredictorpredictor = PerformancePredictor()
Main methods:
predict_lap_time(current_sector_times, historical_data) โ floatpredict_pit_window(fuel_consumption, tire_wear, laps_remaining) โ (int, str)estimate_tire_life(current_wear, laps_completed) โ (int, float)calculate_optimal_pace(fuel_target, laps_remaining, current_fuel) โ floatcalculate_theoretical_best(sector_times_per_lap) โ (float, List[float])SectorAnalyzeranalyzer = SectorAnalyzer()
Main methods:
compare_sector_times(lap_data, reference_lap_data) โ List[Dict]identify_weak_sectors(session_data) โ List[Sector]calculate_sector_consistency(laps) โ Dict[int, float]analyze_braking_points(laps) โ List[BrakingPoint]AdvancedComparatorcomparator = AdvancedComparator()
Main methods:
compare_laps(lap1_data, lap2_data) โ LapComparisoncalculate_time_delta(lap1_data, lap2_data) โ TimeDeltafind_performance_differences(lap1, lap2) โ List[Dict]AlertSystemsystem = AlertSystem(
max_history=1000, # Maximum alerts in history
enable_filtering=True # Duplicate filtering
)
Main methods:
register_handler(handler) โ Nonetrigger_alert(alert, min_interval) โ boolcreate_and_trigger(level, message, data, min_interval) โ boolcheck_conditions(telemetry_data) โ List[Alert]get_history(level, limit) โ List[Alert]MetricsCalculatorcalculator = MetricsCalculator()
Main methods:
calculate_consistency(lap_times) โ floatcalculate_pace_score(lap_times, reference_time) โ floatcalculate_improvement_rate(lap_times) โ floatcalculate_performance_index(lap_times, reference_time) โ floatcalculate_percentile_rank(value, dataset) โ floatAlert@dataclass
class Alert:
level: AlertLevel # INFO, WARNING, ERROR, CRITICAL
message: str
timestamp: float
data: Dict[str, Any]
SectorComparison@dataclass
class SectorComparison:
sector_number: int
lap1_time: float
lap2_time: float
difference: float
percentage_diff: float
LapComparison@dataclass
class LapComparison:
lap1_id: int
lap2_id: int
time_difference: float
sector_comparisons: List[SectorComparison]
speed_trace_comparison: Dict[str, Any]
racing_line_difference: float
suggestions: List[str]
See CONTRIBUTING.md for contribution guidelines.
This project is licensed under the MIT License. See LICENSE for more details.
Developed as part of the LFS-Ayats project to provide advanced telemetry analysis for Live for Speed.