Example #1
0
 def create(self, validated_data):
     car = Car()
     car.name = validated_data.get('name', 'default name')
     car.imageLink = validated_data.get('imageLink', 'assets/test.png')
     car.description = validated_data.get('description',
                                          'default description')
     car.price = validated_data.get('price', '$ 19990')
     car.save()
     return car
Example #2
0
def add_data(request):

	if request.method == 'POST'

		payload = json.loads(request.body)

		car = Car(name=payload['name'], value=payload['value']);

		try:
			car.save()

			results = json.dumps([{'message' : 'success'}])

		except:
			results = json.dumps([{'message' : 'success'}])

	return HttpResponse(results, content_type='text/json')
 def mutate(self, info, *args, **kwargs):
     network = Network()
     print(kwargs)
     res = network.predict(kwargs)
     kwargs.update(res)
     car = Car(**kwargs)
     print(res)
     return car
Example #4
0
def add_car(request):
	
	if request.method == 'POST':

		payload = json.loads(request.body)
		car_name = payload['car_name']
		value = payload['value']

		car = Car(name=car_name, value=value)

		try:
			car.save()
			results = json.dumps([{'message': 'Success' }])
		except:
			results = json.dumps([{'message': 'Error' }])

	
	return HttpResponse(results, content_type='text/json')
Example #5
0
 def create_random():
     return Car(
         reg_number=uuid4().__str__()[:6],
         car_manufacturer=1,
         car_type=1,
         car_colour=1,
         seats=4,
         latitude='59.9139',
         longitude='10.7522',
         hour_rate=20.5,
     )
Example #6
0
def getCars(current_user):
    print(current_user, file=sys.stderr)
    if request.method == "GET":
        cars = Car.query.all()
        return make_response(
            jsonify({"cars": [car.to_json() for car in cars]}),
            201,
        )
    elif request.method == "POST":
        form = request.form
        user_id = form["user_id"]
        make = form["make"]
        model = form["model"]
        colour = form["colour"]
        year = form["year"]
        transmission = form["transmission"]
        car_type = form["car_type"]
        price = form["price"]
        photo = form["photo"]
        description = form["description"]

        car = Car(
            user_id=user_id,
            make=make,
            model=model,
            colour=colour,
            year=year,
            transmission=transmission,
            car_type=car_type,
            price=price,
            photo=photo,
            description=description,
        )

        db.session.add(car)
        db.session.commit()
        return make_response(
            jsonify({"car": car.to_json()}),
            201,
        )
Example #7
0
    def handle(self, *args, **options):
        if Car.objects.exists():
            print('Car Data already loaded ...')
            print(ALREADY_LOADED_MESSAGE)
            return

        if os.path.isfile(csvfile):
            with open(csvfile, 'r') as f_csvfile:
                reader = csv.DictReader(f_csvfile, delimiter=',')
                for line in reader:
                    car = Car()
                    car.carmodel = line['model']
                    car.mileage = line['mpg']
                    car.cylinder = line['cyl']
                    car.gear = line['gear']
                    car.save()
Example #8
0
class DummyCar:
    bmw_suv_white = Car(
        reg_number='abc123',
        car_manufacturer=1,
        car_type=1,
        car_colour=1,
        seats=4,
        latitude='59.9139',
        longitude='10.7522',
        hour_rate=20.5,
    )

    @staticmethod
    def create_random():
        return Car(
            reg_number=uuid4().__str__()[:6],
            car_manufacturer=1,
            car_type=1,
            car_colour=1,
            seats=4,
            latitude='59.9139',
            longitude='10.7522',
            hour_rate=20.5,
        )
Example #9
0
        def insert_cars():
            print("Inserting cars...")
            with open('data/cars.json', 'r') as file:
                cars_str = file.read()
                cars_json = json.loads(cars_str)

            for car_json in cars_json:
                car = Car()
                car.color_type = car_json.get('color_type')
                car.doors = car_json.get('doors')
                car.booking = False
                car.passengers = car_json.get('passengers')
                car.registration = car_json.get('registration')
                car.fuel_type = car_json.get('fuel_type')
                car.category = Category.objects.get(
                    pk=car_json.get('category'))
                car.model = Model.objects.get(pk=car_json.get('model'))
                car.city = City.objects.get(pk=car_json.get('city'))
                car.save()
