Esempio n. 1
0
async def start_tracker(app, tracker_name, feed_id, password, start, end):
    tracker = Tracker('garmin_inreach.{}-{}'.format(feed_id, tracker_name))
    monitor_task = asyncio.ensure_future(
        monitor_feed(app, tracker, feed_id, password, start, end))
    tracker.stop = monitor_task.cancel
    tracker.completed = monitor_task
    return tracker
Esempio n. 2
0
async def start_tracker(app, tracker_name, name, event, end):
    tracker = Tracker(f'trackleaders.{tracker_name}')
    monitor_task = asyncio.ensure_future(
        monitor_feed(app, tracker, name, event, end))
    tracker.stop = monitor_task.cancel
    tracker.completed = monitor_task
    return tracker
Esempio n. 3
0
async def start_replay_tracker(org_tracker,
                               event_start_time,
                               replay_start,
                               offset=timedelta(0),
                               speed_multiply=2000):
    replay_tracker = Tracker('replay.{}'.format(org_tracker.name))
    replay_task = asyncio.ensure_future(
        replay(replay_tracker, org_tracker, event_start_time, replay_start,
               offset, speed_multiply))
    replay_tracker.stop = replay_task.cancel
    replay_tracker.completed = replay_task
    return replay_tracker
Esempio n. 4
0
async def start_event_tracker(app, event, rider_name, tracker_data, start,
                              end):
    tracker = Tracker('mapmytracks.{}'.format(tracker_data['name']))
    monitor_task = asyncio.ensure_future(
        monitor_user(
            app['trackers.mapmytracks_session'], tracker_data['name'], start,
            end,
            os.path.join(app['trackers.settings']['cache_path'], event.name,
                         'mapmytracks'), tracker,
            set(tracker_data.get('exclude', ()))))
    tracker.stop = monitor_task.cancel
    tracker.completed = monitor_task
    return tracker
Esempio n. 5
0
async def start_tracker(app, tracker_name, server_name, device_unique_id,
                        start, end):
    device_unique_id = str(device_unique_id)
    await ensure_login(app, server_name)
    server = app['trackers.traccar_servers'][server_name]
    server_url = server['url']
    session = server['session']

    devices_response = await session.get(f'{server_url}/api/devices',
                                         params={'all': 'true'})
    devices = await devices_response.json()
    try:
        device = more_itertools.first(
            (device for device in devices
             if device['uniqueId'] == device_unique_id))
        device_id = device['id']
        if device['name'] == device['uniqueId']:
            # Update name on traccar
            set_name_response = await session.put(
                f'{server_url}/api/devices/{device_id}',
                json={
                    'name': tracker_name,
                    'uniqueId': device['uniqueId'],
                    'id': device['id']
                })
            await set_name_response.json()
    except ValueError:
        get_device_response = await session.post(f'{server_url}/api/devices',
                                                 json={
                                                     'uniqueId':
                                                     device_unique_id,
                                                     'name': tracker_name
                                                 })
        device_id = (await get_device_response.json())['id']

    tracker = Tracker('traccar.{}.{}-{}'.format(server_name, device_unique_id,
                                                tracker_name))

    try:
        await session.post(f'{server_url}/api/permissions',
                           json={
                               'userId': server['user_id'],
                               'deviceId': device_id
                           })
    except Exception as e:
        tracker.logger.error(f'Error in set permissions: {e}')

    tracker.server = server
    tracker.device_id = device_id
    tracker.start = (start if start else
                     (datetime.datetime.now() -
                      datetime.timedelta(days=2)).replace(microsecond=0))
    tracker.end = end
    tracker.seen_ids = seen_ids = set()

    initial_query_end = (end if end else
                         (datetime.datetime.now() +
                          datetime.timedelta(days=1)).replace(microsecond=0))
    positions_response = await session.get(
        f'{server_url}/api/positions',
        params={
            'deviceId': device_id,
            'from': tracker.start.astimezone(dateutil.tz.UTC).isoformat(),
            'to': initial_query_end.astimezone(dateutil.tz.UTC).isoformat()
        },
        headers={'Accept': 'application/json'})
    positions = await positions_response.json()
    points = [traccar_position_translate(position) for position in positions]
    seen_ids.update([position['id'] for position in positions])
    tracker.position_recived = functools.partial(tracker_position_received,
                                                 tracker)
    server['position_received_observables'][device_id].subscribe(
        tracker.position_recived)
    await tracker.new_points(points)

    tracker.finished = asyncio.Event()
    tracker.stop = functools.partial(tracker_stop, tracker)
    tracker.completed = asyncio.ensure_future(tracker.finished.wait())
    tracker.completed.add_done_callback(
        functools.partial(tracker_on_completed, tracker))
    if end:
        asyncio.get_event_loop().call_at(
            asyncio.get_event_loop().time() - time.time() + end.timestamp(),
            tracker.finished.set)
    return tracker