Prechádzať zdrojové kódy

nooverlap avverte per sovrapposizioni indesiderate

se imposti le preferenze di non sovrapposizione sul campo "nooverlap",
quello ti avverte.

Fa sto gioco anche per il campo "contacts", ma ovviamente i contatti lì
vanno elencati tutti precisi e scritti uguale sennò non funziona.
boyska 6 rokov pred
rodič
commit
1fdda73e9d

+ 41 - 0
plugins/talks.py

@@ -115,6 +115,7 @@ def get_talk_data(talkname):
         return None
     try:
         gridstep = pelican.settings['TALKS_GRID_STEP']
+        data.setdefault('nooverlap', [])
         if 'title' not in data:
             logging.warn("Talk <{}> has no `title` field".format(talkname))
             data['title'] = talkname
@@ -169,6 +170,45 @@ def get_talk_data(talkname):
         raise
 
 
+def overlap(interval_a, interval_b):
+    '''how many minutes do they overlap?'''
+    return max(0, min(interval_a[1], interval_b[1]) - max(interval_a[0], interval_b[0]))
+
+
+def get_talk_overlaps(name):
+    data = get_talk_data(name)
+    overlapping_talks = set()
+    if 'time' not in data:
+        return overlapping_talks
+    start = int(data['time'].strftime('%s'))
+    end = start + data['duration'] * 60
+    for other in get_talk_names():
+        if other == name:
+            continue
+        if 'time' not in get_talk_data(other):
+            continue
+        other_start = int(get_talk_data(other)['time'].strftime('%s'))
+        other_end = other_start + get_talk_data(other)['duration'] * 60
+
+        minutes = overlap((start, end), (other_start, other_end))
+        if minutes > 0:
+            overlapping_talks.add(other)
+    return overlapping_talks
+
+
+@memoize
+def check_overlaps():
+    for t in get_talk_names():
+        over = get_talk_overlaps(t)
+        noover = get_talk_data(t)['nooverlap']
+        contacts = set(get_talk_data(t)['contacts'])
+        for overlapping in over:
+            if overlapping in noover or \
+               set(get_talk_data(overlapping)['contacts']).\
+               intersection(contacts):
+                logging.warning('Talk %s overlaps with %s' % (t, overlapping))
+
+
 @memoize
 def jinja_env():
     env = jinja2.Environment(
@@ -358,6 +398,7 @@ class TalksGenerator(generators.Generator):
     def generate_context(self):
         self.talks = {n: get_talk_data(n) for n in get_talk_names()}
         self._update_context(('talks',))
+        check_overlaps()
 
     def generate_output(self, writer=None):
         for talkname in sorted(self.talks):

+ 4 - 1
talks/_talk_example/meta.yaml

@@ -1,4 +1,3 @@
-# File di esempio; copialo e cambialo
 title: "Il titolo del talk"
 text: |
     Descrizione del talk divisa in molte righe
@@ -37,5 +36,9 @@ mail: "blabla"
 #    - tizio
 #    - caio
 
+# se chiedono di non sovrapporli con qualche talk, segnalo qui
+# cosi' poi il coso ci avvisa quando sbagliamo
+nooverlap: []
+
 # Devi usare UTF-8, non t'inventare scuse, sappiamo ndo abiti
 # vim: set fileencoding=utf-8 ts=4 sw=4 et:

+ 2 - 0
talks/generatorerumore/meta.yaml

@@ -53,5 +53,7 @@ contacts:
     - Unit Hacklab
     - Big Fractal
 
+nooverlap: [ondecorte_email, spaziodicomunicazione]
+
 # Devi usare UTF-8, non t'inventare scuse, sappiamo ndo abiti
 # vim: set fileencoding=utf-8 ts=4 sw=4 et: