def test_search_type_1(self):
        v1 = Vehicle(u'Car', u'Fiat', u'Uno', u'Red', 1000, 0)
        v2 = Vehicle(u'Car', u'Volkswagen', u'Fox', u'Silver', 1600, 10000)

        self.db.session.add(v1)
        self.db.session.add(v2)
        self.db.session.commit()

        vv = Vehicle.perform_search([u'Motorcycle'], '', '', '', 1, 10000, 0, 200000)
        self.assertEqual(len(vv), 0)
示例#2
0
def add():
    form = AddVehicleForm(request.form)
    if form.validate_on_submit():

        nv = Vehicle(form.v_type.data, form.manufacturer.data, form.model.data,
                     form.color.data, form.engine.data, form.mileage.data)
        db.session.add(nv)
        db.session.commit()
        flash(nv.__repr__() + ' added.')
        return redirect(url_for('admin.add'))
    return render_template('vehicle.html', form=form)
    def test_search_type_2(self):
        v1 = Vehicle(u'Car', u'Fiat', u'Uno', u'Red', 1000, 0)
        v2 = Vehicle(u'Motorcycle', u'Honda', u'CG 125', u'Silver', 125, 10000)

        self.db.session.add(v1)
        self.db.session.add(v2)
        self.db.session.commit()

        vv = Vehicle.perform_search([u'Motorcycle'], '', '', '', 1, 10000, 0, 200000)
        self.assertEqual(len(vv), 1)
        self.assertEqual(vv[0].id, v2.id)
示例#4
0
 def post(self):
     if request.is_json:
         name = request.json['name']
         seats = request.json['seats']
         uid = request.json['uid']
         vehicle = Vehicle(name=name,
                           seats=seats,
                           uid=uid,
                           availibility=True)
         vehicle.save()
         return jsonify(vehicle)
     return {'status': 'invalid request'}
    def test_search_manufacturer(self):
        v1 = Vehicle(u'Car', u'Fiat', u'Uno', u'Red', 1000, 0)
        v2 = Vehicle(u'Motorcycle', u'Honda', u'CG 125', u'Silver', 125, 10000)
        v3 = Vehicle(u'Car', u'Honda', u'Civic', u'Silver', 1600, 10000)

        self.db.session.add(v1)
        self.db.session.add(v2)
        self.db.session.add(v3)

        self.db.session.commit()

        vv = Vehicle.perform_search([u'Motorcycle', u'Car'], u'Honda', '', '', 1, 10000, 0, 200000)
        self.assertEqual(set(vv), {v2, v3})
示例#6
0
 def get(self, id=None):
     if id:
         vehicle = self.get_vehicle(id)
         return jsonify(vehicle) if vehicle else {
             'status': 'Vehicle not found'
         }
     return jsonify(Vehicle.objects().exclude('id'))
示例#7
0
def index():
    form = VehicleEntry()
    if form.validate_on_submit():
        vehicle = Vehicle(costno=form.costno, grease_int=form.grease_int,
                          oil_change_int=form.oil_change_int,
                          preventative_maintenance_int=form.preventative_maintenance_int)
        db.session.commit(vehicle)
    return render_template('index.html', form=form)


# @bp.route('/WRM_mileage')
# def wrm_mileage():
#     return
#
#
# @bp.route('/HRM_mileage')
# def hrm_mileage():
#     return
#
#
# @bp.route('/FRM_mileage')
# def frm_mileage():
#     return
#
#
# @bp.route('/MRM_mileage')
# def mrm_mileage():
#     return
示例#8
0
def index():
    form = search_vehicles_form_builder(request.form)
    type_fields = [getattr(form, vt) for vt in Vehicle.VEHICLE_TYPES]

    if form.validate_on_submit():
        types_search = [f.label.text for f in type_fields if f.data]
        manufacturer_search = form.manufacturer.data
        model_search = form.model.data
        color_search = form.color.data
        min_engine_search = form.min_engine.data
        max_engine_search = form.max_engine.data
        min_mileage_search = form.min_mileage.data
        max_mileage_search = form.max_mileage.data

        filtered_vehicles = Vehicle.perform_search(
            types_search, manufacturer_search, model_search, color_search,
            min_engine_search, max_engine_search, min_mileage_search,
            max_mileage_search)
        return render_template('index.html',
                               form=form,
                               vehicles=filtered_vehicles,
                               types=type_fields)

    all_vehicles = Vehicle.query.all()
    return render_template('index.html',
                           form=form,
                           vehicles=all_vehicles,
                           types=type_fields)
    def test_delete_vehicle_post(self):
        v1 = Vehicle(u'Car', u'Fiat', u'Uno', u'Red', 1000, 0)
        v2 = Vehicle(u'Car', u'Volkswagen', u'Fox', u'Silver', 1600, 10000)

        self.db.session.add(v1)
        self.db.session.add(v2)
        self.db.session.commit()

        with self.test_client.session_transaction():
            response = self.test_client.post('/' + str(v2.id) + '/delete',
                                             follow_redirects=True)

        v = Vehicle.query.filter(Vehicle.model == u'Fox').one_or_none()
        self.assertEqual(response._status_code, 200)
        self.assertEqual(len(Vehicle.query.all()), 1)
        self.assertIsNone(v)
