Commits

Guido Draheim committed 1fd8951

new_reduced_regular_groups

  • Participants
  • Parent commits e15802f

Comments (0)

Files changed (1)

File src/dvbcronrecording/computer.py

             group.deleted = False
             group.weekday = group.items[0].weekday
             group.hasonlydays = 0
+            key = ""
             for item in group.items:
+                key += "%02i%04i%04i(%s)" % (item.weekday, item.newtimeMMM, item.endtimeMMM, item.channelname)
                 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)
             if key not in blocks:
                 blocks[key] = BlockGroup()
             blocks[key].groups += [ group ]
             if group.deleted: continue
             newplan.addgroup(group)
         return newplan           
+    def new_reduce_regular_groups(self, plan):
+        class Similar:
+            def __init__(self, value):
+                self.serial = value
+                self.groups = []
+        serial = 1000
+        similar = {}
+        for group in plan.groups():
+            group.deleted = False
+            group.weekday = group.items[0].weekday
+            group.hasonlydays = []
+            key = ""
+            for item in group.items:
+                key += "%02i%04i%04i(%s)" % (item.weekday, item.newtimeMMM, item.endtimeMMM, item.channelname)
+                if item.cloned and item.cloned.onlyday:
+                    group.hasonlydays += [ item.cloned.months[0] ]
+            if key not in similar:
+                similar[key] = Similar(serial)
+                serial += 1
+            similar[key].groups += [ group ]
+        hasonlydays = []
+        for key, sim  in similar.items():
+            sim.hasonlydays = []
+            for group in sim.groups:
+                for month in group.hasonlydays:
+                    if month not in sim.hasonlydays:
+                        sim.hasonlydays += [ month ]
+                    if month not in hasonlydays:
+                        hasonlydays += [ month ]
+        for key, sim  in similar.items():
+            recurring = None
+            for group in sim.groups:
+                group.deleted = False
+                group.recurring = False
+                keep = False
+                if group.hasonlydays:
+                    keep = True
+                for item in group.items:
+                    for month in item.months:
+                        if month in hasonlydays:
+                            keep = True
+                if not keep:
+                    if not recurring:
+                        recurring = group
+                        group.recurring = True
+                    else:
+                        group.deleted = True
+            for group in sim.groups:
+                months = [ month for month in xrange(1,13) if month not in hasonlydays ]
+                for item in group.items:
+                    if group.recurring:
+                        item.onlyday = None
+                        item.months = months
+                self.make_cronmonths(group)
+        newplan = RecorderGroupPlan()
+        for group in plan.groups():
+            if group.deleted: continue
+            newplan.addgroup(group)
+        return newplan
     def plan3(self, entries):
         """ main entry point """
         self.logg.info("plan3")
         for group in self.timelist_groups(timelist):
             plan.addgroup(group)
         if True:
+            return self.new_reduce_regular_groups(plan)
+        if True:
             return self.reduce_regular_groups(plan)
         return plan
     def plan4(self, entries):
                 plan.addgroup(group)
         self.logg.info("adapterlist = %s", self.adapterlist())
         if True:
-            plan.sort()
-            return self.reduce_regular_groups(plan)
+            # plan.sort()
+            return self.new_reduce_regular_groups(plan)
         else:
-            plan.sort()
+            # plan.sort()
             return plan
             
     def plan(self, entries):
         if self.algorithm == "plan4":
             return self.plan4(entries)
         #else:
-        return self.plan3(entries)
+        return self.plan4(entries)
 
 def deltaM(td):
     return td.seconds / 60 + (td.days * 24 * 60)