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

Commit

Permalink
test-graph-view | updated backhand query + graph showing correct valu…
Browse files Browse the repository at this point in the history
…es, Split to be reviewed
  • Loading branch information
marcosantiagomuro committed Oct 5, 2023
1 parent cf937cb commit 6430c75
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 12 deletions.
4 changes: 2 additions & 2 deletions backend/src/conditions/rc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export class RCService {
type: string,
): Promise<Condition[]> {
return Conditions(this.knex_liramap)
.select('fk_way_id', 'type', 'value', 'compute_time')
.select('distance01 as way_dist', 'value')
.where({ type: type, fk_way_id: dbId })
.orderBy('compute_time');
.orderBy('distance01');
}

async getZoomConditions(
Expand Down
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
66 changes: 59 additions & 7 deletions frontend/src/Components/RoadConditions/ConditionsGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Title,
Tooltip,
} from 'chart.js';
import { Line } from 'react-chartjs-2';
import { Scatter } from 'react-chartjs-2';

import { ConditionType } from '../../models/graph';

Expand All @@ -28,8 +28,55 @@ Chart.register(
Tooltip,
Legend,
);
//const colorCode = '#1478BD';

const options = ({ name, min, max }: ConditionType): ChartOptions<'line'> => ({
// const dummyData = {
// data: {
// labels: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
// datasets: [
// {
// backgroundColor: colorCode,
// borderColor: colorCode,
// borderWidth: 2,
// data: [65, 59, 80, 81, 56, 65, 59, 80, 81, 56, 40, 56],
// },
// ],
// },
// options: {
// plugins: {
// legend: {
// display: true,
// label: 'data',
// },
// },
// scales: {
// x: {
// grid: {
// display: false,
// },
// beginAtZero: false,
// ticks: {
// color: colorCode,
// },
// },
// y: {
// grid: {
// display: false,
// },
// beginAtZero: true,
// ticks: {
// color: colorCode,
// },
// },
// },
// },
// };

const options = ({
name,
min,
max,
}: ConditionType): ChartOptions<'scatter'> => ({
responsive: true,
maintainAspectRatio: false,
plugins: {
Expand Down Expand Up @@ -64,11 +111,11 @@ const options = ({ name, min, max }: ConditionType): ChartOptions<'line'> => ({

interface Props {
type: ConditionType;
data: ChartData<'line', number[], number> | undefined;
data: ChartData<'scatter', number[], number> | undefined;
}

const ConditionsGraph: FC<Props> = ({ type, data }) => {
const ref = useRef<Chart<'line', number[], number>>(null);
const ref = useRef<Chart<'scatter', number[], number>>(null);

useEffect(() => {
if (ref.current === null) return;
Expand All @@ -77,7 +124,7 @@ const ConditionsGraph: FC<Props> = ({ type, data }) => {
}, [ref, data]);

// attach events to the graph options
const graphOptions: ChartOptions<'line'> = useMemo(
const graphOptions: ChartOptions<'scatter'> = useMemo(
() => ({
...options(type),
onClick: (
Expand All @@ -94,7 +141,7 @@ const ConditionsGraph: FC<Props> = ({ type, data }) => {
[],
);

const plugins: Plugin<'line'>[] = [
const plugins: Plugin<'scatter'>[] = [
{
id: 'id',
},
Expand All @@ -103,7 +150,12 @@ const ConditionsGraph: FC<Props> = ({ type, data }) => {
return (
<div className="road-conditions-graph">
{data && (
<Line ref={ref} data={data} options={graphOptions} plugins={plugins} />
<Scatter
ref={ref}
data={data}
options={graphOptions}
plugins={plugins}
/>
)}
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Components/RoadConditions/ConditionsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../../css/road_conditions.css';
interface Props {
type: ConditionType;
setWayData: React.Dispatch<
React.SetStateAction<ChartData<'line', number[], number> | undefined>
React.SetStateAction<ChartData<'scatter', number[], number> | undefined>
>;
}

Expand All @@ -28,6 +28,7 @@ const ConditionsMap: FC<Props> = ({ type, setWayData }) => {
labels: wc.map((p) => p.way_dist * way_length),
datasets: [
{
//@ts-ignore
type: 'line' as const,
label: way_id,
borderColor: 'rgb(255, 99, 132)',
Expand Down
27 changes: 25 additions & 2 deletions frontend/src/pages/RoadConditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,37 @@ import Split from 'react-split';
import '../css/split.css';
import '../css/road_conditions.css';
import { ConditionType } from '../models/graph';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { getConditionsWay2 } from '../queries/conditions';

//this is to visualise the Road Conditions (GP) map
const RoadConditions = () => {
const [wayData, setWayData] = useState<ChartData<'line', number[], number>>();
const [wayData, setWayData] =
useState<ChartData<'scatter', number[], number>>();

console.log(wayData);

useEffect(() => {
getConditionsWay2('12e920a5-368c-4484-a0a3-e8a626ec49fe', 'KPI', (wc) => {
console.log(wc);
setWayData({
labels: wc.map((p) => p.way_dist * 100),
datasets: [
{
//@ts-ignore
type: 'line' as const,
label: 'way_id',
borderColor: 'rgb(255, 99, 132)',
borderWidth: 2,
fill: false,
tension: 0.2,
data: wc.map((p) => p.value),
},
],
});
});
}, []);

const type: ConditionType = {
name: 'IRI',
min: 0,
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/queries/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export const getConditions = (
post('/conditions/way', { wayId, type }, setConditions);
};

export const getConditionsWay2 = (
dbId: string,
type: string,
setConditions: (data: Condition[]) => void,
) => {
post('/conditions/way2', { dbId, type }, setConditions);
};

export const getBoundedWaysConditions = async (
bounds: MapBounds,
type: string,
Expand Down

0 comments on commit 6430c75

Please sign in to comment.