def get_calls_from_db(self, min, max): """ Retrieves calls from the database. """ cursor = db.get_db_cursor() sql = '''select callee,'''+db.datetime('datetime')+''' datetime, duration, cost, call_category from calls where '''+db.datetime('datetime')+''' >= ? and '''+db.datetime('datetime')+''' < ?''' sql = db.normalize_sql(sql) cursor.execute(sql, (str(min),str(max))) rows = [row for row in cursor] return rows
def get_data_for_top(top,top_condition): params = (min,max) sql = '''select '''+db.datetime_start_of('datetime',unit)+''' as day, sum(cost) from calls where call_category '''+top_condition+''' and '''+db.datetime('datetime')+''' >= ? and ''' sql += db.datetime('datetime')+''' <= ? group by day order by day''' sql = db.normalize_sql(sql) cursor.execute(sql, params) return { 'label':self.call_category[top]['desc'], 'color':self.call_category[top]['color'], 'data':[[1000*int(row[0]),float(row[1])] for row in cursor], }
def gettops(self,min=None,max=None): """ Returns the top 4 most expensive call groups for a specified period of time. """ cursor = db.get_db_cursor() (min,max)=self.get_default_min_max_time(cursor,min,max) params = (min,max) cursor.execute(db.normalize_sql('''select call_category from calls where '''+ db.datetime('datetime')+'''>= ? and '''+ db.datetime('datetime')+''' <= ? group by call_category order by sum(cost) desc limit 4'''), params) tops = [row[0] for row in cursor] return json.dumps(tops)
def getcalls(self,min,max): """ Returns a detailed listing of the calls made between the specified timestamps. """ cursor = db.get_db_cursor() params = (min,max) sql = '''select callee,round(sum(cost),2),call_category,`desc` from calls left outer join telbook on callee=number where ''' sql += db.datetime('datetime')+'''>= ? and '''+db.datetime('datetime') sql += ''' <= ? group by callee order by sum(cost) desc''' cursor.execute(db.normalize_sql(sql), params) data = [[row[0], float(row[1]), self.call_category[row[2]]['color'], row[3]] for row in cursor] return json.dumps(data)
def add_task(): '''Adds a new task with a task name, and the corresponding deadline. Deadline should be in YYYY-MM-DD format ''' new_task = input('Enter task\n') deadline = input('Enter deadline\n') deadline = [int(x) for x in deadline.split('-')] deadline = db.datetime(deadline[0], deadline[1], deadline[2]) new_task = db.Task(task=new_task, deadline=deadline) session.add(new_task) session.commit()