11/* eslint-disable react/jsx-one-expression-per-line */
22import React , { useContext } from 'react' ;
3- import { Bar } from 'react-chartjs-2' ;
3+ // import { Bar } from 'react-chartjs-2';
44import CommunicationsContext from '../context/OverviewContext' ;
55
66const RouteLocations = ( props ) => {
@@ -20,7 +20,7 @@ const RouteLocations = (props) => {
2020 if ( new Date ( a . timeSent ) < new Date ( b . timeSent ) ) return - 1 ;
2121 return 0 ;
2222 } ) ;
23- console . log ( 'commData (AFTER sorting):' , communicationsData ) ;
23+ // console.log('commData (AFTER sorting):', communicationsData);
2424
2525 // Iterate over sorted array to build up resObj.
2626 for ( let i = 0 ; i < communicationsData . length ; i += 1 ) {
@@ -67,9 +67,8 @@ const RouteLocations = (props) => {
6767 // Filter the array so that only subarrays w/ len > 1 are kept.
6868 // (len == 1 means there's only one point in the route. There's no meaningful data to be gained from those.)
6969 const tracePoints = Object . values ( resObj ) . filter ( subArray => subArray . length > 1 ) ;
70- const position = communicationsData [ 0 ] . correlatingid ? 0 : tracePoints . length - 1 ;
71- console . log ( 'tracePoints arr:' , tracePoints ) ;
72- console . log ( 'position for tracePoints:' , position ) ;
70+ // console.log('tracePoints arr:', tracePoints);
71+
7372
7473 // Construct an obj that stores data necessary for calculating avg speed of requests btw 2 pts.
7574 const avgDataObj = { } ;
@@ -100,14 +99,16 @@ const RouteLocations = (props) => {
10099 }
101100 }
102101 /** End of nested loops */
103-
104102 console . log ( 'avgDataObj:' , avgDataObj ) ;
105-
106103 /****************************************/
104+
107105 // Array of <divs> to be rendered. Each <div> contains route name and time difference.
108106 const resArray = [ ] ;
109107
110- // iterate over Trace Points, creating a <div> for every data obj.
108+ const position = communicationsData [ 0 ] . correlatingid ? 0 : tracePoints . length - 1 ;
109+ console . log ( 'position for tracePoints:' , position ) ;
110+
111+ // iterate over ONE elem in tracePoints, creating a <div> for every data obj.
111112 for ( let i = 0 ; i < tracePoints [ position ] . length ; i += 1 ) {
112113 if ( i !== tracePoints [ position ] . length - 1 ) {
113114 // Calc time difference (when not at the end of array):
@@ -137,14 +138,68 @@ const RouteLocations = (props) => {
137138 ) ;
138139 }
139140 }
141+ // console.log('resArray: ', resArray);
142+
143+ /**** Making a list of avg speed-related data. ********/
144+ // const avgData = [];
145+ // Object.entries(avgDataObj).forEach((el, i) => {
146+ // avgData.push(
147+ // <span className="avgDataDetails" key={`${i}+${el[0]}`}>
148+ // {el[0]}: {el[1]}
149+ // </span>
150+ // )
151+ // })
152+ // console.log('avgData (array):', avgData);
140153
141- console . log ( 'resArray: ' , resArray ) ;
154+ /**** Making CATEGORIZED lists of avg speed-related data. ********/
155+ const avgTime = [ ] , totalTime = [ ] , count = [ ] ;
156+ let i = 0 ; // For unique keys for each <span> //
142157
158+ for ( const key in avgDataObj ) {
159+ i += 1 ;
160+
161+ if ( key . endsWith ( 'AvgTime' ) ) {
162+ avgTime . push (
163+ < span className = "avgDataDetails" key = { i } >
164+ { key . slice ( 0 , - 7 ) } : { avgDataObj [ key ] } ms
165+ </ span >
166+ )
167+ }
168+ if ( key . endsWith ( 'TotalTime' ) ) {
169+ totalTime . push (
170+ < span className = "avgDataDetails" key = { i } >
171+ { key . slice ( 0 , - 9 ) } : { avgDataObj [ key ] } ms
172+ </ span >
173+ )
174+ }
175+ if ( key . endsWith ( 'Count' ) ) {
176+ count . push (
177+ < span className = "avgDataDetails" key = { i } >
178+ { key . slice ( 0 , - 5 ) } : { avgDataObj [ key ] }
179+ </ span >
180+ )
181+ }
182+ }
183+ // console.log('avgTime:', avgTime);
184+ // console.log('totalTime:', totalTime);
185+ // console.log('count:', count);
186+ /****************/
143187
144- // return div with Trace Points data
145188 return (
146- < div >
189+ < div id = "routeDataArea" >
190+ { /* Data on the lastest route */ }
147191 { resArray }
192+
193+ { /* Rendering avg-speed related data */ }
194+ < div id = "avgData" >
195+ { /* {avgData} */ }
196+ < span className = "avgData-titles" > Average time between points:</ span >
197+ { avgTime }
198+ < span className = "avgData-titles" > Total time between points:</ span >
199+ { totalTime }
200+ < span className = "avgData-titles" > Number of trips between points:</ span >
201+ { count }
202+ </ div >
148203 </ div >
149204 ) ;
150205} ;
0 commit comments