Add playback success rate to /api/v1/stats (#4085)

* Add stats-based /videoplayback blockage status

* Count when YouTube returns wrong video as failure

* Cast playback stats hash type prior to return

* Bump stats refresh timer to 10 minutes
This commit is contained in:
syeopite
2023-11-04 13:52:30 +00:00
committed by GitHub
parent db3c57d49f
commit 438467f69a
5 changed files with 54 additions and 1 deletions

View File

@@ -6,6 +6,22 @@ module Invidious::Routes::API::V1::Misc
if !CONFIG.statistics_enabled
return {"software" => SOFTWARE}.to_json
else
# Calculate playback success rate
if (tracker = Invidious::Jobs::StatisticsRefreshJob::STATISTICS["playback"]?)
tracker = tracker.as(Hash(String, Int64 | Float64))
if !tracker.empty?
total_requests = tracker["totalRequests"]
success_count = tracker["successfulRequests"]
if total_requests.zero?
tracker["ratio"] = 1_i64
else
tracker["ratio"] = (success_count / (total_requests)).round(2)
end
end
end
return Invidious::Jobs::StatisticsRefreshJob::STATISTICS.to_json
end
end