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

Revert "feat: dynamic point data entity + gauge layer AB#25124" #1473

Merged
merged 1 commit into from
Nov 29, 2023
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
1 change: 0 additions & 1 deletion interfaces/IBF-dashboard/src/app/types/ibf-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export enum IbfLayerName {
schools = 'schools',
waterpointsInternal = 'waterpoints_internal',
roads = 'roads',
gauges = 'gauges',
}

export enum IbfLayerLabel {
Expand Down
47 changes: 0 additions & 47 deletions services/API-service/migration/1701157179286-DynamicPointData.ts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import {
IsNotEmpty,
IsOptional,
IsString,
ValidateNested,
} from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { LeadTime } from '../../admin-area-dynamic-data/enum/lead-time.enum';
import { DisasterType } from '../../disaster/disaster-type.enum';
import { PointDataEnum } from '../point-data.entity';
import { Type } from 'class-transformer';

export class UploadAssetExposureStatusDto {
@ApiProperty({ example: ['123', '234'] })
Expand Down Expand Up @@ -41,37 +39,3 @@ export class UploadAssetExposureStatusDto {
@IsEnum(PointDataEnum)
public pointDataCategory: PointDataEnum;
}

export class UploadDynamicPointDataDto {
@ApiProperty({ example: LeadTime.hour1 })
@IsOptional()
@IsString()
public leadTime: LeadTime;

@ApiProperty({ example: new Date() })
@IsOptional()
public date: Date;

@ApiProperty({ example: DisasterType.FlashFloods })
@IsNotEmpty()
@IsEnum(DisasterType)
public disasterType: DisasterType;

@ApiProperty({ example: 'waterLevel' })
public key: string;

@ApiProperty({ example: [{ fid: 1, value: 100 }] })
@IsArray()
@ValidateNested()
@Type(() => DynamicPointData)
public dynamicPointData: DynamicPointData[];
}

export class DynamicPointData {
@ApiProperty()
@IsNotEmpty()
public fid: string;

@ApiProperty()
public value: string;
}
20 changes: 0 additions & 20 deletions services/API-service/src/api/point-data/dto/upload-gauge.dto.ts

This file was deleted.

This file was deleted.

18 changes: 1 addition & 17 deletions services/API-service/src/api/point-data/point-data.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ import { RolesGuard } from '../../roles.guard';
import { GeoJson } from '../../shared/geo.model';
import { UserRole } from '../user/user-role.enum';
import { PointDataService } from './point-data.service';
import {
UploadAssetExposureStatusDto,
UploadDynamicPointDataDto,
} from './dto/upload-asset-exposure-status.dto';
import { UploadAssetExposureStatusDto } from './dto/upload-asset-exposure-status.dto';
import { FILE_UPLOAD_API_FORMAT } from '../../shared/file-upload-api-format';

@ApiBearerAuth()
Expand Down Expand Up @@ -135,17 +132,4 @@ export class PointDataController {
): Promise<void> {
return await this.pointDataService.uploadAssetExposureStatus(assetFids);
}

@UseGuards(RolesGuard)
@ApiOperation({ summary: 'Upload dynamic point data' })
@ApiResponse({
status: 201,
description: 'Uploaded dynamic point data.',
})
@Post('dynamic')
public async uploadDynamicPointData(
@Body() dynamicPointData: UploadDynamicPointDataDto,
): Promise<void> {
return await this.pointDataService.uploadDynamicPointData(dynamicPointData);
}
}
10 changes: 1 addition & 9 deletions services/API-service/src/api/point-data/point-data.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { DynamicPointDataEntity } from './dynamic-point-data.entity';
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';

export enum PointDataEnum {
evacuationCenters = 'evacuation_centers',
Expand All @@ -9,7 +8,6 @@ export enum PointDataEnum {
communityNotifications = 'community_notifications',
schools = 'schools',
waterpointsInternal = 'waterpoints_internal',
gauges = 'gauges',
}

@Entity('point-data')
Expand All @@ -31,10 +29,4 @@ export class PointDataEntity {

@Column('json', { nullable: true })
public geom: JSON;

@OneToMany(
(): typeof DynamicPointDataEntity => DynamicPointDataEntity,
(dynamicData): PointDataEntity => dynamicData.point,
)
public dynamicData: DynamicPointDataEntity[];
}
7 changes: 1 addition & 6 deletions services/API-service/src/api/point-data/point-data.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ import { PointDataEntity } from './point-data.entity';
import { PointDataService } from './point-data.service';
import { PointDataDynamicStatusEntity } from './point-data-dynamic-status.entity';
import { HttpModule } from '@nestjs/axios';
import { DynamicPointDataEntity } from './dynamic-point-data.entity';

@Module({
imports: [
HttpModule,
UserModule,
TypeOrmModule.forFeature([
PointDataEntity,
PointDataDynamicStatusEntity,
DynamicPointDataEntity,
]),
TypeOrmModule.forFeature([PointDataEntity, PointDataDynamicStatusEntity]),
WhatsappModule,
],
providers: [PointDataService, HelperService],
Expand Down
77 changes: 7 additions & 70 deletions services/API-service/src/api/point-data/point-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { validate } from 'class-validator';
import { GeoJson } from '../../shared/geo.model';
import { HelperService } from '../../shared/helper.service';
import { IsNull, MoreThanOrEqual, Repository } from 'typeorm';
import { MoreThanOrEqual, Repository } from 'typeorm';
import { EvacuationCenterDto } from './dto/upload-evacuation-centers.dto';
import { PointDataEntity, PointDataEnum } from './point-data.entity';
import { DamSiteDto } from './dto/upload-dam-sites.dto';
Expand All @@ -13,23 +13,16 @@ import { CommunityNotificationDto } from './dto/upload-community-notifications.d
import { WhatsappService } from '../notification/whatsapp/whatsapp.service';
import { SchoolDto } from './dto/upload-schools.dto';
import { WaterpointDto } from './dto/upload-waterpoint.dto';
import {
UploadAssetExposureStatusDto,
UploadDynamicPointDataDto,
} from './dto/upload-asset-exposure-status.dto';
import { UploadAssetExposureStatusDto } from './dto/upload-asset-exposure-status.dto';
import { PointDataDynamicStatusEntity } from './point-data-dynamic-status.entity';
import { DisasterType } from '../disaster/disaster-type.enum';
import { GaugeDto } from './dto/upload-gauge.dto';
import { DynamicPointDataEntity } from './dynamic-point-data.entity';

@Injectable()
export class PointDataService {
@InjectRepository(PointDataEntity)
private readonly pointDataRepository: Repository<PointDataEntity>;
@InjectRepository(PointDataDynamicStatusEntity)
private readonly pointDataDynamicStatusRepo: Repository<PointDataDynamicStatusEntity>;
@InjectRepository(DynamicPointDataEntity)
private readonly dynamicPointDataRepository: Repository<DynamicPointDataEntity>;

public constructor(
private readonly helperService: HelperService,
Expand All @@ -54,38 +47,20 @@ export class PointDataService {
selectColumns.push('geom');
selectColumns.push('"pointDataId"');

const recentDate = await this.helperService.getRecentDate(
countryCodeISO3,
disasterType,
);

const pointDataQuery = this.pointDataRepository
.createQueryBuilder('point')
.select(selectColumns)
.where({
pointDataCategory: pointDataCategory,
countryCodeISO3: countryCodeISO3,
})
.leftJoin(
(subquery) => {
return subquery
.select([
'dynamic."pointPointDataId"',
'json_object_agg("key",value) as "dynamicData"',
])
.from(DynamicPointDataEntity, 'dynamic')
.where('dynamic.timestamp = :modelTimestamp', {
modelTimestamp: recentDate.timestamp,
})
.groupBy('dynamic."pointPointDataId"');
},
'dynamic',
'dynamic."pointPointDataId" = point."pointDataId"',
)
.addSelect('dynamic."dynamicData" as "dynamicData"');
});

// TO DO: hard-code for now
if (disasterType === DisasterType.FlashFloods) {
const recentDate = await this.helperService.getRecentDate(
countryCodeISO3,
disasterType,
);
pointDataQuery
.leftJoin(
PointDataDynamicStatusEntity,
Expand Down Expand Up @@ -120,8 +95,6 @@ export class PointDataService {
return new SchoolDto();
case PointDataEnum.waterpointsInternal:
return new WaterpointDto();
case PointDataEnum.gauges:
return new GaugeDto();
default:
throw new HttpException(
'Not a known point layer',
Expand Down Expand Up @@ -286,40 +259,4 @@ export class PointDataService {
}
await this.pointDataDynamicStatusRepo.save(assetForecasts);
}

async uploadDynamicPointData(dynamicPointData: UploadDynamicPointDataDto) {
const dynamicPointDataArray: DynamicPointDataEntity[] = [];

for (const point of dynamicPointData.dynamicPointData) {
const asset = await this.pointDataRepository.findOne({
where: {
referenceId: Number(point.fid), // TODO: make sure this is unique
},
});
if (!asset) {
continue;
}

// Delete existing entries
await this.dynamicPointDataRepository.delete({
point: { pointDataId: asset.pointDataId },
leadTime: dynamicPointData.leadTime || IsNull(),
timestamp: MoreThanOrEqual(
this.helperService.getUploadCutoffMoment(
dynamicPointData.disasterType,
dynamicPointData.date || new Date(),
),
),
});

const dynamicPoint = new DynamicPointDataEntity();
dynamicPoint.key = dynamicPointData.key;
dynamicPoint.leadTime = dynamicPointData.leadTime;
dynamicPoint.timestamp = dynamicPointData.date || new Date();
dynamicPoint.value = point.value;
dynamicPoint.point = asset;
dynamicPointDataArray.push(dynamicPoint);
}
await this.dynamicPointDataRepository.save(dynamicPointDataArray);
}
}

This file was deleted.

Loading
Loading