Example #10
0
    def handle(self, *args, **options):
        fake = Faker()
        fake.add_provider(VehicleProvider)

        # users
        User = get_user_model()
        users = []
        for i in range(USERS):
            uname = fake.simple_profile()['username']
            passw = fake.password(length=20)
            user = User(username=uname,
                        password=make_password(passw),
                        first_name=fake.first_name(),
                        last_name=fake.last_name(),
                        email=fake.email())
            print(uname, passw)
            user.save()
            users.append(user)

        # cars
        cars = []
        for user in users:
            for i in range(CARS_PER_USER):
                car = Car(user_id=user,
                          licence=fake.license_plate(),
                          brand=fake.vehicle_make(),
                          model=fake.vehicle_model(),
                          release=fake.date(),
                          consumption=random.randint(5, 15),
                          type=fake.vehicle_category())
                car.save()
                cars.append(car)

        # stations
        stations = []
        for user in users:
            for i in range(STATIONS_PER_USER):
                place = random.choice(CITIES)
                CITIES.remove(place)
                street = random.choice(ADDRESSES)
                ADDRESSES.remove(street)
                station = Station(latitude=place[1],
                                  longtitude=place[2],
                                  address=street,
                                  number=random.randint(1, 500),
                                  zipcode=fake.postcode(),
                                  city=place[0],
                                  region="Attica",
                                  country="Greece",
                                  operator=user)
                station.save()
                stations.append(station)

        # pricing schemes
        for station in stations:
            for i in range(random.randint(1, 3)):
                pricing = Pricing(station_id=station,
                                  description=fake.text(),
                                  price=random.randint(1, 3))
                pricing.save()

        # points
        points = []
        for station in stations:
            for i in range(random.randint(1, 3)):
                point = Point(station_id=station)
                point.save()
                points.append(point)

        for car in cars:
            for i in range(CHARGE_SESSIONS_PER_CAR):
                point = random.choice(points)
                station = point.station_id
                pricing = random.choice(
                    Pricing.objects.filter(station_id=station))

                charge_session = ChargeSession(
                    car_id=car,
                    point_id=point,
                    pricing_id=pricing,
                    energy_delivered=random.randint(3, 50),
                    total_cost=random.randint(20, 50),
                    start=fake.date_time_between(
                        start_date='-30d',
                        end_date='-29d',
                        tzinfo=timezone('Europe/Athens')),
                    end=fake.date_time_between(
                        start_date='-29d',
                        end_date='-28d',
                        tzinfo=timezone('Europe/Athens')),
                    payment=random.choice(['CD', 'CH']),
                    protocol=random.choice(['WR', 'WD']))
                charge_session.save()
Example #11
0
def populate_db(app):

    with app.app_context():
        print('Connecting to db..')
        db.drop_all()
        print('Connection successful!')
        print('db dropped..')
        db.create_all()
        db.session.add_all([
            pt1,
            cm1,
            cm2,
            cm3,
            ct1,
            ct2,
            cc1,
            cc2,
            cc3,
        ])
        db.session.commit()
        print("Required foreign key rows commited..")
        p1 = Person(username='******',
                    first_name='Adi',
                    last_name='Lastname',
                    email='*****@*****.**',
                    person_type=pt1.id,
                    password_hashed='password',
                    face=None)

        c1 = Car(
            reg_number='abc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.8182711',
            longitude='144.9670618',
            hour_rate=290.5,
        )

        c2 = Car(
            reg_number='bbc123',
            car_manufacturer=cm2.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.8',
            longitude='144.96667',
            hour_rate=20.5,
        )

        c3 = Car(
            reg_number='cbc123',
            car_manufacturer=cm1.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-38.21792',
            longitude='145.03876',
            hour_rate=12.5,
        )

        c4 = Car(
            reg_number='dbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.98333',
            longitude='145.2',
            hour_rate=25.5,
        )

        c5 = Car(
            reg_number='ebc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.7983459',
            longitude='144.960974',
            hour_rate=20.5,
        )

        c6 = Car(
            reg_number='fbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.829',
            longitude='144.957',
            hour_rate=27.5,
        )

        c7 = Car(
            reg_number='gbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.8081201',
            longitude='144.9644196',
            hour_rate=11.5,
        )

        c8 = Car(
            reg_number='hbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.6690123',
            longitude='144.8410273',
            hour_rate=99.5,
        )

        c9 = Car(
            reg_number='ibc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.8332233',
            longitude='144.9124697',
            hour_rate=30.5,
        )

        c10 = Car(
            reg_number='jbc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='59.9139',
            longitude='10.7522',
            hour_rate=70.5,
        )

        c11 = Car(
            reg_number='kbc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.7923459',
            longitude='144.960974',
            hour_rate=20.5,
        )

        c12 = Car(
            reg_number='lbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.8678765',
            longitude='144.9740049',
            hour_rate=20.5,
        )

        c13 = Car(
            reg_number='mbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-38.21792',
            longitude='144.960974',
            hour_rate=50.5,
        )

        c14 = Car(
            reg_number='nbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.7983459',
            longitude='144.960974',
            hour_rate=20.5,
        )

        c15 = Car(
            reg_number='obc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='37.7983459',
            longitude='144.320974',
            hour_rate=20.5,
        )

        c16 = Car(
            reg_number='pbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='59.9139',
            longitude='144.110974',
            hour_rate=20.5,
        )

        c17 = Car(
            reg_number='qbc123',
            car_manufacturer=cm3.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='37.7183459',
            longitude='144.230974',
            hour_rate=20.5,
        )

        c18 = Car(
            reg_number='rbc123',
            car_manufacturer=cm3.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.3983459',
            longitude='144.460974',
            hour_rate=20.5,
        )

        c19 = Car(
            reg_number='sbc123',
            car_manufacturer=cm1.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.283459',
            longitude='144.990974',
            hour_rate=20.5,
        )

        c20 = Car(
            reg_number='tbc123',
            car_manufacturer=cm1.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.829',
            longitude='144.930974',
            hour_rate=20.5,
        )

        db.session.add_all([
            p1, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14,
            c15, c16, c17, c18, c19, c20
        ])
        db.session.commit()
        print('All data commited!')
    print('Finished!')
