Skip to content

Commit

Permalink
Refactor approach to calculate alert values
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Mar 17, 2024
1 parent 2cb79de commit ab4f5de
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 285 deletions.
23 changes: 18 additions & 5 deletions api/src/modules/eudr-alerts/alerts.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { DataSource } from 'typeorm';
import { AlertsOutput } from 'modules/eudr-alerts/dto/alerts-output.dto';
import {
AlertedGeoregionsBySupplier,
EUDRAlertDatabaseResult,
EUDRAlertDates,
IEUDRAlertsRepository,
Expand Down Expand Up @@ -57,12 +58,24 @@ export class AlertsRepository implements IEUDRAlertsRepository {
this.createQueryBuilder(dto);
// TODO: Make field selection dynamic
queryBuilder.from(this.baseDataset, 'alerts');
queryBuilder.select('alertdate', 'alertDate');
queryBuilder.addSelect('alertconfidence', 'alertConfidence');
queryBuilder.addSelect('year', 'alertYear');
queryBuilder.addSelect('alertcount', 'alertCount');
queryBuilder.select('alert_date', 'alertDate');
queryBuilder.addSelect('supplierid', 'supplierId');
queryBuilder.addSelect('alert_count', 'alertCount');
queryBuilder.addSelect('georegionid', 'geoRegionId');
queryBuilder.orderBy('alertdate', 'ASC');
queryBuilder.orderBy('alert_date', 'ASC');
return this.query(queryBuilder);
}

async getAlertedGeoRegionsBySupplier(dto: {
supplierIds: string[];
startAlertDate: Date;
endAlertDate: Date;
}): Promise<AlertedGeoregionsBySupplier[]> {
const queryBuilder: BigQueryAlertsQueryBuilder =
this.createQueryBuilder(dto);
queryBuilder.from(this.baseDataset, 'alerts');
queryBuilder.select('georegionid', 'geoRegionId');
queryBuilder.addSelect('supplierid', 'supplierId');
return this.query(queryBuilder);
}

Expand Down
Loading

0 comments on commit ab4f5de

Please sign in to comment.