From 47fc603b864b52a70157515f29ec741dd9192f3a Mon Sep 17 00:00:00 2001
From: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Date: Fri, 7 Jun 2019 17:55:16 +0200
Subject: SDNR align ODLUX

Add missing chart view to UX Performance app

Issue-ID: SDNC-790
Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Change-Id: I6f5af1e01d2246927b8d05f826f629c7dd5f59a5
Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
---
 .../src/components/signalToInterference.tsx        | 129 ++++++++++++++-------
 1 file changed, 89 insertions(+), 40 deletions(-)

(limited to 'sdnr/wt/odlux/apps/performanceHistoryApp/src/components/signalToInterference.tsx')

diff --git a/sdnr/wt/odlux/apps/performanceHistoryApp/src/components/signalToInterference.tsx b/sdnr/wt/odlux/apps/performanceHistoryApp/src/components/signalToInterference.tsx
index bd612822e..90ed1a9cb 100644
--- a/sdnr/wt/odlux/apps/performanceHistoryApp/src/components/signalToInterference.tsx
+++ b/sdnr/wt/odlux/apps/performanceHistoryApp/src/components/signalToInterference.tsx
@@ -2,22 +2,25 @@ import * as React from 'react';
 
 import { withRouter, RouteComponentProps } from 'react-router-dom';
 
