Exemple #1
0
    def get_route(self):
        routeexport = []

        for name, area in self._areas.items():
            route = []
            try:
                with open(
                        os.path.join(self._args.file_path,
                                     area['routecalc'] + '.calc'), 'r') as f:
                    for line in f.readlines():
                        latlon = line.strip().split(', ')
                        route.append([
                            getCoordFloat(latlon[0]),
                            getCoordFloat(latlon[1])
                        ])
                    routeexport.append({
                        'name': str(name),
                        'mode': area['mode'],
                        'coordinates': route
                    })
            # ignore missing routes files
            except OSError:
                pass

        return jsonify(routeexport)
Exemple #2
0
    def get_prioroute(self):
        routeexport = []

        routemanager_names = self._mapping_manager.get_all_routemanager_names()

        for routemanager in routemanager_names:
            mode = self._mapping_manager.routemanager_get_mode(routemanager)
            name = self._mapping_manager.routemanager_get_name(routemanager)
            route: Optional[List[
                Location]] = self._mapping_manager.routemanager_get_current_prioroute(
                    routemanager)

            if route is None:
                continue
            route_serialized = []

            for location in route:
                route_serialized.append({
                    "timestamp":
                    location[0],
                    "latitude":
                    getCoordFloat(location[1].lat),
                    "longitude":
                    getCoordFloat(location[1].lng)
                })

            routeexport.append({
                "name": name,
                "mode": mode,
                "coordinates": route_serialized
            })

        return jsonify(routeexport)
Exemple #3
0
    def get_route(self):
        routeexport = []

        routemanager_names = self._mapping_manager.get_all_routemanager_names()

        for routemanager in routemanager_names:
            mode = self._mapping_manager.routemanager_get_mode(routemanager)
            route: Optional[List[
                Location]] = self._mapping_manager.routemanager_get_current_route(
                    routemanager)

            if route is None:
                continue
            route_serialized = []

            for location in route:
                route_serialized.append(
                    [getCoordFloat(location.lat),
                     getCoordFloat(location.lng)])
            routeexport.append({
                "name": routemanager,
                "mode": mode,
                "coordinates": route_serialized
            })

        return jsonify(routeexport)
Exemple #4
0
    def get_geofence(self):
        geofences = {}

        areas = self._mapping_manager.get_areas()
        for name, area in areas.items():
            geofence_include = {}
            geofence_exclude = {}
            geofence_name = 'Unknown'
            geofence_included = Path(area["geofence_included"])
            if not geofence_included.is_file():
                continue
            with geofence_included.open() as gf:
                for line in gf:
                    line = line.strip()
                    if not line:  # Empty line.
                        continue
                    elif line.startswith("["):  # Name line.
                        geofence_name = line.replace("[", "").replace("]", "")
                        geofence_include[geofence_name] = []
                    else:  # Coordinate line.
                        lat, lon = line.split(",")
                        geofence_include[geofence_name].append(
                            [getCoordFloat(lat),
                             getCoordFloat(lon)])

            if area['geofence_excluded']:
                geofence_name = 'Unknown'
                geofence_excluded = Path(area["geofence_excluded"])
                if not geofence_excluded.is_file():
                    continue
                with geofence_excluded.open() as gf:
                    for line in gf:
                        line = line.strip()
                        if not line:  # Empty line.
                            continue
                        elif line.startswith("["):  # Name line.
                            geofence_name = line.replace("[",
                                                         "").replace("]", "")
                            geofence_exclude[geofence_name] = []
                        else:  # Coordinate line.
                            lat, lon = line.split(",")
                            geofence_exclude[geofence_name].append(
                                [getCoordFloat(lat),
                                 getCoordFloat(lon)])

            geofences[name] = {
                'include': geofence_include,
                'exclude': geofence_exclude
            }

        geofencexport = []
        for name, fences in geofences.items():
            coordinates = []
            for fname, coords in fences.get('include').items():
                coordinates.append(
                    [coords, fences.get('exclude').get(fname, [])])
            geofencexport.append({'name': name, 'coordinates': coordinates})

        return jsonify(geofencexport)
Exemple #5
0
    def get_position(self):
        positions = []
        devicemappings = self._mapping_manager.get_all_devicemappings()
        for name, values in devicemappings.items():
            lat = values.get("settings").get("last_location",
                                             Location(0.0, 0.0)).lat
            lon = values.get("settings").get("last_location",
                                             Location(0.0, 0.0)).lng

            worker = {
                "name": str(name),
                "lat": getCoordFloat(lat),
                "lon": getCoordFloat(lon)
            }
            positions.append(worker)

        return jsonify(positions)
Exemple #6
0
    def get_position(self):
        positions = []

        for name, device in self._device_mapping.items():
            try:
                with open(
                        os.path.join(self._args.file_path, name + '.position'),
                        'r') as f:
                    latlon = f.read().strip().split(', ')
                    worker = {
                        'name': str(name),
                        'lat': getCoordFloat(latlon[0]),
                        'lon': getCoordFloat(latlon[1])
                    }
                    positions.append(worker)
            except OSError:
                pass

        return jsonify(positions)