def create(params):
    vehicle = Vehicle(**params)

    if vehicle.save():
        return dict(status=201, body=vehicle, message="Veiculo Registrado!")
    else:
        return dict(status=422, body=vehicle)
示例#2
0
 def gen_ts_item(cls, vehicle, timestamp):
     return Vehicle.timescale_type(
         vehicle_id=vehicle.id,
         timestamp=timestamp,
         **{
             column: getattr(vehicle, column)
             for column in Vehicle.timescale_table_value_columns
         })
示例#3
0
    def import_row(self, row, which):
        if which == self.ACCOUNTS:
            account = Account(
                account_id=row[1],  # Acct Id
                company_name=row[2],  # Account Name
                person_name=None,  # only from Divisions
                phone_number=row[3],
                address=("%s, %s, %s, %s, %s, %s" %
                         (row[8], row[9], row[10], row[11], row[12], row[13])),
                driver_voucher=self.safe_cast(None, bool),
                special_requirements=row[0]  # Account Notes
            )
            account.put()

        elif which == self.VEHICLE:
            vehicle = Vehicle(vehicle_id=row[0])
            vehicle.put()
示例#4
0
def save_status(app):
    with app.app_context():
        max_version = Vehicle.max_version()
        if max_version:
            max_version = max_version + 1
        else:
            max_version = 1

        while True:
            vehicle_local = get_vehicle()
            Vehicle(version=max_version,
                    motor_1=vehicle_local.get_speed_motor_1(),
                    motor_2=vehicle_local.get_speed_motor_2(),
                    speed=vehicle_local.get_speed(),
                    bumper_status=vehicle_local.get_parachoque_status(),
                    created_at=datetime.today()).save()
            time.sleep(1)
示例#5
0
 def mutate(cls, _, info, registration_number, company_id, alias=None):
     with atomic_transaction(commit_at_end=True):
         vehicle = Vehicle(
             registration_number=registration_number,
             alias=alias,
             submitter=current_user,
             company_id=company_id,
         )
         db.session.add(vehicle)
     app.logger.info(f"Created new vehicle {vehicle}")
     return vehicle
示例#6
0
    def create_or_update_from_mailbox(cls, vehicle_id, mailbox, current_time):
        vehicle = Vehicle.query.filter(Vehicle.id == vehicle_id).first()

        if vehicle is None:
            vehicle = Vehicle(id=vehicle_id)
            db.session.add(vehicle)

        method = mailbox["data"]["method"]
        if method in Vehicle.gs_map.keys():
            if method == "GSVehicle.GetProfitLastYear":
                if vehicle.profit_last_year != mailbox["result"]:
                    # TODO: Use a better base for our year end addition
                    last_year_ts = VehicleTimescaleController.gen_ts_item(
                        vehicle,
                        datetime(current_time.year - 1, 12, 31, 23, 59, 59))
                    last_year_ts.profit_this_year = mailbox["result"]
                    db.session.add(last_year_ts)
            setattr(vehicle, Vehicle.gs_map[method], mailbox["result"])

        vehicle.last_updated = current_time

        db.session.commit()
def export():
    vehicles = Vehicle.select()
    with open("vehicles.txt", "w") as file:
        for vehicle in vehicles:
            file.write(f""""
                ---------------------------------
                    Nome: { vehicle.name }
                    Modelo: { vehicle.model }
                    Tipo: { vehicle.type }
                    Combustivel: { vehicle.fuel }
                    Ano: { vehicle.year }
                    
                    R$ { vehicle.price }
                ---------------------------------
                """)
示例#8
0
def register(vehicle_id):
    """
    Starts updating for a specific vehicle ID
    ---
    :return:
    """
    vehicle = Vehicle.query.filter(Vehicle.id == vehicle_id).first()

    if vehicle:
        return "", HTTPStatus.CONFLICT

    vehicle = Vehicle(id=vehicle_id)
    db.session.add(vehicle)
    db.session.commit()
    mailboxes = VehicleController.update_by_id(ottd_connection, vehicle_id)

    return {"status": True, "mailboxes": mailboxes}, HTTPStatus.OK