示例#10
0
def map_vehicle_data_to_role(role: str, twin_data: dict,
                             vehicle: Vehicle) -> dict:
    twin_system_data = extract_twin_data(twin_data)
    vehicle.calculate_health(twin_system_data)

    twin_system_data['brakes']['health'] = vehicle.brakes_health
    twin_system_data['engine']['health'] = vehicle.engine_health
    twin_system_data['fuel']['health'] = vehicle.fuel_health
    twin_system_data['tyres']['health'] = vehicle.tyres_health

    if role == 'INSURANCE':
        return {
            "brakes": None,
            "driver": None,
            "engine": None,
            "fuel": None,
            "license_plate": vehicle.license_plate,
            "model": vehicle.model,
            "overall_health": None,
            "type": None,
            "tyres": None,
            "vin": vehicle.vin
        }
    elif role == 'ADMIN':
        return {**vehicle.to_dict(), **twin_system_data}
    elif role == 'MAINTENANCE':
        # noinspection PyDictCreation
        ret_val = {**vehicle.to_dict(), **twin_system_data}
        ret_val['vin'] = None
        ret_val['license_plate'] = None
        ret_val['driver'] = None
        ret_val['type'] = None

        return ret_val
    else:
        return {
            "brakes": None,
            "driver": None,
            "engine": None,
            "fuel": None,
            "license_plate": None,
            "model": None,
            "overall_health": None,
            "type": None,
            "tyres": None,
            "vin": None
        }
示例#11
0
def newVehicle():
    if request.method == 'POST':
        vehicle = Vehicle(nickname=request.form['inputNickname'],
                          corporationID=request.form['inputCorporationID'],
                          make=request.form['inputMake'],
                          model=request.form['inputModel'],
                          enabled=True)
        db.session.add(vehicle)
        db.session.commit()
        return redirect('newVehicle')
    return render_template('vehicleNew.html', title='New Vehicle')
示例#12
0
def vehicle():
    form = VehicleForm()
    
    if form.validate_on_submit():
        vehicle = Vehicle(vehiclename=form.vehiclename.data, capacity=form.capacity.data)
        db.session.add(vehicle)
        db.session.commit()

        flash('vehicle added')
        return redirect(url_for('index'))

    return render_template('vehicle.html', title='Vehicles', form=form)
示例#13
0
def vehicle_entry():
    form = VehicleForm()
    if form.validate_on_submit():
        vehicle = Vehicle(costno=form.costno.data,
                          grease_interval=form.grease_interval.data,
                          oil_change_interval=form.oil_change_interval.data,
                          preventative_maintenance_interval=form.
                          preventative_maintenance_interval.data)
        db.session.add(vehicle)
        db.session.commit()
        flash(
            f"Congratulations, vehicle {form.costno.data} has been registered")
        return redirect(url_for('vehicle_entry'))
    return render_template('vehicle_entry.html',
                           title='Vehicle Entry',
                           form=form)
示例#14
0
 def wrapper(*args, **kwargs):  # type: ignore
     vehicles = f(*args, **kwargs)
     for v in vehicles:
         vm = Vehicle(
             number=str(v['number']),
             trip_id=None if v['trip'] == 'null_trip' else int(v['trip']),
             driver_id=None if v['driver'] == '0' else int(v['driver']),
             latitude=float(v['latitude']),
             longitude=float(v['longitude']),
             adherence=int(v['adherence']),
             last_message=get_vehicles_datestr_to_datetime(
                 v['last_message']),
             route=None if v['route_short_name'] == 'null' else str(
                 v['route_short_name']),
             headsign=None
             if v['headsign'] == 'null' else str(v['headsign']),
         )
         yield vm
