def setUp(self): damaged_bike = Bike() damaged_bike.damage() self.bike_container = BikeContainer(20) self.other_container = BikeContainer(20) self.bike = Bike() self.damaged_bike = damaged_bike
def main(): ground = Floor() # Create the ground ground.gen_coor() # Generate coordinates of the ground fl_coor = ground.coor # fl_coor are the coordinates of the ground (numpy array) # print fl_coor ground.gen_versors() # Generate local versors in all the ground segments par_ver = ground.par_ver #par_ver has all the parallel versos of the segments nor_ver = ground.nor_ver #par_ver has all the parallel versos of the segments # print par_ver bike_test = Bike() # Initiate Bike object bike_test.gen_rand_bike() # Random parameters #EXAMPLE # l0_ww = bike_test.l0_ww # # print l0_ww # Test Distance routine # res = bk_gd_int(bike_test,ground) # print res # print w1_pos[0],w1_pos[1] RuKu4(bike_test,ground) bike_new = Bike() bike_new.gen_sp_bike(bike_positions,bike_mass,k_sp)
def test_get_speed(self): print("bike get_speed test. ") test = Bike("RED", "BMX") testTwo = Bike("RED", "mountain") testThree = Bike("RED", "street") if self.assertEqual(test.get_speed(), 25): if self.assertEqual(testTwo.get_speed(), 8): if self.assertEqual(testThree.get_speed(), 15): return
def get_bike(self, key): with dbapi2.connect(self.app.config['dsn']) as connection: cursor = connection.cursor() query = "SELECT MODEL, BRAND, TYPE, SIZE, YEAR, PRICE,USERNAME FROM BIKE WHERE (ID = %s)" cursor.execute(query, (key,)) model,brand, type, size, year, price,username = cursor.fetchone() return Bike(model, brand, type, size, year, price,username)
def main(): bike = Bike() car = Car() car.start() bike.pedal() print(car.color) print(bike.name)
def createObjects(csvData): """ Function name: createObjects Description: Using the CSV file data, creates all bike objects with no duplicates. Arguments: IN -- CSV data OUT -- Bike Objects """ bikes = [] # Get the number of records in the data for i in range(len(csvData.index)): # Create a temporal object temporalBikeObject = Bike(csvData[1][i], csvData[2][i], csvData[3][i]) existingBike = checkIfExist(bikes, temporalBikeObject) if (not existingBike): # Add new bike to list bikes.append(temporalBikeObject) else: # If the bike exists add times to existing bike existingBike.setTimes(temporalBikeObject.getFirstArrival(), temporalBikeObject.getFirstDeparture()) return bikes
def fetch_bikes(error_text, user_location): location = user_location.get() location = location.upper() # check the entry for location if ((len(location) <= 3 and len(location) > 1) and location.startswith('G')): cursor.execute( "SELECT * FROM Bikes WHERE rented = 0 and location = ? and damaged = 0", (location, )) bike_res = cursor.fetchall() if (len(bike_res) != 0): for x in bike_res: bike = Bike(x[0], x[1], x[2], x[3], x[4], round(x[5], 2)) bikes.append(bike) # Clear the screen window_bike_rent.destroy_children() # display the bikes display_bikes() else: error_text.set('There are no bikes at this location') else: error_text.set('wrong input type')
def add_item(self, model, price, colour, size, gender, quantity): if self.find_bike_by_model(model) != -1: # find bike by model print(f"This bike {model} exists") else: # if ti doesn't exist it is creating new object bike = Bike(model, price, colour, size, gender, quantity) self.stock.append(bike) # append to stock self._save_stock() # save to stock
def test_set_and_get_wheel(self): print("bike set/get wheel integration test. ") test = Bike("red", "BMX") if Test_bike.test_set_wheel_amount(self): if Test_bike.test_get_wheel_amount(self): if self.assertEqual(test.get_wheel_amount(), 2): return
def add_item(self, model, price, description, count): if self.find_bike_by_model(model) != -1: print(f"This bike {model} exists") else: bike = Bike(model, price, description, count) self.stock.append(bike) self._save_stock()
def get_bikes(self): with dbapi2.connect(self.app.config['dsn']) as connection: cursor = connection.cursor() query = "SELECT * FROM BIKE ORDER BY ID" cursor.execute(query) bikes = [(key, Bike(model,brand, type, size, year, price,username)) for key, model,brand, type, size, year, price,username,date in cursor] return bikes
def get_efficiency(gear_ratio): bike = Bike(gear_ratio=gear_ratio) try: perf = bike.steady_state_performance(speed=speed) except ValueError: return np.NaN return perf['motor state']['efficiency']
def search_bike(self,keyword): with dbapi2.connect(self.app.config['dsn']) as connection: cursor = connection.cursor() query="SELECT * FROM BIKE WHERE (MODEL ILIKE %s OR BRAND ILIKE%s OR TYPE ILIKE %s ) ORDER BY ID" keyword='%'+keyword+'%' cursor.execute(query, (keyword,keyword,keyword)) bikes = [(key, Bike(model,brand, type, size, year, price,username)) for key, model,brand, type, size, year, price,username,date in cursor] return bikes
def random_bike_data(): list = [0] * NUM_BIKES for i in range(NUM_BIKES): list[i] = randint(1, 101) bikes = {} for i in range(NUM_BIKES): bikes[list[i]] = create_list(Bike(list[i])) return bikes
def _create_bike_rack(N): """ Generate a random bike rack. Bike.distance_made = "None" (default). Input: N: number of bike objects Output: List of N bike objects. """ return [Bike("random") for x in range(N)]
def get_mileage(speed): bike = Bike() try: perf = bike.steady_state_performance(speed=speed, ) except ValueError: return np.NaN motor = perf['motor state'] power = motor['voltage'] * motor['current'] return power / speed
def crossover(bike1, bike2): new_bike_mass = np.zeros(4) new_bike_pos = np.array([np.zeros(2) for _ in range(4)]) for i in range(4): new_bike_mass[i] = (bike1.bike_mass[i] + bike2.bike_mass[i]) / 2.0 for i_dim in range(2): new_bike_pos[i][i_dim] = (bike1.init_pos[i][i_dim] + bike2.init_pos[i][i_dim]) / 2 new_k_sp = (bike1.k_sp + bike2.k_sp) / 2.0 new_bike = Bike(pos=new_bike_pos, mass=new_bike_mass, k_sp=new_k_sp) return new_bike
def _default_child(): """ Define random default output so that entire toolchain "works" to some degree Input: Nothing(?) Returns: One random baby bicycle object """ default_baby_Bike = Bike("random") return default_baby_Bike
def new_bike(): if request.method == "GET": return render_template ("add_bike.html") else: form = request.form m = form["Model"] d = form["Dailyfee"] i = form["Image"] y = form["Year"] n = Bike(Model = m, Dailyfee = d, Image = i, Year = y) n.save() return "Ahihi DO ngoc", print(n)
def mutation(bike): new_bike_attrs = {} attrs = ['bike_mass', 'init_pos', 'k_sp'] for attr in attrs: new_bike_attrs[attr] = deepcopy(getattr(bike, attr)) mut_attr = sample(attrs, 1).pop() new_bike_attrs[mut_attr] *= .5 + np.random.random() new_bike = Bike(pos=new_bike_attrs['init_pos'], mass=new_bike_attrs['bike_mass'], k_sp=new_bike_attrs['k_sp']) return new_bike
def add_bike(): if request.method == "GET": return render_template("add_bike.html") elif request.method == "POST": form = request.form m = form["model"] f = form["fee"] i = form["image"] y = form["year"] b = Bike(model=m, fee=f, image=i, year=y) b.save() return "Xac nhan"
def new_bike(): if request.method == "GET": return render_template("bike.html") if request.method == "POST": form = request.form m = form["model"] f = form["fee"] img = form["image"] y = form["year"] # print(m, f, img, y) b = Bike(model=m, fee=f, image=img, year=y) b.save() return "OK"
def _generate_bike_rack(N): """ Only called if SIM module is not connected. Generate a random bike rack with a set of N bike objects and randomly assigned values for Bike.distance_made """ # Test bikes: bike_rack = [Bike("random") for x in range(N)] for i in range(len(bike_rack)): bike_rack[i].distance_made = random.uniform(0, 25) return bike_rack
def new_bike(): if request.method == "GET": return render_template("new_bike.html") elif request.method == "POST": form = request.form model = form['model'] dailyfee = form['dailyfee'] img = form['image'] year = form['year'] b = Bike(model=model, dailyfee=dailyfee, image=img, year=year) # print(b) b.save() return "success"
def sell(self, model_name): """ Build and sell certain model of bike Args: model_name: The name of the model Returns: A Bike object """ specification = self.models[model_name] bike = Bike(specification) return bike
def home(): if request.method == 'GET': return render_template('form.html') elif request.method == 'POST': mlab.connect() form = request.form model = form['model'] fee = form['fee'] link = form['link'] year = form['year'] b = Bike(model = model, fee = int(fee), link = link, year = int(year)) b.save() print(model,fee,link,year) return ('HOST')
def _read_stock(self, filename='bikes.json'): f = open(filename, "r") content = f.read() f.close() stock_list_bikes = [] if content: # converts content of json file to python list of dictionaries stock_list_dict = json.loads(content) for bike_dict in stock_list_dict: # convert dictionary to the Bike object stock_list_bikes.append(Bike(**bike_dict)) else: stock = [] return stock_list_bikes
def home(): if request.method == 'GET': return render_template('form.html') elif request.method == 'POST': mlab.connect() form = request.form m = form["model"] d = form["daily_fee"] i = form["image"] y = form["year"] b = Bike(model=m, daily_fee=int(d), image=i, year=int(y)) b.save() # print(m, d, i, y) return "DONE"
def _add_mutation(Bike_input): """ Add natural mutation. Input: One bike object Returns: Slightly mutated bike object """ # mutate the location of both wheels with 0-20 % random increase or decrease rand_mutate = random.uniform(-0.2, 0.2) bike_loc = Bike_input.locations bike_loc[0][:2] = (1 + rand_mutate) * bike_loc[0][:2] bike_loc[1][:2] = (1 + rand_mutate) * bike_loc[1][:2] Baby_mutated = Bike(bike_loc) return Baby_mutated
def _create_child(parent_couple): """ How to combine [currently: average] between two parents. Inputs: Two bicycle objects Returns: One shiny new baby bicycle object """ parent1 = parent_couple[0] parent2 = parent_couple[1] parent1_loc = parent1.locations parent2_loc = parent2.locations baby_loc = (parent1_loc + parent2_loc) * 0.5 # return numpy array of x and y average value of newgen baby Baby_Bike = Bike(np.array(baby_loc)) return Baby_Bike