Merge branch 'analog_pressure_component' into dev_environment
This commit is contained in:
commit
c92c4d392d
116 changed files with 1917 additions and 1086 deletions
|
|
@ -39,7 +39,8 @@ import {
|
|||
Voltage,
|
||||
VPD,
|
||||
Weight,
|
||||
CapacitorCable
|
||||
CapacitorCable,
|
||||
AnalogPressure
|
||||
} from "pbHelpers/ComponentTypes";
|
||||
//import { multilineGrainCableData } from "pbHelpers/ComponentTypes/GrainCable";
|
||||
//import { multilineCapCableData } from "./ComponentTypes/CapacitorCable";
|
||||
|
|
@ -98,7 +99,8 @@ const COMPONENT_TYPE_MAP = new Map<quack.ComponentType, Function>([
|
|||
[quack.ComponentType.COMPONENT_TYPE_VIBRATION_CHAIN, VibrationCable],
|
||||
[quack.ComponentType.COMPONENT_TYPE_DRAGER_GAS_DONGLE, dragerGasDongle],
|
||||
[quack.ComponentType.COMPONENT_TYPE_AIRFLOW, Airflow],
|
||||
[quack.ComponentType.COMPONENT_TYPE_TEMP_HUMIDITY, TempHumidity]
|
||||
[quack.ComponentType.COMPONENT_TYPE_TEMP_HUMIDITY, TempHumidity],
|
||||
[quack.ComponentType.COMPONENT_TYPE_ANALOG_PRESSURE, AnalogPressure]
|
||||
]);
|
||||
|
||||
export interface Subtype {
|
||||
|
|
@ -238,16 +240,16 @@ export function unitMeasurementSummary(
|
|||
): Summary {
|
||||
let vals: string[] = [];
|
||||
convertedMeasurement.values.forEach(val => {
|
||||
vals.push(val + describer.unit());
|
||||
vals.push(val + convertedMeasurement.unit);
|
||||
});
|
||||
let v = vals.join(", ");
|
||||
if (describer.enumerations().length > 0) {
|
||||
v = describer.enumerations()[parseFloat(vals[0])];
|
||||
}
|
||||
return {
|
||||
colour: describer.colour(),
|
||||
label: describer.label(),
|
||||
type: describer.type(),
|
||||
colour: convertedMeasurement.colour,
|
||||
label: convertedMeasurement.label,
|
||||
type: convertedMeasurement.type,
|
||||
value: v,
|
||||
error: convertedMeasurement.error
|
||||
};
|
||||
|
|
@ -260,6 +262,8 @@ export function unitMeasurementSummaries(
|
|||
): Summary[] {
|
||||
let summaries: Summary[] = [];
|
||||
measurements.measurementsFor.forEach(measurement => {
|
||||
//the only reason the user doesnt need to be passed in here is because it is only used for enumerations,
|
||||
//things like the unit and colour are in the measurement itself at this point
|
||||
let describer = describeMeasurement(measurement.type, compType, subtype);
|
||||
summaries.push(unitMeasurementSummary(measurement, describer));
|
||||
});
|
||||
|
|
@ -532,6 +536,7 @@ export function simpleLineChartData(
|
|||
}
|
||||
});
|
||||
}
|
||||
console.log(lineData)
|
||||
return lineData;
|
||||
}
|
||||
|
||||
|
|
@ -947,6 +952,15 @@ function getOverlayAreas(
|
|||
return overlayAreas;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this function adds lines to victory graphs for interactions on the component
|
||||
* DEPRECATED: we now use Recharts for our graphs
|
||||
* @param componentType
|
||||
* @param subtype
|
||||
* @param interactionCondition
|
||||
* @returns
|
||||
*/
|
||||
function createInteractionLine(
|
||||
componentType: quack.ComponentType,
|
||||
subtype: number,
|
||||
|
|
|
|||
88
src/pbHelpers/ComponentTypes/AnalogPressure.ts
Normal file
88
src/pbHelpers/ComponentTypes/AnalogPressure.ts
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import {
|
||||
ComponentTypeExtension,
|
||||
Summary,
|
||||
Subtype,
|
||||
simpleMeasurements,
|
||||
simpleSummaries,
|
||||
unitMeasurementSummaries,
|
||||
AreaChartData,
|
||||
GraphFilters,
|
||||
simpleAreaChartData,
|
||||
LineChartData,
|
||||
simpleLineChartData
|
||||
} from "pbHelpers/ComponentType";
|
||||
import PressureDarkIcon from "assets/components/pressureDark.png";
|
||||
import PressureLightIcon from "assets/components/pressureLight.png";
|
||||
import { quack } from "protobuf-ts/quack";
|
||||
import { describeMeasurement } from "pbHelpers/MeasurementDescriber";
|
||||
import { convertedUnitMeasurement } from "models/UnitMeasurement";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
|
||||
export function AnalogPressure(subtype: number = 0): ComponentTypeExtension {
|
||||
let pressure = describeMeasurement(
|
||||
quack.MeasurementType.MEASUREMENT_TYPE_PRESSURE,
|
||||
quack.ComponentType.COMPONENT_TYPE_ANALOG_PRESSURE,
|
||||
subtype
|
||||
);
|
||||
let voltage = describeMeasurement(
|
||||
quack.MeasurementType.MEASUREMENT_TYPE_VOLTAGE,
|
||||
quack.ComponentType.COMPONENT_TYPE_ANALOG_PRESSURE,
|
||||
subtype
|
||||
)
|
||||
let addressTypes = [quack.AddressType.ADDRESS_TYPE_I2C];
|
||||
return {
|
||||
type: quack.ComponentType.COMPONENT_TYPE_PRESSURE,
|
||||
subtypes: [
|
||||
{
|
||||
key: quack.AnalogPressureSubtype.ANALOG_PRESSURE_SUBTYPE_PMC21,
|
||||
value: "ANALOG_PRESSURE_SUBTYPE_PMC21",
|
||||
friendlyName: "PMC 21"
|
||||
} as Subtype
|
||||
],
|
||||
friendlyName: "Analog Pressure",
|
||||
description: "Measures the atmospheric pressure or absolute pressure",
|
||||
isController: false,
|
||||
isSource: true,
|
||||
isCalibratable: true,
|
||||
hasFan: true,
|
||||
addressTypes: addressTypes,
|
||||
interactionResultTypes: [],
|
||||
states: [],
|
||||
measurements: simpleMeasurements(pressure, voltage),
|
||||
measurementSummary: async function(measurement: quack.Measurement): Promise<Array<Summary>> {
|
||||
return simpleSummaries(measurement, pressure);
|
||||
},
|
||||
unitMeasurementSummary: (
|
||||
measurements: convertedUnitMeasurement,
|
||||
): Summary[] => {
|
||||
return unitMeasurementSummaries(
|
||||
measurements,
|
||||
quack.ComponentType.COMPONENT_TYPE_PRESSURE,
|
||||
subtype,
|
||||
);
|
||||
},
|
||||
areaChartData: (
|
||||
measurement: pond.UnitMeasurementsForComponent,
|
||||
smoothingAverages?: number,
|
||||
filters?: GraphFilters
|
||||
): AreaChartData => {
|
||||
return simpleAreaChartData(measurement, smoothingAverages, filters);
|
||||
},
|
||||
lineChartData: (
|
||||
measurement: pond.UnitMeasurementsForComponent,
|
||||
smoothingAverages?: number,
|
||||
filters?: GraphFilters
|
||||
): LineChartData => {
|
||||
return simpleLineChartData(
|
||||
quack.ComponentType.COMPONENT_TYPE_PRESSURE,
|
||||
measurement,
|
||||
smoothingAverages,
|
||||
filters
|
||||
);
|
||||
},
|
||||
minMeasurementPeriodMs: 1000,
|
||||
icon: (theme?: "light" | "dark"): string | undefined => {
|
||||
return theme === "light" ? PressureDarkIcon : PressureLightIcon;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -29,3 +29,4 @@ export * from "./Voltage";
|
|||
export * from "./VPD";
|
||||
export * from "./Weight";
|
||||
export * from "./CapacitorCable";
|
||||
export * from "./AnalogPressure";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Interaction, Component } from "models";
|
||||
import { Interaction, Component, User } from "models";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { quack } from "protobuf-ts/quack";
|
||||
import { or, notNull } from "utils/types";
|
||||
|
|
@ -172,7 +172,8 @@ export const interactionResultText = (interaction: Interaction, sink?: Component
|
|||
export const interactionConditionText = (
|
||||
source: Component | undefined,
|
||||
condition: pond.IInteractionCondition,
|
||||
and: boolean
|
||||
and: boolean,
|
||||
user?: User
|
||||
) => {
|
||||
let comparison = "is exactly";
|
||||
switch (condition.comparison) {
|
||||
|
|
@ -189,7 +190,7 @@ export const interactionConditionText = (
|
|||
if (!condition.measurementType) return "Unknown " + comparison + " " + condition.value;
|
||||
let sourceType = source && source.settings.type;
|
||||
let sourceSubtype = source && source.settings.subtype;
|
||||
let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype);
|
||||
let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype, undefined, user);
|
||||
return (
|
||||
(and ? "and " : "") +
|
||||
measurement.label() +
|
||||
|
|
|
|||
|
|
@ -13,12 +13,13 @@ import {
|
|||
yellow
|
||||
} from "@mui/material/colors";
|
||||
import { GraphType } from "common/Graph";
|
||||
import { User } from "models";
|
||||
import { IsCardController } from "products/DeviceProduct";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { quack } from "protobuf-ts/quack";
|
||||
import { getTextSecondary } from "theme/text";
|
||||
// import { getTextSecondary } from "theme";
|
||||
import { getDistanceUnit, getPressureUnit, getTemperatureUnit, roundTo } from "utils";
|
||||
import { roundTo } from "utils";
|
||||
import { extract } from "utils/types";
|
||||
|
||||
interface Enumeration {
|
||||
|
|
@ -64,7 +65,8 @@ export class MeasurementDescriber {
|
|||
measurementType: quack.MeasurementType,
|
||||
componentType: quack.ComponentType,
|
||||
componentSubtype: number,
|
||||
product?: pond.DeviceProduct
|
||||
product?: pond.DeviceProduct,
|
||||
user?: User
|
||||
) {
|
||||
this.measurementType = measurementType;
|
||||
this.details = {
|
||||
|
|
@ -87,7 +89,7 @@ export class MeasurementDescriber {
|
|||
case quack.MeasurementType.MEASUREMENT_TYPE_INVALID:
|
||||
break;
|
||||
case quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE:
|
||||
let temperatureUnit = getTemperatureUnit();
|
||||
let temperatureUnit = user?.tempUnit() ?? pond.TemperatureUnit.TEMPERATURE_UNIT_CELSIUS;
|
||||
let isFahrenheit = temperatureUnit === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT;
|
||||
this.details.label = "Temperature";
|
||||
this.details.unit = isFahrenheit ? "°F" : "°C";
|
||||
|
|
@ -233,7 +235,8 @@ export class MeasurementDescriber {
|
|||
}
|
||||
break;
|
||||
case quack.MeasurementType.MEASUREMENT_TYPE_PRESSURE:
|
||||
let pressureUnit = getPressureUnit();
|
||||
let pressureUnit =
|
||||
user?.pressureUnit() ?? pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER;
|
||||
let isIWG = pressureUnit === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER;
|
||||
this.details.label = "Pressure";
|
||||
this.details.unit = isIWG ? "iwg" : "kPa";
|
||||
|
|
@ -437,7 +440,8 @@ export class MeasurementDescriber {
|
|||
this.details.max = 100000;
|
||||
break;
|
||||
case quack.MeasurementType.MEASUREMENT_TYPE_DISTANCE_CM:
|
||||
let distanceUnit = getDistanceUnit();
|
||||
let distanceUnit =
|
||||
user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET;
|
||||
this.details.label = "Distance";
|
||||
this.details.unit = "cm";
|
||||
if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
|
||||
|
|
@ -451,7 +455,8 @@ export class MeasurementDescriber {
|
|||
this.details.max = 100000;
|
||||
break;
|
||||
case quack.MeasurementType.MEASUREMENT_TYPE_SPEED:
|
||||
let speedUnit = getDistanceUnit()
|
||||
let speedUnit =
|
||||
user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET;
|
||||
this.details.label = "Speed";
|
||||
this.details.unit = speedUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m/s" : "ft/m"; //yes this is meters per second and feet per minute
|
||||
this.details.colour = green["500"];
|
||||
|
|
@ -689,11 +694,12 @@ export function describeMeasurement(
|
|||
componentType: quack.ComponentType | null | undefined = quack.ComponentType
|
||||
.COMPONENT_TYPE_INVALID,
|
||||
componentSubtype: number = 0,
|
||||
product?: pond.DeviceProduct
|
||||
product?: pond.DeviceProduct,
|
||||
user?: User
|
||||
): MeasurementDescriber {
|
||||
measurementType = measurementType
|
||||
? measurementType
|
||||
: quack.MeasurementType.MEASUREMENT_TYPE_INVALID;
|
||||
componentType = componentType ? componentType : quack.ComponentType.COMPONENT_TYPE_INVALID;
|
||||
return new MeasurementDescriber(measurementType, componentType, componentSubtype, product);
|
||||
return new MeasurementDescriber(measurementType, componentType, componentSubtype, product, user);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue