def getsales(self, message): #print len(self.sales) event1 = json.loads(message.value) prod_id = event1['product_id'].encode('ascii', 'ignore') units= event1['unit_sold'].encode('ascii', 'ignore') sales_rep = event1['sales_rep_id'].encode('ascii', 'ignore') tstamp = event1['timestamp'].encode('ascii','ignore') territory = self.reps[sales_rep]['TerritoryId'] gallons = float(self.prods[prod_id]['Gallons'])*float(units) self.sales[territory]['Tstamp'] = tstamp actual = self.sales[territory]['Act'] + gallons self.sales[territory]['Act'] = actual ave = (self.sales[territory]['Ave'] + gallons)/2 self.sales[territory]['Ave'] = ave plan = float(self.sales[territory]['Plan']) if actual > plan: self.sales[territory]['Stat'] = 1 elif actual == plan: self.sales[territory]['Stat'] = 0 elif actual < plan: self.sales[territory]['Stat'] = -1