This commit is contained in:
silva guimaraes 2025-06-28 20:09:06 -03:00
parent 6e35f8eae9
commit 3e9b5f483b

View file

@ -102,50 +102,49 @@ module Tournament = struct
let make context matches = { context; matches } let make context matches = { context; matches }
let pp (day : Unix.tm) tournament = let pp (day : Unix.tm) (tournament : t) =
let m = let format_timestamp x =
tournament.matches let is_today start =
|> List.filter (fun x -> let t = start |> float_of_int |> Unix.localtime in
match x.status with t.tm_mday = day.tm_mday && t.tm_mon = day.tm_mon
| Postponed | Completed _ | Canceled -> false
| Suspended _ | InProgress _ | NotStarted _ -> true)
|> List.filter (fun x ->
if tournament.context.filter_foreigners then
is_conmebol x.home_team || is_conmebol x.away_team
else true)
|> List.filter (fun x ->
let ts =
match x.status with
| Postponed | Canceled -> -1
| Suspended t -> t.start_timestamp
| NotStarted t -> t.start_timestamp
| InProgress t -> t.start_timestamp
| Completed t -> t.start_timestamp
in in
let t = ts |> float_of_int |> Unix.localtime in let important_match =
t.tm_mday = day.tm_mday && t.tm_mon = day.tm_mon) is_conmebol x.home_team || is_conmebol x.away_team
|> List.map (fun x -> in
if tournament.context.filter_foreigners && not important_match then None
else
let timestamp = let timestamp =
match x.status with match x.status with
| Postponed | Completed _ | Canceled -> | Postponed | Completed _ | Canceled -> None
failwith "impossible: improper filter" | Suspended t ->
| InProgress _ -> "NOW! " if is_today t.start_timestamp then Some "SUS! " else None
| Suspended _ -> "SUS! " | InProgress t ->
if is_today t.start_timestamp then Some "NOW! " else None
| NotStarted t -> ( | NotStarted t -> (
let ts1 = if not (is_today t.start_timestamp) then None
t.start_timestamp |> float_of_int |> Unix.localtime else
in let ts1 = t.start_timestamp |> float_of_int |> Unix.localtime in
match tournament.context.timezone_offset with match tournament.context.timezone_offset with
| None -> sprintf "%02d:%02d" ts1.tm_hour ts1.tm_min | None -> Some (sprintf "%02d:%02d" ts1.tm_hour ts1.tm_min)
| Some off -> | Some off ->
let ts2 = let ts2 =
t.start_timestamp |> float_of_int |> Unix.gmtime t.start_timestamp |> float_of_int |> Unix.gmtime
in in
sprintf "%02d:%02d/%02d:%02d" ts1.tm_hour ts1.tm_min Some
(sprintf "%02d:%02d/%02d:%02d" ts1.tm_hour ts1.tm_min
(mmod (ts2.tm_hour + off) 24) (mmod (ts2.tm_hour + off) 24)
ts2.tm_min) ts2.tm_min))
in in
sprintf "%s | %s x %s" timestamp x.home_team.name x.away_team.name) match timestamp with
| None -> None
| Some timestamp ->
Some
(sprintf "%s | %s x %s" timestamp x.home_team.name
x.away_team.name)
in
let m =
tournament.matches
|> List.filter_map format_timestamp
|> String.concat "\n" |> String.concat "\n"
in in
if m = "" then "" if m = "" then ""
@ -206,7 +205,8 @@ let matches_of_api_events (e : api_events) =
in in
let t = { start_timestamp = m.startTimestamp; half = h } in let t = { start_timestamp = m.startTimestamp; half = h } in
match typ with match typ with
| "notstarted" -> NotStarted { start_timestamp = m.startTimestamp } | "notstarted" ->
NotStarted { start_timestamp = m.startTimestamp }
| "postponed" -> Postponed | "postponed" -> Postponed
| "canceled" -> Canceled | "canceled" -> Canceled
| "suspended" -> Suspended { start_timestamp = m.startTimestamp } | "suspended" -> Suspended { start_timestamp = m.startTimestamp }