Ciaran Farrell avatar Ciaran Farrell committed 87dd500

messing about with the busy search

Comments (0)

Files changed (1)

       for block in blocks:
         bs = block.startDate+gdelta
         be = block.endDate+gdelta
-        dtlist.append((bs,0))
-        dtlist.append((be,1))
+        #dtlist.append((bs,0))
+        #dtlist.append((be,1))
         foo.append({'d':bs,'t':0})
         foo.append({'d':be,'t':1})
-    dtlist.sort()
+    #dtlist.sort()
     # the free block from now until the start of the first busyblock is:
     #dtlist.append([datetime.now(),dtlist[0][0]])
     nl = sorted(foo, key=itemgetter('d')) 
-    #nl is chronological list of stamps with additional bit 0 for start, 1 for end
-    
+    #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
+    is that $dyck below will immediately become 1 - signalling that there is
+    no available time. This is fine if at least one user currently has an 
+    appointment which began before the script was called and happens to be 
+    running right when the script is called. What happens if the first busy
+    block of any user is in the future - that means that the time between when
+    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
+      if stamp['t'] == 0: # startDate of a BUSY PERIOD!
         dyck += 1
       else:
         dyck -= 1
-
-      if i == 0: #first iteration
-        if (dyck==1) and (previous==0): # means we've started in the middle of an appointment
-          print "Adding None for 1st iteration tstamp %s"%stamp['d']
-          workaround_delta = timedelta(hours=-1)
-          workaround_start = stamp['d']+workaround_delta
-          free.append([workaround_start,stamp['d']])
-        elif dyck == 0:
-          free.append([stamp['d']])
+      if dyck == 0:
+        print "appending start of free time %s"%stamp['d']
+        free.append(stamp['d'])
       else:
-        if dyck == 0:
-          free.append([stamp['d']])
-        else:
-          if (dyck == 1) and (previous == 0): # rising
-            free[-1].append(stamp['d'])
-
-          
+        if ((dyck == 1) and (previous==0)): #rising
+          print "appending end of free time %s"%stamp['d']
+          free.append(stamp['d']) 
       i+=1
     print free
+    print len(free)
+    exit()
     #print udict
     return free
 
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 ProjectModifiedEvent.java.
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.