示例#9
0
def historical():
    array_json = []
    regs = Vehicle.last(15)
    for veh in regs:
        array_json.append({
            'version':
            veh.version,
            'motor_1':
            veh.motor_1,
            'motor_2':
            veh.motor_2,
            'speed':
            veh.speed,
            'bumper_status':
            veh.bumper_status,
            'created_at':
            veh.created_at.strftime("%d/%m/%Y-%H:%M:%S")
        })
    return jsonify({'data': array_json})
示例#10
0
def export():
    array_json = []
    regs = Vehicle.all_max_version()
    for veh in regs:
        array_json.append({
            'version':
            veh.version,
            'motor_1':
            veh.motor_1,
            'motor_2':
            veh.motor_2,
            'speed':
            veh.speed,
            'bumper_status':
            veh.bumper_status,
            'created_at':
            veh.created_at.strftime("%d/%m/%Y-%H:%M:%S")
        })

    return jsonify({"data": array_json})
示例#11
0
 def test_max_distance_from_drop(self):
     vehicle_id, distance = Vehicle.max_distance_from_drop(self.session)
     self.assertEqual(vehicle_id, 'VEHICLE1')
     self.assertEqual(distance, 15572131.792956578)
示例#12
0
def longest_vehicle_distance(session):
    # Please note that distance measures are in meters and have decimals truncated for clarity
    vehicle_id, distance = Vehicle.max_distance_traveled(session)
    return f'\nVehicle {vehicle_id} traveled the most distance today with {distance:.0f} meters'
示例#13
0
def farthest_from_drop_location(session):
    # Please note that distance measures are in meters and have decimals truncated for clarity
    vehicle_id, distance = Vehicle.max_distance_from_drop(session)
    return f'\nVehicle {vehicle_id} was the farthest from the initial drop location at {distance:.0f} meters'
示例#14
0
def vehicle_drop_count(session):
    count = Vehicle.vehicles_count(session)
    return f'\nNumber of Penguin Vehicles Dropped in Simulation: {count}'
示例#15
0
 def test_max_distance_traveled(self):
     vehicle_id, distance = Vehicle.max_distance_traveled(self.session)
     self.assertEqual(vehicle_id, 'VEHICLE1')
     self.assertEqual(distance, 46716395.378869735)
示例#16
0
def index():
    vehicles = Vehicle.select()
    return vehicles
示例#17
0
 def test_vehicles_count(self):
     self.assertEqual(Vehicle.vehicles_count(self.session), 1)
示例#18
0
@vehicle_routes.route("/<int:vehicle_id>/update", methods=["PUT"])
@vehicle_routes.response(VehicleSchema(), code=HTTPStatus.OK)
def update(vehicle_id):
    """
    Requests an update ASAP for a vehicle
    ---
    :return:
    """
    vehicle = Vehicle.query.filter(Vehicle.id == vehicle_id).first_or_404()
    mailboxes = VehicleController.update_by_id(ottd_connection, vehicle_id)
    return {"status": True, "mailboxes": mailboxes}, HTTPStatus.OK


@vehicle_routes.route("/<int:vehicle_id>/timescale_data", methods=["GET"])
@vehicle_routes.arguments(TimeScaleRequestSchema, location="query", as_kwargs=True)
@vehicle_routes.response(Vehicle.timescale_schema()(many=True), code=HTTPStatus.OK)
def vehicle_timescale(vehicle_id, **kwargs):
    """
    Gets the timescale data of one company
    ---
    :param vehicle_id:
    :return:
    """
    vehicle = Vehicle.query.filter_by(id=vehicle_id).first_or_404()

    query = vehicle.timescale_type.query.filter_by(vehicle_id=vehicle_id)

    if "start" in kwargs:
        query = query.filter(vehicle.timescale_type.timestamp >= kwargs["start"])
    if "end" in kwargs:
        query = query.filter(vehicle.timescale_type.timestamp <= kwargs["end"])