def parse_line(self, line): """ Parse a line. Take care of comments and blank lines here. """ line = line.strip() if line == '' or line[0] == '#': return # Ok, do the real parsing now: the first bit of the string is the # date. Split on the '|' to get the date bit. (date_str, tr_data) = line.split('|') date = datetime.strptime(date_str.strip(), '%b %d, %Y') # Now split off a comment, in case one is there if '#' in tr_data: tr_data, comment = tr_data.split('#') else: comment = '' # And now split the tr_data into items and parse them. tr_items = tr_data.split() l = None # This is a deposit/withdrawl. if len(tr_items) == 2: if tr_items[0] == 'DEPOSIT': self.cash += float(tr_items[1]) elif tr_items[0] == 'WITHDRAWL': self.cash -= float(tr_items[1]) else: print 'Unrecognized transaction type: %s' % tr_items[0] # Looks like we might have a stock trade. elif len(tr_items) == 4: if tr_items[0] == 'BUY': # If we have a buy then we just need to add a new lot to our # list of lots. Sells will go and modify the lots. l = Lot(Stock(tr_items[2]), date, float(tr_items[3]), float(tr_items[1]), cmt=comment) elif tr_items[0] == 'SELL': self.__handle_sell(tr_items) else: print 'Unrecognized transaction type: %s' % tr_items[0] else: print 'Bad data line: "%s"' % line # If we have a lot then add it to our list! if l: self.lots.append(l)
def setUp(self): self.lot1_4 = Lot( front_sb=1, sm_side_sb=2, lg_side_sb=3, rear_sb=4, ) self.lot4_1 = Lot( front_sb=4, sm_side_sb=3, lg_side_sb=2, rear_sb=1, ) self.lotfoo = Lot( front_sb='foo', sm_side_sb=2, lg_side_sb=3, rear_sb='foo', )
def __init__(self, lot_count): """ -constructor class for parking lot object -Lots are kept with ids in hashmap so that updation (empty and park operations) are fast :param lot_count: count of Lot's to be in parking lot :return: None Complexity : O(n) """ self.lot_count = lot_count self.lots = {i: Lot(i, i) for i in range(1, lot_count + 1)} self.available_lots = CustomHeap( [item for k, item in self.lots.items()], 'id', 'distance') self.cars_parked = {}
def testLotInit(self): function_name = "Lot.__init__" print("Running unittest cases for {}\n".format(function_name)) lot_id = 1 lot_distance = 5 new_lot = Lot(lot_id, lot_distance) self.assertEqual(new_lot.id, lot_id, "unittest for {} failed ".format(function_name)) self.assertEqual(new_lot.distance, lot_distance, "unittest for {} failed ".format(function_name)) self.assertEqual(new_lot.available, True, "unittest for {} failed ".format(function_name)) self.assertEqual(new_lot.parked_car, None, "unittest for {} failed ".format(function_name))
def testLotEmpty(self): function_name = "Lot.available" print("Running unittest cases for {}\n".format(function_name)) lot_id = 1 lot_distance = 5 new_lot = Lot(lot_id, lot_distance) car_reg_no = 'KA-01-BB-0001' car_color = 'White' new_lot.park(Car(car_reg_no, car_color)) new_lot.empty() self.assertEqual(new_lot.available, True, "unittest for {} failed ".format(function_name)) self.assertEqual(new_lot.parked_car, None, "unittest for {} failed ".format(function_name)) with self.assertRaises(Exception) as context: new_lot.empty() self.assertTrue('Lot already empty !' in str(context.exception), "unittest for {} failed ".format(function_name))
def import_csv(self): csvi = GlensCSVImporter with open(GlensCSVImporter.SETBACKS_CSV) as csvfile: reader = csv.DictReader(csvfile) for row in reader: lot = Lot( street=row[csvi.STREET], st_number=row[csvi.ST_NUMBER], apn=row[csvi.APN], lot_area=row[csvi.LOT_AREA], res_size=row[csvi.RES_SIZE], yr_built=row[csvi.YR_BUILT], yr_reno=row[csvi.YR_RENO], front_sb=row[csvi.FRONT_SB], sm_side_sb=row[csvi.SM_SIDE_SB], lg_side_sb=row[csvi.LG_SIDE_SB], rear_sb=row[csvi.REAR_SB], ) self.lots.append(lot) self.lots.sort(key=self.get_lot_area_for_sort)
def add_lot(self, points): lot = Lot(self, points) if lot is not None: self.lots.add(lot) return True return False
if res_type.lower() in Type_Residential[1:]: abutments = input('With abutments?\n(Type Yes or No)\n') while abutments.lower() != 'yes' and abutments.lower() != 'no': abutments = input('(Type Yes or No only.)\n') if abutments.lower() == 'yes': for i in Abutments_RType: if i == res_type.lower(): if len(Abutments_RType[i]) == 3: a_opt = input( str(Abutments_RType[i][0]) + ' or ' + str(Abutments_RType[i][1]) + ' or ' + str(Abutments_RType[i][0]) + '\n') while a_opt not in Abutments_RType[i]: a_opt = input('Not in options!\nType ' + Abutments_RType[i][0] + ' or ' + str(Abutments_RType[i][1]) + ' or ' + str(Abutments_RType[i][2]) + '\n') else: print('The only option is ' + Abutments_RType[i]) a_opt = Abutments_RType[i] lot_f = Lot_Abutment(float(x), float(y), res_type, l_type, a_opt) lot_firewall_comp() else: lot_a = Lot(float(x), float(y), res_type, l_type) lot_computations() option = input( '\n\nDo you want to input more lots? (Type Yes or No)\n')