1.4 KiB
first, the user defines a range of time over which to spread the commits, and describes the valid times that commits may be in. (for example, 2024-01-01 14:55 to 2024-01-10 15:32, 9:00 to 17:00 on weekdays, 9:00 to 11:00 on saturdays, never on sundays).
then we calculate the allowed regions, storing them for later. mon tue wed thu fri sat sun mon tue wed |--++--|--++--|--++--|--++--|--++--|----++|------|--++--|--++--|--++--|
we calculate the total duration of all the allowed region, to make a 'compressed' timeline, stored simply as number of seconds from the start of the range. |++|++|++|++|++|++||++|++|++|
we distribute a number of 'events' equal to the number of commits over the compressed timeline |+|++|+|+|++|+||+|++|+|
we apply a user specified amount of jitter to each event |+|++|+|+|++|+||+|+|++|
we then re-expand the timeline with the following algorithm:
expanded_events = [] for event in events: for region in allowed_regions: if event.timestamp > region.duration: event.timestamp -= region.duration else: events.push(region.start+event.timestamp) break the expanded timeline will then look like: |--+--|--++--|--+--|--+--|--++--|----+|------|--+--|--+--|--++--|
we then sort the events (as the jitter may have put them out of order) and assign eatch commit, in order, to an event.