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 pp (day : Unix.tm) tournament =
let m =
tournament.matches
|> List.filter (fun x ->
match x.status with
| 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
let pp (day : Unix.tm) (tournament : t) =
let format_timestamp x =
let is_today start =
let t = start |> float_of_int |> Unix.localtime in
t.tm_mday = day.tm_mday && t.tm_mon = day.tm_mon
in
let t = ts |> float_of_int |> Unix.localtime in
t.tm_mday = day.tm_mday && t.tm_mon = day.tm_mon)
|> List.map (fun x ->
let important_match =
is_conmebol x.home_team || is_conmebol x.away_team
in
if tournament.context.filter_foreigners && not important_match then None
else
let timestamp =
match x.status with
| Postponed | Completed _ | Canceled ->
failwith "impossible: improper filter"
| InProgress _ -> "NOW! "
| Suspended _ -> "SUS! "
| Postponed | Completed _ | Canceled -> None
| Suspended t ->
if is_today t.start_timestamp then Some "SUS! " else None
| InProgress t ->
if is_today t.start_timestamp then Some "NOW! " else None
| NotStarted t -> (
let ts1 =
t.start_timestamp |> float_of_int |> Unix.localtime
in
if not (is_today t.start_timestamp) then None
else
let ts1 = t.start_timestamp |> float_of_int |> Unix.localtime in
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 ->
let ts2 =
t.start_timestamp |> float_of_int |> Unix.gmtime
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)
ts2.tm_min)
ts2.tm_min))
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"
in
if m = "" then ""
@ -206,7 +205,8 @@ let matches_of_api_events (e : api_events) =
in
let t = { start_timestamp = m.startTimestamp; half = h } in
match typ with
| "notstarted" -> NotStarted { start_timestamp = m.startTimestamp }
| "notstarted" ->
NotStarted { start_timestamp = m.startTimestamp }
| "postponed" -> Postponed
| "canceled" -> Canceled
| "suspended" -> Suspended { start_timestamp = m.startTimestamp }