Skip to content

Commit

Permalink
Use Bar as unit for pressure limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Jan 31, 2024
1 parent f26ff46 commit 9a8d081
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions backend/api/Controllers/Models/CreateRobotModelQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public struct CreateRobotModelQuery
public float? BatteryWarningThreshold { get; set; }

/// <summary>
/// Upper pressure warning threshold in mBar
/// Upper pressure warning threshold in Bar
/// </summary>
public float? UpperPressureWarningThreshold { get; set; }

/// <summary>
/// Lower pressure warning threshold in mBar
/// Lower pressure warning threshold in Bar
/// </summary>
public float? LowerPressureWarningThreshold { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Controllers/Models/UpdateRobotModelQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public struct UpdateRobotModelQuery
public float? BatteryWarningThreshold { get; set; }

/// <summary>
/// Upper pressure warning threshold in mBar
/// Upper pressure warning threshold in Bar
/// </summary>
public float? UpperPressureWarningThreshold { get; set; }

/// <summary>
/// Lower pressure warning threshold in mBar
/// Lower pressure warning threshold in Bar
/// </summary>
public float? LowerPressureWarningThreshold { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Database/Context/InitDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,8 @@ public static void AddRobotModelsToDatabase(FlotillaDbContext context)
{
Type = type,
BatteryWarningThreshold = 0f,
LowerPressureWarningThreshold = 0f,
UpperPressureWarningThreshold = 80f
LowerPressureWarningThreshold = 0.01f,
UpperPressureWarningThreshold = 0.08f
};
context.Add(model);
}
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Database/Models/RobotModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public RobotModel(CreateRobotModelQuery query)
public float? BatteryWarningThreshold { get; set; }

/// <summary>
/// Upper pressure warning threshold in mBar
/// Upper pressure warning threshold in Bar
/// </summary>
public float? UpperPressureWarningThreshold { get; set; }

/// <summary>
/// Lower pressure warning threshold in mBar
/// Lower pressure warning threshold in Bar
/// </summary>
public float? LowerPressureWarningThreshold { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,22 @@ const LocalisationDialog = ({ setIsCheckConfirmed, robot, deckName }: CheckDialo

const PressureDialog = ({ setIsCheckConfirmed, robot, deckName }: CheckDialogProps) => {
const { TranslateText } = useLanguageContext()
const barToMillibar = 1000

let statusText = ''
if (robot.pressureLevel) {
if (
robot.pressureLevel * 1000 > robot.model.lowerPressureWarningThreshold &&
robot.pressureLevel * 1000 < robot.model.upperPressureWarningThreshold
(!robot.model.lowerPressureWarningThreshold ||
robot.pressureLevel > robot.model.lowerPressureWarningThreshold) &&
(!robot.model.upperPressureWarningThreshold ||
robot.pressureLevel < robot.model.upperPressureWarningThreshold)
) {
statusText = `${TranslateText('The current pressure level is')} ${
robot.pressureLevel * 1000
robot.pressureLevel * barToMillibar
} ${TranslateText('which is within the specified range')}`
} else {
statusText = `${TranslateText('Warning')}: ${TranslateText('The current pressure level is')} ${
robot.pressureLevel * 1000
robot.pressureLevel * barToMillibar
} ${TranslateText('which is NOT within the specified range')}`
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,26 @@ const StyledTypography = styled(Typography)<{ $fontSize?: 24 | 16 | 18 | 32 | 40
font-size: ${(props) => props.$fontSize};
`
interface PressureStatusDisplayProps {
pressureInBar: number
pressure: number
itemSize?: 24 | 16 | 18 | 32 | 40 | 48 | undefined
upperPressureWarningThreshold?: number
lowerPressureWarningThreshold?: number
}

export const PressureStatusDisplay = ({
pressureInBar,
pressure,
itemSize,
upperPressureWarningThreshold,
lowerPressureWarningThreshold,
}: PressureStatusDisplayProps): JSX.Element => {
const barToMillibar = 1000
const pressureInMilliBar = `${Math.round(pressureInBar * barToMillibar)}mBar`
const pressureInMilliBar = `${Math.round(pressure * barToMillibar)}mBar`
let icon_color: string = tokens.colors.interactive.primary__resting.hex
let pressureStatus: PressureStatus

if (!upperPressureWarningThreshold || !lowerPressureWarningThreshold) {
pressureStatus = PressureStatus.Normal
} else if (
pressureInBar * barToMillibar > upperPressureWarningThreshold ||
pressureInBar * barToMillibar < lowerPressureWarningThreshold
) {
} else if (pressure > upperPressureWarningThreshold || pressure < lowerPressureWarningThreshold) {
pressureStatus = PressureStatus.Critical
} else {
pressureStatus = PressureStatus.Normal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const RobotStatusCard = ({ robot }: RobotProps) => {
<>
{robot.pressureLevel && (
<PressureStatusDisplay
pressureInBar={robot.pressureLevel}
pressure={robot.pressureLevel}
upperPressureWarningThreshold={robot.model.upperPressureWarningThreshold}
lowerPressureWarningThreshold={robot.model.lowerPressureWarningThreshold}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Pages/RobotPage/RobotPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const RobotPage = () => {
{selectedRobot.pressureLevel && (
<PressureStatusDisplay
itemSize={48}
pressureInBar={selectedRobot.pressureLevel}
pressure={selectedRobot.pressureLevel}
upperPressureWarningThreshold={
selectedRobot.model.upperPressureWarningThreshold
}
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/models/RobotModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ export interface RobotModel {
id: string
type: RobotType
batteryWarningThreshold?: number
upperPressureWarningThreshold: number
lowerPressureWarningThreshold: number
upperPressureWarningThreshold?: number
lowerPressureWarningThreshold?: number
}
export const placeholderRobotModel: RobotModel = {
id: 'placeholderModelId',
type: RobotType.Robot,
upperPressureWarningThreshold: 100,
lowerPressureWarningThreshold: 10,
}

0 comments on commit 9a8d081

Please sign in to comment.