示例#15
0
    def test_update_vehicle_post(self):

        v1 = Vehicle(u'Car', u'Fiat', u'Uno', u'Red', 1000, 0)

        self.db.session.add(v1)
        self.db.session.commit()

        form = UpdateVehicleForm(formdata=None, obj=v1)
        form.v_type.data = u'Motorcycle'
        form.manufacturer.data = u'Yamaha'
        form.model.data = u'Tenere'
        form.engine.data = 250

        with self.test_client.session_transaction():
            response = self.test_client.post('/' + str(v1.id) + '/update', data=form.data, follow_redirects=True)

        self.assertEqual(response._status_code, 200)
        self.assertEqual(v1.v_type, u'Motorcycle')
        self.assertEqual(v1.manufacturer, u'Yamaha')
        self.assertEqual(v1.model, u'Tenere')
        self.assertEqual(v1.engine, 250)
示例#16
0
def find_or_create_vehicle(vehicle_id, vehicle_registration_number, company):
    if not vehicle_id:
        vehicle = Vehicle.query.filter(
            Vehicle.registration_number == vehicle_registration_number,
            Vehicle.company_id == company.id,
        ).one_or_none()

        if not vehicle:
            vehicle = Vehicle(
                registration_number=vehicle_registration_number,
                submitter=current_user,
                company=company,
            )
            db.session.add(vehicle)
            db.session.flush()  # To get a DB id for the new vehicle

    else:
        vehicle = Vehicle.query.filter(
            Vehicle.id == vehicle_id,
            Vehicle.company_id == company.id,
        ).one_or_none()

    return vehicle
示例#17
0
def add_favorites(fav):
    find_dup = Vehicle.query.filter_by(
        image=fav["image"],
        title=fav["title"],
        price=fav["price"],
        reg=fav["reg"],
        mileage=fav["mileage"],
    ).first()
    current_favs = eval(current_user.favorites)
    if find_dup != None:
        if not find_dup.id in current_favs:
            current_favs[find_dup.id] = [change for change in eval(find_dup.changes)]
            current_user.favorites = str(current_favs)
            db.session.commit()
            return True
        else:
            return False
    else:
        fav_db = Vehicle(
            url=fav["url"],
            image=fav["image"],
            title=fav["title"],
            price=fav["price"],
            reg=fav["reg"],
            mileage=fav["mileage"],
            user_added=current_user.id,
            availability=True,
        )
        db.session.add(fav_db)
        db.session.flush()

        current_favs[fav_db.id] = []
        current_user.favorites = str(current_favs)

        db.session.commit()
        return True
示例#18
0
from app.services.thebus_service import get_routes
from app.services.thebus_service import get_vehicles
from app.services.thebus_service import get_vehicles_datestr_to_datetime

ANY_URL = re.compile('.*')


