Beispiel #1
0
def post_add_car():
    mfg = request.form.get("mfg")
    model = request.form.get("model")
    year = request.form.get("year")
    year = year if year else 0
    color = request.form.get("color")

    c = models.Car(mfg=mfg, model=model, year=year, color=color)
    g.user.cars.append(c)
    db.session.commit()
    return redirect(url_for("get_list_cars"))
Beispiel #2
0
def read_input(input_file):
    file = open(input_file, "r")
    first_line = file.readline()

    first_line = first_line.split()
    sim_time = int(first_line[0])
    intersect_count = int(first_line[1])
    street_count = int(first_line[2])
    car_count = int(first_line[3])
    points = int(first_line[4])

    streets = []
    for i in range(street_count):
        street = file.readline()
        street = street.split()
        streets.append(
            models.Street(street[0], street[1], street[2], street[3]))

    cars = []
    for i in range(car_count):
        car = file.readline()
        car = car.split()
        path = []
        street_count = int(car[0])
        for y in range(street_count):
            path.append(car[y + 1])
        cars.append(models.Car(street_count, path))

    for s in streets:
        print(s.__dict__)

    for c in cars:
        print(c.__dict__)

    return models.StreetSystem(sim_time, intersect_count, street_count,
                               car_count, points, streets, cars)
Beispiel #3
0
carRoutes = []
with open(expanduser('~/TransportSim/var/car/routes.polystrings-1700'),'r') as carRoutesFile:
  for route in carRoutesFile:
    carRoutes.append(decode(route.rstrip()))

People = []
Bicycles = []
Cars = []

for a in range(len(carRoutes)):
  footBicycleCar = randint(1,100) 
  departureTime = randint(beginDepartures,endDepartures)
  if footBicycleCar <= 80:
    p = models.Person(carRoutes[a],departureTime)
    People.append(p)
    c = models.Car()
    p.vehicle = c
    c.driver = p
    Cars.append(c)
  elif 80 < footBicycleCar < 83:
    p = models.Person(bicycleRoutes[a],departureTime)
    People.append(p)
    b = models.Bicycle()
    p.vehicle = b
    b.driver = p
    Bicycles.append(c)
  elif 83 < footBicycleCar:
    p = models.Person(footRoutes[a],departureTime)
    People.append(p)

footRoutes = False
Beispiel #4
0
import os
import pprint
from google.appengine.api import users
from google.appengine.api import memcache
from google.appengine.api import mail
from google.appengine.api import urlfetch
from google.appengine.ext import db

pprint.pprint(os.environ.copy())

import models

s = models.Sponsor(name='Burger King').put()
t = models.Track(name='Watkins Glen', lap_distance=1.0).put()
c = models.Car(make='Volkswagen',
               model='Rabbit',
               year='1981',
               color='red',
               number='24').put()
c = models.Car(make='Audi',
               model='S4',
               year='2005',
               color='silver',
               number='69').put()
cl = models.RaceClass(name='American Iron').put()
r = models.Racer(driver=users.User('*****@*****.**'),
                 points=0,
                 car=c,
                 sponsor=s,
                 raceclass=cl).put()
