refactor(predicates): return features instead of bool, add P00/P11 predicates
- Change predicate return type from `bool` to `features list option` to carry extracted event data (Summary, Day_start, Multi_day) alongside match results - Add `features` type with Generic_feature_presence, Summary, Day_start, Multi_day variants - Add P00 (has_summary) and P11 (override_events) predicates - Remove large commented-out icalendar/ptime type definitions - Refactor main.ml to group events by UID using a Map - Add get_y_m_d_from_timedesc helper to Utils
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -3,13 +3,19 @@ let default_implementation = Remind.make_default_event "TODO: implement conversi
|
||||
let remind_of_event (ev : Icalendar.event) : Remind.event =
|
||||
let found =
|
||||
ListLabels.fold_left ~init:[] EventPredicates.all_predicates ~f:(fun acc (pred, desc) ->
|
||||
if pred ev then desc :: acc else acc)
|
||||
match pred ev with
|
||||
| Some feats -> (desc, feats) :: acc
|
||||
| None -> acc)
|
||||
|> List.rev
|
||||
in
|
||||
if List.length found > 0
|
||||
then begin
|
||||
Printf.printf " ⇒ matches these predicates:\n";
|
||||
List.iter (fun d -> Printf.printf " - %s\n" (EventPredicates.show_event_description d)) found;
|
||||
Printf.printf " \u{f04d3} \u{21d2} matches these predicates:\n";
|
||||
ListLabels.iter
|
||||
~f:(fun (desc, features) ->
|
||||
Printf.printf " - %s\n" (EventPredicates.show_event_description desc);
|
||||
ListLabels.iter ~f:(fun feat -> Printf.printf " - %s\n" (EventPredicates.show_features feat)) features)
|
||||
found;
|
||||
Printf.printf "\n"
|
||||
end;
|
||||
default_implementation
|
||||
|
||||
49
bin/main.ml
49
bin/main.ml
@@ -1,3 +1,12 @@
|
||||
module Map = MoreLabels.Map.Make (String)
|
||||
|
||||
type event = Icalendar.event list
|
||||
(*
|
||||
We use a list of events here because there can be multiple events with the same UID, and we want to preserve all of
|
||||
them. This is important for handling cases where there are multiple events with the same UID but different properties
|
||||
(e.g., due to updates or recurring events or cancellations).
|
||||
*)
|
||||
|
||||
let ical2rem ical_file =
|
||||
let ic = open_in ical_file in
|
||||
let n = in_channel_length ic in
|
||||
@@ -8,18 +17,30 @@ let ical2rem ical_file =
|
||||
match cal_or_error with
|
||||
| Error e -> prerr_endline ("Error parsing iCalendar file: " ^ e)
|
||||
| Ok (_, components) -> begin
|
||||
let events = ref 0 in
|
||||
List.iter
|
||||
(fun comp ->
|
||||
match comp with
|
||||
| `Event event ->
|
||||
events := !events + 1;
|
||||
let uid = Utils.get_uid event in
|
||||
Printf.printf " ⇒ UID: %s\n" uid;
|
||||
Printf.printf "%s\n\n\n" (Icalendar.show_component comp)
|
||||
| _ -> () (* Ignore non-event components *))
|
||||
components;
|
||||
Printf.printf "\nEvents: %d\n" !events;
|
||||
let events_map : event Map.t =
|
||||
ListLabels.fold_left ~init:Map.empty components ~f:(fun acc comp ->
|
||||
match comp with
|
||||
| `Event ev ->
|
||||
let uid = Utils.get_uid ev in
|
||||
let event_list = Map.find_opt uid acc |> Option.value ~default:[] in
|
||||
Map.add ~key:uid ~data:(ev :: event_list) acc
|
||||
| _ -> acc (* Ignore non-event components *))
|
||||
in
|
||||
|
||||
(* Now revert all the lists *)
|
||||
let events_map = Map.map ~f:List.rev events_map in
|
||||
|
||||
(* let () = *)
|
||||
(* Map.iter *)
|
||||
(* ~f:(fun ~key ~data -> *)
|
||||
(* let uid = key in *)
|
||||
(* let evs = data in *)
|
||||
(* Printf.printf " ⇒ UID: %s\n" uid; *)
|
||||
(* List.iter (fun ev -> Printf.printf "%s\n" (Icalendar.show_component (`Event ev))) evs; *)
|
||||
(* Printf.printf "\n\n") *)
|
||||
(* events_map *)
|
||||
(* in *)
|
||||
Printf.printf "Events: %d\n\n" (Map.cardinal events_map);
|
||||
let events =
|
||||
List.filter_map
|
||||
(function
|
||||
@@ -27,8 +48,10 @@ let ical2rem ical_file =
|
||||
| _ -> None)
|
||||
components
|
||||
in
|
||||
|
||||
let _reminders = List.map EventTransformer.remind_of_event events in
|
||||
|
||||
()
|
||||
end
|
||||
end
|
||||
|
||||
let () = if !Sys.interactive then () else exit (CommandLine.main ical2rem)
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
(*
|
||||
FILE INTERAMENTE GENERATO DA LLM, DA RIVEDERE COMPLETAMENTE
|
||||
*)
|
||||
|
||||
(** Types for representing Remind events *)
|
||||
|
||||
(** Weekday names in Remind format *)
|
||||
|
||||
@@ -24,6 +24,10 @@ let timedesc_of_date_or_datetime (t : date_or_datetime) : Timedesc.t =
|
||||
| `Date (year, month, day) ->
|
||||
Timedesc.make_exn ~year ~month ~day ~hour:0 ~minute:0 ~second:0 ~tz:(Timedesc.Time_zone.local_exn ()) ()
|
||||
|
||||
let get_y_m_d_from_timedesc (t : Timedesc.t) : int * int * int =
|
||||
let date = Timedesc.date t in
|
||||
(Timedesc.Date.year date, Timedesc.Date.month date, Timedesc.Date.day date)
|
||||
|
||||
let get_start ev =
|
||||
let _, start = ev.dtstart in
|
||||
timedesc_of_date_or_datetime start
|
||||
|
||||
Reference in New Issue
Block a user