Skip to content

Commit

Permalink
chore: prettier 120 characters formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
regeter committed Feb 13, 2025
1 parent ee0d41c commit 551b1fc
Show file tree
Hide file tree
Showing 26 changed files with 234 additions and 546 deletions.
166 changes: 41 additions & 125 deletions src/App.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// src/App.test.js

//import { render, screen } from "@testing-library/react";
//import App from "./App";

Expand Down
2 changes: 1 addition & 1 deletion src/Dataframe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Dataframe.js
* src/Dataframe.js
*
* JSON viewer for log entries. Clicking on a property _value_
* adds it to the log viewer.
Expand Down
25 changes: 6 additions & 19 deletions src/HighVelocityJump.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*
* HighVelocityJump.js
*
* Representation of a HighVelocityJump
*/
// src/HighVelocityJump.js

import _ from "lodash";
const velocityOutlier = 68; // true velocities higher than this unlikely (in Meters/sec aprrox 150 MPH)
import Stats from "./Stats";
Expand All @@ -21,11 +18,7 @@ class HighVelocityJump {
lng: curLoc.rawlocation.longitude,
});

const distanceTraveled =
window.google.maps.geometry.spherical.computeDistanceBetween(
startLoc,
endLoc
);
const distanceTraveled = window.google.maps.geometry.spherical.computeDistanceBetween(startLoc, endLoc);
const timeSpentMS = curEntry.date - prevEntry.date;
const velocity = distanceTraveled / (timeSpentMS / 1000.0);

