Esempio n. 1
0
    def from_file(cls, filename: PathLike) -> List["APRSTrack"]:
        tracks = LocationPacketTrack.from_file(filename)

        for index in range(len(tracks)):
            track = tracks[index]
            packets = []
            for packet in track.packets:
                packets.append(
                    APRSPacket(
                        from_callsign=packet.attributes["from"],
                        to_callsign=packet.attributes["to"],
                        time=packet.time,
                        x=packet.coordinates[0],
                        y=packet.coordinates[1],
                        z=packet.coordinates[2],
                        **{
                            key: value
                            for key, value in packet.attributes.items()
                            if key not in ["from", "to"]
                        },
                    ))
            tracks[index] = APRSTrack(packets=packets,
                                      crs=track.crs,
                                      **track.attributes)

        return tracks
Esempio n. 2
0
    def packets(self) -> List[APRSPacket]:
        if self.__last_access_time is not None and self.interval is not None:
            interval = datetime.now() - self.__last_access_time
            if interval < self.interval:
                raise TimeIntervalError(
                    f"interval {interval} less than minimum interval {self.interval}"
                )

        packets = []
        for record in self.records:
            record = {
                field if field in ["time", "x", "y", "z"] else field.replace(
                    "packet_", ""): value
                for field, value in record.items() if field not in ["point"]
            }
            record["from_callsign"] = record["from"]
            del record["from"]
            if "to" in record:
                record["to_callsign"] = record["to"]
                del record["to"]
            else:
                record["to"] = None
            if record["source"] is None:
                record["source"] = self.location
            packets.append(APRSPacket(**record))

        self.__last_access_time = datetime.now()
        return packets
Esempio n. 3
0
    def packets(self) -> List[LocationPacket]:
        if self.__last_access_time is not None and self.interval is not None:
            interval = datetime.now() - self.__last_access_time
            if interval < self.interval:
                raise TimeIntervalError(
                    f"interval {interval} less than minimum interval {self.interval}"
                )

        if Path(self.location).exists():
            with open(Path(
                    self.location).expanduser().resolve()) as file_connection:
                features = geojson.load(file_connection)
        else:
            response = requests.get(self.location, stream=True)
            features = geojson.loads(response.text)

        packets = []
        for feature in features["features"]:
            if feature["geometry"]["type"] == "Point":
                properties = feature["properties"]
                time = typepigeon.convert_value(properties["time"], datetime)
                del properties["time"]

                if "from" in properties:
                    from_callsign = properties["from"]
                    to_callsign = properties["to"]
                    del properties["from"], properties["to"]

                    packet = APRSPacket(
                        from_callsign,
                        to_callsign,
                        time,
                        *feature["geometry"]["coordinates"],
                        source=self.location,
                        **properties,
                    )
                else:
                    packet = LocationPacket(
                        time,
                        *feature["geometry"]["coordinates"],
                        source=self.location,
                        **properties,
                    )

                packets.append(packet)

        self.__last_access_time = datetime.now()

        return packets
Esempio n. 4
0
 def __getitem__(self, key: (datetime, str)) -> APRSPacket:
     packet = PacketDatabaseTable.__getitem__(self, key)
     attributes = packet.attributes
     from_callsign = attributes["from"]
     del attributes["from"]
     if "to" in attributes:
         to_callsign = attributes["to"]
         del attributes["to"]
     else:
         to_callsign = None
     return APRSPacket(
         from_callsign,
         to_callsign,
         packet.time,
         *packet.coordinates,
         packet.crs,
         **attributes,
     )