Exemplo n.º 1
0
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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
def main():
    bike = Bike()
    car = Car()
    car.start()
    bike.pedal()
    print(car.color)
    print(bike.name)
Exemplo n.º 4
0
	def get_cycle_property(self):
		self.gear = input("Need Gear in cycle (y/n): ")
		self.backseat = input("Do you need backseat (y/n): ")
		self.height = int(input("Size of cycle height: "))
		self.color = input("Cycle Color: ")
		self.price()
		Bike.setAge(self, 5)
 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
Exemplo n.º 6
0
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']
Exemplo n.º 7
0
 def __init__(self, fuel_used, handle, is_gear, ac, steering_wheel,
              seat_belt, audio_player, no_of_wheels, speed, weight, milage,
              colour):
     self.fuel_used = fuel_used
     Bike.__init__(self, handle, is_gear, no_of_wheels, speed, weight,
                   milage, colour)
     Car.__init__(self, ac, steering_wheel, seat_belt, audio_player,
                  no_of_wheels, speed, weight, milage, colour)
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
Exemplo n.º 9
0
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"
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
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"
Exemplo n.º 13
0
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"
Exemplo n.º 14
0
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')
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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"
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
    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')
Exemplo n.º 19
0
 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()
Exemplo n.º 20
0
 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
Exemplo n.º 21
0
 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 bike():
    if request.method == "GET":
        return render_template('bike.html')
    elif request.method == "POST":
        database.connect()
        form = request.form
        model = form['model']
        daily_fee = form['daily_fee']
        img = form['img']
        year = form['year']
        b = Bike(model=model,
                 daily_fee=int(daily_fee),
                 img=img,
                 year=int(year))
        b.save()
        print(model, daily_fee, img, year)
        return "OK"
Exemplo n.º 23
0
 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
Exemplo n.º 24
0
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)]
Exemplo n.º 25
0
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
Exemplo n.º 26
0
 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
Exemplo n.º 27
0
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
Exemplo n.º 28
0
    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
Exemplo n.º 29
0
    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
Exemplo n.º 30
0
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
Exemplo n.º 31
0
	 	w1x = 2 * R.random() - 1
	 	w1y = 2 * R.random() - 1
	 	w1r = 0.2 + R.random() * 0.5
	 	w2x = 2 * R.random() - 1
	 	w2y = 2 * R.random() - 1
	 	w2r = 0.2 + R.random() * 0.5
	 	Dm1m2 = 5000 + 20000 * R.random()
	 	Dm1w1 = 5000 + 20000 * R.random()
	 	Dm1w2 = 5000 + 20000 * R.random()
	 	Dm2w1 = 5000 + 20000 * R.random()
	 	Dm2w2 = 5000 + 20000 * R.random()
	 	Dw1w2 = 5000 + 20000 * R.random()

		c = [Point(m2x, m2y), Point(w1x, w1y), w1r, Point(w2x, w2y), w2r,
			Dm1m2, Dm1w1, Dm1w2, Dm2w1, Dm2w2, Dw1w2]
		b = Bike(c, Point(2, 2))
		bikes.append(b)

	# c = [Point[-0.5, 0], Point(-1, 1), 0.5, Point(-1, -1.5), 0.5, 100, 100, 100, 100, 100, 100]

	generation = 1 		# show generation in the corner
	doRunAll = True		# a button to stop the simulation?
	while doRunAll:
		nbike = 1
		for b in bikes:
			fit = sim.run(generation, nbike, b, timestep)
			b.setFitness(fit)
			nbike += 1

		# nextgen = GeneticAlgorithm(bikes)
		nextgen = bikes
Exemplo n.º 32
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    pygame.display.set_caption("TouchMoto")

    background = pygame.Surface(screen.get_size()).convert()

    font = pygame.font.Font(None, 16)
        
    screen.blit(background, (0, 0))
    pygame.display.flip()

    clock = pygame.time.Clock()

    player = Bike()

    bikes = [player]
    
    # This is a bit of a hack
    player.rect.midleft = pygame.display.get_surface().get_rect().midleft
    player.x, player.y = player.rect.centerx, player.rect.centery

    # delegate rendering and updating to Pygame. Probably needs to 
    # be reworked eventually.
    allsprites = pygame.sprite.RenderPlain((player.target, player))

    while True:
        # don't go (much) faster than 60 fps
        dt = clock.tick(60) 
        for bike in bikes:
            bike.dt = dt

        # Handle Input Events
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                return 
            elif event.type == pygame.MOUSEBUTTONDOWN:
                player.target.tracking = 1
                player.target.place()
            elif event.type == pygame.MOUSEBUTTONUP:
                player.target.tracking = 0
                
        # This is how we respond to mouse dragging events
        if player.target.tracking:
            player.target.place()

        allsprites.update()

        # Clear the screen
        background.fill((127, 127, 127))
        screen.blit(background, (0, 0))

        # Draw the sprite callbacks. These are for debugging so I'm not going
        # to even try to generalize it.
        for s in allsprites:
            if hasattr(s, 'draw_cb'):
                for callback in s.draw_cb:
                    callback(screen)

        # Draw your speed
        text = font.render("%s" % int(player.speed*10), 1, (10, 10, 10))
        textpos = text.get_rect(centerx=background.get_width()/2)
        screen.blit(text, textpos)

        # Let pygame draw all 2 sprites
        allsprites.draw(screen)

        # And show `screen`
        pygame.display.flip()