Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Test graph view #43

Merged
merged 19 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2ac76c6
test-graph-view | test remove everything and start bottom up _1
marcosantiagomuro Sep 28, 2023
c423e82
test-graph-view | clean code and set map _2
marcosantiagomuro Sep 29, 2023
2d664b8
test-graph-view | started putting map + graph on road details view
marcosantiagomuro Sep 29, 2023
dcdcf89
test-graph-view | tried improving graph + resizeable components
marcosantiagomuro Oct 1, 2023
ea13e5f
test-graph-view | graph in middle now resizeable to do
marcosantiagomuro Oct 2, 2023
9478b72
test-graph-view | first resize, to be improved
marcosantiagomuro Oct 2, 2023
7b491bf
test-graph-view | test resize, to be improved, not ok
marcosantiagomuro Oct 2, 2023
5ce61d6
add split component
marcosantiagomuro Oct 5, 2023
ce3eca9
test-graph-view | test resize, map to be fixed
marcosantiagomuro Oct 5, 2023
01050f5
add split component
marcosantiagomuro Oct 5, 2023
814f6f4
test-graph-view | removed dummy data, map to be fixed
marcosantiagomuro Oct 5, 2023
e501e66
test-graph-view | backend now fetches data for graph with this query …
marcosantiagomuro Oct 5, 2023
a3ed4ee
test-graph-view | updated backhand query + graph showing correct valu…
marcosantiagomuro Oct 5, 2023
d434a78
test-graph-view | updated backend with 2 types, updated frontend with…
marcosantiagomuro Oct 7, 2023
ddb699a
test-graph-view | improved graph with 2 axis, refeactored code (remov…
marcosantiagomuro Oct 8, 2023
5427395
test-graph-view | code cleanup in backend and frontend + dependencies
marcosantiagomuro Oct 8, 2023
2505497
ForceMapUpdate: Allow to force update the map or to go to specific po…
Seb-sti1 Oct 8, 2023
58d656f
test-graph-view | added force map update on conditions map to trigger…
marcosantiagomuro Oct 8, 2023
108baa0
test-graph-view | integration with dev
marcosantiagomuro Oct 8, 2023
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: 1 addition & 2 deletions backend/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AppService } from './app.service';

import { KnexModule } from 'nestjs-knex';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { DB_LIRAMAP_CONFIG, POSTGIS_DB_CONFIG } from './database';
import { DB_LIRAMAP_CONFIG } from './database';

