From 3739e781fa45cacceb42e15ec0373c03de92aa10 Mon Sep 17 00:00:00 2001 From: Paolo Donadeo Date: Sat, 23 May 2026 17:54:38 +0200 Subject: [PATCH] feat(alarms): collect VALARM trigger offsets from iCalendar events - Add `triggers` field to `Remind.rem` type to store alarm trigger offsets as `Timedesc.Span.t list` - Implement `get_triggers` in `Utils` to extract duration-based triggers from audio/display alarms, ignoring email and NONE alarms - Add `collect_triggers` collector that populates the triggers field and logs them to stderr for debugging - Register `collect_triggers` in the collector pipeline - Remove leftover debug log for processed filenames in `main.ml` - Remove stale commented-out RRULE dataset and type documentation from `simple_recurrence` --- bin/eventPredicates.ml | 58 ++++++++---------------------------------- bin/main.ml | 1 - bin/remind.ml | 2 ++ bin/utils.ml | 22 ++++++++++++++++ 4 files changed, 35 insertions(+), 48 deletions(-) diff --git a/bin/eventPredicates.ml b/bin/eventPredicates.ml index 46b16c2..e49e1f9 100644 --- a/bin/eventPredicates.ml +++ b/bin/eventPredicates.ml @@ -255,6 +255,16 @@ let collect_exdates rem ev : (Remind.rem, error) result = let exdates = Utils.get_exdates ev in Ok { rem with Remind.exdate = exdates } +let collect_triggers rem ev : (Remind.rem, error) result = + let triggers = Utils.get_triggers ev in + if List.length triggers > 0 then begin + Printf.eprintf "UID: %s\n" (Utils.get_uid ev); + ListLabels.iteri triggers ~f:(fun i trigger -> + Printf.eprintf " Trigger %d: %s\n" (i + 1) (Timedesc.Span.to_string trigger)); + Printf.eprintf "\n" + end; + Ok { rem with Remind.triggers } + let yearly_simple_date rem ev : (Remind.rem, error) result = match ev.rrule with | Some (_, (`Yearly, None, None, [])) -> @@ -269,53 +279,6 @@ let debug_print_of_recurrence_and_skip ev recurs = skip let simple_recurrence rem ev : (Remind.rem, error) result = - (* Here we want to handle simple recurrences, both weekly and daily, but without RDATE or EXDATE or overrides *) - - (* -type recur = - [ `Byminute of int list - | `Byday of (int * weekday) list - | `Byhour of int list - | `Bymonth of int list - | `Bymonthday of int list - | `Bysecond of int list - | `Bysetposday of int list - | `Byweek of int list - | `Byyearday of int list - | `Weekday of weekday ] -[@@deriving show] - -type freq = [ `Daily | `Hourly | `Minutely | `Monthly | `Secondly | `Weekly | `Yearly ] [@@deriving show] -type count_or_until = [ `Count of int | `Until of utc_or_timestamp_local (* TODO date or datetime *) ] [@@deriving show] -type interval = int [@@deriving show] -type recurrence = freq * count_or_until option * interval option * recur list [@@deriving show] - -QUESTE SONO **TUTTE** LE RRULE NEL MIO DATASET - -RRULE: (`Daily, (Some `Count (11)), None, []) UID: 0b48208b22php2mv6r157rk23v@google.com -RRULE: (`Daily, (Some `Count (11)), None, []) UID: 0cb95edhq1d00bd3gcpomb9mcg@google.com -RRULE: (`Daily, (Some `Count (11)), None, []) UID: 0kbt3i5d6dpq6uncmhlcr335vq@google.com -RRULE: (`Daily, (Some `Until (`Utc (2008-05-11 11:15:00 +00:00))), None, [`Weekday (`Monday)]) UID: dmkfr0h3p1fq6p6v8i62vm1n4k@google.com -RRULE: (`Daily, (Some `Until (`Utc (2008-05-11 15:00:00 +00:00))), None, [`Weekday (`Monday)]) UID: bh5mhev3uq6p5casisrqufksd8@google.com -RRULE: (`Daily, (Some `Until (`Utc (2014-12-24 22:00:00 +00:00))), None, [`Weekday (`Monday)]) UID: tsdjd2jlcsgi0c0ei1celg41v4@google.com -RRULE: (`Daily, (Some `Until (`Utc (2014-12-25 10:00:00 +00:00))), None, [`Weekday (`Monday)]) UID: ha0rjkp62uqh3boc9n6k4f6cuo@google.com -RRULE: (`Daily, (Some `Until (`Utc (2025-05-22 07:00:00 +00:00))), (Some 1), []) UID: 040000008200E00074C5B7101A82E008000000008FD3AF9B24B9DB01000000000000000010000000A152B8147DB736439366702297C68F98 -RRULE: (`Daily, (Some `Until (`Utc (2026-02-04 13:30:00 +00:00))), (Some 1), []) UID: 040000008200E00074C5B7101A82E00800000000CEF108493A94DC010000000000000000100000005D7F32754B6575419990179984830EFC -RRULE: (`Weekly, (Some `Count (3)), None, [`Byday ([(0, `Wednesday)])]) UID: 605de987-4600-419f-a40a-eb585b7e1ba2 -RRULE: (`Weekly, (Some `Count (7)), (Some 2), [`Byday ([(0, `Tuesday)])]) UID: 13C-6A06C880-D-48221A00 -RRULE: (`Weekly, (Some `Until (`Utc (2009-07-31 18:00:00 +00:00))), None, [`Byday ([(0, `Tuesday); (0, `Friday)]); `Weekday (`Monday)]) UID: hrpg4ovdou2ae57pqb9niobb3c@google.com -RRULE: (`Weekly, (Some `Until (`Utc (2013-04-18 17:30:00 +00:00))), None, [`Byday ([(0, `Monday); (0, `Thursday)])]) UID: ool8g85jgfd5db57mdqbkt52nk@google.com -RRULE: (`Weekly, (Some `Until (`Utc (2014-12-20 10:30:00 +00:00))), None, [`Byday ([(0, `Saturday)])]) UID: rr96e7fr98g8j9vner8mmdtfls@google.com -RRULE: (`Weekly, (Some `Until (`Utc (2020-09-16 21:59:59 +00:00))), None, [`Byday ([(0, `Thursday)])]) UID: 5n174r33j7ep7t5eete9307949@google.com -RRULE: (`Weekly, (Some `Until (`Utc (2021-08-25 21:59:59 +00:00))), None, [`Byday ([(0, `Wednesday)]); `Weekday (`Monday)]) UID: 20kb6se0oog5e9hi5l7uu6jiq6@google.com -RRULE: (`Weekly, (Some `Until (`Utc (2021-09-18 21:59:59 +00:00))), (Some 1), [`Byday ([(0, `Sunday)]); `Weekday (`Monday)]) UID: 6sp30e9oc4sjebb264o3gb9kcos3ab9pccoj2b9j6kom2chjcco6ad9nck@google.com -RRULE: (`Weekly, (Some `Until (`Utc (2024-06-12 08:00:00 +00:00))), (Some 4), [`Weekday (`Sunday); `Byday ([(0, `Wednesday)])]) UID: 040000008200E00074C5B7101A82E00800000000DD1EB23CE8ACDA01000000000000000010000000FED71D085A97144F8C716EC999301E3A -RRULE: (`Weekly, (Some `Until (`Utc (2025-02-04 22:59:59 +00:00))), (Some 1), [`Weekday (`Sunday); `Byday ([(0, `Wednesday)])]) UID: _60q30c1g60o30e1i60o4ac1g60rj8gpl88rj2c1h84s34h9g60s30c1g60o30c1g85248hhg6kq30hhn6ork8ghg64o30c1g60o30c1g60o30c1g60o32c1g60o30c1g6kqj4g9g89234chl852kadpk890j2h9m6op44dpn6t238h1k8ks0_R20250129T080000@google.com -RRULE: (`Weekly, (Some `Until (`Utc (2025-06-22 21:59:59 +00:00))), (Some 1), [`Weekday (`Monday); `Byday ([(0, `Monday)])]) UID: 040000008200E00074C5B7101A82E00800000000AE5AF0ED6ADCDB0100000000000000001000000040E4ACABB0843749950BEB4B273F862E -RRULE: (`Weekly, (Some `Until (`Utc (2026-02-24 22:59:59 +00:00))), (Some 2), [`Weekday (`Monday); `Byday ([(0, `Tuesday)])]) UID: fjlqvi1ekuefpa8rb65meoklct@google.com -RRULE: (`Weekly, (Some `Until (`Utc (2026-03-25 00:00:00 +00:00))), None, [`Weekday (`Monday); `Byday ([(0, `Wednesday)])]) UID: 1iue0uq2l3imtfdsff785o9u35@google.com -RRULE: (`Weekly, (Some `Until (`Utc (2026-07-01 09:00:00 +00:00))), None, []) UID: 4479f7fd-7be9-470f-bc10-5ed61636547b -*) match ev.rrule with | Some (_, (`Yearly, None, None, [])) -> Ok rem (* handled in yearly_simple_date *) | Some (_, ((`Weekly as freq), count_or_until, interval, recurs)) @@ -440,6 +403,7 @@ let all_collectors : collector list = collect_conference_url; collect_start_end_duration; collect_exdates; + collect_triggers; collect_overrides; yearly_simple_date; simple_recurrence; diff --git a/bin/main.ml b/bin/main.ml index 9ef6e40..6eb1243 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -19,7 +19,6 @@ let ical2rem tz_opt ical_files = let good_rems = ListLabels.fold_left ~init:[] ical_files ~f:(fun good_rems_acc filename -> try - Printf.eprintf "Processing file: %s\n" filename; let file_content = read_file filename in let basename = Filename.remove_extension (Filename.basename filename) in match Icalendar.parse file_content with diff --git a/bin/remind.ml b/bin/remind.ml index 5c8cf81..00b5ad1 100644 --- a/bin/remind.ml +++ b/bin/remind.ml @@ -50,6 +50,7 @@ type rem = { exdate : Icalendar.date_or_datetime list; (** List of excluded dates for recurring events *) overrides : rem list; (** Single-event REMs generated from non-cancelled RECURRENCE-ID overrides *) tz : Timedesc.Time_zone.t option; (** Timezone of the event's DTSTART, used for UNTIL conversion *) + triggers : Timedesc.Span.t list; (** List of trigger offsets for alarms, in seconds *) } (** A complete REM command *) @@ -74,6 +75,7 @@ let empty = exdate = []; overrides = []; tz = None; + triggers = []; } (* ── buffer primitives ────────────────────────────────────────── *) diff --git a/bin/utils.ml b/bin/utils.ml index eb1f6e7..512f3cf 100644 --- a/bin/utils.ml +++ b/bin/utils.ml @@ -160,6 +160,28 @@ let get_exdates ev = List.map (fun d -> `Date d) dates @ List.map (fun dt -> `Datetime dt) datetimes +let get_triggers ev : Timedesc.Span.t list = + let alarms = ev.Icalendar.alarms in + let triggers = + ListLabels.fold_left ~init:[] alarms ~f:(fun acc alarm -> + let trigger = + match alarm with + | `Audio a -> Some a.Icalendar.trigger (* we keep audio triggers *) + | `Display d -> Some d.Icalendar.trigger (* we keep display triggers *) + | `Email _ -> None (* we ignore email triggers *) + | `None _ -> None (* we ignore VAL=NONE triggers *) + in + match trigger with + | Some trigger -> begin + let _, trigger_duration_or_datetime = trigger in + match trigger_duration_or_datetime with + | `Duration dur -> Timedesc.Utils.span_of_ptime_span dur :: acc + | `Datetime _ -> acc + end + | None -> acc) + in + triggers + let get_rdates ev = let uid = get_uid ev in let event_props = ev.props in