Example #12
0
 def create(self, validated_data):
     car = Car(**validated_data)
     car.save()
     # UserProfile.objects.create(user=user, **profile_data)
     return car
Example #13
0
    def handle(self, *args, **options):
        fake = Faker()
        fake.add_provider(VehicleProvider)

        # users
        User = get_user_model()
        users = []
        for i in range(USERS):
            uname = fake.simple_profile()['username']
            passw = fake.password(length=20)
            user = User(username=uname,
                        password=make_password(passw),
                        first_name=fake.first_name(),
                        last_name=fake.last_name(),
                        email=fake.email())
            print(uname, passw)
            user.save()
            users.append(user)

        # cars
        cars = []
        user_cnt = 0
        for user in users:
            for i in range(CARS_PER_USER):
                car = Car(user_id=user,
                          licence=fake.license_plate(),
                          brand=BRANDS[user_cnt + i],
                          model=MODELS[user_cnt + i],
                          release=fake.date_between(start_date='-2y'),
                          consumption=random.randint(5, 15),
                          type=fake.vehicle_category())
                car.save()
                cars.append(car)
            user_cnt += CARS_PER_USER

        # stations
        stations = []
        user_cnt = 0
        for user in users:
            for i in range(STATIONS_PER_USER):
                STATION = STATIONS[user_cnt + i]
                station = Station(latitude=STATION[0],
                                  longtitude=STATION[1],
                                  address=STATION[2],
                                  number=STATION[3],
                                  zipcode=STATION[4],
                                  city=STATION[5],
                                  region="Attica",
                                  country="Greece",
                                  operator=user)
                station.save()
                stations.append(station)
            user_cnt += STATIONS_PER_USER

        # pricing schemes
        for station in stations:
            for i in range(random.randint(1, 3)):
                pricing = Pricing(station_id=station,
                                  description=fake.text(),
                                  price=round(random.uniform(1, 3), 3))
                pricing.save()

        # points
        points = []
        for station in stations:
            for i in range(random.randint(2, 6)):
                point = Point(station_id=station)
                point.save()
                points.append(point)

        for car in cars:
            for i in range(random.randint(10, 20)):
                point = random.choice(points)
                station = point.station_id
                pricing = random.choice(
                    Pricing.objects.filter(station_id=station))
                charge_start = fake.date_time_between(
                    start_date='-60d',
                    end_date='-2d',
                    tzinfo=timezone('Europe/Athens'))
                charge_end = charge_start + datetime.timedelta(
                    hours=random.randint(3, 12), seconds=random.randint(1, 59))

                charge_session = ChargeSession(
                    car_id=car,
                    point_id=point,
                    pricing_id=pricing,
                    energy_delivered=round(random.uniform(3, 50), 3),
                    total_cost=round(random.uniform(20, 50), 2),
                    start=charge_start,
                    end=charge_end,
                    payment=random.choice(['CD', 'CH']),
                    protocol=random.choice(['WR', 'WD']))
                charge_session.save()
class ListPopularCars(generics.ListAPIView):
    queryset = Car.most_popular()
    serializer_class = ReviewedCarSerializer