const database = (config: any, name: string) => {
return KnexModule.forRootAsync(
Expand All @@ -22,7 +22,6 @@ describe('AppController', () => {
const app: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot(),
database(POSTGIS_DB_CONFIG, 'postgis'),
database(DB_LIRAMAP_CONFIG, 'lira-map'),
],
controllers: [AppController],
Expand Down
8 changes: 2 additions & 6 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AppService } from './app.service';
import { RCController } from './conditions/rc.controller';
import { RCService } from './conditions/rc.service';

import { DB_LIRAMAP_CONFIG, POSTGIS_DB_CONFIG } from './database';
import { DB_LIRAMAP_CONFIG } from './database';

const database = (config: any, name: string) => {
return KnexModule.forRootAsync(
Expand All @@ -20,11 +20,7 @@ const database = (config: any, name: string) => {
};

@Module({
imports: [
ConfigModule.forRoot(),
database(POSTGIS_DB_CONFIG, 'postgis'),
database(DB_LIRAMAP_CONFIG, 'lira-map'),
],
imports: [ConfigModule.forRoot(), database(DB_LIRAMAP_CONFIG, 'lira-map')],
controllers: [AppController, RCController],
providers: [AppService, ConfigService, RCService],
})
Expand Down
3 changes: 1 addition & 2 deletions backend/src/conditions/rc.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RCService } from './rc.service';

import { KnexModule } from 'nestjs-knex';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { DB_LIRAMAP_CONFIG, POSTGIS_DB_CONFIG } from '../database';
import { DB_LIRAMAP_CONFIG } from '../database';

const database = (config: any, name: string) => {
return KnexModule.forRootAsync(
Expand All @@ -23,7 +23,6 @@ describe('Road Condition Controller', () => {
const app: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot(),
database(POSTGIS_DB_CONFIG, 'postgis'),
database(DB_LIRAMAP_CONFIG, 'lira-map'),
],
controllers: [RCController],
Expand Down
18 changes: 4 additions & 14 deletions backend/src/conditions/rc.controller.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import { Controller, Get, Query } from '@nestjs/common';

import { Condition, WaysConditions } from 'src/models';
import { Condition } from 'src/models';
import { RCService } from './rc.service';

@Controller('conditions')
export class RCController {
constructor(private readonly service: RCService) {}

@Get('ways')
getWaysConditions(
@Query() query: { type: string; zoom: string },
): Promise<WaysConditions> {
const { type, zoom } = query;
return this.service.getWaysConditions(type, zoom);
}

@Get('way')
getWayConditions(
@Query() query: { wayId: string; type: string },
): Promise<Condition[]> {
const { wayId, type } = query;
return this.service.getWayRoadConditions(wayId, type);
getWayConditions(@Query() query: { dbId: string }): Promise<Condition[]> {
const { dbId } = query;
return this.service.getWayRoadConditions(dbId);
}

@Get('')
Expand Down
107 changes: 24 additions & 83 deletions backend/src/conditions/rc.service.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,35 @@
import { Injectable } from '@nestjs/common';

import { InjectConnection, Knex } from 'nestjs-knex';
import { Condition, LatLngDist, WayId, WaysConditions } from 'src/models';
import groupBy from '../util';
import { RoadConditions, Ways, ZoomConditions, Conditions2 } from '../tables';
import { Condition } from 'src/models';
import { Conditions2, Conditions } from '../tables';

import knexPostgis = require('knex-postgis');

@Injectable()
export class RCService {
constructor(
@InjectConnection('postgis') private readonly knex: Knex,
@InjectConnection('lira-map') private readonly knex_liramap: Knex,
) {}
constructor(@InjectConnection('lira-map') private readonly liramap: Knex) {}

async getWays(
wayIds: string[],
): Promise<[{ [key: WayId]: LatLngDist[] }, { [key: WayId]: number }]> {
const ways = await Ways(this.knex)
.select(
'id as way_id',
this.knex.raw(
"ST_AsGeoJSON((ST_DumpPoints(geom)).geom)::json->'coordinates' as pos",
),
this.knex.raw(
'ST_LineLocatePoint(geom, (ST_DumpPoints(geom)).geom) as way_dist',
),
this.knex.raw('ST_Length(geom::geography) as length'),
)
.whereIn('id', wayIds)
.orderBy(this.knex.raw('id::integer') as any);

return [
groupBy<any, LatLngDist>(ways, 'way_id', (cur: any) => ({
lat: cur.pos[1],
lng: cur.pos[0],
way_dist: cur.way_dist,
})),
ways.reduce((acc, cur) => {
acc[cur.way_id] = cur.length;
return acc;
}, {}),
];
}

async getWayRoadConditions(
way_id: string,
type: string,
): Promise<Condition[]> {
return RoadConditions(this.knex)
.select('way_id', 'way_dist', 'value')
.where({ type: type, way_id: way_id })
.orderBy('way_dist');
}

async getZoomConditions(
type: string,
zoom: string,
): Promise<{ [key: WayId]: Condition[] }> {
const res = await ZoomConditions(this.knex)
.select('way_id', 'way_dist', 'value')
.where({ type: type, zoom: parseInt(zoom, 10) })
.orderBy('way_dist');
return groupBy(res, 'way_id', ({ way_dist, value }) => ({
way_dist,
value,
}));
}

async getWaysConditions(type: string, zoom: string): Promise<WaysConditions> {
const zoomConditions = await this.getZoomConditions(type, zoom);
const wayIds = Object.keys(zoomConditions);
const [ways, way_lengths] = await this.getWays(wayIds);

return wayIds.reduce(
(acc, way_id) => {
{
acc.way_ids.push(way_id);
acc.way_lengths.push(way_lengths[way_id]);
acc.geometry.push(ways[way_id]);
acc.conditions.push(zoomConditions[way_id]);
}
return acc;
},
{
way_ids: [],
way_lengths: [],
geometry: [],
conditions: [],
} as WaysConditions,
async getWayRoadConditions(dbId: string): Promise<Condition[]> {
return (
Conditions(this.liramap)
.select(
'cond1.value as KPI',
'cond2.value as DI',
'cond1.distance01 as way_dist',
)
.join(
'condition_coverages as cond2',
'cond1.distance01',
'=',
'cond2.distance01',
)
.where('cond1.type', 'KPI')
.where('cond2.type', 'DI')
.where(this.liramap.raw('cond1.fk_way_id = cond2.fk_way_id'))
// .where('cond1.distance01', '<>', 0)
.where('cond1.fk_way_id', dbId)
.orderBy('cond1.distance01')
);
}

Expand All @@ -102,7 +43,7 @@ export class RCService {
valid_after: string,
computed_after: string,
) {
const db = this.knex_liramap;
const db = this.liramap;
const st = knexPostgis(db);

let res;
Expand Down
14 changes: 0 additions & 14 deletions backend/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as dotenv from 'dotenv';
dotenv.config();

const {
DB_USER_POSTGIS,
DB_PWD_POSTGIS,
DB_LIRAMAP_HOST,
DB_LIRAMAP_PORT,
DB_LIRAMAP_NAME,
Expand Down Expand Up @@ -41,18 +39,6 @@ const BASE_CONFIG = {
},
};

export const POSTGIS_DB_CONFIG = {
...BASE_CONFIG,
connection: {
host: 'liradb.postgres.database.azure.com',
port: 5432,
user: DB_USER_POSTGIS,
password: DB_PWD_POSTGIS,
database: 'postgis',
ssl: true,
},
};

export const DB_LIRAMAP_CONFIG = {
...BASE_CONFIG,
connection: {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ export const ZoomConditions = (k: Knex) =>
// [email protected]: This is for PostGIS in the LiRAMap (LiraVis) database
export interface Condition_Coverage {
id: string;
fk_way_id: string;
type: string;
value: number;
section_geom: Geometry;
compute_time: Date;
}

export const Conditions = (k: Knex) =>
k.from<Condition_Coverage>('condition_coverages');
k.from<Condition_Coverage>('condition_coverages as cond1');

export const Conditions2 = (k: Knex) =>
k.from<Condition_Coverage>('coverage_values');
1 change: 1 addition & 0 deletions frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
Expand Down
18 changes: 18 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"react-router-dom": "^6.16.0",
"react-scripts": "^5.0.1",
"react-slider": "^2.0.6",
"react-split": "^2.0.14",
"typescript": "^4.9.5",
"web-vitals": "^3.4.0"
},
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/Components/Map/ForceMapUpdate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { LatLng } from '../../models/models';
import { useMap } from 'react-leaflet';
import React, { useEffect } from 'react';

interface Props {
/** A modification of this value is used to trigger an update of the map */
triggerUpdate: number;
/** The coordinates of the map center*/
position?: LatLng;
}

/**
* This component is used to force an update of the map. It is used in conjunction with the useMap hook.
*/
const ForceMapUpdate: React.FC<Props> = ({ triggerUpdate, position }) => {
const map = useMap();

useEffect(() => {
console.log('hello');
map.invalidateSize();
}, [triggerUpdate]);

useEffect(() => {
if (position) {
map.flyTo(position);
}
}, [position]);

return null;
};

export default ForceMapUpdate;
46 changes: 0 additions & 46 deletions frontend/src/Components/Palette/PaletteEditor.tsx

This file was deleted.

Loading