def dayReport(year=None, month=None, day=None): ''' ''' assert(year is not None and month is not None and day is not None) startNum = year * 10000 + month * 100 + day s = db.session() events = s.query(db.Event).filter(db.Event.date==startNum).all() idx = 0 #ignore all events before the first start for event in events: print event.id print event if event.id == db.Events.start: break idx += 1 print 'first start found in ', idx events = events[idx:] #create SessionInfo objects for.... sessionInfo = None sessions = [] for event in events: print event if sessionInfo is None or sessionInfo.id != event.sessionId: sessionInfo = SessionInfo(event.sessionId) sessions.append(sessionInfo) sessionInfo.addEvent(event) print 'Sessions..... ', len(sessions) for sessionInfo in sessions: sessionInfo.totalTime() sessionInfo.pausedTime() if 0: #reports is a dictionary which will keep the generated report for each user reports = {} content = '' for event in db.events(): if reports.has_key(event.userId): report = reports[event.userId] else: report = [] reports[event.userId] = report content += '>>> ' + str(event) + '\n' return None
def weekReport(year=None, month=None, day=None, week=None): ''' Should return the report object for given day TODO: This should take the user name and day for the event week=week number year, month, day: date to be used to find the week number for the report ''' startDate = None endDate = None if week is not None: assert(False, 'week number is not implemented yet') else: assert(year is not None and month is not None and day is not None) startDate = datetime.datetime(year, month, day) startDate = startDate - datetime.timedelta(startDate.weekday()) endDate = startDate + datetime.timedelta(4) assert(startDate is not None and endDate is not None) startNum = startDate.year * 10000 + startDate.month * 100 + startDate.day endNum = endDate.year * 10000 + endDate.month * 100 + endDate.day s = db.session() events = s.query(db.Event).filter(db.Event.date>=startNum and db.Event.date <= endNum).all() for event in events: print event if 0: #reports is a dictionary which will keep the generated report for each user reports = {} content = '' for event in db.events(): if reports.has_key(event.userId): report = reports[event.userId] else: report = [] reports[event.userId] = report content += '>>> ' + str(event) + '\n' return None
def events(self): content = '>> All events:\n' for event in db.events(): content += '>>> ' + str(event) + '\n' return content
def event( eid ): e = db.events( [ eid ] )[ 0 ] return Response( str( e ), mimetype = 'application/json' )
def testRemove(self): event = db.Event.add('oy', db.Events.start, datetime.datetime.today(), 'sample') db.Event.remove(event) self.assertEqual(len(db.events()), 0)
def testAdd(self): event = db.Event.add('oy', db.Events.start, datetime.datetime.today(), 'sample') self.assert_(event) self.assertEqual(len(db.events()), 1)