-import { MaterialTable, ColumnType, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
+import { MaterialTable, ColumnType, ColumnModel, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
 import connect, { Connect, IDispatcher } from '../../../../framework/src/flux/connect';
 
 import { SignalToInterferenceDataType } from '../models/signalToInteferenceDataType';
+import { IDataSet, IDataSetsObject } from '../models/chartTypes';
 import { createSignalToInterference15minProperties, createSignalToInterference15minActions } from '../handlers/signalToInterference15minHandler';
 import { createSignalToInterference24hoursProperties, createSignalToInterference24hoursActions } from '../handlers/signalToInterference24hoursHandler';
+import { lineChart, sortDataByTimeStamp } from '../utils/chartUtils';
+import { addColumnLabels } from '../utils/tableUtils';
 
 const mapProps = (state: IApplicationStoreState) => ({
   signalToInterference15minProperties: createSignalToInterference15minProperties(state),
-  signalToInterference24hoursProperties: createSignalToInterference24hoursProperties(state),
+  signalToInterference24hoursProperties: createSignalToInterference24hoursProperties(state)
 });
 
 const mapDisp = (dispatcher: IDispatcher) => ({
   signalToInterference15minActions: createSignalToInterference15minActions(dispatcher.dispatch),
-  signalToInterference24hoursActions: createSignalToInterference24hoursActions(dispatcher.dispatch),
+  signalToInterference24hoursActions: createSignalToInterference24hoursActions(dispatcher.dispatch)
 });
 
 type SignalToInterferenceComponentProps = RouteComponentProps & Connect<typeof mapProps, typeof mapDisp> & {
@@ -31,45 +34,91 @@ const SignalToInterferenceTable = MaterialTable as MaterialTableCtorType<SignalT
  */
 class SignalToInterferenceComponent extends React.Component<SignalToInterferenceComponentProps>{
   render(): JSX.Element {
-    if (this.props.selectedTimePeriod == "15min") {
-      return (
-        <SignalToInterferenceTable idProperty={"_id"} columns={[
-          { property: "radio-signal-id", title: "Radio signal", type: ColumnType.text },
-          { property: "scanner-id", title: "Scanner ID", type: ColumnType.text },
-          { property: "time-stamp", title: "End Time", type: ColumnType.text, disableFilter: true },
-          {
-            property: "suspect-interval-flag", title: "Suspect Interval", type: ColumnType.custom, customControl: ({ rowData }) => {
-              const suspectIntervalFlag = rowData["suspect-interval-flag"].toString();
-              return <div >{suspectIntervalFlag} </div>
-            }
-          },
-          { property: "snir-min", title: "SINR (min)[db]", type: ColumnType.text, disableFilter: true, disableSorting: true },
-          { property: "snir-avg", title: "SINR (avg)[db]", type: ColumnType.text, disableFilter: true, disableSorting: true },
-          { property: "snir-max", title: "SINR (max)[db]", type: ColumnType.text, disableFilter: true, disableSorting: true },
-        ]} {...this.props.signalToInterference15minProperties} {...this.props.signalToInterference15minActions}
-        />
-      );
-    } else {
-      return (
-        <SignalToInterferenceTable idProperty={"_id"} columns={[
-          { property: "radio-signal-id", title: "Radio signal", type: ColumnType.text },
-          { property: "scanner-id", title: "Scanner ID", type: ColumnType.text },
-          { property: "time-stamp", title: "End Time", type: ColumnType.text, disableFilter: true },
-          {
-            property: "suspect-interval-flag", title: "Suspect Interval", type: ColumnType.custom, customControl: ({ rowData }) => {
-              const suspectIntervalFlag = rowData["suspect-interval-flag"].toString();
-              return <div >{suspectIntervalFlag} </div>
-            }
-          },
-          { property: "snir-min", title: "SINR (min)[db]", type: ColumnType.text, disableFilter: true, disableSorting: true },
-          { property: "snir-avg", title: "SINR (avg)[db]", type: ColumnType.text, disableFilter: true, disableSorting: true },
-          { property: "snir-max", title: "SINR (max)[db]", type: ColumnType.text, disableFilter: true, disableSorting: true },
-        ]} {...this.props.signalToInterference24hoursProperties} {...this.props.signalToInterference24hoursActions}
+    const properties = this.props.selectedTimePeriod === "15min"
+      ? this.props.signalToInterference15minProperties
+      : this.props.signalToInterference24hoursProperties;
+    const actions = this.props.selectedTimePeriod === "15min"
+      ? this.props.signalToInterference15minActions
+      : this.props.signalToInterference24hoursActions;
+
+    const chartPagedData = this.getChartDataValues(properties.rows);
+
+    const sinrColumns: ColumnModel<SignalToInterferenceDataType>[] = [
+
+      { property: "radio-signal-id", title: "Radio signal", type: ColumnType.text },
+      { property: "scanner-id", title: "Scanner ID", type: ColumnType.text },
+      { property: "time-stamp", title: "End Time", type: ColumnType.text, disableFilter: true },
+      {
+        property: "suspect-interval-flag", title: "Suspect Interval", type: ColumnType.custom, customControl: ({ rowData }) => {
+          const suspectIntervalFlag = rowData["suspect-interval-flag"].toString();
+          return <div >{suspectIntervalFlag} </div>
+        }
+      }
+    ];
+    
+    chartPagedData.datasets.forEach(ds => {
+      sinrColumns.push(addColumnLabels<SignalToInterferenceDataType>(ds.name, ds.columnLabel));
+    });
+    return (
+      <>
+        {lineChart(chartPagedData)}
+        <SignalToInterferenceTable idProperty={"_id"} columns={sinrColumns} {...properties} {...actions}
         />
-      );
-    }
+      </>
+    );
   };
+
+  /**
+   * This function gets the performance values for SINR according on the chartjs dataset structure 
+   * which is to be sent to the chart.
+   */
+
+  private getChartDataValues = (rows: SignalToInterferenceDataType[]): IDataSetsObject => {
+    const _rows = [...rows];
+    sortDataByTimeStamp(_rows);
+
+    const datasets: IDataSet[] = [{
+      name: "snir-min",
+      label: "snir-min",
+      borderColor: '#0e17f3de',
+      bezierCurve: false,
+      lineTension: 0,
+      fill: false,
+      data: [],
+      columnLabel: "SINR (min)[db]"
+    }, {
+      name: "snir-avg",
+      label: "snir-avg",
+      borderColor: '#08edb6de',
+      bezierCurve: false,
+      lineTension: 0,
+      fill: false,
+      data: [],
+      columnLabel: "SINR (avg)[db]"
+    }, {
+      name: "snir-max",
+      label: "snir-max",
+      borderColor: '#b308edde',
+      bezierCurve: false,
+      lineTension: 0,
+      fill: false,
+      data: [],
+      columnLabel: "SINR (max)[db]"
+    }];
+
+    _rows.forEach(row => {
+      datasets.forEach(ds => {
+        ds.data.push({
+          x: row["time-stamp"],
+          y: row[ds.name as keyof SignalToInterferenceDataType] as string
+        });
+      });
+    });
+    return {
+      datasets: datasets
+    };
+  }
 }
 
-export const SignalToInterference = withRouter(connect(mapProps, mapDisp)(SignalToInterferenceComponent));
+const SignalToInterference = withRouter(connect(mapProps, mapDisp)(SignalToInterferenceComponent));
 export default SignalToInterference;
-- 
cgit 1.2.3-korg

