Ciaran Farrell avatar Ciaran Farrell committed 90aee6b

Some progress on busy search - maybe...

Comments (0)

Files changed (2)

                 f = "%Y-%m-%d %H:%M"
                 print "The following time slots are available:"
                 for x in bt:
-                  print "%s until %s"%(x[0].strftime(f),x[1].strftime(f))
+                  print "%s until %s"%x
                   #view = GWSimpleBusyView(bt)
       for block in blocks:
         bs = block.startDate+gdelta
         be = block.endDate+gdelta
-        #dtlist.append((bs,0))
-        #dtlist.append((be,1))
-    #dtlist.sort()
-    # the free block from now until the start of the first busyblock is:
-    #dtlist.append([,dtlist[0][0]])
     nl = sorted(foo, key=itemgetter('d')) 
-    #nl is chronological list of stamps with additional bit 0 for start, 1 for end    
     ''' Because Groupwise always returns a list of blocks, for which the first
     block is _always_ the chronologically first appointment of all of the users
     queried - irrespective of whether this is in the past or not - what happens
     the script is called and the first busy block is actually free. $dyck will,
     however, still be 1. It may be an idea to prepend this period afterwards...
-    print nl
     i = 0
     dyck = 0
     previous = 0 # need to check for a rising or falling edge
-    firstfree = False
     for stamp in nl:
       previous = dyck
       if stamp['t'] == 0: # startDate of a BUSY PERIOD!
         dyck -= 1
       if dyck == 0:
-        print "appending start of free time %s"%stamp['d']
+        logger.debug("appending start of free time %s"%stamp['d'])
         if ((dyck == 1) and (previous==0)): #rising
-          print "appending end of free time %s"%stamp['d']
-          free.append(stamp['d']) 
+          if stamp['d'] <
+            logger.debug("Ignoring end of free time %s as it is in the past"%stamp['d'])
+          else:
+            logger.debug("appending end of free time %s"%stamp['d'])
+            free.append(stamp['d']) 
+      i+=1
+    if len(free)==0:
+      logger.debug('Looks like there is no available time in the window queried')
+      return []
+    if len(free)%2==0: # first busyblock starts in the future
+      logger.debug("First busyblock starts at %s. Prepending current tstamp"%free[0])
+      free.insert(0,
+    else:
+      logger.debug("Starting in the middle of a busy block!")
+    logger.debug('Removing the final entry as assuming it is "start of free time" without a corresponding end entry')
+    free.pop(free.index(free[-1]))
+    l,r,t = [],[],[]
+    i = 0
+    for x in free:
+      if (i%2)==0:
+        l.append(x)
+      else:
+        r.append(x)
-    print free
-    print len(free)
-    exit()
-    #print udict
-    return free
+    for x in l:
+      f = "%Y-%m-%d %H:%M"
+      s,e = x.strftime(f),r[l.index(x)].strftime(f)
+      if s == e:
+        logger.debug('Ignoring tuple (%s %s) as the times are identical'%(s,e))
+      else:
+        t.append((s,e))
+    return t
   def getBusyTimes(self,sessionid,st=datetime.utcnow(),et=None):
     logger.debug('Groupwise.getBusyTimes with id %s'%sessionid)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.