Skip to content

Commit

Permalink
Tel 107 add unit conversion to pis transformer (#86)
Browse files Browse the repository at this point in the history
* started unit conversion logic

* Create dockerfile for backend (#77)

* make the CarGraphicComponent SSR instead of the HeroComponent (#80)

* local storage and darkmode settings implemented

* Create dockerfile for backend (#77)

* make the CarGraphicComponent SSR instead of the HeroComponent (#80)

* local storage and darkmode settings implemented

* continued unit conversion function

Co-authored-by: JenniferJa <[email protected]>

* finsihed unit handler function without changes from setting modal changes

* yarn issue fixed by brian

* local storage and darkmode settings implemented

* yarn issue fixed by brian

* moved enum to appStateContext

* fixed small issue with displaying units

* fixed PR comments

* made unit conversion logic work with setting modal

* made speed adapt value adapt to change in units

* addressed comments. Changed to switch, case and destructured appState

* changed to switch

* fixed bug with undefined units and addressed comment

* fixed the miles per hour to 0 decimal places

---------

Co-authored-by: alexwhelan12 <[email protected]>
Co-authored-by: brian nguyen <[email protected]>
Co-authored-by: jenniferja <[email protected]>
Co-authored-by: JenniferJa <[email protected]>
  • Loading branch information
5 people authored May 22, 2024
1 parent 9126a7d commit 6b4d9a5
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/add_reviewers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- uses: hkusu/[email protected]
with:
assignees: ${{ github.actor }}
reviewers: ideen1, IshaHaider, brian-ngyn, haley-lynn, jjason-nn, JenniferJa, justin-phxm, CalebBourb, alexwhelan12, maaryaahmed
reviewers: ideen1, IshaHaider, brian-ngyn, haley-lynn, jjason-nn, JenniferJa, justin-phxm, CalebBourb, alexwhelan12, maaryaahmed
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

Deployment available at: https://telemetry-beta.calgarysolarcar.ca


### Start Web App + Backend (Dev Build)

```
yarn dev
```

Appending `:client` or `:server` behind the dev command will start the servers individually

### Build Web App + Backend (Production build)
Expand All @@ -16,4 +16,5 @@ Appending `:client` or `:server` behind the dev command will start the servers i
yarn build
yarn start
```

Appending `:client` or `:server` behind the build command will build/start the production servers individually
2 changes: 1 addition & 1 deletion amplify/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"type": "module"
}
}
26 changes: 20 additions & 6 deletions client/public/models/Duck.gltf
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,22 @@
],
"bufferViews": [
{ "buffer": 0, "byteOffset": 0, "byteLength": 25272, "target": 34963 },
{ "buffer": 0, "byteOffset": 25276, "byteLength": 404352, "byteStride": 32, "target": 34962 }
{
"buffer": 0,
"byteOffset": 25276,
"byteLength": 404352,
"byteStride": 32,
"target": 34962
}
],
"cameras": [
{
"perspective": { "aspectRatio": 1.5, "yfov": 0.6605931592458378, "zfar": 10000, "znear": 1 },
"perspective": {
"aspectRatio": 1.5,
"yfov": 0.6605931592458378,
"zfar": 10000,
"znear": 1
},
"type": "perspective",
"name": "cameraShape1"
}
Expand Down Expand Up @@ -91,14 +102,17 @@
{
"camera": 0,
"matrix": [
-0.7289686274214113, 0, -0.6845471059286886, 0, -0.4252049153435464, 0.7836934573258398,
0.45279724481533634, 0, 0.5364750881476519, 0.6211477802783104, -0.5712879439059578, 0,
400.113, 463.264, -431.078, 1
-0.7289686274214113, 0, -0.6845471059286886, 0, -0.4252049153435464,
0.7836934573258398, 0.45279724481533634, 0, 0.5364750881476519,
0.6211477802783104, -0.5712879439059578, 0, 400.113, 463.264, -431.078,
1
],
"name": "camera1"
}
],
"samplers": [{ "magFilter": 9729, "minFilter": 9987, "wrapS": 10497, "wrapT": 10497 }],
"samplers": [
{ "magFilter": 9729, "minFilter": 9987, "wrapS": 10497, "wrapT": 10497 }
],
"scene": 0,
"scenes": [{ "nodes": [0, 1] }],
"textures": [{ "sampler": 0, "source": 0, "name": "file2" }]
Expand Down
19 changes: 13 additions & 6 deletions client/src/components/atoms/SpeedAtom.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { useEffect, useState } from "react";

import { useAppState } from "@/contexts/AppStateContext";
import { APPUNITS } from "@/contexts/AppStateContext";
import { usePacket } from "@/contexts/PacketContext";

function SpeedAtom() {
const { currentPacket } = usePacket();
const { currentAppState } = useAppState();

let speedValue = 0;
let speedUnit = "km/h";
if (currentAppState.appUnits === APPUNITS.IMPERIAL) {
speedValue = currentPacket.KeyMotor[0].VehicleVelocity * 0.621371;
speedUnit = "mph";
} else {
speedValue = currentPacket.KeyMotor[0].VehicleVelocity;
}

return (
<>
<div className="col-span-2 grid h-10 w-full content-center justify-items-center">
<div className="grid grid-cols-2">
<div className="col-span-1 grid">
<h1 className="text-4xl">
{currentPacket.KeyMotor[0].VehicleVelocity}
</h1>
<h1 className="text-4xl">{speedValue.toFixed(0)}</h1>
</div>
<div className="col-span-1 grid">
<h1 className="text-sm">km/h</h1>
<h1 className="text-sm">{speedUnit}</h1>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function SettingsComponent() {
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<div className="fixed left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 transform flex-col rounded-lg bg-white p-4 shadow-lg shadow-lg">
<div className="fixed left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col rounded-lg bg-white p-4 shadow-lg">
<h5 className="text-text-gray dark:text-text-gray-dark mb-4 text-2xl">
Settings
</h5>
Expand Down
74 changes: 66 additions & 8 deletions client/src/components/transformers/PISTransformer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,75 @@
import { APPUNITS, useAppState } from "@/contexts/AppStateContext";
import type I_PIS from "@/objects/PIS/PIS.interface";
import type { I_PISField, I_PISFieldData } from "@/objects/PIS/PIS.interface";
import {
type I_PISField,
type I_PISFieldData,
UnitType,
} from "@/objects/PIS/PIS.interface";

type RangeCheckedFieldDataProps = {
fieldData: I_PISFieldData;
};

function FieldUnitsHandler(
unit: UnitType | undefined,
value: string | number | boolean,
) {
const { currentAppState } = useAppState();

let unitReturn: string | undefined;
let valueReturn: string | number | boolean;
unitReturn = unit;
valueReturn = value;

switch (unit) {
case UnitType.TEMP:
if (
typeof value === "number" &&
currentAppState.appUnits === APPUNITS.IMPERIAL
) {
unitReturn = "°F";
valueReturn = (value * 9) / 5 + 32;
} else {
unitReturn = "°C";
valueReturn = value;
}
break;
case UnitType.SPEED:
if (
typeof value === "number" &&
currentAppState.appUnits === APPUNITS.IMPERIAL
) {
unitReturn = "mph";
valueReturn = value * 0.621371;
} else {
unitReturn = "km/h";
valueReturn = value;
}
break;
case UnitType.DISTANCE:
if (
typeof value === "number" &&
currentAppState.appUnits === APPUNITS.IMPERIAL
) {
unitReturn = "mi";
valueReturn = value * 0.621371;
} else {
unitReturn = "km";
valueReturn = value;
}
break;
case undefined:
unitReturn = "";
valueReturn = value;
break;
}

return `${typeof valueReturn === "number" ? valueReturn.toFixed(0) : valueReturn} ${unitReturn}`;
}

function RangeCheckedFieldData(props: RangeCheckedFieldDataProps): JSX.Element {
const { value, unit, min, max, expectedBool } = props.fieldData;

const inRange =
// If value is of type string range is true
typeof value === "string"
Expand All @@ -24,12 +87,7 @@ function RangeCheckedFieldData(props: RangeCheckedFieldDataProps): JSX.Element {
const color = inRange ? "text-green" : "text-red-500";
const displayValue = typeof value === "boolean" ? (value ? "T" : "F") : value;

return (
<span className={color}>
{displayValue}
{unit}
</span>
);
return <span className={color}>{FieldUnitsHandler(unit, displayValue)}</span>;
}

type FormatStringProps = {
Expand Down Expand Up @@ -69,7 +127,7 @@ function FieldDataFormatter(props: FieldDataFormatterProps): JSX.Element {

const formatString = (string: string, params: I_PISFieldData[]) => {
// %s •C (%s) - %s •C (%s)
console.log("TEST", string.split("%s"));
// console.log("TEST", string.split("%s"));
return string
.split("%s")
.map((part, index) => {
Expand Down
29 changes: 15 additions & 14 deletions client/src/objects/PIS/PIS.battery.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { usePacket } from "@/contexts/PacketContext";
import type I_PIS from "@/objects/PIS/PIS.interface";
import { type I_PISField } from "@/objects/PIS/PIS.interface";
import { UnitType } from "@/objects/PIS/PIS.interface";

const Battery = (): I_PIS => {
const { currentPacket } = usePacket();
Expand Down Expand Up @@ -94,7 +95,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.FanVoltage,
unit: "V",
unit: UnitType.VOLTAGE,
min: 0,
max: 100,
},
Expand All @@ -109,7 +110,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.RequestedFanSpeed,
unit: "V",
unit: UnitType.VOLTAGE,
min: 0,
max: 100,
},
Expand All @@ -124,7 +125,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.LowTemperature,
unit: "°C",
unit: UnitType.TEMP,
min: 10,
max: 25,
hover: "Low Cell Temperature",
Expand All @@ -135,7 +136,7 @@ const Battery = (): I_PIS => {
},
{
value: currentPacket?.Battery?.HighTemperature,
unit: "°C",
unit: UnitType.TEMP,
min: 50,
max: 75,
hover: "High Cell Temperature",
Expand All @@ -151,7 +152,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.AverageTemperature,
unit: "°C",
unit: UnitType.TEMP,
min: 0,
max: 100,
},
Expand All @@ -162,7 +163,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.InternalTemperature,
unit: "°C",
unit: UnitType.TEMP,
min: 0,
max: 100,
},
Expand All @@ -177,14 +178,14 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.LowCellVoltage,
unit: "V",
unit: UnitType.VOLTAGE,
min: 0,
max: 100,
},
{ value: currentPacket?.Battery?.LowCellVoltageId },
{
value: currentPacket?.Battery?.HighCellVoltage,
unit: "V",
unit: UnitType.VOLTAGE,
min: 0,
max: 100,
},
Expand All @@ -196,7 +197,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.AverageCellVoltage,
unit: "V",
unit: UnitType.VOLTAGE,
min: 0,
max: 100,
},
Expand All @@ -216,7 +217,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.PackCurrent,
unit: "A",
unit: UnitType.AMPERAGE,
min: 0,
max: 100,
},
Expand All @@ -227,7 +228,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.PackVoltage,
unit: "V",
unit: UnitType.VOLTAGE,
min: 0,
max: 100,
},
Expand All @@ -238,7 +239,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery?.PackAmphours,
unit: "Ah",
unit: UnitType.AMPHOUR,
min: 0,
max: 100,
},
Expand Down Expand Up @@ -271,7 +272,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.Battery["12vInputVoltage"],
unit: "V",
unit: UnitType.VOLTAGE,
min: 0,
max: 100,
},
Expand Down Expand Up @@ -327,7 +328,7 @@ const Battery = (): I_PIS => {
data: [
{
value: currentPacket?.AuxBms?.AuxVoltage,
unit: "mV",
unit: UnitType.MILLIVOLTS,
min: 0,
max: 100,
},
Expand Down
1 change: 1 addition & 0 deletions client/src/objects/PIS/PIS.faults.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { usePacket } from "@/contexts/PacketContext";
import type I_PIS from "@/objects/PIS/PIS.interface";
import { UnitType } from "@/objects/PIS/PIS.interface";

const Faults = (): I_PIS => {
const { currentPacket } = usePacket();
Expand Down
16 changes: 15 additions & 1 deletion client/src/objects/PIS/PIS.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
enum UnitType {
TEMP = "temperature",
SPEED = "speed",
DISTANCE = "distance",
VOLTAGE = "V",
AMPERAGE = "A",
AMPHOUR = "Ah",
MILLIVOLTS = "mV",
RPM = "RPM",
AMPRMS = "A(rms)",
HERTZ = "Hz",
}

type I_PISFieldData = {
value: number | string | boolean;
unit?: string;
unit?: UnitType;
min?: number;
max?: number;
expectedBool?: boolean;
Expand All @@ -19,3 +32,4 @@ type I_PIS = {

export default I_PIS;
export type { I_PISField, I_PISFieldData };
export { UnitType };
Loading

0 comments on commit 6b4d9a5

Please sign in to comment.