<commit_before>import timely

start_date = timely.Instant('1996-01-01')
end_date = timely.Instant('1996-12-31') # watch for time within day?
year_1996 = timely.Interval((start_date, end_date))

worker_spell = timely.Interval(('1996-11-01', '2009-06-30'))
period_worked_in_1996 = worker_spell.intersection(year_1996)
worker_joined_in_1996 = worker_spell.beginnin in year_1996

other_worker_spell = timely.Interval(('2007-01-01', '')) # open spell
two_workers_overlapped = worker_spell.intersects(other_worker_spell)

sample_period = timely.MultiInterval([year_1996, worker_spell, other_worker_spell]).envelope
# = Interval(('1996-01-01', ''))<commit_msg>a more advanced example, counting number of concurrent spells<commit_after>import timely

start_date = timely.Instant('1996-01-01')
end_date = timely.Instant('1996-12-31') # watch for time within day?
year_1996 = timely.Interval((start_date, end_date))

worker_spell = timely.Interval(('1996-11-01', '2009-06-30'))
period_worked_in_1996 = worker_spell.intersection(year_1996)
worker_joined_in_1996 = worker_spell.beginning in year_1996

other_worker_spell = timely.Interval(('2007-01-01', '')) # open spell
two_workers_overlapped = worker_spell.intersects(other_worker_spell)

sample_period = timely.MultiInterval([year_1996, worker_spell, other_worker_spell]).envelope
# = Interval(('1996-01-01', ''))

# A more advanced example. Count the number of workers at the firm over time.
worker_spells = [worker_spell, other_worker_spell]
sample_period = timely.MultiInterval(worker_spells).envelope
events = [spell.beginning for spell in worker_spells] + [spell.end for spell in worker_spells]
segments = sample_period.segment_by_instant(events)

output = []
for segment in segments:
	output.append(dict(time_period=segment, number_of_workers=sum([1 for spell in worker_spells if spell.intersects(segment)])))
{'fraction_non_alphanumeric': 0.11954765751211632, 'fraction_numerical': 0.078082929456112, 'mean_word_length': 7.36936936936937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3126247', 'n_tokens_mistral': 716, 'n_tokens_neox': 616, 'n_words': 121}