Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only query single route if segmentRange specified #522

Merged
merged 14 commits into from
Jul 12, 2024
22 changes: 16 additions & 6 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import MyCommaAuth from '@commaai/my-comma-auth';

import * as Types from './types';
import { resetPlayback, selectLoop } from '../timeline/playback';
import {hasRoutesData } from '../timeline/segments';
import { hasRoutesData } from '../timeline/segments';
import { getDeviceFromState, deviceVersionAtLeast } from '../utils';
import { getCommaAccessToken } from '@commaai/my-comma-auth/storage';

let routesRequest = null;
let routesRequestPromise = null;
Expand Down Expand Up @@ -37,7 +38,7 @@ export function checkRoutesData() {
dongleId,
};

routesRequestPromise = routesRequest.req.then((routesData) => {
routesRequestPromise = routesRequest.req.then(async (routesData) => {
state = getState();
const currentRange = state.filter;
if (currentRange.start !== fetchRange.start
Expand All @@ -53,14 +54,24 @@ export function checkRoutesData() {
return;
}

const routes = routesData.map((r) => {
if (!state.currentRoute && state.segmentRange) {
sshane marked this conversation as resolved.
Show resolved Hide resolved
await fetch(`https://api.aks.comma.ai/v1/devices/${dongleId}/routes_segments?route_str=${`${dongleId}|${state.segmentRange.log_id}`.replace(/%7C/g, '|')}`, {
headers: { 'Authorization': `JWT ${await getCommaAccessToken()}` }
})
.then(res => res.json())
.then(res => {
routesData.push(res[0])
}).catch(err => console.error(err.message))
}

let routes = routesData.map((r) => {
let startTime = r.segment_start_times[0];
let endTime = r.segment_end_times[r.segment_end_times.length - 1];

// TODO: these will all be relative times soon
// fix segment boundary times for routes that have the wrong time at the start
if ((Math.abs(r.start_time_utc_millis - startTime) > 24 * 60 * 60 * 1000)
&& (Math.abs(r.end_time_utc_millis - endTime) < 10 * 1000)) {
&& (Math.abs(r.end_time_utc_millis - endTime) < 10 * 1000)) {
startTime = r.start_time_utc_millis;
endTime = r.end_time_utc_millis;
r.segment_start_times = r.segment_numbers.map((x) => startTime + (x * 60 * 1000));
Expand Down Expand Up @@ -111,7 +122,6 @@ export function checkLastRoutesData() {
return
}

console.log(`fetching ${limit +LIMIT_INCREMENT } routes`)
dispatch({
type: Types.ACTION_UPDATE_ROUTE_LIMIT,
limit: limit + LIMIT_INCREMENT,
Expand Down Expand Up @@ -157,7 +167,7 @@ function updateTimeline(state, dispatch, log_id, start, end, allowPathChange) {
}

if (allowPathChange) {
const desiredPath = urlForState(state.dongleId, log_id, Math.floor(start/1000), Math.floor(end/1000), false);
const desiredPath = urlForState(state.dongleId, log_id, Math.floor(start / 1000), Math.floor(end / 1000), false);
if (window.location.pathname !== desiredPath) {
dispatch(push(desiredPath));
}
Expand Down