Skip to content

Commit 2d16bb8

Browse files
committed
Filter out short probe sessions from stats to prevent double-counting on intro playback
1 parent 0625f02 commit 2d16bb8

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎config/config.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ type GeoConfig struct {
5151
}
5252

5353
type StatsConfig struct {
54-
DBPath string `toml:"db_path"`
54+
DBPath string `toml:"db_path"`
55+
MinSession int `toml:"min_session"` // Minimum session duration in seconds to record (default 10)
5556
}
5657

5758
type Config struct {

‎main.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,21 @@ func main() {
154154
defer statsDB.Close()
155155
slog.Info("statistics database loaded", "path", cfg.Stats.DBPath)
156156

157+
// Minimum session duration to filter out media-player probe connections
158+
// that connect briefly to check stream metadata before the real playback.
159+
minSession := int64(cfg.Stats.MinSession)
160+
if minSession <= 0 {
161+
minSession = 10
162+
}
163+
157164
// Wire disconnect hooks to record sessions
158165
for _, st := range stations {
159166
st.Hub.SetDisconnectHook(func(stationID string, snap broadcast.ListenerSnapshot, disconnectedAt time.Time) {
160167
dur := int64(disconnectedAt.Sub(snap.ConnectedAt).Seconds())
168+
if dur < minSession {
169+
slog.Debug("session too short, not recording", "station", stationID, "duration", dur, "min", minSession)
170+
return
171+
}
161172
if err := statsDB.Record(stats.Session{
162173
Station: stationID,
163174
Country: snap.Info.Country,

0 commit comments

Comments
 (0)