Expand Down Expand Up @@ -95,9 +88,7 @@ class HighVelocityJump {
const velocities = jumps.map((jump) => jump.velocity);
const avgVelocity = _.mean(velocities);
const medianVelocity = Stats.median(velocities);
const stdDevVelocity = Math.sqrt(
_.mean(velocities.map((v) => Math.pow(v - avgVelocity, 2)))
);
const stdDevVelocity = Math.sqrt(_.mean(velocities.map((v) => Math.pow(v - avgVelocity, 2))));

console.log("avgVelocity", avgVelocity);
console.log("medianVelocity", medianVelocity);
Expand All @@ -107,15 +98,11 @@ class HighVelocityJump {
// 1. Its velocity is greater than the median + 2 standard deviations
// 2. OR its velocity is greater than velocityOutlier (150 MPH)
// 3. AND the distance traveled is more than 1 meter
const significantThreshold = Math.min(
medianVelocity + 2 * stdDevVelocity,
velocityOutlier
);
const significantThreshold = Math.min(medianVelocity + 2 * stdDevVelocity, velocityOutlier);

const significantJumps = jumps.filter(
(jump) =>
(jump.velocity > significantThreshold ||
jump.velocity > velocityOutlier) &&
(jump.velocity > significantThreshold || jump.velocity > velocityOutlier) &&
jump.distanceTraveled > 1 &&
jump.timeSpentMS > 0 // Ensure we're not dividing by zero
);
Expand Down
115 changes: 30 additions & 85 deletions src/LogTable.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
/*
* LogTable.js
*
* Handles the log viewing component.
*/
// src/LogTable.js

import React, { useState } from "react";
import { useSortBy, useTable } from "react-table";
import { FixedSizeList as List } from "react-window";
import AutoSizer from "react-virtualized-auto-sizer";
import _ from "lodash";

function Table({
columns,
data,
onSelectionChange,
listRef,
selectedRow,
centerOnLocation,
}) {
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } =
useTable(
{
columns,
data,
autoResetSortBy: false,
},
useSortBy
);
function Table({ columns, data, onSelectionChange, listRef, selectedRow, centerOnLocation }) {
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable(
{
columns,
data,
autoResetSortBy: false,
},
useSortBy
);

const handleRowSelection = React.useCallback(
(index, rowData) => {
Expand Down Expand Up @@ -60,25 +49,13 @@ function Table({
};

const handleLongPress = () => {
const lat = _.get(
row.original,
"lastlocationResponse.rawlocation.latitude"
);
const lng = _.get(
row.original,
"lastlocationResponse.rawlocation.longitude"
);
const lat = _.get(row.original, "lastlocationResponse.rawlocation.latitude");
const lng = _.get(row.original, "lastlocationResponse.rawlocation.longitude");
if (lat && lng && centerOnLocation) {
console.log(
"Calling centerOnLocation due to long press with:",
lat,
lng
);
console.log("Calling centerOnLocation due to long press with:", lat, lng);
centerOnLocation(lat, lng);
} else {
console.log(
"Unable to center: Invalid coordinates or centerOnLocation not available"
);
console.log("Unable to center: Invalid coordinates or centerOnLocation not available");
}
};

Expand Down Expand Up @@ -137,16 +114,11 @@ function Table({
<div {...getTableProps()}>
<div>
{headerGroups.map((headerGroup) => (
<div
{...headerGroup.getHeaderGroupProps()}
className="logtable-header-row"
>
<div {...headerGroup.getHeaderGroupProps()} className="logtable-header-row">
{headerGroup.headers.map((column) => (
<div
{...column.getHeaderProps()}
className={`logtable-header-cell ${
column.className || ""
}`}
className={`logtable-header-cell ${column.className || ""}`}
style={{ width: column.width }}
>
{column.render("Header")}
Expand Down Expand Up @@ -180,9 +152,7 @@ function LogTable(props) {
const [selectedRowIndex, setSelectedRowIndex] = useState(-1);
const minTime = props.timeRange.minTime;
const maxTime = props.timeRange.maxTime;
const data = props.logData.tripLogs
.getLogs_(new Date(minTime), new Date(maxTime))
.value();
const data = props.logData.tripLogs.getLogs_(new Date(minTime), new Date(maxTime)).value();
const columnShortWidth = 50;
const columnRegularWidth = 120;
const columnLargeWidth = 150;
Expand All @@ -192,21 +162,15 @@ function LogTable(props) {
{
Header: "DayTime",
accessor: "formattedDate",
Cell: ({ cell: { value } }) =>
value.substring(8, 10) + "T" + value.substring(11, 23),
Cell: ({ cell: { value } }) => value.substring(8, 10) + "T" + value.substring(11, 23),
width: columnRegularWidth,
className: "logtable-cell",
solutionTypes: ["ODRD", "LMFS"],
},
{
Header: "Method",
accessor: "@type",
Cell: ({ cell: { value } }) => (
<TrimCell
value={value}
trim="type.googleapis.com/maps.fleetengine."
/>
),
Cell: ({ cell: { value } }) => <TrimCell value={value} trim="type.googleapis.com/maps.fleetengine." />,
width: columnRegularWidth,
className: "logtable-cell",
solutionTypes: ["ODRD", "LMFS"],
Expand All @@ -228,9 +192,7 @@ function LogTable(props) {
Header: "Sensor",
accessor: "lastlocation.rawlocationsensor",
id: "lastlocation_rawlocationsensor",
Cell: ({ cell: { value } }) => (
<TrimCell value={value} trim="LOCATION_SENSOR_" />
),
Cell: ({ cell: { value } }) => <TrimCell value={value} trim="LOCATION_SENSOR_" />,
width: columnShortWidth,
maxWidth: columnShortWidth,
className: "logtable-cell",
Expand All @@ -240,9 +202,7 @@ function LogTable(props) {
Header: "Location",
accessor: "lastlocation.locationsensor",
id: "lastlocation_locationsensor",
Cell: ({ cell: { value } }) => (
<TrimCell value={value} trim="_LOCATION_PROVIDER" />
),
Cell: ({ cell: { value } }) => <TrimCell value={value} trim="_LOCATION_PROVIDER" />,
width: columnRegularWidth,
className: "logtable-cell",
solutionTypes: ["ODRD", "LMFS"],
Expand All @@ -266,19 +226,15 @@ function LogTable(props) {
Header: "Vehicle State",
accessor: "response.vehiclestate",
id: "response_vehiclestate",
Cell: ({ cell: { value } }) => (
<TrimCell value={value} trim="VEHICLE_STATE_" />
),
Cell: ({ cell: { value } }) => <TrimCell value={value} trim="VEHICLE_STATE_" />,
width: columnRegularWidth,
className: "logtable-cell",
solutionTypes: ["ODRD"],
},
{
Header: "Task State",
accessor: "response.state",
Cell: ({ cell: { value } }) => (
<TrimCell value={value} trim="TASK_STATE_" />
),
Cell: ({ cell: { value } }) => <TrimCell value={value} trim="TASK_STATE_" />,
width: columnRegularWidth,
className: "logtable-cell",
solutionTypes: ["LMFS"],
Expand All @@ -287,9 +243,7 @@ function LogTable(props) {
Header: "Trip Status",
accessor: "response.tripstatus",
id: "response_tripstatus",
Cell: ({ cell: { value } }) => (
<TrimCell value={value} trim="TRIP_STATUS_" />
),
Cell: ({ cell: { value } }) => <TrimCell value={value} trim="TRIP_STATUS_" />,
width: columnLargeWidth,
className: "logtable-cell",
solutionTypes: ["ODRD"],
Expand All @@ -298,9 +252,7 @@ function LogTable(props) {
Header: "Remaining tasks",
id: "reamining_tasks",
accessor: "response.remainingvehiclejourneysegments",
Cell: ({ cell: { value } }) => (
<>{value && _.sumBy(value, "stop.tasks.length")}</>
),
Cell: ({ cell: { value } }) => <>{value && _.sumBy(value, "stop.tasks.length")}</>,
width: columnRegularWidth,
className: "logtable-cell",
solutionTypes: ["LMFS"],
Expand All @@ -323,9 +275,7 @@ function LogTable(props) {
{
Header: "Nav Status",
accessor: "navStatus",
Cell: ({ cell: { value } }) => (
<TrimCell value={value} trim="NAVIGATION_STATUS_" />
),
Cell: ({ cell: { value } }) => <TrimCell value={value} trim="NAVIGATION_STATUS_" />,
width: columnLargeWidth,
className: "logtable-cell",
solutionTypes: ["ODRD", "LMFS"],
Expand All @@ -348,8 +298,7 @@ function LogTable(props) {
});
const headers = [
{
Header:
"Event Logs Table (click row to view full log entry and long click to also center map)",
Header: "Event Logs Table (click row to view full log entry and long click to also center map)",
columns: stdColumns,
},
];
Expand All @@ -367,9 +316,7 @@ function LogTable(props) {
const focusOnRow = React.useCallback(
(rowData) => {
if (rowData && listRef.current) {
const rowIndex = data.findIndex(
(row) => row.timestamp === rowData.timestamp
);
const rowIndex = data.findIndex((row) => row.timestamp === rowData.timestamp);
if (rowIndex !== -1) {
listRef.current.scrollToItem(rowIndex, "center");
setSelectedRowIndex(rowIndex);
Expand Down Expand Up @@ -404,6 +351,4 @@ const TrimCell = ({ value, trim }) => {
return <>{value && value.replace(trim, "")}</>;
};

export default React.forwardRef((props, ref) => (
<LogTable {...props} ref={ref} />
));
export default React.forwardRef((props, ref) => <LogTable {...props} ref={ref} />);
7 changes: 2 additions & 5 deletions src/MissingUpdate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*
* MissingUpdate.js
*
* Representation of a missing update
*/
// src/MissingUpdate.js

import _ from "lodash";
const updateOutlier = 60000; // 60 seconds
import Stats from "./Stats";
Expand Down
23 changes: 5 additions & 18 deletions src/PolylineCreation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// PolylineCreation.js
// src/PolylineCreation.js

import { useState } from "react";
import { decode } from "s2polyline-ts";
Expand Down Expand Up @@ -35,14 +35,9 @@ function PolylineCreation({ onSubmit, onClose, buttonPosition }) {
}

// Existing JSON parsing logic
const jsonString = trimmedInput
.replace(/(\w+):/g, '"$1":')
.replace(/\s+/g, " ");
const jsonString = trimmedInput.replace(/(\w+):/g, '"$1":').replace(/\s+/g, " ");

const inputWithBrackets =
jsonString.startsWith("[") && jsonString.endsWith("]")
? jsonString
: `[${jsonString}]`;
const inputWithBrackets = jsonString.startsWith("[") && jsonString.endsWith("]") ? jsonString : `[${jsonString}]`;

const waypoints = JSON.parse(inputWithBrackets);

Expand Down Expand Up @@ -111,11 +106,7 @@ Or paste an encoded S2 polyline string`;
<div style={{ margin: "5px" }}>
<label>
Color:
<input
type="color"
value={color}
onChange={(e) => setColor(e.target.value)}
/>
<input type="color" value={color} onChange={(e) => setColor(e.target.value)} />
</label>
</div>
<div style={{ margin: "5px" }}>
Expand All @@ -133,11 +124,7 @@ Or paste an encoded S2 polyline string`;
<button type="submit" className="map-button inner-button">
Create Polyline
</button>
<button
type="button"
className="map-button inner-button"
onClick={onClose}
>
<button type="button" className="map-button inner-button" onClick={onClose}>
Close
</button>
</form>
Expand Down
Loading

0 comments on commit 551b1fc

Please sign in to comment.