cabana: fix times and minor refactor

main
Andy Haden 2017-08-04 15:36:15 -07:00
parent 75134701f7
commit 414d0675c0
3 changed files with 17 additions and 10 deletions

View File

@ -636,7 +636,7 @@ export default class CanExplorer extends Component {
autoplay={this.props.autoplay}
showEditMessageModal={this.showEditMessageModal}
onPartChange={this.onPartChange}
routeStartTime={this.state.route ? this.state.route.start_time : 0}
routeStartTime={this.state.route ? this.state.route.start_time : Moment()}
partsCount={this.state.route ? this.state.route.proclog : 0}
/>
: null}

View File

@ -3,7 +3,7 @@ import Moment from 'moment';
const ROUTES_ENDPOINT = 'https://api.commadotai.com/v1/{dongleId}/routes/';
const DEMO_ROUTES = {
let DEMO_ROUTES = {
"2017-06-12--18-51-47": {
"can": true,
"device_type": 3,
@ -73,10 +73,20 @@ const DEMO_ROUTES = {
}
};
DEMO_ROUTES = momentizeTimes(DEMO_ROUTES);
function getCommaAccessToken() {
return Cookies.get('comma_access_token');
}
function momentizeTimes(routes) {
for(let routeName in routes) {
routes[routeName].start_time = Moment(routes[routeName].start_time);
routes[routeName].end_time = Moment(routes[routeName].end_time);
}
return routes;
}
export async function fetchRoutes(dongleId) {
if(dongleId === undefined) {
dongleId = 'me';
@ -93,7 +103,7 @@ export async function fetchRoutes(dongleId) {
const resp = await fetch(request);
const routes = await resp.json();
if('routes' in routes) {
return routes.routes;
return momentizeTimes(routes.routes);
}
} catch(err) {
console.log(err);

View File

@ -137,7 +137,7 @@ export default class Explorer extends Component {
if(nextProps.selectedMessage && nextProps.selectedMessage != this.props.selectedMessage) {
// Update segment and seek state
// by finding new message entry indices
// by finding a entry indices
// corresponding to old message segment/seek times.
let {segment, segmentIndices} = this.state;
@ -212,7 +212,8 @@ export default class Explorer extends Component {
.map((plottedMessageIds, index) => {return {plottedMessageIds, index}}) // preserve index so we can look up graphData
.filter(({plottedMessageIds, index}) => {
let maxGraphTime = 0;
if(graphData.length > 0) {
if(index < graphData.length) {
maxGraphTime = graphData[index][graphData[index].length - 1].relTime;
}
@ -365,12 +366,8 @@ export default class Explorer extends Component {
if(typeof plottedSignals === 'undefined') {
plottedSignals = this.state.plottedSignals;
}
let graphData = Array(plottedSignals.length);
let graphData = plottedSignals.map((plotSignals, index) => this.calcGraphData(plotSignals, messages));
plottedSignals.forEach((plotSignals, index) => {
const plotGraphData = this.calcGraphData(plotSignals, messages);
graphData[index] = plotGraphData;
});
this.setState({graphData});
}