best = models.BestLap(driver=r, track=t, time=59.062).put()
Beispiel #5
0
def racing_game(auto):
    '''
    Code  from: http://101computing.net/pygame-tutorial-adding-more-sprites/
    with some modifications
    '''
    global menu  # Menu option
    data = []
    counter = 0  # Frames counter
    SPEED = 3  # Car speed
    screen = pygame.display.set_mode((util.WIDTH, util.HEIGHT))
    pygame.display.set_caption("Racing game")
    sprite_list = pygame.sprite.Group()
    # Info text
    info_text = "(r) Reset     (q) quit"
    info, info_rect =\
        models.text(info_text, 530, 450, color=util.white, size=12)
    rows_text = f"{len(data)} rows collected"
    rows, rows_rect =\
        models.text(rows_text, 530, 20, color=util.white, size=12)
    # Player Car
    playerCar = models.Car(util.red, 60, 80, 70)
    playerCar.rect.x = 160
    playerCar.rect.y = util.HEIGHT - 100
    # Othe player cars
    car1 = models.Car(util.green, 60, 80, random.randint(50, 100))
    car1.rect.x = 60
    car1.rect.y = -100
    car2 = models.Car(util.blue, 60, 80, random.randint(50, 100))
    car2.rect.x = 160
    car2.rect.y = -600
    car3 = models.Car(util.yellow, 60, 80, random.randint(50, 100))
    car3.rect.x = 260
    car3.rect.y = -300
    car4 = models.Car(util.green, 60, 80, random.randint(50, 100))
    car4.rect.x = 360
    car4.rect.y = -900
    # Add the cars to the list of objects
    sprite_list.add(playerCar)
    sprite_list.add(car1)
    sprite_list.add(car2)
    sprite_list.add(car3)
    sprite_list.add(car4)
    # Coming cars group
    coming_cars = pygame.sprite.Group()
    coming_cars.add(car1)
    coming_cars.add(car2)
    coming_cars.add(car3)
    coming_cars.add(car4)
    # Allowing the user to close the window...
    running = True
    clock = pygame.time.Clock()
    while running:
        if (counter % 10 == 0):
            rows_text = f"{len(data)} rows collected"
            rows, rows_rect =\
                models.text(rows_text, 530, 20, color=util.white, size=12)
        for event in pygame.event.get():
            # Quit game
            if event.type == pygame.QUIT:
                running = False
                menu = util.MENU_RACING
        keys = pygame.key.get_pressed()
        # Pressed q KEY
        if keys[pygame.K_q]:
            if auto:
                # Quit
                running = False
                menu = util.MENU_RACING
            else:
                # Save collected data and start training
                running = False
                header = "PlayerPos, Car1, Car2, Car3, Car4, Movement"
                np.savetxt('train_racing.csv',
                           data,
                           delimiter=",",
                           comments='',
                           header=header)
                thread = Thread(target=racing_train)
                thread.start()
                menu = util.TRAINING_SCREEN
        # Pressed r KEY
        if keys[pygame.K_r]:
            # Reset
            running = False
            data = []
        # Pressed DOWN KEY
        elif keys[pygame.K_DOWN]:
            SPEED -= 0.05
        # Pressed UP KEY
        elif keys[pygame.K_UP]:
            SPEED += 0.05
        # Move player car
        if (auto):
            playerCar.autoMove(model_racing, coming_cars)
        else:
            playerCar.move(keys, data, coming_cars)
        # Game Logic
        for car in coming_cars:
            car.moveForward(SPEED)
            if car.rect.y > util.HEIGHT:
                # Regenerates cars
                car.changeSpeed(random.randint(70, 90))
                car.repaint(random.choice(util.CAR_COLORS))
                car.rect.y = random.randint(-700, -100)
        # Detects car collisions
        car_collision_list = pygame.sprite.spritecollide(
            playerCar, coming_cars, False)
        if len(car_collision_list) > 0:
            crash_text = "CRASH!!"
        else:
            crash_text = " "
        crash, crash_rect =\
            models.text(crash_text, 540, 200, color=util.white, size=30)

        sprite_list.update()
        # Drawing on Screen
        screen.fill((0, 100, 0))
        # Draw The Road
        pygame.draw.rect(screen, util.gray, [40, 0, 400, util.HEIGHT])
        # Draw Line painting on the road
        pygame.draw.line(screen, util.white, [140, 0], [140, util.HEIGHT], 5)
        # Draw Line painting on the road
        pygame.draw.line(screen, util.white, [240, 0], [240, util.HEIGHT], 5)
        # Draw Line painting on the road
        pygame.draw.line(screen, util.white, [340, 0], [340, util.HEIGHT], 5)
        # Now let's draw all the sprites in one go
        sprite_list.draw(screen)
        # Draw Text
        screen.blit(info, info_rect)
        screen.blit(rows, rows_rect)
        screen.blit(crash, crash_rect)
        # Refresh Screen
        pygame.display.flip()
        # Number of frames per second
        clock.tick(util.FPS)