Skip to content

Commit

Permalink
Merge pull request #69 from Solar-Gators/date-autopopulate
Browse files Browse the repository at this point in the history
added semi-scuffed auto-populate dates to strategy tab
  • Loading branch information
jackschedel authored Nov 7, 2023
2 parents b46dd3e + ba012ee commit d958044
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
24 changes: 23 additions & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"devDependencies": {
"@types/node": "^18.0.0",
"@types/sequelize": "^4.28.17",
"axios": "^1.5.1"
"axios": "^1.5.1",
"prettier": "3.0.3"
}
}
1 change: 0 additions & 1 deletion client/src/component/TelemetryCan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function TelemetryCAN<T>({
<>
<h3>{config.title}</h3>
<div className="center-align">

{Object.keys(config.data).map((messageName: string) => {
const message = config.data?.[messageName];

Expand Down
9 changes: 7 additions & 2 deletions client/src/pages/LiveTelemetry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,13 @@ function LiveTelemetry() {
</Row>
<Row>
<Label label="Lap Count" value={data?.laps?.rx0?.lap ?? 0} />
<Label label="Power Draw" value={(data?.mitsuba?.rx0?.battVoltage ?? 0) * (data?.mitsuba?.rx0?.battCurrent ?? 0)}
unit = 'W'
<Label
label="Power Draw"
value={
(data?.mitsuba?.rx0?.battVoltage ?? 0) *
(data?.mitsuba?.rx0?.battCurrent ?? 0)
}
unit="W"
/>
</Row>

Expand Down
44 changes: 44 additions & 0 deletions client/src/pages/Strategy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as moment from "moment";
import { SimpleLinearRegression } from "ml-regression";
import { useSearchParams } from "react-router-dom";
import Select from "react-select";
import * as telemetry from "../shared/sdk/telemetry";

const allShape = {
bms: bmsShape,
Expand Down Expand Up @@ -49,9 +50,12 @@ function Strategy() {
const [dataKey, setDataKey] = useState(
searchParams.get("key") ?? localGraph["key"] ?? "pack_sum_volt_",
);
// replace localGraph["start"] with dayBefore
const [startTime, setStartTime] = useState(
searchParams.get("start") ?? localGraph["start"] ?? "2023-04-16 12:00",
);

// replace localGraph["end"] with latest date
const [endTime, setEndTime] = useState(
searchParams.get("end") ?? localGraph["end"] ?? "2023-04-16 12:10",
);
Expand All @@ -75,6 +79,46 @@ function Strategy() {
`${telemetryType}.${messageNumber}.${dataKey}`,
);

telemetry
.getAll()
.then((response) => {
//console.log(response["bms"]["rx0"]["createdAt"]);

const responseStartTime = response.bms.rx0.createdAt;
const formattedEndTime = responseStartTime
.replace(/\.\d+/, "")
.replace("Z", "");

//console.log(formattedStartTime);
const formattedStartTime =
formattedEndTime.substring(0, 9) +
(+formattedEndTime[9] - 1).toString() +
formattedEndTime.substring(10);
//console.log(formattedEndTime);
setEndTime(formattedEndTime);

setStartTime(formattedStartTime);

// The password may needed to reset but it's actually empty so it didn't
if (localStorage.getItem("passwordNeedsSet") == "true") {
localStorage.setItem("passwordNeedsSet", "false");
window.location.reload();
}
})
.catch((reason) => {
// clear username/password if it changed for some reason
if (
reason.request.status == 402 &&
(!localStorage.getItem("passwordNeedsSet") ||
localStorage.getItem("passwordNeedsSet") == "false")
) {
localStorage.setItem("passwordNeedsSet", "true");
localStorage.setItem("username", "");
localStorage.setItem("password", "");
window.location.reload();
}
});

const handleSelectChange = (selectedOption) => {
const { value } = selectedOption;
const [type, num, key] = value.split(".");
Expand Down

0 comments on commit d958044

Please sign in to comment.