Skip to content

Commit

Permalink
feat: reading from influx
Browse files Browse the repository at this point in the history
  • Loading branch information
VilemRaska committed Jan 27, 2025
1 parent 7013035 commit 8d91e7e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GAPP/apps/gapp-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const app = async (fastify: FastifyInstance, opts: AppOptions) => {
token: opts.influxDbToken,
org: opts.influxDbOrg,
});
await fastify.register(sondehubPlugin, { dev: false });
await fastify.register(sondehubPlugin, { dev: true });
await fastify.register(carsServicePlugin);
await fastify.register(telemetryServicePlugin);

Expand Down
2 changes: 2 additions & 0 deletions GAPP/apps/gapp-server/src/services/cars.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { InfluxDB, Point, QueryApi, WriteApi } from '@influxdata/influxdb-client
import { InfluxDbServiceBase } from '../utils/influxdb-service-base';
import { Organization } from '@influxdata/influxdb-client-apis';
import { CarStatus } from '../schemas';
import { arrayAsString } from '../utils/array-as-atring';

export class CarsService extends InfluxDbServiceBase {
private writeAPi: WriteApi;
Expand Down Expand Up @@ -36,6 +37,7 @@ export class CarsService extends InfluxDbServiceBase {
console.log(callsigns);
const query = `from(bucket: "cars")
|> range(start: -24h)
|> filter(fn: (r) => contains(value: r.callsign, set: ${arrayAsString(callsigns)}))
|> last()
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> keep(columns: ["_time", "altitude", "longitude", "latitude", "callsign"])`;
Expand Down
3 changes: 3 additions & 0 deletions GAPP/apps/gapp-server/src/utils/array-as-atring.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const arrayAsString = (array: (string | number)[]): string => {
return `["${array.join('","')}"]`;
};
4 changes: 3 additions & 1 deletion GAPP/libs/sondehub/src/lib/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface BasePacket {
}

export interface TelemetryPacket extends Partial<BasePacket> {
dev?: boolean;
dev?: string;
time_received?: string;
payload_callsign: string;
datetime: string;
Expand Down Expand Up @@ -238,6 +238,8 @@ export class Uploader {
enhancedPacket.time_received = new Date().toISOString();
}

enhancedPacket.dev = packet.dev ?? this.uploaderConfig.dev ? 'true' : 'false';

return enhancedPacket;
}

Expand Down

0 comments on commit 8d91e7e

Please sign in to comment.