def report_team_stat_day(request, team, year, month, day): team = get_object_or_404(Teams, slug=team) agents = Agent.objects.filter(teamid=team).filter(haveleft=0) title = team.name + " Day Breakdown: " + day + "/" + month_display(month) + "/"+ year var = [year, month_number(month), day] date = '-'.join(var) stats = Dstats.objects.filter(team=team).filter(date=date) teamtotals = stats.aggregate(Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('prodhours'), Sum('sickhours')) template = 'reports/breakdown.html' context = RequestContext(request, {"title":title, 'team':team, }) response = render_to_response(template, context) return response
def stats_this_month(request): #done thedate = datetime.today()-timedelta(days=1) if thedate.isoweekday() == 7: thedate = datetime.today()-timedelta(days=3) month = month_number(thedate.strftime("%b").lower()) year = thedate.strftime("%Y") stat = monthly_stats(year, thedate.strftime("%b").lower()) title = "Agent Stats: " + month_display(thedate.strftime("%b").lower()) + " " + year switch = "/stats/team/"+str(year)+"/"+thedate.strftime("%b").lower() switchtype = "Team" template = 'stats/stats.html' context = RequestContext(request, {'title':title, 'tstats':stat, 'switch':switch, 'switchtype':switchtype}) response = render_to_response(template, context) return response
def team_page(request, team): user = request.user.get_profile() type = int(user.agenttype) if not request.user.has_perm('agents.super'): team = Teams.objects.get(name=user.teamid) slug = team.slug url = "/team/" + slug + "/info" return HttpResponseRedirect(url) team = get_object_or_404(Teams, slug=team) agent = Agent.objects.filter(teamid__pk=team.pk).filter(agenttype=0).filter(haveleft=0) super = Supers.objects.get(pk=team.supervisor_id) targets = Targets.objects.get(name=team.targets) thedate = datetime.today()-timedelta(days=1) if thedate.isoweekday() == 7: thedate = datetime.today()-timedelta(days=3) week = int(thedate.isocalendar()[1]) month = thedate.strftime("%b").lower() year = str(thedate.strftime("%Y")) date = {'week':week, 'month':month_display(month), 'year':year} todaymonth = int(month_number(month)) todayyear = int(thedate.strftime("%Y")) todaymonth = todaymonth - 1 if todaymonth == 0: todaymonth = 12 todayyear = todayyear-1 todayreadmonth = number_month(todaymonth) today = [todayyear, todaymonth, todayreadmonth] stats = Dstats.objects.filter(team=team.id).filter(isoyear=year) appstable = [] for staff in agent: qapps = QualifiedApps.objects.filter(year=year).filter(agent=staff).filter(month=month).aggregate(Sum('qualifiedapps')) appstable.append([staff.name, qapps['qualifiedapps__sum']]) weektodate = stats.filter(isoweek=week).aggregate(Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('prodhours'), Sum('sickhours')) monthtodate = stats.filter(month=month).aggregate(Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('prodhours'), Sum('sickhours')) yeartodate = stats.aggregate(Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('prodhours'), Sum('sickhours')) weekfte = {} monthfte = {} yearfte = {} if yeartodate['prodhours__sum'] > 0: yearfte['calltime'] = int(yeartodate['calltime__sum'] / (yeartodate['prodhours__sum'] / targets.hours)) yearfte['totalcalltime'] = yeartodate['calltime__sum'] yearfte['callattempts'] = int(yeartodate['callattempts__sum'] / (yeartodate['prodhours__sum'] / targets.hours)) yearfte['totalcallattempts'] = yeartodate['callattempts__sum'] yearfte['totalapps'] = yeartodate['totalapps__sum'] yearfte['fteapps'] = yeartodate['totalapps__sum'] / ((yeartodate['prodhours__sum']+yeartodate['sickhours__sum']) / targets.hours) if monthtodate['prodhours__sum'] > 0: monthfte['calltime'] = int(monthtodate['calltime__sum'] / (monthtodate['prodhours__sum'] / targets.hours)) monthfte['totalcalltime'] = monthtodate['calltime__sum'] monthfte['callattempts'] = int(monthtodate['callattempts__sum'] / (monthtodate['prodhours__sum'] / targets.hours)) monthfte['totalcallattempts'] = monthtodate['callattempts__sum'] monthfte['totalapps'] = monthtodate['totalapps__sum'] monthfte['fteapps'] = monthtodate['totalapps__sum'] / ((monthtodate['prodhours__sum']+monthtodate['sickhours__sum']) / targets.hours) if weektodate['prodhours__sum'] > 0: weekfte['calltime'] = int(weektodate['calltime__sum'] / (weektodate['prodhours__sum'] / targets.hours)) weekfte['totalcalltime'] = weektodate['calltime__sum'] weekfte['callattempts'] = int(weektodate['callattempts__sum'] / (weektodate['prodhours__sum'] / targets.hours)) weekfte['totalcallattempts'] = weektodate['callattempts__sum'] weekfte['totalapps'] = weektodate['totalapps__sum'] weekfte['fteapps'] = weektodate['totalapps__sum'] / ((weektodate['prodhours__sum']+weektodate['sickhours__sum']) / targets.hours) agentweek = OrderedDict() agentmonth = OrderedDict() agentyear = OrderedDict() agentavgvol = OrderedDict() for each in agent: volmonth = thedate.strftime("%b").lower() yearstats = [] monthstats = [] weekstats = [] volume = [] volsum = WeeklyStats.objects.filter(agent=each).filter(isomonth=today[2]).filter(isoyear=today[0]).aggregate(Sum('volume')) if volsum['volume__sum'] is None: volsum = 0 else: volsum = int(volsum['volume__sum']) if not volsum > 0: volsum = 0 startdate = each.startdate volmonth = startdate.strftime("%b").lower() volmonth = int(month_number(volmonth)) year = int(startdate.strftime("%Y")) starting = [year, volmonth] diff = (today[0] - starting[0])*12 + (today[1]-starting[1]) diff = diff - 3 if diff > 0 : volavg = int(volsum) / diff else: volavg = int(volsum) agentavgvol[each.name] = volavg weektodate = stats.filter(agent=each).filter(isoweek=week).aggregate(Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('prodhours'), Sum('sickhours')) monthtodate = stats.filter(agent=each).filter(month=month).aggregate(Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('prodhours'), Sum('sickhours')) yeartodate = stats.filter(agent=each).aggregate(Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('prodhours'), Sum('sickhours')) if yeartodate['prodhours__sum'] > 0: yearstats.append(int(yeartodate['calltime__sum'] / (yeartodate['prodhours__sum'] / targets.hours))) yearstats.append(yeartodate['calltime__sum']) yearstats.append(int(yeartodate['callattempts__sum'] / (yeartodate['prodhours__sum'] / targets.hours))) yearstats.append(yeartodate['callattempts__sum']) yearstats.append(yeartodate['totalapps__sum']) yearstats.append(yeartodate['totalapps__sum'] / ((yeartodate['prodhours__sum']+yeartodate['sickhours__sum']) / targets.hours)) if monthtodate['prodhours__sum'] > 0: monthstats.append(int(monthtodate['calltime__sum'] / (monthtodate['prodhours__sum'] / targets.hours))) monthstats.append(monthtodate['calltime__sum']) monthstats.append(int(monthtodate['callattempts__sum'] / (monthtodate['prodhours__sum'] / targets.hours))) monthstats.append(monthtodate['callattempts__sum']) monthstats.append(monthtodate['totalapps__sum']) monthstats.append(monthtodate['totalapps__sum'] / ((monthtodate['prodhours__sum']+monthtodate['sickhours__sum']) / targets.hours)) if weektodate['prodhours__sum'] > 0: weekstats.append(int(weektodate['calltime__sum'] / (weektodate['prodhours__sum'] / targets.hours))) weekstats.append(weektodate['calltime__sum']) weekstats.append(int(weektodate['callattempts__sum'] / (weektodate['prodhours__sum'] / targets.hours))) weekstats.append(weektodate['callattempts__sum']) weekstats.append(weektodate['totalapps__sum']) if weektodate['totalapps__sum'] > 0 and (weektodate['prodhours__sum']+weektodate['sickhours__sum']) > 0: weekstats.append(weektodate['totalapps__sum'] / ((weektodate['prodhours__sum']+weektodate['sickhours__sum']) / targets.hours)) agentweek[each.name] = weekstats agentmonth[each.name] = monthstats agentyear[each.name] = yearstats template = 'team/page.html' context = RequestContext(request, {'monthtodate':monthtodate, 'agentavgvol':agentavgvol, 'appstable':appstable, 'agentyear':agentyear, 'agentmonth':agentmonth, 'agentweek':agentweek, 'date':date, 'team':team, 'agent':agent, 'super':super, 'yearfte':yearfte, 'monthfte':monthfte, 'weekfte':weekfte}) response = render_to_response(template, context) return response
def stats_day_print(request, year, month, day): var = [year, month_number(month), day] date = '-'.join(var) thedate = datetime.strptime(date, '%Y-%m-%d') statteams = [] eachteam = OrderedDict() teamcolours = {} allteams = Teams.objects.all() allteams = allteams.exclude(teamtype=4).order_by('teamtype') allteams = allteams.exclude(teamtype=5).order_by('teamtype') x = 0 month = thedate.strftime("%b").lower() year = thedate.strftime("%Y") for teams in allteams: teamstat = 0 targets = Targets.objects.get(name=teams.targets) teamagents = Agent.objects.filter(teamid__pk=teams.pk).filter(agenttype=0) teamstats = Dstats.objects.filter(date=thedate).filter(team=teams).aggregate(Sum('prodhours'), Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('sickhours')) teamstat = Dstats.objects.filter(month=month).filter(isoyear=year).filter(team=teams).aggregate(Sum('totalapps')) mtdapps = teamstat['totalapps__sum'] teamcolours[teams.name] = teams.button for agent in teamagents: agentstat = Dstats.objects.filter(date=thedate).filter(agent=agent) for stat in agentstat: month = stat.month if stat.sickhours == targets.hours: sick = 1 else: sick = 0 if stat.holhours == targets.hours: hol = 1 else: hol = 0 if stat.prodhours == 0 and stat.otherhours == 0 and stat.innovhours == 0 and stat.sickhours == 0 and stat.holhours == 0: ptcheck = 1 else: ptcheck = 0 monthstat = Dstats.objects.filter(month=month).filter(isoyear=year).filter(agent=agent).aggregate(Sum('totalapps')) statteams.append([agent.name, stat.calltime, stat.callattempts, stat.totalapps, monthstat['totalapps__sum'], "", sick, hol, ptcheck, stat.prodhours, stat.otherhours, stat.innovhours, targets.hours]) monthstat = 0 teamstats = Dstats.objects.filter(date=thedate).filter(team=teams).aggregate(Sum('prodhours'), Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('sickhours'), Sum('innovhours')) fteapps = 0 if teamstats['calltime__sum'] > 0 and teamstats['prodhours__sum'] > 0: calltime = teamstats['calltime__sum'] / (teamstats['prodhours__sum'] / targets.hours) calltime = int(calltime) else: calltime = 0 if teamstats['callattempts__sum'] > 0 and teamstats['prodhours__sum'] > 0: callattempts = teamstats['callattempts__sum'] / (teamstats['prodhours__sum'] / targets.hours) callattempts = int(callattempts) else: callattempts = 0 if teamstats['totalapps__sum'] > 0 and teamstats['prodhours__sum'] > 0: totalapps = teamstats['totalapps__sum'] else: totalapps = 0 if teamstats['totalapps__sum'] > 0 and teamstats['prodhours__sum'] > 0 and teamstats['sickhours__sum'] > 0: fteapps = teamstats['totalapps__sum'] / ((teamstats['prodhours__sum'] + teamstats['sickhours__sum'] + teamstats['innovhours__sum']) / targets.hours) else: fteapps = 0 statteams.append([teams.name, calltime, callattempts, totalapps, mtdapps, fteapps, "", "", 0, "", 1, 0]) calltime = 0 callattempts = 0 totalapps = 0 fteapps = 0 eachteam[teams.name] = statteams statteams=[] allteams = Teams.objects.filter(teamtype=5).order_by('teamtype') for teams in allteams: targets = Targets.objects.get(name=teams.targets) targets = Targets.objects.get(name=teams.targets) teamagents = Agent.objects.filter(teamid__pk=teams.pk).filter(agenttype=0) teamcolours[teams.name] = teams.button for agent in teamagents: agentstat = Dstats.objects.filter(date=thedate).filter(agent=agent) for stat in agentstat: month = stat.month if stat.sickhours == targets.hours: sick = 1 else: sick = 0 if stat.holhours == targets.hours: hol = 1 else: hol = 0 if stat.prodhours == 0 and stat.otherhours == 0 and stat.innovhours == 0 and stat.sickhours == 0 and stat.holhours == 0: ptcheck = 1 else: ptcheck = 0 monthstat = Dstats.objects.filter(month=month).filter(agent=agent).aggregate(Sum('totalapps')) statteams.append([agent.name, stat.calltime, stat.callattempts, stat.totalapps, monthstat['totalapps__sum'], "", sick, hol, ptcheck, stat.prodhours, stat.otherhours, stat.innovhours, targets.hours]) stats = Dstats.objects.filter(date=thedate).filter(team=teams).aggregate(Sum('prodhours'), Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('sickhours'), Sum('innovhours')) monthstat = Dstats.objects.filter(month=month).filter(team=teams).aggregate(Sum('totalapps')) if stats['calltime__sum'] > 0: calltime = stats['calltime__sum'] / (stats['prodhours__sum'] / targets.hours) calltime = int(calltime) else: calltime = 0 if stats['callattempts__sum'] > 0: callattempts = stats['callattempts__sum'] / (stats['prodhours__sum'] / targets.hours) callattempts = int(callattempts) else: callattempts = 0 if stats['totalapps__sum'] > 0: totalapps = stats['totalapps__sum'] else: totalapps = 0 if stats['totalapps__sum'] > 0: fteapps = stats['totalapps__sum'] / ((stats['prodhours__sum'] + stats['sickhours__sum'] + stats['innovhours__sum']) / targets.hours) else: fteapps = 0 statteams.append([teams.name, calltime, callattempts, totalapps, monthstat['totalapps__sum'], fteapps, "", "", 0, "", 1, 0]) calltime = 0 callattempts = 0 totalapps = 0 fteapps = 0 eachteam[teams.name] = statteams statteams=[] internal = Teams.objects.filter(teamtype=1) tstats = [] totals = [] calltime = 0 totalcalltime = 0 callattempts = 0 totalcallattempts = 0 totalapps = 0 floortotalapps = 0 fteapps = 0 floorfteapps = 0 for teams in internal: stats = Dstats.objects.filter(date=thedate).filter(team=teams).aggregate(Sum('prodhours'), Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('sickhours'), Sum('innovhours')) if stats['calltime__sum'] > 0 and stats['prodhours__sum'] > 0: calltime = stats['calltime__sum'] / (stats['prodhours__sum'] / targets.hours) calltime = int(calltime) else: calltime = 0 if stats['callattempts__sum'] > 0 and stats['prodhours__sum'] > 0: callattempts = stats['callattempts__sum'] / (stats['prodhours__sum'] / targets.hours) callattempts = int(callattempts) else: callattempts = 0 if stats['totalapps__sum'] > 0: totalapps = stats['totalapps__sum'] else: totalapps = 0 if stats['totalapps__sum'] > 0 and stats['prodhours__sum'] > 0 and stats['sickhours__sum'] >= 0: fteapps = stats['totalapps__sum'] / ((stats['prodhours__sum'] + stats['sickhours__sum'] + stats['innovhours__sum']) / targets.hours) else: fteapps = 0 tstats.append([teams.name, calltime, callattempts, totalapps, fteapps]) calltime = 0 callattempts = 0 totalapps = 0 fteapps = 0 dstatstotals = Dstats.objects.all() dstatstotals = dstatstotals.filter(date=thedate) dstatstotals = dstatstotals.filter(agent__agenttype=0) dstatstotals = dstatstotals.filter(team__teamtype=1) dstatstotals = dstatstotals.aggregate(Sum('prodhours'), Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('sickhours'), Sum('innovhours')) if dstatstotals['calltime__sum'] > 0: totalcalltime = dstatstotals['calltime__sum'] / (dstatstotals['prodhours__sum'] / targets.hours) totalcalltime = int(totalcalltime) else: totalcalltime = 0 if dstatstotals['callattempts__sum'] > 0: totalcallattempts = dstatstotals['callattempts__sum'] / (dstatstotals['prodhours__sum'] / targets.hours) totalcallattempts = int(totalcallattempts) else: totalcallattempts = 0 if dstatstotals['totalapps__sum'] > 0: floortotalapps = dstatstotals['totalapps__sum'] else: floortotalapps = 0 if dstatstotals['totalapps__sum'] > 0: floorfteapps = dstatstotals['totalapps__sum'] / ((dstatstotals['prodhours__sum'] + dstatstotals['sickhours__sum'] + dstatstotals['innovhours__sum']) / targets.hours) else: floorfteapps = 0 totals.append(totalcalltime) totals.append(totalcallattempts) totals.append(floortotalapps) totals.append(floorfteapps) highcalls = [] highattempts = [] highapps = [] highest = 0 highest2 = 0 highest3= 0 x = 0 dstats = Dstats.objects.filter(date=date).filter(agent__agenttype=0).exclude(team__teamtype=5).order_by('team') highcall = dstats.exclude(team__teamtype=5).order_by('-calltime') for Dstat in highcall: if Dstat.calltime >= highest: highest = Dstat.calltime agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country highcalls.append([Dstat.agent, Dstat.calltime, flag]) x +=1 elif Dstat.calltime >= highest2: highest2 = Dstat.calltime agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country highcalls.append([Dstat.agent, Dstat.calltime, flag]) x +=1 elif Dstat.calltime >= highest3: highest3 = Dstat.calltime agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country highcalls.append([Dstat.agent, Dstat.calltime, flag]) x +=1 highest = 0 highest2 = 0 highest3 = 0 x = 0 highattempt = dstats.exclude(team__teamtype=5).order_by('-callattempts') for Dstat in highattempt: if Dstat.callattempts >= highest: agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country highest = Dstat.callattempts highattempts.append([Dstat.agent, Dstat.callattempts, flag]) x +=1 elif Dstat.callattempts >= highest2: agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country highest2 = Dstat.callattempts highattempts.append([Dstat.agent, Dstat.callattempts, flag]) x +=1 elif Dstat.callattempts >= highest3: agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country highest3 = Dstat.callattempts highattempts.append([Dstat.agent, Dstat.callattempts, flag]) x +=1 highest = 0 highest2 = 0 highest3 = 0 x = 0 highapp = dstats.exclude(team__teamtype=5).order_by('-totalapps') for Dstat in highapp: if Dstat.totalapps >= highest: agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country highest = Dstat.totalapps highapps.append([Dstat.agent, Dstat.totalapps, flag]) x +=1 elif Dstat.totalapps >= highest2: agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country highest2 = Dstat.totalapps highapps.append([Dstat.agent, Dstat.totalapps, flag]) x +=1 elif Dstat.totalapps >= highest3: agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country highest3 = Dstat.totalapps highapps.append([Dstat.agent, Dstat.totalapps, flag]) x +=1 '''''''''''''''''''''''''''''''''''''''''''''''' ' Belgium Stats ' '''''''''''''''''''''''''''''''''''''''''''''''' bhighcalls = [] bhighattempts = [] bhighapps = [] bhighest = 0 x = 0 bdstats = Dstats.objects.filter(team__teamtype=5).filter(date=date).filter(agent__agenttype=0).order_by('team') bhighcall = bdstats.order_by('-calltime') for Dstat in bhighcall: if Dstat.calltime >= bhighest: agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country bhighest = Dstat.calltime bhighcalls.append([Dstat.agent, Dstat.calltime]) highcalls.append([Dstat.agent, Dstat.calltime, flag]) x +=1 bhighest = 0 x = 0 bhighattempt = bdstats.order_by('-callattempts') for Dstat in bhighattempt: if Dstat.callattempts >= bhighest: agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country bhighest = Dstat.callattempts bhighattempts.append([Dstat.agent, Dstat.callattempts]) highattempts.append([Dstat.agent, Dstat.callattempts, flag]) x +=1 bhighest = 0 x = 0 bhighapp = bdstats.order_by('-totalapps') for Dstat in bhighapp: if Dstat.totalapps >= bhighest: agent = Agent.objects.get(name=Dstat.agent) team = Teams.objects.get(name=agent.teamid) flag = team.country bhighest = Dstat.totalapps bhighapps.append([Dstat.agent, Dstat.totalapps]) highapps.append([Dstat.agent, Dstat.totalapps, flag]) x +=1 def sort_inner(inner): """ inner is each inner list in the list of lists to be sorted (here item at index 1 of each inner list is to be sorted) """ return inner[1] highapps.sort(key=sort_inner, reverse=True) highcalls.sort(key=sort_inner, reverse=True) highattempts.sort(key=sort_inner, reverse=True) template = 'osiris/reports/printstats.html' context = RequestContext(request, {'colour':teamcolours, 'targets':targets, 'dtotals': dstatstotals, 'bhighapps':bhighapps, 'bhighattempts':bhighattempts, 'bhighcall':bhighcalls, 'highapps':highapps, 'highattempts':highattempts, 'highcall':highcalls, 'eachteam':eachteam ,'statteams':statteams, 'tstats':tstats, 'thedate':thedate, 'totals':totals}) response = render_to_response(template, context) return response
def daily_stats(year, month, day): #done var = [year, month_number(month), day] date = '-'.join(var) dstats = Dstats.objects.filter(date=date).filter(agent__agenttype=0).exclude(team__teamtype=5).exclude(team__teamtype=4).order_by('team') return dstats
def team_daily_stats(year, month, day): #done var = [year, month_number(month), day] date = '-'.join(var) internal = Teams.objects.all() targets = Targets.objects.get(pk=1) fullstats = Dstats.objects.filter(date=date).filter(agent__agenttype=0) dstatstotals = fullstats.aggregate(Sum('prodhours'), Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('sickhours'), Sum('innovhours')) tstats = [] totals = [] calltime = 0 totalcalltime = 0 callattempts = 0 totalcallattempts = 0 totalapps = 0 floortotalapps = 0 fteapps = 0 floorfteapps = 0 for teams in internal: stats = fullstats.filter(team=teams).aggregate(Sum('prodhours'), Sum('totalapps'), Sum('calltime'), Sum('callattempts'), Sum('sickhours'), Sum('innovhours')) if stats['calltime__sum'] > 0 and stats['prodhours__sum'] > 0: calltime = stats['calltime__sum'] / (stats['prodhours__sum'] / targets.hours) calltime = int(calltime) if stats['callattempts__sum'] > 0 and stats['prodhours__sum'] > 0: callattempts = stats['callattempts__sum'] / (stats['prodhours__sum'] / targets.hours) callattemtps = int(callattempts) if stats['totalapps__sum'] > 0: totalapps = stats['totalapps__sum'] if stats['totalapps__sum'] > 0 and stats['prodhours__sum'] > 0: fteapps = stats['totalapps__sum'] / ((stats['prodhours__sum'] + stats['sickhours__sum'] + stats['innovhours__sum']) / targets.hours) tstats.append([teams.name, calltime, callattempts, totalapps, fteapps]) stats['calltime__sum'] = 0 stats['callattempts__sum'] = 0 stats['totalapps__sum'] = 0 stats['prodhours__sum'] = 0 stats['sickhours__sum'] = 0 calltime = 0 callattempts = 0 totalapps = 0 fteapps = 0 if dstatstotals['calltime__sum'] > 0: totalcalltime = int(dstatstotals['calltime__sum'] / (dstatstotals['prodhours__sum'] / targets.hours)) else: totalcalltime = 0 if dstatstotals['callattempts__sum'] > 0: totalcallattempts = int(dstatstotals['callattempts__sum'] / (dstatstotals['prodhours__sum'] / targets.hours)) else: totalcallattempts = 0 if dstatstotals['totalapps__sum'] > 0: floortotalapps = dstatstotals['totalapps__sum'] floorfteapps = dstatstotals['totalapps__sum'] / ((dstatstotals['prodhours__sum'] + dstatstotals['sickhours__sum'] + dstatstotals['innovhours__sum']) / targets.hours) else: floorfteapps = 0 floortotalapps = 0 totals.append(totalcalltime) totals.append(totalcallattempts) totals.append(floortotalapps) totals.append(floorfteapps) teamstats = {"tstats":tstats, "totals":totals} return teamstats