Skip to content

Commit

Permalink
filter rrule w/o timings when other rrule w/ timings
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMapado committed Sep 13, 2016
1 parent b45e0f2 commit 972414d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions datection/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,9 @@ def unlimited_date_interval(self):
if not end_date:
return False
return (end_date - start_date).days > 8 * 30

@property
def has_timings(self):
return (
self.duration < ALL_DAY
)
17 changes: 17 additions & 0 deletions datection/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ def __init__(self, schedule, apply_exlusion=True, format_exclusion=True):
self.schedule = [
DurationRRule(drr, apply_exlusion) for drr in schedule]
self.schedule = self.deduplicate(self.schedule)
self.schedule = self.filter_non_informative(self.schedule)
self.format_exclusion = format_exclusion
self.templates = {
'fr_FR': u'{dates} {time}',
Expand Down Expand Up @@ -1260,6 +1261,22 @@ def _filterby_year_and_month(dates, year, month):
if date['start'].year == year
if date['start'].month == month]

def filter_non_informative(self, schedules):
"""
Removes schedules which do not add any information to the
schedule list. (e.g: more vague than the others).
@param schedules: list(DurationRRule)
"""
output = schedules
has_time_lvl_schedule = any([sched for sched in output if
sched.has_timings])

if has_time_lvl_schedule:
output = [sched for sched in output if sched.has_timings]

return output

def format_single_dates_and_interval(self, conseq_groups, *args, **kwargs):
""" First formatting technique, using dates interval
Expand Down
22 changes: 22 additions & 0 deletions datection/test/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,28 @@ def test_regrouping_weekdays_by_interval(self):
u'- du mardi au samedi, de 20 h \xe0 21 h\n'
u'- le dimanche, de 17 h \xe0 18 h\n')

def test_filter_non_informative(self):
# test the filtering of the rrule without time information
# in case there is a more precise rule
schedule = [
{
"duration": 0,
"rrule": ("DTSTART:20151223\nRRULE:FREQ=DAILY;COUNT=1;"
"INTERVAL=1;BYMINUTE=00;BYHOUR=20;"
"BYDAY=MO,TU,WE,TH,FR,SA,SU")
},
{
"duration": 1439,
"rrule": ("DTSTART:20151215\nRRULE:FREQ=DAILY;"
"UNTIL=20151231T235959;INTERVAL=1;BYMINUTE=0;"
"BYHOUR=0;BYDAY=MO,TU,WE,TH,FR,SA,SU")
},
]
fmt = LongFormatter(schedule)
self.assertEqual(
fmt.display(),
u'Le mercredi 23 décembre 2015 à 20 h')


class TestSeoFormatter_fr_FR(GetCurrentDayMocker):

Expand Down

0 comments on commit 972414d

Please sign in to comment.