Python Forum
Greater Than - Less Than
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Greater Than - Less Than
#1
For quick reference, I marked the lines of interest with ***. Any guidance or insight would be much appreciated. The problem is if EID1C number is 169 or lower the print statement outputs the correct %, but then displays (above average). It should be (below average). If the E1D1C number is 170 the print statement outputs the correct % and displays (below average) when it's below and (above average) when it's above. I have found that python doesn't like the EID1C to drop below 10%. If it does then 9.90% which is below average will display the correct % (9.90), but the wrong text (above average).

from __future__ import division
import numpy as np
import datetime as dt
#Known Error -- if >= threshold drops below 10% then above/below average text isn't accurate.

h0 = 0 #define the number of paid holidays between first date set
h1 = 0 #define the number of paid holidays between second date set
d0 = dt.date( 2017, 1, 1 ) #define the start date, first date set
d1 = dt.date( 2017, 6, 1 ) #define the end date, first date set

days0 = np.busday_count( d0, d1 )+1-h0 #+1 is used to calculate end of day

d2 = dt.date( 2017, 6, 1 ) #define the start date, second date set
d3 = dt.date( 2017, 12, 1 ) #define the end date, second date set

days1 = np.busday_count( d2, d3 )+1-h1 #+1 is used to calculate end of day
print ('Working Days between January 1 - June 1 are %d') %days0
print ('Working Days between July 1 - December 1 are %d') %days1

invoice0 = 1200 #total number of invoices, first date set
invoice1 = 1700 #total number of invoices, second date set

EID0A = 135 #total invoices processed by employee 001, first date set
EID0B = 165 #total invoices processed by employee 002, first date set
EID0C = 225 #total invoices processed by employee 003, first date set
EID0D = 425 #total invoices processed by employee 004, first date set

EID1A = 435 #total invoices processed by employee 001, second date set
EID1B = 265 #total invoices processed by employee 002, second date set
***EID1C = 170 #total invoices processed by employee 003, second date set
EID1D = 525 #total invoices processed by employee 004, second date set

proprocess0 = np.mean([EID0A,EID0B, EID0C, EID0D])
proavg0 = "{0:.2f}%".format((np.mean([EID0A,EID0B, EID0C, EID0D])/invoice0)*100)
EID0APro = "{0:.2f}%".format((EID0A/invoice0)*100) #Employee percentage of invoices processed during the first data set period. number in front of f defines decimal places
EID0BPro = "{0:.2f}%".format((EID0B/invoice0)*100) #Employee percentage of invoices processed during the first data set period. number in front of f defines decimal places
EID0CPro = "{0:.2f}%".format((EID0C/invoice0)*100) #Employee percentage of invoices processed during the first data set period. number in front of f defines decimal places
EID0DPro = "{0:.2f}%".format((EID0D/invoice0)*100) #Employee percentage of invoices processed during the first data set period. number in front of f defines decimal places
print "\nThe average number of invoices processed, per employee during the first data set period was", proprocess0, "\nand the average production percentage during the first data set period was",proavg0 #average production during first data set
if EID0APro >= proavg0:
print "\nEmployee 001 was responsible for", EID0APro,"(above average) of the total", invoice0, "invoices processed during the first data set period."
else:
print "\nEmployee 001 was responsible for", EID0APro,"(below average) of the total", invoice0, "invoices processed during the first data set period."

if EID0BPro >= proavg0:
print "\nEmployee 002 was responsible for", EID0BPro,"(above average) of the total", invoice0, "invoices processed during the first data set period."
else:
print "\nEmployee 002 was responsible for", EID0BPro,"(below average) of the total", invoice0, "invoices processed during the first data set period."

if EID0CPro >= proavg0:
print "\nEmployee 003 was responsible for", EID0CPro,"(above average) of the total", invoice0, "invoices processed during the first data set period."
else:
print "\nEmployee 003 was responsible for", EID0CPro,"(below average) of the total", invoice0, "invoices processed during the first data set period."
if EID0DPro >= proavg0:
print "\nEmployee 004 was responsible for", EID0DPro,"(above average) of the total", invoice0, "invoices processed during the first data set period."
else:
print "\nEmployee 004 was responsible for", EID0DPro,"(below average) of the total", invoice0, "invoices processed during the first data set period."


proprocess1 = np.mean([EID1A,EID1B, EID1C, EID1D])
proavg1 = "{0:.2f}%".format((np.mean([EID1A,EID1B, EID1C, EID1D])/invoice1)*100)
EID1APro = "{0:.2f}%".format((EID1A/invoice1)*100) #Employee percentage of invoices processed during the second data set period. number in front of f defines decimal places
EID1BPro = "{0:.2f}%".format((EID1B/invoice1)*100) #Employee percentage of invoices processed during the second data set period. number in front of f defines decimal places
EID1CPro = "{0:.2f}%".format((EID1C/invoice1)*100) #Employee percentage of invoices processed during the second data set period. number in front of f defines decimal places
EID1DPro = "{0:.2f}%".format((EID1D/invoice1)*100) #Employee percentage of invoices processed during the second data set period. number in front of f defines decimal places
print "\nThe average number of invoices processed, per employee during the second data set period was", proprocess1, "\nand the average production percentage during the second data set period was",proavg1 #average production during second data set
if EID1APro >= proavg1:
print "\nEmployee 001 was responsible for", EID1APro,"(above average) of the total", invoice1, "invoices processed during the second data set period."
else:
print "\nEmployee 001 was responsible for", EID1APro,"(below average) of the total", invoice1, "invoices processed during the second data set period."

if EID1BPro >= proavg1:
print "\nEmployee 002 was responsible for", EID1BPro,"(above average) of the total", invoice1, "invoices processed during the second data set period."
else:
print "\nEmployee 002 was responsible for", EID1BPro,"(below average) of the total", invoice1, "invoices processed during the second data set period."

***if EID1CPro >= proavg1:
***print "\nEmployee 003 was responsible for", EID1CPro,"(above average) of the total", invoice1, "invoices processed during the second data set period."
***else:
***print "\nEmployee 003 was responsible for", EID1CPro,"(below average) of the total", invoice1, "invoices processed during the second data set period."

if EID1DPro >= proavg1:
print "\nEmployee 004 was responsible for", EID1DPro,"(above average) of the total", invoice1, "invoices processed during the second data set period."
else:
print "\nEmployee 004 was responsible for", EID1DPro,"(below average) of the total", invoice1, "invoices processed during the second data set period."
Reply
#2
Your program is comparing floating point numbers as strings.
e.g.: if EID1APro >= proavg1:

EID1APro and proavg1 are strings.

'9.00%' >= '10.00%'
Output:
True
Normally you put code like this into functions:


def invoices_per_employee(employees, total_invoices):
    avg_processed = np.mean(list(employees.values()))
    avg_total = avg_processed / total_invoices * 100
    for name, processes_invoices in employees.items():
        processed = processes_invoices / total_invoices * 100
        yield name, avg_processed, avg_total, processes_invoices, processed, processed > avg_total

emp = {'David': 170, 'Lisa': 50}
total = 1700

list(invoices_per_employee(emp, total))
Think about better variable names.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  F-score and Recall values Greater Than 1 Hani 5 2,479 May-13-2020, 01:47 AM
Last Post: Hani

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020