Added stat methods and anomaly detection algorithm

This commit is contained in:
2025-06-19 12:09:23 +02:00
parent 2db2c57ce2
commit ca4b75af7a
5 changed files with 230 additions and 10 deletions

View File

@@ -50,3 +50,15 @@ func (statDB *StatDB) IsKeyInvalid(key string) bool {
return true
}
func (statDB *StatDB) GetCityStatistics(cityName string) []Weather {
result := make([]Weather, 0)
for key, record := range statDB.db {
if strings.HasSuffix(key, cityName) {
result = append(result, record)
}
}
return result
}

View File

@@ -10,12 +10,12 @@ type WeatherAnomaly struct {
// The StatResult data type, representing weather statistics
// of past meteorological events
type StatResult struct {
Min float64 `json:"min"`
Max float64 `json:"max"`
Count int `json:"count"`
Mean float64 `json:"mean"`
StdDev float64 `json:"stdDev"`
Median float64 `json:"median"`
Mode float64 `json:"mode"`
Anomaly WeatherAnomaly `json:"anomaly"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Count int `json:"count"`
Mean float64 `json:"mean"`
StdDev float64 `json:"stdDev"`
Median float64 `json:"median"`
Mode float64 `json:"mode"`
Anomaly *[]WeatherAnomaly `json:"anomaly"`
}