Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.2: new core #24

Merged
merged 15 commits into from
Jun 25, 2024
Merged

v0.1.2: new core #24

merged 15 commits into from
Jun 25, 2024

Conversation

cathaypacific8747
Copy link
Owner

The current core is quite cumbersome to use:

async with FR24() as fr24:
    fl = fr24.flight_list("id")
    fl.data.load() # read flight_list/{id}.parquet
    response = await fl.api.fetch() # optional parameters goes here, e.g. page, limit
    fl.data.add(response) # json -> pyarrow
    fl.data.save() # write flight_list/{id}.parquet

It is unclear where data is actually stored. It would be ideal to have something like:

async with FR24() as fr24:
    await fr24.login()
    data_old = fr24.flight_list.load("id") # reads flight_list/{id}.parquet
    # FlightListArrow { ctx: FlightListContext, table: pyarrow.Table }

    data_new = (
        await fr24.flight_list.fetch("id") # FlightListAPIResp { ctx: {"id": "{id}", "page": "..."}, response: json }
    ).to_arrow() # FlightListArrow { ctx: ..., table: pyarrow.Table }
    data = data_old.concat(data_new)
    data.save() # calls self.table.write_parquet("flight_list/{id}.parquet")
  • make logins explicit instead of trying to login in __aenter__
  • wrap around the raw/processed data with composition

Things to implement for the new core:

  • .flight_list.fetch_all()
  • .playback.*
  • .livefeed.*
  • .find.*
  • store request context in arrow table .schema.metadata

.github/workflows/docs.yml Outdated Show resolved Hide resolved
@cathaypacific8747
Copy link
Owner Author

cathaypacific8747 commented Jun 18, 2024

The rewrite is now complete, the core now supports three major services (livefeed, playback and flight_list):

async def main() -> None:
    async with FR24() as fr24:
        # download livefeed of entire world
        response = await fr24.livefeed.fetch() # {ctx: {...}, data: list[dict]}
        datac = response.to_arrow() # {ctx: {...}, data: pa.Table}
        datac.save() # saves to ~/.cache/fr24/livefeed/{timestamp}.parquet, determined from .ctx
        datac_disk = fr24.livefeed.load(timestamp) # reads data from cache and builds ctx

        # download and save trajectory for one flight
        response = await fr24.playback.fetch(0x2FB3041).to_arrow().save()
        datac_disk = fr24.playback.load(0x2FB3041)
        print(datac_disk.metadata) # accesses metadata stored in arrow schema

        # iteratively upsert pages of flight list to an existing arrow table
        data = fr24.flight_list.load(reg="B-HPB")
        async for response in fr24.flight_list.fetch_all(reg="B-HPB"):
            data_new = response.to_arrow()
            data.concat(data_new, inplace=True)
            data.save()

await main()

Documentation and tests are also updated for the new core. Some details:

  • low level functions are left mostly untouched, except:
    • login_with_token_subscription_key: checks if the token is expired by parsing the JWT claim
    • livefeed_flightdata_dict: added missing squawk field
    • find: parameterised AsyncClient and modified parts of the TUI to use the app state's one instead
  • switched to httpx.AsyncClient(http2=True) by default to avoid 464/525
  • CLI now supports all three services
  • previously, protobuf definitions are heavily nested - they have been rewritten to their match the official names and structure as far as possible
  • fr24 seems to have recently added new gRPC endpoints (e.g. flight_list) - their definitions are partially added and we can possibly use them in the future

@cathaypacific8747 cathaypacific8747 marked this pull request as ready for review June 18, 2024 19:53
@xoolive
Copy link
Collaborator

xoolive commented Jun 19, 2024

Hi @cathaypacific8747 will do

Copy link
Collaborator

@xoolive xoolive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also tried the text user interface, and it's still working 🥳

docs/usage/cli.md Outdated Show resolved Hide resolved
docs/usage/cli.md Outdated Show resolved Hide resolved
docs/usage/examples.md Show resolved Hide resolved
src/fr24/history.py Outdated Show resolved Hide resolved
src/fr24/livefeed.py Outdated Show resolved Hide resolved
src/fr24/tui/tui.py Show resolved Hide resolved
Copy link

cloudflare-pages bot commented Jun 23, 2024

Deploying flightradar24 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3edf447
Status: ✅  Deploy successful!
Preview URL: https://8cc46558.flightradar24.pages.dev
Branch Preview URL: https://new-core.flightradar24.pages.dev

View logs

- `flight_list_df`: times are now ms instead of ns, `flight_id` and `icao24` no longer floats
- `playback_df`: `ems` and metadata now serialised
@cathaypacific8747 cathaypacific8747 merged commit 3edf447 into master Jun 25, 2024
11 checks passed
@cathaypacific8747 cathaypacific8747 deleted the new-core branch June 27, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants