Ejemplo n.º 1
0
    def from_allft_7z(cls: Type[AllFTTypeVar],
                      filename: Union[str, Path]) -> AllFTTypeVar:
        from libarchive.public import memory_reader

        _prepare_libarchive()

        with open(filename, "rb") as fh:
            with memory_reader(fh.read()) as entries:
                b = BytesIO()
                for file in entries:
                    for block in file.get_blocks():
                        b.write(block)

        cumul = list()
        max_, current, previous = b.tell(), 0, 0
        b.seek(0)

        iterator = pd.read_csv(
            b,
            header=None,
            names=allft_fields,
            sep=";",
            dtype={
                "aobt": str,
                "iobt": str,
                "cobt": str,
                "eobt": str,
                "arcAddr": str,
            },
            skiprows=1,
            chunksize=2000,
        )

        with tqdm(total=max_, unit="B", unit_scale=True,
                  unit_divisor=1024) as pbar:
            for chunk in iterator:
                cumul.append(
                    chunk.assign(
                        icao24=lambda df: df.arcAddr.str.lower(),
                        aobt=lambda df: parse_date(df.aobt),
                        iobt=lambda df: parse_date(df.iobt),
                        cobt=lambda df: parse_date(df.cobt),
                        eobt=lambda df: parse_date(df.eobt),
                    ).rename(
                        columns={
                            "departureAerodromeIcaoId": "origin",
                            "arrivalAerodromeIcaoId": "destination",
                            "aircraftId": "callsign",
                            "aobt": "AOBT",
                            "iobt": "IOBT",
                            "cobt": "COBT",
                            "eobt": "EOBT",
                        }))

                current = b.tell()
                if current != previous:
                    pbar.update(current - previous)
                previous = current

        return cls(pd.concat(cumul, sort=False).sort_values("EOBT"))
Ejemplo n.º 2
0
    def from_so6_7z(self, filename: Union[str, Path]) -> "SO6":
        from libarchive.public import memory_reader

        with open(filename, "rb") as fh:
            with memory_reader(fh.read()) as entries:
                s = StringIO()
                for file in entries:
                    for block in file.get_blocks():
                        s.write(block.decode())
                s.seek(0)
                so6 = SO6.from_so6(s)
                s.close()
                return so6
Ejemplo n.º 3
0
    def from_so6_7z(cls: Type[SO6TypeVar],
                    filename: Union[str, Path]) -> SO6TypeVar:
        _prepare_libarchive()
        from libarchive.public import memory_reader

        with open(filename, "rb") as fh:
            with memory_reader(fh.read()) as entries:
                s = StringIO()
                for file in entries:
                    for block in file.get_blocks():
                        s.write(block.decode())
                s.seek(0)
                so6 = cls.from_so6(s)
                s.close()
                return so6