-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrats.ml
63 lines (55 loc) · 1.24 KB
/
strats.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
open Base
open Opium
let show_config_handler _ =
let config = Config.parse() in
Response.of_json (
`Assoc
[
("Seed", `Int config.seed );
("Candidates", `List (config.candidates |> List.map ~f:(fun c -> `String c)))
]
)
|> Lwt.return
let show_schedule_handler _ =
Response.of_json (
`Assoc
[
("Schedule", `List (Schedule.main_schedule |> List.map ~f:(fun c -> `String c)))
]
)
|> Lwt.return
let day_response day =
let (candidate, alternative) = Schedule.day_with_alternative day in
Response.of_json (
`Assoc
[
("Today", `String candidate);
("Alternative", `String alternative)
]
)
|> Lwt.return
let show_day_handler req =
Router.param req "day"
|> Int.of_string
|> day_response
let show_today_handler _ =
let today =
Unix.time()
|> Unix.localtime in
day_response today.tm_yday
let liveness_handler _ =
Response.of_json (
`Assoc
[
("Ok", `String "Ok")
]
)
|> Lwt.return
let _ =
App.empty
|> App.get "/today" show_today_handler
|> App.get "/day/:day" show_day_handler
|> App.get "/schedule" show_schedule_handler
|> App.get "/config" show_config_handler
|> App.get "/liveness" liveness_handler
|> App.run_command