Skip to content

Commit

Permalink
V1 Ressources influencées ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlaine committed Nov 19, 2024
1 parent 998d696 commit b92fe72
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/zones/dto/zone.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class ZoneDto {
})
TypeZAS: string;

@ApiProperty({ example: true, description: "Cette ressource naturelle est-elle influencée / stockée ?" })
ressourceInfluencee: boolean;

@ApiProperty({
enum: ['vigilance', 'alerte', 'alerte_renforcee', 'crise'],
example: 'alerte_renforcee',
Expand Down
3 changes: 3 additions & 0 deletions src/zones/entities/zone_alerte_computed.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class ZoneAlerteComputed extends BaseEntity {
@Column({ nullable: false, length: 50 })
type: 'SOU' | 'SUP' | 'AEP';

@Column({ default: false, nullable: false })
ressourceInfluencee: boolean;

@Column({ default: false })
enabled: boolean;

Expand Down
27 changes: 15 additions & 12 deletions src/zones/zones.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { MoreThan, Repository } from 'typeorm';
import { FindOneOptions, MoreThan, Repository } from 'typeorm';
import computeBbox from '@turf/bbox';
import { VigieauLogger } from '../logger/vigieau.logger';
import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
Expand Down Expand Up @@ -36,7 +36,7 @@ export class ZonesService {
private readonly dataService: DataService,
private readonly communesService: CommunesService,
@InjectRepository(ArreteMunicipal)
private readonly arreteMunicipalRepository: Repository<ArreteMunicipal>,) {
private readonly arreteMunicipalRepository: Repository<ArreteMunicipal>) {
this.loadAllZones(true);
}

Expand Down Expand Up @@ -97,9 +97,9 @@ export class ZonesService {
.filter(feature => booleanPointInPolygon([lon, lat], feature))
.map(feature => this.zonesIndex[feature.properties.idZone]);

const sup = zones.filter(z => z.type === 'SUP');
const sou = zones.filter(z => z.type === 'SOU');
const aep = zones.filter(z => z.type === 'AEP');
const sup = zones.filter(z => !z.ressourceInfluencee && z.type === 'SUP');
const sou = zones.filter(z => !z.ressourceInfluencee && z.type === 'SOU');
const aep = zones.filter(z => !z.ressourceInfluencee && z.type === 'AEP');

if (sup.length <= 1 && sou.length <= 1 && aep.length <= 1) {
return zones;
Expand All @@ -122,9 +122,9 @@ export class ZonesService {
return [];
}

const sup = zones.filter(z => z.type === 'SUP');
const sou = zones.filter(z => z.type === 'SOU');
const aep = zones.filter(z => z.type === 'AEP');
const sup = zones.filter(z => !z.ressourceInfluencee && z.type === 'SUP');
const sou = zones.filter(z => !z.ressourceInfluencee && z.type === 'SOU');
const aep = zones.filter(z => !z.ressourceInfluencee && z.type === 'AEP');

if (sup.length <= 1 && sou.length <= 1 && aep.length <= 1) {
return zones;
Expand Down Expand Up @@ -154,6 +154,7 @@ export class ZonesService {
.addSelect('zone_alerte_computed.code', 'code')
.addSelect('zone_alerte_computed.nom', 'nom')
.addSelect('zone_alerte_computed.type', 'type')
.addSelect('zone_alerte_computed.ressourceInfluencee', 'ressourceInfluencee')
.addSelect('zone_alerte_computed.niveauGravite', 'niveauGravite')
.addSelect(
'ST_AsGeoJSON(ST_TRANSFORM(zone_alerte_computed.geom, 4326))',
Expand All @@ -168,7 +169,7 @@ export class ZonesService {
for (let i = 0; i < zonesWithRestrictions.length; i += batchSize) {
this.logger.log(`LOADING ALL ZONES & COMMUNES - MAPPING RESTRICTION - BATCH ${i}`);
await Promise.all(zonesWithRestrictions.slice(i, i + batchSize).map(async (zone) => {
const z = await this.zoneAlerteComputedRepository.findOne({
const z = await this.zoneAlerteComputedRepository.findOne(<FindOneOptions>{
where: {
id: zone.id,
restriction: {
Expand Down Expand Up @@ -229,6 +230,7 @@ export class ZonesService {
code: z.code,
nom: z.nom,
type: z.type,
ressourceInfluencee: z.ressourceInfluencee,
niveauGravite: z.niveauGravite,
departement: z.restriction?.arreteRestriction?.departement?.code,
arrete: {
Expand Down Expand Up @@ -282,6 +284,7 @@ export class ZonesService {
code: zone.code,
nom: zone.nom,
type: zone.type,
ressourceInfluencee: zone.ressourceInfluencee,
niveauGravite: zone.niveauGravite,
};
const bbox = computeBbox(geojson);
Expand Down Expand Up @@ -327,15 +330,15 @@ export class ZonesService {

const zonesFormated = zonesToReturn?.map(z => this.formatZone(z, profil, communeArreteMunicipal));

if(communeArreteMunicipal?.fichier?.url) {
if (communeArreteMunicipal?.fichier?.url) {
const zonesTypes = ['AEP', 'SOU', 'SUP'];
zonesTypes.forEach(zoneType => {
if(zonesFormated.findIndex(z => z.type === zoneType) < 0) {
if (zonesFormated.findIndex(z => z.type === zoneType) < 0) {
zonesFormated.push({
id: null,
type: zoneType,
arreteMunicipalCheminFichier: communeArreteMunicipal.fichier.url,
})
});
}
});
}
Expand Down

0 comments on commit b92fe72

Please sign in to comment.