Fixed bug related to anomaly detection system
This commit is contained in:
@@ -19,12 +19,11 @@ Zephyr is designed to be simple, fast and efficient, providing only the
|
|||||||
weather data of a given location, without any additional nonsense.
|
weather data of a given location, without any additional nonsense.
|
||||||
|
|
||||||
This service communicates through a JSON API, making it suitable for
|
This service communicates through a JSON API, making it suitable for
|
||||||
any kind of internet-based project or device. I already use it on a widget
|
any kind of internet-based project or device. I already use it as a [standalone web app](https://m.marcocetica.com),
|
||||||
on my phone, on my terminal, on the tmux's status bar, in a couple of
|
as a phone widget and on my terminal.
|
||||||
smart bedside clocks I've built and as a standalone web app.
|
|
||||||
|
|
||||||
## Weather
|
## Weather
|
||||||
As state before, Zephyr talks via HTTP using the JSON format. Therefore, you
|
As stated before, Zephyr talks via HTTP using JSON formatting. Therefore, you
|
||||||
can query it using any HTTP client of your choice. Below you can find some examples
|
can query it using any HTTP client of your choice. Below you can find some examples
|
||||||
using `curl`:
|
using `curl`:
|
||||||
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
|||||||
module github.com/ceticamarco/zephyr
|
module github.com/ceticamarco/zephyr
|
||||||
|
|
||||||
go 1.24.4
|
go 1.25.3
|
||||||
|
|||||||
@@ -45,14 +45,17 @@ func Median(temperatures []float64) float64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
slices.Sort(temperatures)
|
// Sort the array without mutating the original values
|
||||||
length := len(temperatures)
|
sortedTemps := slices.Clone(temperatures)
|
||||||
|
slices.Sort(sortedTemps)
|
||||||
|
|
||||||
|
length := len(sortedTemps)
|
||||||
midValue := length / 2
|
midValue := length / 2
|
||||||
|
|
||||||
if length%2 == 0 {
|
if length%2 == 0 {
|
||||||
return (temperatures[midValue-1] + temperatures[midValue]) / 2
|
return (sortedTemps[midValue-1] + sortedTemps[midValue]) / 2
|
||||||
} else {
|
} else {
|
||||||
return temperatures[midValue]
|
return sortedTemps[midValue]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,10 +66,12 @@ func Mode(temperatures []float64) float64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
slices.Sort(temperatures)
|
// Sort the array without mutating the original values
|
||||||
|
sortedTemps := slices.Clone(temperatures)
|
||||||
|
slices.Sort(sortedTemps)
|
||||||
|
|
||||||
frequencies := make(map[float64]int)
|
frequencies := make(map[float64]int)
|
||||||
for _, val := range temperatures {
|
for _, val := range sortedTemps {
|
||||||
frequencies[val]++
|
frequencies[val]++
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +129,7 @@ func RobustZScore(temperatures []float64) []struct {
|
|||||||
Idx int
|
Idx int
|
||||||
Value float64
|
Value float64
|
||||||
}
|
}
|
||||||
|
|
||||||
for idx, val := range temperatures {
|
for idx, val := range temperatures {
|
||||||
z := scale * (val - med) / madAbsDev
|
z := scale * (val - med) / madAbsDev
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user