示例#1
0
 def test_sdk(self):
     res = {
         'lastPosition': {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [9.65457, 49.96119, 21]},
                          'properties': {'updatedAt': '2021-03-29T05:16:10Z', 'heading': 126,
                                         'type': 'Estimated'}}, 'preconditionning': {
             'airConditioning': {'updatedAt': '2021-04-01T16:17:01Z', 'status': 'Disabled', 'programs': [
                 {'enabled': False, 'slot': 1, 'recurrence': 'Daily', 'start': 'PT21H40M',
                  'occurence': {'day': ['Sat']}}]}},
         'energy': [{'updatedAt': '2021-02-23T22:29:03Z', 'type': 'Fuel', 'level': 0},
                    {'updatedAt': '2021-04-01T16:17:01Z', 'type': 'Electric', 'level': 70, 'autonomy': 192,
                     'charging': {'plugged': True, 'status': 'InProgress', 'remainingTime': 'PT0S',
                                  'chargingRate': 20, 'chargingMode': 'Slow', 'nextDelayedTime': 'PT21H30M'}}],
         'createdAt': '2021-04-01T16:17:01Z',
         'battery': {'voltage': 99, 'current': 0, 'createdAt': '2021-04-01T16:17:01Z'},
         'kinetic': {'createdAt': '2021-03-29T05:16:10Z', 'moving': False},
         'privacy': {'createdAt': '2021-04-01T16:17:01Z', 'state': 'None'},
         'service': {'type': 'Electric', 'updatedAt': '2021-02-23T21:10:29Z'}, '_links': {'self': {
             'href': 'https://api.groupe-psa.com/connectedcar/v4/user/vehicles/myid/status'},
             'vehicles': {
                 'href': 'https://api.groupe-psa.com/connectedcar/v4/user/vehicles/myid'}},
         'timed.odometer': {'createdAt': None, 'mileage': 1107.1}, 'updatedAt': '2021-04-01T16:17:01Z'}
     api = ApiClient()
     status: psacc.models.status.Status = api._ApiClient__deserialize(res, "Status")
     geocode_res = reverse_geocode.search([(status.last_position.geometry.coordinates[:2])[::-1]])[0]
     assert geocode_res["country_code"] == "DE"
     get_new_test_db()
     car = Car("XX", "vid", "Peugeot")
     car.status = status
     myp = MyPSACC.load_config(DATA_DIR + "config.json")
     myp.record_info(car)
     assert "features" in json.loads(Database.get_recorded_position())
     # electric should be first
     assert car.status.energy[0].type == 'Electric'
示例#2
0
    def test_record_position_charging(self):
        get_new_test_db()
        ElecPrice.CONFIG_FILENAME = DATA_DIR + "config.ini"
        car = self.vehicule_list[0]
        record_position()
        Database.add_altitude_to_db(Database.get_db())
        data = json.loads(Database.get_recorded_position())
        assert data["features"][1]["geometry"]["coordinates"] == [float(longitude), float(latitude)]
        trips = Trips.get_trips(self.vehicule_list)[car.vin]
        trip = trips[0]
        map(trip.add_temperature, [10, 13, 15])
        res = trip.get_info()
        assert compare_dict(res, {'consumption_km': 24.21052631578947,
                                  'start_at': date0,
                                  'consumption_by_temp': None,
                                  'positions': {'lat': [latitude], 'long': [longitude]},
                                  'duration': 40.0, 'speed_average': 28.5, 'distance': 19.0, 'mileage': 30.0,
                                  'altitude_diff': 2, 'id': 1, 'consumption': 4.6})

        Charging.elec_price = ElecPrice.read_config()
        start_level = 40
        end_level = 85
        Charging.record_charging(car, "InProgress", date0, start_level, latitude, longitude, None, "slow", 20, 60)
        Charging.record_charging(car, "InProgress", date1, 70, latitude, longitude, "FR", "slow", 20, 60)
        Charging.record_charging(car, "InProgress", date1, 70, latitude, longitude, "FR", "slow", 20, 60)
        Charging.record_charging(car, "InProgress", date2, 80, latitude, longitude, "FR", "slow", 20, 60)
        Charging.record_charging(car, "Stopped", date3, end_level, latitude, longitude, "FR", "slow", 20, 60)
        chargings = Charging.get_chargings()
        co2 = chargings[0]["co2"]
        assert isinstance(co2, float)
        assert compare_dict(chargings, [{'start_at': date0,
                                         'stop_at': date3,
                                         'VIN': 'VR3UHZKX',
                                         'start_level': 40,
                                         'end_level': 85,
                                         'co2': co2,
                                         'kw': 20.7,
                                         'price': 3.84,
                                         'charging_mode': 'slow'}])
        print()
        assert get_figures(car)
        row = {"start_at": date0.strftime('%Y-%m-%dT%H:%M:%S.000Z'),
               "stop_at": date3.strftime('%Y-%m-%dT%H:%M:%S.000Z'), "start_level": start_level, "end_level": end_level}
        assert get_battery_curve_fig(row, car) is not None
        assert get_altitude_fig(trip) is not None
示例#3
0
def get_recorded_position():
    return FlaskResponse(Database.get_recorded_position(),
                         mimetype='application/json')