2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import React from 'react';
19 import { RouteComponentProps, withRouter } from 'react-router-dom';
21 import { ColumnModel, ColumnType, MaterialTable, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
22 import { connect, Connect, IDispatcher } from '../../../../framework/src/flux/connect';
23 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
25 import { SetFilterVisibility, SetSubViewAction } from '../actions/toggleActions';
26 import { createSignalToInterferenceActions, createSignalToInterferenceProperties } from '../handlers/signalToInterferenceHandler';
27 import { IDataSet, IDataSetsObject } from '../models/chartTypes';
28 import { SignalToInterferenceDatabaseDataType, SignalToInterferenceDataType } from '../models/signalToInteferenceDataType';
29 import { lineChart, sortDataByTimeStamp } from '../utils/chartUtils';
30 import { addColumnLabels } from '../utils/tableUtils';
31 import ToggleContainer from './toggleContainer';
33 const mapProps = (state: IApplicationStoreState) => ({
34 signalToInterferenceProperties: createSignalToInterferenceProperties(state),
35 currentView: state.performanceHistory.subViews.SINR.subView,
36 isFilterVisible: state.performanceHistory.subViews.SINR.isFilterVisible,
37 existingFilter: state.performanceHistory.signalToInterference.filter,
40 const mapDisp = (dispatcher: IDispatcher) => ({
41 signalToInterferenceActions: createSignalToInterferenceActions(dispatcher.dispatch),
42 setSubView: (value: 'chart' | 'table') => dispatcher.dispatch(new SetSubViewAction('SINR', value)),
43 toggleFilterButton: (value: boolean) => { dispatcher.dispatch(new SetFilterVisibility('SINR', value)); },
46 type SignalToInterferenceComponentProps = RouteComponentProps & Connect<typeof mapProps, typeof mapDisp> & {
47 selectedTimePeriod: string;
50 const SignalToInterferenceTable = MaterialTable as MaterialTableCtorType<SignalToInterferenceDataType>;
53 * The Component which gets the signal to interference data from the database based on the selected time period.
55 class SignalToInterferenceComponent extends React.Component<SignalToInterferenceComponentProps> {
56 onToggleFilterButton = () => {
57 this.props.toggleFilterButton(!this.props.isFilterVisible);
60 onChange = (value: 'chart' | 'table') => {
61 this.props.setSubView(value);
64 onFilterChanged = (property: string, filterTerm: string) => {
65 this.props.signalToInterferenceActions.onFilterChanged(property, filterTerm);
66 if (!this.props.signalToInterferenceProperties.showFilter)
67 this.props.signalToInterferenceActions.onToggleFilter(false);
70 render(): JSX.Element {
71 const properties = this.props.signalToInterferenceProperties;
72 const actions = this.props.signalToInterferenceActions;
74 const chartPagedData = this.getChartDataValues(properties.rows);
76 const sinrColumns: ColumnModel<SignalToInterferenceDataType>[] = [
77 { property: 'radioSignalId', title: 'Radio signal', type: ColumnType.text },
78 { property: 'scannerId', title: 'Scanner ID', type: ColumnType.text },
79 { property: 'timeStamp', title: 'End Time', type: ColumnType.text },
81 property: 'suspectIntervalFlag', title: 'Suspect Interval', type: ColumnType.boolean,
85 chartPagedData.datasets.forEach(ds => {
86 sinrColumns.push(addColumnLabels<SignalToInterferenceDataType>(ds.name, ds.columnLabel));
90 <ToggleContainer onToggleFilterButton={this.onToggleFilterButton} showFilter={this.props.isFilterVisible}
91 existingFilter={this.props.signalToInterferenceProperties.filter} onFilterChanged={this.onFilterChanged} selectedValue={this.props.currentView} onChange={this.onChange}>
92 {lineChart(chartPagedData)}
93 <SignalToInterferenceTable stickyHeader idProperty={'_id'} tableId="signal-to-interference-table" columns={sinrColumns} {...properties} {...actions}
101 * This function gets the performance values for SINR according on the chartjs dataset structure
102 * which is to be sent to the chart.
105 private getChartDataValues = (rows: SignalToInterferenceDataType[]): IDataSetsObject => {
106 const data_rows = [...rows];
107 sortDataByTimeStamp(data_rows);
109 const datasets: IDataSet[] = [{
112 borderColor: '#0e17f3de',
117 columnLabel: 'SINR (min)[db]',
121 borderColor: '#08edb6de',
126 columnLabel: 'SINR (avg)[db]',
130 borderColor: '#b308edde',
135 columnLabel: 'SINR (max)[db]',
138 data_rows.forEach(row => {
139 row.snirMin = row.performanceData.snirMin;
140 row.snirAvg = row.performanceData.snirAvg;
141 row.snirMax = row.performanceData.snirMax;
142 datasets.forEach(ds => {
144 x: row['timeStamp' as keyof SignalToInterferenceDataType] as string,
145 y: row.performanceData[ds.name as keyof SignalToInterferenceDatabaseDataType] as string,
155 const SignalToInterference = withRouter(connect(mapProps, mapDisp)(SignalToInterferenceComponent));
156 export default SignalToInterference;