@responses.activate
@pytest.mark.parametrize('row,expected', [
    (0,
     Vehicle(
         number='020',
         trip_id=2558851,
         driver_id=7828,
         latitude=21.39357,
         longitude=-157.7444,
         adherence=0,
         last_message=get_vehicles_datestr_to_datetime('1/7/2020 7:05:54 AM'),
         route='671',
         headsign='KAILUA TOWN',
     )),
    (4,
     Vehicle(
         number='026',
         trip_id=None,
         driver_id=None,
         latitude=21.4005346,
         longitude=-157.9701914,
         adherence=-1,
         last_message=get_vehicles_datestr_to_datetime('7/18/2012 3:12:42 PM'),
         route=None,
示例#19
0

depot = '-0.068372,109.362745'
f = open('./data/destinations.txt', 'r')
lines = f.readlines()
loads = np.random.randint(5, 12, len(lines))
for i in range(len(lines)):
    line = lines[i]
    latlon = line.split()
    latlon = latlon[0]+latlon[1]    
    reverse_geocode_result = gmaps.reverse_geocode((float(latlon.split(',')[0]), float(latlon.split(',')[1])))[0]
    address = reverse_geocode_result['formatted_address']
    load = loads[i]
    order = Order(address = address, latlon=latlon, load=load)
    db.session.add(order)
    db.session.commit()
    # break

caps = [45, 40, 45, 50]
for i in range(len(caps)):
    vehicle = Vehicle(vehiclename='KB'+str(i)+str(i)+str(i)+str(i)+'SS', capacity=caps[i])
    db.session.add(vehicle)
    db.session.commit()

# hash_pass = generate_password_hash('foobar')
# print(hash_pass)

# login = check_password_hash(hash_pass, 'foobar')
# print(login)
# login = check_password_hash(hash_pass, 'blobsie')
# print(login)
示例#20
0
def populate_db(db):
    """
    Populate the database with sample data
    """
    print("POPULATING DB...")
    db.create_all()

    db.session.add_all([
        User(user_id=40, user_name="Alisha"),
        User(user_id=50, user_name="Akshat")
    ])

    db.session.commit()

    print("added users")

    db.session.add_all([
        Vehicle(
            vin="12389347324",
            user_id=40,
            type="Wagon",
            make="BMW",
            model="X4 M40i",
            colour="Silver",
            tare_weight=1700,
            gross_mass=None,
            plate_number="CXD82F",
        ),
        Vehicle(
            vin="54646546313",
            user_id=40,
            type="Hatch",
            make="Toyota",
            model="X4 M40i",
            colour="Blue",
            tare_weight=1432,
            gross_mass=1500,
            plate_number="CXD82G",
        ),
        Vehicle(
            vin="87676676762",
            user_id=50,
            type="Sedan",
            make="Mercedes",
            model="X4 M40i",
            colour="Blue",
            tare_weight=1700,
            gross_mass=None,
            plate_number="CXD89G",
        ),
        Vehicle(
            vin="65465466541",
            user_id=50,
            type="SUV",
            make="Jaguar",
            model="XJ",
            colour="Navy Blue",
            tare_weight=1620,
            gross_mass=None,
            plate_number="EMD82G",
        ),
    ])

    db.session.commit()

    print("added vehicles")

    db.session.add_all([
        Registration(vin="12389347324",
                     expired=True,
                     expiry_date=datetime.datetime.now()),
        Registration(vin="54646546313",
                     expired=False,
                     expiry_date=datetime.datetime.now()),
        Registration(vin="87676676762",
                     expired=True,
                     expiry_date=datetime.datetime.now()),
        Registration(vin="65465466541",
                     expired=True,
                     expiry_date=datetime.datetime.now()),
        Insurer(vin="12389347324", name="Allianz", code=32),
        Insurer(vin="54646546313", name="AAMI", code=17),
        Insurer(vin="87676676762", name="GIO", code=13),
        Insurer(vin="65465466541", name="NRMA", code=27),
    ])

    db.session.commit()

    print("DB populated!")
示例#21
0
    def _parse_vehicle(self, data, vehicle=None):
        load_planning_id, VIN, model, status, port_load_id, port_load_original_name, port_load_name, port_load_in, port_load_out_ETS, port_load_out_ATS, port_discharge_id, port_discharge_original_name, port_discharge_name, port_discharge_in_ETA, port_discharge_in_ATA, vessel_id, vessel_name, vessel_voyage, hash_value, port_load_in_text, port_load_out_ETS_text, port_load_out_ATS_text, port_discharge_in_ETA_text, port_discharge_in_ATA_text = None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None

        if 'load_planning_id' in data:
            load_planning_id = data['load_planning_id']

        if 'VIN' in data:
            VIN = str(data['VIN']).strip()
        if 'model' in data:
            model = str(data['model']).strip()
        if 'status' in data:
            status = str(data['status']).strip()

        if 'port_load_id' in data:
            port_load_id = data['port_load_id']
        if 'port_load_original_name' in data:
            port_load_original_name = str(data['port_load_original_name']).strip()
        if 'port_load_name' in data:
            port_load_name = str(data['port_load_name']).strip()
        if 'port_load_in' in data:
            try:
                port_load_in = data['port_load_in']
            except Exception as e:
                print(e.__str__())
                pass
        if 'port_load_out_ETS' in data:
            try:
                port_load_out_ETS = data['port_load_out_ETS']
            except Exception as e:
                print(e.__str__())
                pass
        if 'port_load_out_ATS' in data:
            try:
                port_load_out_ATS = data['port_load_out_ATS']
            except Exception as e:
                print(e.__str__())
                pass

        if 'port_discharge_id' in data:
            port_discharge_id = data['port_discharge_id']
        if 'port_discharge_original_name' in data:
            port_discharge_original_name = str(data['port_discharge_original_name']).strip()
        if 'port_discharge_name' in data:
            port_discharge_name = str(data['port_discharge_name']).strip()
        if 'port_discharge_in_ETA' in data:
            try:
                port_discharge_in_ETA = data['port_discharge_in_ETA']
            except Exception as e:
                print(e.__str__())
                pass
        if 'port_discharge_in_ATA' in data:
            try:
                port_discharge_in_ATA = data['port_discharge_in_ATA']
            except Exception as e:
                print(e.__str__())
                pass

        if 'vessel_id' in data:
            vessel_id = data['vessel_id']
        if 'vessel_name' in data:
            vessel_name = str(data['vessel_name']).strip()
        if 'vessel_voyage' in data:
            vessel_voyage = str(data['vessel_voyage']).strip()

        # if 'date_created' in data:
        #     try:
        #         date_created = data['date_created']  # date.fromisoformat(data['date_created'])
        #     except Exception as e:
        #         print(e.__str__())
        if 'hash_value' in data:
            hash_value = str(data['hash_value']).strip()

        if 'port_load_in_text' in data:
            port_load_in_text = str(data['port_load_in_text']).strip()
        if 'port_load_out_ETS_text' in data:
            port_load_out_ETS_text = str(data['port_load_out_ETS_text']).strip()
        if 'port_load_out_ATS_text' in data:
            port_load_out_ATS_text = str(data['port_load_out_ATS_text']).strip()
        if 'port_discharge_in_ETA_text' in data:
            port_discharge_in_ETA_text = str(data['port_discharge_in_ETA_text']).strip()
        if 'port_discharge_in_ATA_text' in data:
            port_discharge_in_ATA_text = str(data['port_discharge_in_ATA_text']).strip()

        if vehicle is None:
            vehicle = Vehicle(load_planning_id=load_planning_id, VIN=VIN, model=model, status=status,
                              port_load_id=port_load_id, port_load_original_name=port_load_original_name,
                              port_load_name=port_load_name, port_load_in=port_load_in,
                              port_load_out_ETS=port_load_out_ETS,
                              port_load_out_ATS=port_load_out_ATS, port_discharge_id=port_discharge_id,
                              port_discharge_original_name=port_discharge_original_name,
                              port_discharge_name=port_discharge_name, port_discharge_in_ETA=port_discharge_in_ETA,
                              port_discharge_in_ATA=port_discharge_in_ATA, vessel_id=vessel_id, vessel_name=vessel_name,
                              vessel_voyage=vessel_voyage, hash_value=hash_value,
                              port_load_in_text=port_load_in_text, port_load_out_ETS_text=port_load_out_ETS_text,
                              port_load_out_ATS_text=port_load_out_ATS_text,
                              port_discharge_in_ETA_text=port_discharge_in_ETA_text,
                              port_discharge_in_ATA_text=port_discharge_in_ATA_text)
        else:
            vehicle.load_planning_id = load_planning_id
            vehicle.VIN = VIN
            vehicle.model = model
            vehicle.status = status

            vehicle.port_load_id = port_load_id
            vehicle.port_load_original_name = port_load_original_name
            vehicle.port_load_name = port_load_name
            vehicle.port_load_in = port_load_in
            vehicle.port_load_out_ETS = port_load_out_ETS
            vehicle.port_load_out_ATS = port_load_out_ATS

            vehicle.port_discharge_id = port_discharge_id
            vehicle.port_discharge_original_name = port_discharge_original_name
            vehicle.port_discharge_name = port_discharge_name
            vehicle.port_dischare_in_ETA = port_discharge_in_ETA
            vehicle.port_discharge_in_ATA = port_discharge_in_ATA

            vehicle.vessel_id = vessel_id
            vehicle.vessel_name = vessel_name
            vehicle.vessel_voyage = vessel_voyage

            # vehicle.date_created = date_created
            vehicle.hash_value = hash_value

            vehicle.port_load_in_text = port_load_in_text
            vehicle.port_load_out_ETS_text = port_load_out_ETS_text
            vehicle.port_load_out_ATS_text = port_load_out_ATS_text
            vehicle.port_discharge_in_ETA_text = port_discharge_in_ETA_text
            vehicle.port_discharge_in_ATA_text = port_discharge_in_ATA_text

        return vehicle
示例#22
0
文件: test.py 项目: scul86/mx_tracker
 def test_mileage(self):
     v = Vehicle(total_mileage=10.9)
     v.add_mileage(10.2)
     self.assertTrue(v.mileage == 21.1)
示例#23
0
文件: test.py 项目: scul86/mx_tracker
 def test_set_mileage(self):
     v = Vehicle(total_mileage=20)
     v.set_mileage(10)
     self.assertTrue(v.mileage == 10)