Example #15
0
def populate_db(app):

    with app.app_context():
        print('Connecting to db..')
        db.drop_all()
        print('Connection successful!')
        print('db dropped..')
        db.create_all()
        db.session.add_all([
            cm1,
            cm2,
            cm3,
            ct1,
            ct2,
            cc1,
            cc2,
            cc3,
        ])
        db.session.commit()
        print("Required foreign key rows commited..")
        admin = Person(username='******',
                       first_name='Mr. Admin',
                       last_name='Boss',
                       email='*****@*****.**',
                       type=PersonType.ADMIN,
                       password=generate_password_hash('admin'),
                       face=None)
        engineer = Person(username='******',
                          first_name='Engineer',
                          last_name='Person',
                          email='*****@*****.**',
                          type=PersonType.ENGINEER,
                          password=generate_password_hash('engineer'),
                          face=None)
        manager = Person(username='******',
                         first_name='Mr. Manager',
                         last_name='Ad',
                         email='*****@*****.**',
                         type=PersonType.MANAGER,
                         password=generate_password_hash('manager'),
                         face=None)
        p1 = Person(username='******',
                    first_name='Random',
                    last_name='Person',
                    email='*****@*****.**',
                    type=PersonType.CUSTOMER,
                    password=generate_password_hash('as'),
                    face=None)
        p2 = Person(username='******',
                    first_name='Adi',
                    last_name='Lastname',
                    email='*****@*****.**',
                    type=PersonType.CUSTOMER,
                    password=generate_password_hash('abc123'),
                    face=None)

        c1 = Car(
            reg_number='abc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.8182711',
            longitude='144.9670618',
            hour_rate=290.5,
        )

        c2 = Car(
            reg_number='bbc123',
            car_manufacturer=cm2.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.8',
            longitude='144.96667',
            hour_rate=20.5,
        )

        c3 = Car(
            reg_number='cbc123',
            car_manufacturer=cm1.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-38.21792',
            longitude='145.03876',
            hour_rate=12.5,
        )

        c4 = Car(
            reg_number='dbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.98333',
            longitude='145.2',
            hour_rate=25.5,
        )

        c5 = Car(
            reg_number='ebc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.7983459',
            longitude='144.960974',
            hour_rate=20.5,
        )

        c6 = Car(
            reg_number='fbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.829',
            longitude='144.957',
            hour_rate=27.5,
        )

        c7 = Car(
            reg_number='gbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.8081201',
            longitude='144.9644196',
            hour_rate=11.5,
        )

        c8 = Car(
            reg_number='hbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.6690123',
            longitude='144.8410273',
            hour_rate=99.5,
        )

        c9 = Car(
            reg_number='ibc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.8332233',
            longitude='144.9124697',
            hour_rate=30.5,
        )

        c10 = Car(
            reg_number='jbc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='59.9139',
            longitude='10.7522',
            hour_rate=70.5,
        )

        c11 = Car(
            reg_number='kbc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.7923459',
            longitude='144.960974',
            hour_rate=20.5,
        )

        c12 = Car(
            reg_number='lbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.8678765',
            longitude='144.9740049',
            hour_rate=20.5,
        )

        c13 = Car(
            reg_number='mbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-38.21792',
            longitude='144.960974',
            hour_rate=50.5,
        )

        c14 = Car(
            reg_number='nbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.7983459',
            longitude='144.960974',
            hour_rate=20.5,
        )

        c15 = Car(
            reg_number='obc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='37.7983459',
            longitude='144.320974',
            hour_rate=20.5,
        )

        c16 = Car(
            reg_number='pbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='59.9139',
            longitude='144.110974',
            hour_rate=20.5,
        )

        c17 = Car(
            reg_number='qbc123',
            car_manufacturer=cm3.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='37.7183459',
            longitude='144.230974',
            hour_rate=20.5,
        )

        c18 = Car(
            reg_number='rbc123',
            car_manufacturer=cm3.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.3983459',
            longitude='144.460974',
            hour_rate=20.5,
        )

        c19 = Car(
            reg_number='sbc123',
            car_manufacturer=cm1.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.283459',
            longitude='144.990974',
            hour_rate=20.5,
        )

        c20 = Car(
            reg_number='tbc123',
            car_manufacturer=cm1.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.829',
            longitude='144.930974',
            hour_rate=20.5,
        )
        db.session.add_all([
            admin, engineer, manager, p1, p2, c1, c2, c3, c4, c5, c6, c7, c8,
            c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20
        ])
        db.session.commit()
        b1 = Booking(
            car_id=c1.id,
            person_id=p1.id,
            start_time=datetime.now().replace(microsecond=0, second=0) -
            timedelta(days=4),
            end_time=datetime.now().replace(microsecond=0, second=0) -
            timedelta(days=2),
            status=BookingStatusEnum.CANCELLED)
        b2 = Booking(
            car_id=c2.id,
            person_id=p1.id,
            start_time=datetime.now().replace(microsecond=0, second=0) -
            timedelta(days=1),
            end_time=datetime.now().replace(microsecond=0, second=0) -
            timedelta(hours=10),
            status=BookingStatusEnum.FINISHED)
        i1 = CarIssue(car_id=c1.id, issue='There are no tiers')
        i2 = CarIssue(car_id=c2.id, issue='The engine is gone')
        i3 = CarIssue(car_id=c3.id, issue='Can only drive backwards')
        i4 = CarIssue(car_id=c4.id, issue='Totalled')
        db.session.add_all([b1, b2, i1, i2, i3, i4])
        db.session.commit()
        print('All data commited!')
    print('Finished!')