def do_job(self): """ SELECT *, coalesce(end_time,now)-start_time FROM task t, subject s WHERE t.subject_id=s.id AND start_time > GetDate() - @days ORDER BY start_time :return: """ session = DBSession() now = datetime.now() time_worked = (func.julianday(func.coalesce(Task.end_time,now)) - func.julianday(Task.start_time)) * 86400 query = session.query(Task.start_time, func.coalesce(Task.end_time, now), time_worked, Subject.title, Task.title) \ .filter(Subject.id==Task.subject_id) \ .filter(func.date(Task.start_time) > func.date('now', '-%s day' % self.args.days)) \ .order_by(Task.start_time) print '\n' table = PrettyTable(['Start', 'End', 'Time', 'Subject', 'Title']) table.align["Title"] = "l" total_time = 0 day_total = 0 last_date = None for row in query: if last_date == None: last_date = row[0].date() if row[0].date() != last_date: table.add_row([ '', '', timedelta(seconds=round(day_total)), '', '' ]) last_date = row[0].date() day_total = 0 day_total += row[2] total_time += row[2] table.add_row([ row[0], row[1], timedelta(seconds=round(row[2])), row[3], row[4], ]) if day_total > 0: table.add_row([ '', '', timedelta(seconds=round(day_total)), '', '' ]) print table print 'Total Work time: %s' % timedelta(seconds=total_time) print
def do_job(self): task = Task.get_last_task() if task: task.title = ' '.join(self.args.task) DBSession.commit() else: print 'Last task not found'
def do_job(self): """ SELECT *, coalesce(end_time,now)-start_time FROM task t, subject s WHERE t.subject_id=s.id AND start_time > GetDate() - @days ORDER BY start_time :return: """ session = DBSession() now = datetime.now() time_worked = (func.julianday(func.coalesce(Task.end_time, now)) - func.julianday(Task.start_time)) * 86400 query = session.query(Task.start_time, func.coalesce(Task.end_time, now), time_worked, Subject.title, Task.title) \ .filter(Subject.id == Task.subject_id) \ .filter(func.date(Task.start_time) > func.date('now', '-%s day' % self.args.days)) \ .order_by(Task.start_time) print() table = PrettyTable(['Start', 'End', 'Time', 'Subject', 'Title']) table.align["Title"] = "l" total_time = 0 day_total = 0 last_date = None for row in query: if last_date == None: last_date = row[0].date() if row[0].date() != last_date: table.add_row( ['', '', timedelta(seconds=round(day_total)), '', '']) last_date = row[0].date() day_total = 0 day_total += row[2] total_time += row[2] table.add_row([ row[0], row[1], timedelta(seconds=round(row[2])), row[3], row[4], ]) if day_total > 0: table.add_row( ['', '', timedelta(seconds=round(day_total)), '', '']) print(table) print('Total Work time: %s\n' % timedelta(seconds=total_time))
def do_job(self): active_task = Task.get_active_task() if active_task: print('Aborting active task: %s' % active_task) DBSession.delete(active_task) DBSession.commit() else: print("You don't have any active task")
def do_job(self): subject = Subject.query.filter(Subject.title == self.args.subject).first() if not subject: print 'Subject can not found: %s' % self.args.subject else: DBSession.delete(subject) DBSession.commit() print "Subject `%s` was deleted successfully" % self.args.subject
def do_job(self): active_task = Task.get_active_task() if not active_task: print("You don't have any active task") return active_task.end() DBSession.commit() print('Task ended: %s' % active_task)
def do_job(self): subject = Subject.query.filter( Subject.title == self.args.subject).first() if not subject: print('Subject can not found: %s' % self.args.subject) else: DBSession.delete(subject) DBSession.commit() print("Subject `%s` was deleted successfully" % self.args.subject)
def process_row(self, row): subject_name, task_name, start_time, end_time = row start_time = datetime.strptime(start_time, config.datetime_format) end_time = datetime.strptime(end_time, config.datetime_format) if subject_name not in self.subjects: self.subjects[subject_name] = Subject.ensure(subject_name) DBSession.commit() task = Task(title=task_name, start_time=start_time, end_time=end_time) self.subjects[subject_name].tasks.append(task) print('Adding %s' % task) DBSession.commit()
def do_job(self): if not self.args.subject: print("Please specify a subject to rename") subject = Subject.query.filter(Subject.title == self.args.subject).first() if not subject: print('Subject can not found: %s' % self.args.subject) return new_subject = Subject.query.filter(Subject.title == self.args.new_name).first() if new_subject: print("There is already a subject with name: %s" % self.args.new_name) answer = raw_input("Do you want to merge these subjects? [Y/n]: ") if not answer or answer.lower() == 'y': for task in subject.tasks: task.subject = new_subject DBSession.flush() DBSession.delete(subject) DBSession.commit() else: print('Operation aborted by user.') else: subject.title = self.args.new_name DBSession.commit()
def do_job(self): if not self.args.subject: print("Please specify a subject to rename") subject = Subject.query.filter( Subject.title == self.args.subject).first() if not subject: print('Subject can not found: %s' % self.args.subject) return new_subject = Subject.query.filter( Subject.title == self.args.new_name).first() if new_subject: print("There is already a subject with name: %s" % self.args.new_name) answer = input("Do you want to merge these subjects? [Y/n]: ") if not answer or answer.lower() == 'y': for task in subject.tasks: task.subject = new_subject DBSession.flush() DBSession.delete(subject) DBSession.commit() else: print('Operation aborted by user.') else: subject.title = self.args.new_name DBSession.commit()
def do_job(self): task = Task.get_last_task() if task: if self.args.title: task.title = self.args.title if self.args.end_time: task.end_time = self.parse_datetime(self.args.end_time) if self.args.start_time: task.start_time = self.parse_datetime(self.args.start_time) DBSession.commit() else: print('Last task not found')
def do_job(self): active_task = Task.get_active_task() if active_task: print 'You have an active task: %s' % active_task answer = raw_input("Do you want to terminate the currently active task ([y]/n)? ") if not answer or answer.lower() == 'y': active_task.end() else: return subject = Subject.ensure(self.args.subject) task = Task(title=' '.join(self.args.task)) subject.tasks.append(task) DBSession.commit() print 'Started task: %s' % task
def do_job(self): active_task = Task.get_active_task() if active_task: print('You have an active task: %s' % active_task) answer = input( "Do you want to terminate the currently active task ([y]/n)? ") if not answer or answer.lower() == 'y': active_task.end() else: return subject = Subject.ensure(self.args.subject) task = Task(title=' '.join(self.args.task), user=config.user if hasattr(config, 'user') else os.environ.get('USER')) subject.tasks.append(task) DBSession.commit() print('Started task: %s' % task)
def do_job(self): """ SELECT sum(t.end_time - t.start_time) FOM task t GROUP BY day(t.start_time) WHERE start_time > GetDate() - @days :return: """ session = DBSession() daywork = func.sum(func.julianday(Task.end_time) - func.julianday(Task.start_time)) * 86400 day = func.date(Task.start_time) query = session.query(day, daywork) \ .group_by(day) \ .filter(func.date(Task.start_time) > func.date('now', '-%s day' % self.args.days)) \ .filter(Task.end_time != None) \ .order_by(Task.start_time) print '\n' table = PrettyTable(['Day', 'Work Time', 'Graph']) table.align["Graph"] = "l" total_hours = timedelta(0) last_day = None for row in query: day = datetime.strptime(row[0], '%Y-%m-%d').date() if last_day: diff = (day - last_day) for i in range(diff.days - 1): table.add_row([last_day + timedelta(i + 1), 0, '']) worktime = timedelta(seconds=round(row[1])) total_hours += worktime table.add_row([day, worktime, '#' * int(round((row[1] * 60 / 86400)))]) last_day = day print table print 'Total Work time: %s' % total_hours print
def do_job(self): """ SELECT sum(t.end_time - t.start_time) FOM task t GROUP BY day(t.start_time) WHERE start_time > GetDate() - @days :return: """ session = DBSession() daywork = func.sum(func.julianday(Task.end_time) - func.julianday(Task.start_time)) * 86400 day = func.date(Task.start_time) query = session.query(day, daywork) \ .group_by(day) \ .filter(func.date(Task.start_time) > func.date('now', '-%s day' % self.args.days)) \ .filter(Task.end_time != None) \ .order_by(Task.start_time) print() table = PrettyTable(['Day', 'Work Time', 'Graph']) table.align["Graph"] = "l" total_hours = timedelta(0) last_day = None for row in query: day = datetime.strptime(row[0], '%Y-%m-%d').date() if last_day: diff = (day - last_day) for i in range(diff.days - 1): table.add_row([last_day + timedelta(i + 1), 0, '']) worktime = timedelta(seconds=round(row[1])) total_hours += worktime table.add_row([day, worktime, '#' * int(round((row[1] * 60 / 86400)))]) last_day = day print(table) print('Total Work time: %s\n' % total_hours)