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

Commit

Permalink
Add new DB, interfaces and types (#99)
Browse files Browse the repository at this point in the history
- Cleanup tables interfaces and types
- Add our database
  • Loading branch information
Seb-sti1 authored Nov 6, 2023
1 parent aacb1c4 commit 5c78ef6
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 155 deletions.
8 changes: 6 additions & 2 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 } from './database';
import { DB_GROUPD_CONFIG, DB_LIRAMAP_CONFIG } from './database';
import { RoadController } from './roads/road.controller';
import { RoadService } from './roads/road.service';

Expand All @@ -22,7 +22,11 @@ const database = (config: any, name: string) => {
};

@Module({
imports: [ConfigModule.forRoot(), database(DB_LIRAMAP_CONFIG, 'lira-map')],
imports: [
ConfigModule.forRoot(),
database(DB_LIRAMAP_CONFIG, 'lira-map'),
database(DB_GROUPD_CONFIG, 'group-d'),
],
controllers: [AppController, RCController, RoadController],
providers: [AppService, ConfigService, RCService, RoadService],
})
Expand Down
4 changes: 2 additions & 2 deletions backend/src/conditions/rc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';

import { InjectConnection, Knex } from 'nestjs-knex';
import { Condition } from 'src/models';
import { Conditions, Conditions2 } from '../tables';
import { Conditions, CoverageValues } from '../tables';
import knexPostgis = require('knex-postgis');

@Injectable()
Expand Down Expand Up @@ -47,7 +47,7 @@ export class RCService {

let res;
try {
let query = Conditions2(db)
let query = CoverageValues(db)
.select(
'coverage_values.id',
'type',
Expand Down
28 changes: 23 additions & 5 deletions backend/src/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as dotenv from 'dotenv';
import * as process from 'process';

dotenv.config();

const {
Expand All @@ -7,11 +9,16 @@ const {
DB_LIRAMAP_NAME,
DB_LIRAMAP_USER,
DB_LIRAMAP_PASSWORD,
DB_GROUPD_HOST,
DB_GROUPD_PORT,
DB_GROUPD_NAME,
DB_GROUPD_USER,
DB_GROUPD_PASSWORD,
} = process.env;

const BASE_CONFIG = {
client: 'pg',
debug: true,
debug: process.env.NESTJS_DEBUG !== 'false',
useNullAsDefault: true,
pool: {
min: 2,
Expand All @@ -25,16 +32,16 @@ const BASE_CONFIG = {
},
log: {
warn(msg: any) {
console.log('warning', msg);
console.warn(msg);
},
error(msg: any) {
console.log('error', msg);
console.error(msg);
},
deprecate(msg: any) {
console.log('deprecate', msg);
console.warn('deprecate:', msg);
},
debug(msg: any) {
console.log('debug', msg);
console.debug(msg);
},
},
};
Expand All @@ -49,3 +56,14 @@ export const DB_LIRAMAP_CONFIG = {
password: DB_LIRAMAP_PASSWORD,
},
};

export const DB_GROUPD_CONFIG = {
...BASE_CONFIG,
connection: {
host: DB_GROUPD_HOST,
port: DB_GROUPD_PORT,
database: DB_GROUPD_NAME,
user: DB_GROUPD_USER,
password: DB_GROUPD_PASSWORD,
},
};
171 changes: 59 additions & 112 deletions backend/src/models.ts
Original file line number Diff line number Diff line change
@@ -1,129 +1,76 @@
/**
* The latitude and longitude of a point.
*/
export interface LatLng {
lat: number;
lng: number;
}

export interface LatLon {
lat: number;
lon: number;
}

export interface PointData extends LatLng {
properties?: PointProperties;
value?: number;
metadata?: any;
}

export type Path = PointData[];

export enum RendererName {
circle = 'circle',
circles = 'circles',
rectangles = 'rectangles',
line = 'line',
hotline = 'hotline',
hotpoints = 'hotpoints',
}

export interface PaletteColor {
offset: number;
color: string;
stopValue?: number;
}
export type Palette = PaletteColor[];

// Rendering properties of a single point belonging to a Path
// If an attribute is defined for a point, it overwrites the properties for the path
export interface PointProperties {
// Color of a point or the entire path
color?: string;
// Radius or largeness of a point or the entire path
width?: number;
// Weight (boldness) of a point or the entire path
weight?: number;
// Opacity (between 0 and 1) of a point or the entire path
opacity?: number;
}

// Rendering properties of an entire Path
export interface PathProperties extends PointProperties {
// The name of the renderer to use - see ./renderers for the list of names
rendererName: RendererName;
// Weight can be multiplied by the dilatationFactor
// < 1 -> shrinks ; > 1 -> grows ; == 1 -> stays the same
dilatationFactor?: number;
// Palette used for coloring the path and graph
palette?: Palette;
}

export interface Measurement extends PathProperties {
// measurement as it is in the database
dbName: string;
// human friendly name of the measurement
name: string;
// Needs to be specified if the points have a value attached to them
hasValue?: boolean;
}

export type Position3D = {
x: number;
y: number;
z: number;
};

export interface LatLngDist extends LatLng {
way_dist: number;
}

export interface LatLonDist extends LatLon {
way_dist: number;
}

export interface ValueLatLng extends LatLng {
value: number;
}

/**
* Used in the data plot to show the condition of a road.
* The way_dist is the distance from the start of the way. It will be the x-axis in the plot.
* The value is the condition value. It will be the y-axis in the plot.
*/
export interface Condition {
way_dist: number;
value: number;
}

/**
* The OSM id of a way.
*/
export type WayId = string;

export interface WaysConditions {
way_lengths: number[];
way_ids: WayId[];
geometry: LatLngDist[][];
conditions: Condition[][];
}

export interface MapBounds {
minLat: number;
maxLat: number;
minLng: number;
maxLng: number;
}

// geometry: LatLng[][]
// wayIds: WayId[]
// conditions:

export interface BoundedCondition {
conditions: { [condition_type: string]: Condition[] };
length: number;
coordinates: LatLonDist[];
}

/**
* The description of a road
* The way_ids are the ids of the ways of each branch of the way. Can be the two directions or when a road
* split into two branches.
*
* Example:
* /---<---\
* ---------- -----------
* \--->---/
*
* The list of point for the geometry of each way.
*/
export interface Road {
// the name of the road
way_name: string;
// the ids of the ways of each branch of the way. Can be the two directions or when a road
// split into two branches
// Example:
// /---<---\
// ----------- -----------
// \--->---/
way_ids: WayId[][];
// the geometry of each way
geometries: Record<WayId, LatLng[]>;
}

/**
* The image types.
*/
export enum ImageType {
Image3D,
ImageInt,
ImageRng,
Overlay3D,
OverlayInt,
OverlayRng,
}

/**
* The measurement types.
*/
export enum MeasurementType {
Rutting = 1,
MacroTexture = 2,
LaneMarking = 3,
RumbleStrip = 4,
Potholes = 5,
DropOffCurb = 6,
Joint = 7,
Raveling = 8,
Roughness = 9,
RoadGeometry = 10,
WaterEntrapment = 11,
Shoving = 12,
PickOut = 13,
Bleeding = 14,
SealedCrack = 15,
Manholes = 16,
Patch = 17,
Pumping = 18,
}
Loading

0 comments on commit 5c78ef6

Please sign in to comment.