refactor
This commit is contained in:
parent
6e35f8eae9
commit
3e9b5f483b
1 changed files with 43 additions and 43 deletions
86
lib/lib.ml
86
lib/lib.ml
|
|
@ -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 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 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 -> 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 -> (
|
||||||
|
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 -> Some (sprintf "%02d:%02d" ts1.tm_hour ts1.tm_min)
|
||||||
|
| Some off ->
|
||||||
|
let ts2 =
|
||||||
|
t.start_timestamp |> float_of_int |> Unix.gmtime
|
||||||
|
in
|
||||||
|
Some
|
||||||
|
(sprintf "%02d:%02d/%02d:%02d" ts1.tm_hour ts1.tm_min
|
||||||
|
(mmod (ts2.tm_hour + off) 24)
|
||||||
|
ts2.tm_min))
|
||||||
|
in
|
||||||
|
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 =
|
let m =
|
||||||
tournament.matches
|
tournament.matches
|
||||||
|> List.filter (fun x ->
|
|> List.filter_map format_timestamp
|
||||||
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
|
|
||||||
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 timestamp =
|
|
||||||
match x.status with
|
|
||||||
| Postponed | Completed _ | Canceled ->
|
|
||||||
failwith "impossible: improper filter"
|
|
||||||
| InProgress _ -> "NOW! "
|
|
||||||
| Suspended _ -> "SUS! "
|
|
||||||
| NotStarted t -> (
|
|
||||||
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
|
|
||||||
| Some off ->
|
|
||||||
let ts2 =
|
|
||||||
t.start_timestamp |> float_of_int |> Unix.gmtime
|
|
||||||
in
|
|
||||||
sprintf "%02d:%02d/%02d:%02d" ts1.tm_hour ts1.tm_min
|
|
||||||
(mmod (ts2.tm_hour + off) 24)
|
|
||||||
ts2.tm_min)
|
|
||||||
in
|
|
||||||
sprintf "%s | %s x %s" timestamp x.home_team.name x.away_team.name)
|
|
||||||
|> 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 }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue