Commits

Guido Draheim committed 9ee1531

sorted plan4 that can split to other adapters

Comments (0)

Files changed (1)

src/dvbcronrecording/computer.py

 onlydate_rank = 0.5 # +1
 rankup_channels = [ "3sat", "arte" ]
 rankup_plus = 0.3
-default_adapter = "00"
+default_adapter = "0"
 
 def intnull(value, default = None):
     if value is None: return default
 class RecorderGroup:
     def __init__(self):
         self.items = [] # RecordingItem
+        self.weekday = None
         self.newtimeMMM = None
         self.endtimeMMM = None
         self.extratimeM = None
+        self.adapter = None
     def __unicode__(self):
         return u"["+unicode(",".join([unicode(item) for item in self.items]))+"]"
 
             yield group
     def addgroup(self, group):
         self._groups += [ group ]
+    def sort(self):
+        """ weekday, starttime, adapter """
+        groups = sorted(self._groups, key = lambda x: (x.weekday, x.newtimeMMM, x.adapter))
+        self._groups = groups
 
 class RecorderFlatPlan:
     def __init__(self):
             extratimeM = item.extratimeM 
             if group is None: # first run
                 group = RecorderGroup()
+                group.weekday = item.weekday
                 group.newtimeMMM = newtimeMMM
             elif group.endtimeMMM + group.extratimeM < newtimeMMM + nextday:
                 yield group # non-recording interval
                 group = RecorderGroup()
+                group.weekday = item.weekday
                 group.newtimeMMM = newtimeMMM
             else: # overlapping?
                 assert previous is not None # because of first run
                 if item.weekday != previous_ended_weekday:
                     yield group # non-recording interval
                     group = RecorderGroup()
+                    group.weekday = item.weekday
                     group.newtimeMMM = newtimeMMM
                 pass 
             if endtimeMMM < newtimeMMM:
         for item in itemlist: 
             if not group:
                 group = RecorderGroup()
+                group.weekday = item.weekday
                 group.firstdate = item.onlydate
                 group.newtimeMMM = item.newtimeMMM
                 group.endtimeMMM = item.endtimeMMM
             if group.endtimeMMM < item.newtimeMMM + deltaMMM:
                 yield group
                 group = RecorderGroup()
+                group.weekday = item.weekday
                 group.firstdate = item.onlydate
                 group.newtimeMMM = item.newtimeMMM
                 group.endtimeMMM = item.endtimeMMM
                 else:
                     previous = elem
                     group = RecorderGroup()
+                    group.weekday = item.weekday
                     group.newtimeMMM = item.newtimeMMM
                     group.endtimeMMM = item.endtimeMMM
                     group.extratimeM = item.extratimeM
+                    group.adapter = item.adapter
                     group.items = predeletes + [ item ]
                     predeletes = []
             else:
             for item in group.items:
                 if item.cloned and item.cloned.onlyday:
                     group.hasonlydays += 1
-            key = (group.weekday, group.newtimeMMM, group.endtimeMMM, group.extratimeM)
+            key = (group.weekday, group.newtimeMMM, group.endtimeMMM, group.extratimeM, group.adapter)
             if key not in blocks:
                 blocks[key] = BlockGroup()
             blocks[key].groups += [ group ]
         for adapter in self.adapterlist():
             for group in self.timelist_groups(timelist, adapter):
                 plan.addgroup(group)
+        plan.sort()
         if True:
             return self.reduce_regular_groups(plan)
         return plan
             
     def plan(self, entries):
-        return self.plan3(entries)
+        return self.plan4(entries)
 
 def deltaM(td):
     return td.seconds / 60 + (td.days * 24 * 60)