consumer_1.py 962 B

12345678910111213141516171819202122232425262728293031
  1. def getrefs(self):
  2. #get data from the database into a list
  3. self.cur.execute("""SELECT sales_rep_id,sales_rep_territory,daily_gallon_plan from sales_rep""")
  4. self.sales_rows = self.cur.fetchall()
  5. for sr in self.sales_rows:
  6. self.reps[sr[0]] = {'TerritoryId':sr[1], 'Plan':sr[2]}
  7. self.cur.execute("""SELECT product_id,gallons from product""")
  8. self.prod_rows = self.cur.fetchall()
  9. for p in self.prod_rows:
  10. self.prods[p[0]] = {'Gallons': p[1]}
  11. self.cur.execute(
  12. """
  13. SELECT territory_id,territory_name, SUM(daily_gallon_plan) plan
  14. from territory t, sales_rep r
  15. WHERE r.sales_rep_territory = t.territory_id
  16. GROUP BY t.territory_id, t.territory_name
  17. """
  18. )
  19. self.terr_rows = self.cur.fetchall()
  20. for t in self.terr_rows:
  21. self.sales[t[0]] = {'Name':t[1], 'Plan':t[2], 'Act':0.0, 'Ave':0.0, 'Stat':0, 'Tstamp':''}
  22. self.cur.close()
  23. self.conn.close()