def before_request(): g.db = connect_db() Slot_Conf.set_db(g.db) Job.set_db(g.db) TimeInfo.set_db(g.db) slotStartEnd.set_db(g.db) Projects.set_db(g.db) Results.set_db(g.db) ProjNames.set_db(g.db) SlotTimes.set_db(g.db) ProjectTimes.set_db(g.db)
def makechart(): #request view from couchdb #weekbefore = (date.today()-timedelta(6)).strftime('%Y-%m-%d') endtimes = TimeInfo.view('statistics/completionTime',group = True, startkey = weekbefore) starttimes = TimeInfo.view('statistics/startTime',group = True, startkey = weekbefore) data ={} for t in starttimes: data[t['key']]={} data[t['key']]['minseconds'] = t['value']['min'] for t in endtimes: data[t['key']]['maxseconds'] = t['value']['max'] data = json.dumps(data,sort_keys=True) return data
def todayStats(): slots = [] #today = time.strftime("%Y-%m-%d") #weekbefore = (date.today()-timedelta(6)).strftime('%Y-%m-%d') jobEnds = Job.view('statistics/jobEnds',group_level=3,startkey = [today]) jobStarts = Job.view('statistics/jobStarts',group_level=3,startkey = [today]) slots = Slot_Conf.view('statistics/Slots',startkey = today) times = TimeInfo.view('statistics/completionTime',group = True, startkey = weekbefore) data = [] jobsEnded = {} jobsStarted = {} for s in slots: jobsEnded[s.slot] = 0 jobsStarted[s.slot] = 0 for j in jobEnds: jobsEnded[j['key'][1]]=j['value'] for j in jobStarts: jobsStarted[j['key'][1]]=j['value'] unfinished = 0 unstarted = 0 unfinished_list = [] unstarted_list = [] completed_list = [] for s in slots: if(jobsEnded[s.slot]!=len(s.platforms)): unfinished+=1 unfinished_list.append(s.slot) if(jobsStarted[s.slot]!=len(s.platforms)): unstarted+=1 unstarted_list.append(s.slot) if(jobsStarted[s.slot]==len(s.platforms) and jobsEnded[s.slot]==len(s.platforms)): completed_list.append(s.slot) sum = 0 for t in times: if t['key']==today: todaymin = t['value']['min'] sum = sum - (t['value']['max'] - t['value']['min']) sum = sum + (t['value']['max'] - t['value']['min']) avgcompletion = sum/6 data = [] all_list = unfinished_list+unstarted_list+completed_list data.append({"total":len(slots),"all":all_list,"finished":len(slots)-unfinished,"unfinished":unfinished,"unstarted":unstarted,"todaymin":todaymin,"avgcompletion":avgcompletion,"listofunfinished":unfinished_list,"listofunstarted":unstarted_list,"listofcompleted":completed_list}) data =json.dumps(data) return data
def makechart(): #request view from couchdb #weekbefore = (date.today()-timedelta(6)).strftime('%Y-%m-%d') endtimes = TimeInfo.view('statistics/completionTime', group=True, startkey=weekbefore) starttimes = TimeInfo.view('statistics/startTime', group=True, startkey=weekbefore) data = {} for t in starttimes: data[t['key']] = {} data[t['key']]['minseconds'] = t['value']['min'] for t in endtimes: data[t['key']]['maxseconds'] = t['value']['max'] data = json.dumps(data, sort_keys=True) return data
def todayStats(): slots = [] #today = time.strftime("%Y-%m-%d") #weekbefore = (date.today()-timedelta(6)).strftime('%Y-%m-%d') jobEnds = Job.view('statistics/jobEnds', group_level=3, startkey=[today]) jobStarts = Job.view('statistics/jobStarts', group_level=3, startkey=[today]) slots = Slot_Conf.view('statistics/Slots', startkey=today) times = TimeInfo.view('statistics/completionTime', group=True, startkey=weekbefore) data = [] jobsEnded = {} jobsStarted = {} for s in slots: jobsEnded[s.slot] = 0 jobsStarted[s.slot] = 0 for j in jobEnds: jobsEnded[j['key'][1]] = j['value'] for j in jobStarts: jobsStarted[j['key'][1]] = j['value'] unfinished = 0 unstarted = 0 unfinished_list = [] unstarted_list = [] completed_list = [] for s in slots: if (jobsEnded[s.slot] != len(s.platforms)): unfinished += 1 unfinished_list.append(s.slot) if (jobsStarted[s.slot] != len(s.platforms)): unstarted += 1 unstarted_list.append(s.slot) if (jobsStarted[s.slot] == len(s.platforms) and jobsEnded[s.slot] == len(s.platforms)): completed_list.append(s.slot) sum = 0 for t in times: if t['key'] == today: todaymin = t['value']['min'] sum = sum - (t['value']['max'] - t['value']['min']) sum = sum + (t['value']['max'] - t['value']['min']) avgcompletion = sum / 6 data = [] all_list = unfinished_list + unstarted_list + completed_list data.append({ "total": len(slots), "all": all_list, "finished": len(slots) - unfinished, "unfinished": unfinished, "unstarted": unstarted, "todaymin": todaymin, "avgcompletion": avgcompletion, "listofunfinished": unfinished_list, "listofunstarted": unstarted_list, "listofcompleted": completed_list }) data = json.dumps(data) return data