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

Add an optimizer library to score tracks #203

Merged
merged 21 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
]
}
],
"require-node-import-prefix/no-empty-import-prefix": "error"
"require-node-import-prefix/no-empty-import-prefix": "error",
"@typescript-eslint/consistent-type-imports": "error"
}
},
{
Expand Down
28 changes: 28 additions & 0 deletions .verdaccio/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# path to a directory with all packages
storage: ../tmp/local-registry/storage

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
maxage: 60m

packages:
'**':
# give all users (including non-authenticated users) full access
# because it is a local registry
access: $all
publish: $all
unpublish: $all

# if package is not available locally, proxy requests to npm registry
proxy: npmjs

# log settings
logs:
type: stdout
format: pretty
level: warn

publish:
allow_offline: true # set offline to true to allow publish offline
51 changes: 51 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# How to contribute.

## Required tools

- node.js
- npm
- on mac-os, you have to install xcode command line developer tools (run xcode-select --install)
- gcloud
- docker
- the IDE of your choice

## Project setup

- run `npm install`
- add default key definitions
- `cp apps/fxc-front/src/app/keys.ts.dist apps/fxc-front/src/app/keys.ts`
- `cp libs/common/src/lib/keys.ts.dist libs/common/src/lib/keys.ts`

### Simplistic configuration

**redis server**

- `cd docker; docker compose up -d redis`

**pubsub**

- `cd docker; docker compose up -d pubsub`

**datastore**

For the moment, it does not work with docker compose. But if you install the cloud-datastore-emulator, you will have a working configuration.
vicb marked this conversation as resolved.
Show resolved Hide resolved

**_Installation_**

- `gcloud components install cloud-datastore-emulator`

**_run the data store:_**

- `gcloud beta emulators datastore start --data-dir=MY_DATA_DIR`

**_before npm run dev:_**

- open another shell.
- define the required environment variables:`eval $(gcloud beta emulators datastore --data-dir=MY_DATA_DIR env-init)`
- you can then run the application locally in this shell with `npm run dev`

## Helpful commands

`npx nx check` runs the build, lint, and test targets for all the projects. Nice to use before uploading a PR.

`nx affected:test --all --parallel --maxParallel 10 --watch` will run the tests affected by your code changes.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
- Ufo 3d model by [pawinc](https://sketchfab.com/demarerik),
- the many open source libraries, projects, and data sources used by FlyXc.

✨ _This workspace has been generated by [Nx, a Smart, fast and extensible build system.](https://nx.dev)_ ✨

## Support flyxc

You can support the development of flyxc via the Buy me a Coffee platform

<a href="https://www.buymeacoffee.com/vic.b" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>

Any contribution is greatly appreciated!

✨ _This workspace has been generated by [Nx, a Smart, fast and extensible build system.](https://nx.dev)_ ✨
2 changes: 1 addition & 1 deletion apps/airspaces/src/app/create-geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { readFileSync, writeFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import * as oaip from './parser/openaip';
import * as oair from './parser/openair';
import { Airspace } from './parser/parser';
import type { Airspace } from './parser/parser';
const GeoJSON = require('geojson'); // eslint-disable-line @typescript-eslint/no-var-requires

// Filter out airspaces above:
Expand Down
3 changes: 2 additions & 1 deletion apps/airspaces/src/app/parser/openaip.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Activity, Class, Type } from '@flyxc/common';
import { Airspace, METER_PER_FEET, roundCoords } from './parser';
import type { Airspace } from './parser';
import { METER_PER_FEET, roundCoords } from './parser';

enum Unit {
Meter = 0,
Expand Down
3 changes: 2 additions & 1 deletion apps/airspaces/src/app/parser/openair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import { Activity, Class, Type, decodeClass } from '@flyxc/common';
import { computeDestinationPoint, getDistance, getGreatCircleBearing, sexagesimalToDecimal } from 'geolib';
import { Airspace, METER_PER_FEET, roundCoords } from './parser';
import type { Airspace } from './parser';
import { METER_PER_FEET, roundCoords } from './parser';

const enum Direction {
Clockwise = 1,
Expand Down
3 changes: 2 additions & 1 deletion apps/airspaces/src/app/parser/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AirspaceTyped, round } from '@flyxc/common';
import type { AirspaceTyped } from '@flyxc/common';
import { round } from '@flyxc/common';

export interface Airspace extends AirspaceTyped {
polygon: [number, number][][];
Expand Down
3 changes: 2 additions & 1 deletion apps/airspaces/src/app/upload-tiles-diff.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Unzip tiles to Google Cloud Storage.

import { parallelTasksWithTimeout } from '@flyxc/common';
import { Bucket, Storage } from '@google-cloud/storage';
import type { Bucket } from '@google-cloud/storage';
import { Storage } from '@google-cloud/storage';
import { program } from 'commander';
import { existsSync, readFileSync } from 'node:fs';
import path, { join, resolve } from 'node:path';
Expand Down
2 changes: 1 addition & 1 deletion apps/fetcher/src/app/elevation/arcgis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LatLon } from '@flyxc/common';
import type { LatLon } from '@flyxc/common';

// URL of the elevation service.
//
Expand Down
3 changes: 2 additions & 1 deletion apps/fetcher/src/app/elevation/elevation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//
// We mostly care about the AGL of the last fix.

import { fetchResponse, formatReqError, LatLon, protos } from '@flyxc/common';
import type { LatLon, protos } from '@flyxc/common';
import { fetchResponse, formatReqError } from '@flyxc/common';
import { getElevationUrl, parseElevationResponse } from './arcgis';

export interface ElevationUpdates {
Expand Down
9 changes: 5 additions & 4 deletions apps/fetcher/src/app/redis.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Keys, protos, trackerNames } from '@flyxc/common';
import { pushListCap } from '@flyxc/common-node';
import { Datastore } from '@google-cloud/datastore';
import { ChainableCommander, Redis } from 'ioredis';
import type { Datastore } from '@google-cloud/datastore';
import type { ChainableCommander, Redis } from 'ioredis';
import * as nos from 'node-os-utils';
import * as zlib from 'node:zlib';
import { ElevationUpdates } from './elevation/elevation';
import type { ElevationUpdates } from './elevation/elevation';
import { exportToStorage } from './state/serialize';
import { BUCKET_NAME, EXPORT_FILE_SEC, PERIODIC_STATE_PATH } from './state/state';
import { SyncStatus, syncFromDatastore } from './state/sync';
import type { SyncStatus } from './state/sync';
import { syncFromDatastore } from './state/sync';

// Logs for syncs.
export function addSyncLogs(pipeline: ChainableCommander, status: SyncStatus, timeSec: number) {
Expand Down
3 changes: 2 additions & 1 deletion apps/fetcher/src/app/state/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { protos } from '@flyxc/common';
import { File, Storage } from '@google-cloud/storage';
import type { File } from '@google-cloud/storage';
import { Storage } from '@google-cloud/storage';
import { isBefore, lightFormat, parse, sub } from 'date-fns';
import * as zlib from 'node:zlib';

Expand Down
2 changes: 1 addition & 1 deletion apps/fetcher/src/app/state/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { protos } from '@flyxc/common';
import type { protos } from '@flyxc/common';
import { environment } from '../../environments/environment.prod';
import { importFromStorage } from './serialize';

Expand Down
6 changes: 4 additions & 2 deletions apps/fetcher/src/app/state/sync.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { LiveTrackEntity, protos, TrackerEntity, TrackerNames } from '@flyxc/common';
import { Datastore, Key } from '@google-cloud/datastore';
import type { LiveTrackEntity, TrackerEntity, TrackerNames } from '@flyxc/common';
import { protos } from '@flyxc/common';
import type { Key } from '@google-cloud/datastore';
import { Datastore } from '@google-cloud/datastore';
import { createInitState } from './state';
import { syncLiveTrack } from './sync';

Expand Down
5 changes: 2 additions & 3 deletions apps/fetcher/src/app/state/sync.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { LiveTrackEntity, TrackerNames } from '@flyxc/common';
import {
LIVE_REFRESH_SEC,
LiveTrackEntity,
TrackerNames,
protos,
trackerNames,
trackerValidators,
Expand All @@ -10,7 +9,7 @@ import {
} from '@flyxc/common';
import { LIVE_TRACK_TABLE } from '@flyxc/common-node';
import { Datastore } from '@google-cloud/datastore';
import { RunQueryResponse } from '@google-cloud/datastore/build/src/query';
import type { RunQueryResponse } from '@google-cloud/datastore/build/src/query';
import { FULL_SYNC_SEC, PARTIAL_SYNC_SEC } from './state';

const BATCH_SIZE = 50;
Expand Down
9 changes: 5 additions & 4 deletions apps/fetcher/src/app/trackers/flymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
//
// https://lt.flymaster.net/wlb/?

import type { protos, TrackerNames } from '@flyxc/common';
import {
fetchResponse,
formatReqError,
LIVE_MINIMAL_INTERVAL_SEC,
protos,
removeBeforeFromLiveTrack,
simplifyLiveTrack,
TrackerNames,
validateFlymasterAccount,
SecretKeys,
} from '@flyxc/common';
import { LivePoint, makeLiveTrack } from './live-track';
import { TrackerFetcher, TrackerUpdates } from './tracker';
import type { LivePoint } from './live-track';
import { makeLiveTrack } from './live-track';
import type { TrackerUpdates } from './tracker';
import { TrackerFetcher } from './tracker';

// Latency before a fix is available (usually ~4min).
const FLYMASTER_LATENCY_SEC = 5 * 60;
Expand Down
9 changes: 6 additions & 3 deletions apps/fetcher/src/app/trackers/flyme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
//
// http://xcglobe.com/flyme/

import { fetchResponse, formatReqError, protos, SecretKeys, TrackerNames, validateFlymeAccount } from '@flyxc/common';
import { LivePoint, makeLiveTrack } from './live-track';
import { TrackerFetcher, TrackerUpdates } from './tracker';
import type { protos, TrackerNames } from '@flyxc/common';
import { fetchResponse, formatReqError, SecretKeys, validateFlymeAccount } from '@flyxc/common';
import type { LivePoint } from './live-track';
import { makeLiveTrack } from './live-track';
import type { TrackerUpdates } from './tracker';
import { TrackerFetcher } from './tracker';

export class FlymeFetcher extends TrackerFetcher {
protected getTrackerName(): TrackerNames {
Expand Down
8 changes: 5 additions & 3 deletions apps/fetcher/src/app/trackers/inreach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// - https://support.garmin.com/en-US/?faq=tdlDCyo1fJ5UxjUbA9rMY8 (offline)
// - https://web.archive.org/web/20230328084014/https://support.garmin.com/en-US/?faq=tdlDCyo1fJ5UxjUbA9rMY8

import type { TrackerNames } from '@flyxc/common';
import {
fetchResponse,
formatReqError,
Expand All @@ -14,14 +15,15 @@ import {
protos,
SecretKeys,
simplifyLiveTrack,
TrackerNames,
validateInreachAccount,
} from '@flyxc/common';
import { pushListCap } from '@flyxc/common-node';
import { DOMParser } from '@xmldom/xmldom';
import { LivePoint, makeLiveTrack } from './live-track';
import type { LivePoint } from './live-track';
import { makeLiveTrack } from './live-track';
import { Proxies } from './proxies';
import { TrackerFetcher, TrackerUpdates } from './tracker';
import type { TrackerUpdates } from './tracker';
import { TrackerFetcher } from './tracker';

// Local state
let useProxyUntilS = 0;
Expand Down
3 changes: 2 additions & 1 deletion apps/fetcher/src/app/trackers/live-track.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getTrackerName, isEmergencyFix, isLowBatFix, isValidFix, LiveTrackFlag, trackerIdByName } from '@flyxc/common';
import { computeDestinationPoint } from 'geolib';
import { LivePoint, makeLiveTrack } from './live-track';
import type { LivePoint } from './live-track';
import { makeLiveTrack } from './live-track';

describe('makeLiveTrack', () => {
it('should order the points in chronological order', () => {
Expand Down
3 changes: 2 additions & 1 deletion apps/fetcher/src/app/trackers/live-track.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getTrackerFlags as getLiveTrackFlags, protos, round, TrackerNames, UfoFleetNames } from '@flyxc/common';
import type { TrackerNames, UfoFleetNames } from '@flyxc/common';
import { getTrackerFlags as getLiveTrackFlags, protos, round } from '@flyxc/common';
import { getDistance } from 'geolib';

export interface LivePoint {
Expand Down
6 changes: 4 additions & 2 deletions apps/fetcher/src/app/trackers/ogn-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Client for the OGN APRS server

import { AprsPosition, parseAprsPosition } from '@flyxc/common';
import type { AprsPosition } from '@flyxc/common';
import { parseAprsPosition } from '@flyxc/common';
import { Socket } from 'node:net';
import readline, { Interface } from 'node:readline';
import type { Interface } from 'node:readline';
import readline from 'node:readline';

const VERSION = '1.0';
const OGN_FAST_ID_REGEXP = /\bid[0-9a-z]{2}(?<id>[0-9a-z]{6})\b/i;
Expand Down
5 changes: 3 additions & 2 deletions apps/fetcher/src/app/trackers/ogn-push.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AprsPosition, findIndexes, generateAprsPosition, getFixSpeed, getTrackerName, protos } from '@flyxc/common';
import type { AprsPosition, protos } from '@flyxc/common';
import { findIndexes, generateAprsPosition, getFixSpeed, getTrackerName } from '@flyxc/common';
import { getRhumbLineBearing } from 'geolib';
import { OgnClient } from './ogn-client';
import type { OgnClient } from './ogn-client';

// Don't push obsolete fixes.
const RECENT_FIX_AGE_SEC = 10 * 60;
Expand Down
13 changes: 8 additions & 5 deletions apps/fetcher/src/app/trackers/ogn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
//
// See http://wiki.glidernet.org/.

import { protos, TrackerNames, validateOgnAccount } from '@flyxc/common';
import { ChainableCommander } from 'ioredis';
import { LivePoint, makeLiveTrack } from './live-track';
import { OgnClient } from './ogn-client';
import type { protos, TrackerNames } from '@flyxc/common';
import { validateOgnAccount } from '@flyxc/common';
import type { ChainableCommander } from 'ioredis';
import type { LivePoint } from './live-track';
import { makeLiveTrack } from './live-track';
import type { OgnClient } from './ogn-client';
import { OgnPusher } from './ogn-push';
import { TrackerFetcher, TrackerUpdates } from './tracker';
import type { TrackerUpdates } from './tracker';
import { TrackerFetcher } from './tracker';

// Push positions to OGN.
let ognPusher: OgnPusher | undefined;
Expand Down
8 changes: 4 additions & 4 deletions apps/fetcher/src/app/trackers/refresh.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { protos } from '@flyxc/common';
import {
Keys,
LIVE_AGE_OLD_SEC,
Expand All @@ -7,13 +8,12 @@ import {
LIVE_TRACKER_RETENTION_SEC,
SecretKeys,
mergeLiveTracks,
protos,
removeBeforeFromLiveTrack,
simplifyLiveTrack,
} from '@flyxc/common';
import { pushListCap } from '@flyxc/common-node';
import { Datastore } from '@google-cloud/datastore';
import { ChainableCommander, Redis } from 'ioredis';
import type { Datastore } from '@google-cloud/datastore';
import type { ChainableCommander, Redis } from 'ioredis';
import { patchLastFixAGL } from '../elevation/elevation';
import { addElevationLogs } from '../redis';
import { FlymasterFetcher } from './flymaster';
Expand All @@ -23,7 +23,7 @@ import { OgnFetcher } from './ogn';
import { OGN_HOST, OGN_PORT, OgnClient } from './ogn-client';
import { SkylinesFetcher } from './skylines';
import { SpotFetcher } from './spot';
import { TrackerUpdates } from './tracker';
import type { TrackerUpdates } from './tracker';
import { XcontestFetcher } from './xcontest';
import { ZoleoFetcher } from './zoleo';

Expand Down
Loading
Loading