with changing unit preferences and such to use the user object and not local storage, the decriber needed to be updated as well and i missed that part, so now describeMeasurement takes in an optional user and uses its settings for the unit and such and when not passed in will use the defaults
This commit is contained in:
parent
9d41499c27
commit
52c8a02af3
18 changed files with 117 additions and 56 deletions
|
|
@ -103,7 +103,7 @@ export default function BinConditioningInteraction(props: Props) {
|
||||||
let sliderVals: Map<quack.MeasurementType, number> = new Map();
|
let sliderVals: Map<quack.MeasurementType, number> = new Map();
|
||||||
let sliderMarks: Map<quack.MeasurementType, number> = new Map();
|
let sliderMarks: Map<quack.MeasurementType, number> = new Map();
|
||||||
passedInteraction.conditions().forEach(condition => {
|
passedInteraction.conditions().forEach(condition => {
|
||||||
let describer = describeMeasurement(condition.measurementType, source.type());
|
let describer = describeMeasurement(condition.measurementType, source.type(), undefined, undefined, user);
|
||||||
//NOTE: toDisplay will convert the temp value to fahrenheit
|
//NOTE: toDisplay will convert the temp value to fahrenheit
|
||||||
sliderVals.set(condition.measurementType, describer.toDisplay(condition.value));
|
sliderVals.set(condition.measurementType, describer.toDisplay(condition.value));
|
||||||
});
|
});
|
||||||
|
|
@ -173,17 +173,17 @@ export default function BinConditioningInteraction(props: Props) {
|
||||||
return (
|
return (
|
||||||
<Grid container>
|
<Grid container>
|
||||||
{interaction.conditions().map((condition, i) => {
|
{interaction.conditions().map((condition, i) => {
|
||||||
let describer = describeMeasurement(condition.measurementType, source?.type());
|
let describer = describeMeasurement(condition.measurementType, source?.type(), source.subType(), undefined, user);
|
||||||
let labelTail = "";
|
let labelTail = describer.unit();
|
||||||
let marks: Mark[] = [];
|
let marks: Mark[] = [];
|
||||||
|
|
||||||
if (condition.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE) {
|
// if (condition.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE) {
|
||||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
// if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||||
labelTail = "°F";
|
// labelTail = "°F";
|
||||||
} else {
|
// } else {
|
||||||
labelTail = "°C";
|
// labelTail = "°C";
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (condition.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_PERCENT) {
|
if (condition.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_PERCENT) {
|
||||||
labelTail = "%";
|
labelTail = "%";
|
||||||
}
|
}
|
||||||
|
|
@ -198,7 +198,7 @@ export default function BinConditioningInteraction(props: Props) {
|
||||||
return (
|
return (
|
||||||
<Grid key={i} container item xs={12} alignContent="center" alignItems="center">
|
<Grid key={i} container item xs={12} alignContent="center" alignItems="center">
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
{interactionConditionText(source, condition, false)}
|
{interactionConditionText(source, condition, false, user)}
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} style={{ marginBottom: 20 }}>
|
<Grid item xs={12} style={{ marginBottom: 20 }}>
|
||||||
<Slider
|
<Slider
|
||||||
|
|
|
||||||
|
|
@ -87,9 +87,24 @@ export default function GrainNodeInteractions(props: Props) {
|
||||||
const [nodeHum, setNodeHum] = useState<number>();
|
const [nodeHum, setNodeHum] = useState<number>();
|
||||||
const [nodeMoist, setNodeMoist] = useState<number | undefined>();
|
const [nodeMoist, setNodeMoist] = useState<number | undefined>();
|
||||||
const [{ user, as }] = useGlobalState();
|
const [{ user, as }] = useGlobalState();
|
||||||
const tempDescriber = describeMeasurement(quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE);
|
const tempDescriber = describeMeasurement(
|
||||||
const humDescriber = describeMeasurement(quack.MeasurementType.MEASUREMENT_TYPE_PERCENT);
|
quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE,
|
||||||
const moistureDescriber = describeMeasurement(quack.MeasurementType.MEASUREMENT_TYPE_GRAIN_EMC);
|
quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
user);
|
||||||
|
const humDescriber = describeMeasurement(
|
||||||
|
quack.MeasurementType.MEASUREMENT_TYPE_PERCENT,
|
||||||
|
quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
user);
|
||||||
|
const moistureDescriber = describeMeasurement(
|
||||||
|
quack.MeasurementType.MEASUREMENT_TYPE_GRAIN_EMC,
|
||||||
|
quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
user);
|
||||||
const [topNode, setTopNode] = useState(false);
|
const [topNode, setTopNode] = useState(false);
|
||||||
const [excluded, setExcluded] = useState(false);
|
const [excluded, setExcluded] = useState(false);
|
||||||
const componentAPI = useComponentAPI();
|
const componentAPI = useComponentAPI();
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,9 @@ if (!selectedDevice) return;
|
||||||
describeMeasurement(
|
describeMeasurement(
|
||||||
quack.MeasurementType.MEASUREMENT_TYPE_PERCENT,
|
quack.MeasurementType.MEASUREMENT_TYPE_PERCENT,
|
||||||
sensor.settings.type,
|
sensor.settings.type,
|
||||||
sensor.settings.subtype
|
sensor.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).toStored(hum)
|
).toStored(hum)
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
@ -301,7 +303,9 @@ if (!selectedDevice) return;
|
||||||
let tempVal = describeMeasurement(
|
let tempVal = describeMeasurement(
|
||||||
quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE,
|
quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE,
|
||||||
sensor.settings.type,
|
sensor.settings.type,
|
||||||
sensor.settings.subtype
|
sensor.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).toStored(temp);
|
).toStored(temp);
|
||||||
|
|
||||||
let tempCondition = pond.InteractionCondition.create({
|
let tempCondition = pond.InteractionCondition.create({
|
||||||
|
|
@ -385,7 +389,9 @@ if (!selectedDevice) return;
|
||||||
value: describeMeasurement(
|
value: describeMeasurement(
|
||||||
quack.MeasurementType.MEASUREMENT_TYPE_PERCENT,
|
quack.MeasurementType.MEASUREMENT_TYPE_PERCENT,
|
||||||
sensor.settings.type,
|
sensor.settings.type,
|
||||||
sensor.settings.subtype
|
sensor.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).toStored(humidityPreset)
|
).toStored(humidityPreset)
|
||||||
});
|
});
|
||||||
conditions.push(fanConditionOne);
|
conditions.push(fanConditionOne);
|
||||||
|
|
@ -397,7 +403,9 @@ if (!selectedDevice) return;
|
||||||
let tempVal = describeMeasurement(
|
let tempVal = describeMeasurement(
|
||||||
quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE,
|
quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE,
|
||||||
sensor.settings.type,
|
sensor.settings.type,
|
||||||
sensor.settings.subtype
|
sensor.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).toStored(tempPreset);
|
).toStored(tempPreset);
|
||||||
|
|
||||||
let fanConditionTwo = pond.InteractionCondition.create({
|
let fanConditionTwo = pond.InteractionCondition.create({
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ export default function MeasurementsChart(props: Props) {
|
||||||
const [currentMax, setCurrentMax] = useState<number | string>("dataMax");
|
const [currentMax, setCurrentMax] = useState<number | string>("dataMax");
|
||||||
const [newChart, setNewChart] = useState(false);
|
const [newChart, setNewChart] = useState(false);
|
||||||
const [xDomain, setXDomain] = useState<string[] | number[]>(["dataMin", "dataMax"]);
|
const [xDomain, setXDomain] = useState<string[] | number[]>(["dataMin", "dataMax"]);
|
||||||
const [{ showErrors }, dispatch] = useGlobalState();
|
const [{ showErrors, user }, dispatch] = useGlobalState();
|
||||||
const isMobile = useMobile();
|
const isMobile = useMobile();
|
||||||
// const [zoomStart, setZoomStart] = useState<Moment>();
|
// const [zoomStart, setZoomStart] = useState<Moment>();
|
||||||
// const [zoomEnd, setZoomEnd] = useState<Moment>();
|
// const [zoomEnd, setZoomEnd] = useState<Moment>();
|
||||||
|
|
@ -123,7 +123,7 @@ export default function MeasurementsChart(props: Props) {
|
||||||
if (filters?.selectedInteractions?.includes(interaction.key())) {
|
if (filters?.selectedInteractions?.includes(interaction.key())) {
|
||||||
interaction.settings.conditions.forEach((condition, j) => {
|
interaction.settings.conditions.forEach((condition, j) => {
|
||||||
if (condition.measurementType === measurementType) {
|
if (condition.measurementType === measurementType) {
|
||||||
let describer = describeMeasurement(condition.measurementType);
|
let describer = describeMeasurement(condition.measurementType, undefined, undefined, undefined, user);
|
||||||
selectedInteractions.push(
|
selectedInteractions.push(
|
||||||
<ReferenceLine
|
<ReferenceLine
|
||||||
key={interaction.key() + ":condition" + j}
|
key={interaction.key() + ":condition" + j}
|
||||||
|
|
@ -197,7 +197,9 @@ export default function MeasurementsChart(props: Props) {
|
||||||
let describer = describeMeasurement(
|
let describer = describeMeasurement(
|
||||||
m.type,
|
m.type,
|
||||||
component.settings.type,
|
component.settings.type,
|
||||||
component.settings.subtype
|
component.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
);
|
);
|
||||||
let min: string | number = "dataMin";
|
let min: string | number = "dataMin";
|
||||||
let max: string | number = "dataMax";
|
let max: string | number = "dataMax";
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,9 @@ export default function ComponentForm(props: Props) {
|
||||||
let describer = describeMeasurement(
|
let describer = describeMeasurement(
|
||||||
primaryMeasurement(formComponent.settings.type),
|
primaryMeasurement(formComponent.settings.type),
|
||||||
formComponent.settings.type,
|
formComponent.settings.type,
|
||||||
formComponent.settings.subtype
|
formComponent.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
);
|
);
|
||||||
let offset = describer.toDisplay(formComponent.settings.calibrationOffset);
|
let offset = describer.toDisplay(formComponent.settings.calibrationOffset);
|
||||||
let formCoefficients: string[] = [];
|
let formCoefficients: string[] = [];
|
||||||
|
|
@ -480,7 +482,9 @@ export default function ComponentForm(props: Props) {
|
||||||
f.component.settings.calibrationOffset = describeMeasurement(
|
f.component.settings.calibrationOffset = describeMeasurement(
|
||||||
primaryMeasurement(f.component.settings.type),
|
primaryMeasurement(f.component.settings.type),
|
||||||
f.component.settings.type,
|
f.component.settings.type,
|
||||||
f.component.settings.subtype
|
f.component.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).toStored(+event.target.value);
|
).toStored(+event.target.value);
|
||||||
}
|
}
|
||||||
setForm(f);
|
setForm(f);
|
||||||
|
|
@ -493,7 +497,9 @@ export default function ComponentForm(props: Props) {
|
||||||
f.component.settings.calibrations[index].calibrationOffset = describeMeasurement(
|
f.component.settings.calibrations[index].calibrationOffset = describeMeasurement(
|
||||||
primaryMeasurement(f.component.settings.type),
|
primaryMeasurement(f.component.settings.type),
|
||||||
f.component.settings.type,
|
f.component.settings.type,
|
||||||
f.component.settings.subtype
|
f.component.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).toStored(+event.target.value);
|
).toStored(+event.target.value);
|
||||||
}
|
}
|
||||||
setForm(f);
|
setForm(f);
|
||||||
|
|
@ -731,7 +737,9 @@ export default function ComponentForm(props: Props) {
|
||||||
{describeMeasurement(
|
{describeMeasurement(
|
||||||
primaryMeasurement(component.settings.type),
|
primaryMeasurement(component.settings.type),
|
||||||
component.settings.type,
|
component.settings.type,
|
||||||
component.settings.subtype
|
component.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).unit()}
|
).unit()}
|
||||||
</InputAdornment>
|
</InputAdornment>
|
||||||
)
|
)
|
||||||
|
|
@ -823,7 +831,7 @@ export default function ComponentForm(props: Props) {
|
||||||
|
|
||||||
const describeSource = (measurementType: quack.MeasurementType): MeasurementDescriber => {
|
const describeSource = (measurementType: quack.MeasurementType): MeasurementDescriber => {
|
||||||
const { component } = form;
|
const { component } = form;
|
||||||
return describeMeasurement(measurementType, component.type(), component.subType());
|
return describeMeasurement(measurementType, component.type(), component.subType(), undefined, user);
|
||||||
};
|
};
|
||||||
|
|
||||||
const availableMeasurementTypes = (type: quack.ComponentType): quack.MeasurementType[] => {
|
const availableMeasurementTypes = (type: quack.ComponentType): quack.MeasurementType[] => {
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ class ExportDataSettings extends React.Component<Props, State> {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
formatMeasurements(measurements: Array<pond.Measurement>): Promise<Array<any>> {
|
formatMeasurements(measurements: Array<pond.Measurement>): Promise<Array<any>> {
|
||||||
const { device, component } = this.props;
|
const { device, component, user } = this.props;
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
if (!measurements) reject("Invalid measurements");
|
if (!measurements) reject("Invalid measurements");
|
||||||
|
|
@ -237,7 +237,9 @@ class ExportDataSettings extends React.Component<Props, State> {
|
||||||
let unit = describeMeasurement(
|
let unit = describeMeasurement(
|
||||||
componentMeasurement.measurementType,
|
componentMeasurement.measurementType,
|
||||||
component.settings.type,
|
component.settings.type,
|
||||||
component.settings.subtype
|
component.settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).unit();
|
).unit();
|
||||||
let key = componentMeasurement.label + " (" + unit + ")";
|
let key = componentMeasurement.label + " (" + unit + ")";
|
||||||
row[key] = componentMeasurement.extract(measurement.measurement);
|
row[key] = componentMeasurement.extract(measurement.measurement);
|
||||||
|
|
|
||||||
|
|
@ -282,13 +282,13 @@ export default function GateGraphs(props: Props) {
|
||||||
if (um.values[0] && um.values[0].values.length > 1) {
|
if (um.values[0] && um.values[0].values.length > 1) {
|
||||||
return areaGraph(
|
return areaGraph(
|
||||||
um,
|
um,
|
||||||
describeMeasurement(um.type, component.type(), component.subType()),
|
describeMeasurement(um.type, component.type(), component.subType(), undefined, user),
|
||||||
component.settings.smoothingAverages
|
component.settings.smoothingAverages
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return lineGraph(
|
return lineGraph(
|
||||||
um,
|
um,
|
||||||
describeMeasurement(um.type, component.type(), component.subType()),
|
describeMeasurement(um.type, component.type(), component.subType(), undefined, user),
|
||||||
component.settings.smoothingAverages
|
component.settings.smoothingAverages
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,9 @@ export default function InteractionSettings(props: Props) {
|
||||||
let value = describeMeasurement(
|
let value = describeMeasurement(
|
||||||
condition.measurementType,
|
condition.measurementType,
|
||||||
or(initialComponent, Component.create()).settings.type,
|
or(initialComponent, Component.create()).settings.type,
|
||||||
or(initialComponent, Component.create()).settings.subtype
|
or(initialComponent, Component.create()).settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).toDisplay(condition.value);
|
).toDisplay(condition.value);
|
||||||
rawConditionValues.push(value.toString());
|
rawConditionValues.push(value.toString());
|
||||||
});
|
});
|
||||||
|
|
@ -425,7 +427,7 @@ export default function InteractionSettings(props: Props) {
|
||||||
mappedComponents.get(componentIDToString(interaction.settings.source)),
|
mappedComponents.get(componentIDToString(interaction.settings.source)),
|
||||||
Component.create()
|
Component.create()
|
||||||
);
|
);
|
||||||
return describeMeasurement(measurementType, source.settings.type, source.settings.subtype);
|
return describeMeasurement(measurementType, source.settings.type, source.settings.subtype, undefined, user);
|
||||||
};
|
};
|
||||||
|
|
||||||
const describeSink = (): MeasurementDescriber => {
|
const describeSink = (): MeasurementDescriber => {
|
||||||
|
|
@ -433,7 +435,9 @@ export default function InteractionSettings(props: Props) {
|
||||||
return describeMeasurement(
|
return describeMeasurement(
|
||||||
Measurement.boolean,
|
Measurement.boolean,
|
||||||
or(sink, Component.create()).settings.type,
|
or(sink, Component.create()).settings.type,
|
||||||
or(sink, Component.create()).settings.subtype
|
or(sink, Component.create()).settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -861,7 +865,7 @@ export default function InteractionSettings(props: Props) {
|
||||||
const conditionGroup = (index: number) => {
|
const conditionGroup = (index: number) => {
|
||||||
if (index >= numConditions) return;
|
if (index >= numConditions) return;
|
||||||
let measurementType = interaction.settings.conditions[index].measurementType;
|
let measurementType = interaction.settings.conditions[index].measurementType;
|
||||||
let source = describeSource(measurementType);
|
let source = describeSource(measurementType, );
|
||||||
let isBoolean = isBooleanValue(index);
|
let isBoolean = isBooleanValue(index);
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={index}>
|
<React.Fragment key={index}>
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ interface Props {
|
||||||
|
|
||||||
export default function InteractionsOverview(props: Props) {
|
export default function InteractionsOverview(props: Props) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [{as}] = useGlobalState();
|
const [{as, user}] = useGlobalState();
|
||||||
const interactionsAPI = useInteractionsAPI();
|
const interactionsAPI = useInteractionsAPI();
|
||||||
const { success, error } = useSnackbar();
|
const { success, error } = useSnackbar();
|
||||||
const { device, component, components, permissions, refreshCallback } = props;
|
const { device, component, components, permissions, refreshCallback } = props;
|
||||||
|
|
@ -118,12 +118,12 @@ export default function InteractionsOverview(props: Props) {
|
||||||
if (!conditions) return items;
|
if (!conditions) return items;
|
||||||
conditions.forEach((condition: pond.IInteractionCondition, conditionIndex: number) => {
|
conditions.forEach((condition: pond.IInteractionCondition, conditionIndex: number) => {
|
||||||
let measurementType = condition.measurementType;
|
let measurementType = condition.measurementType;
|
||||||
let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype);
|
let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype, undefined, user);
|
||||||
items.push(
|
items.push(
|
||||||
<Grid container size={{ sm: 12 }} key={conditionIndex} alignItems="center">
|
<Grid container size={{ sm: 12 }} key={conditionIndex} alignItems="center">
|
||||||
<Grid size={{ xs: 12, sm: 6 }}>
|
<Grid size={{ xs: 12, sm: 6 }}>
|
||||||
<Typography variant="caption" gutterBottom>
|
<Typography variant="caption" gutterBottom>
|
||||||
{interactionConditionText(source, condition, conditionIndex > 0)}
|
{interactionConditionText(source, condition, conditionIndex > 0, user)}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid size={{ xs: 12, sm: 6 }}>
|
<Grid size={{ xs: 12, sm: 6 }}>
|
||||||
|
|
@ -185,7 +185,7 @@ export default function InteractionsOverview(props: Props) {
|
||||||
let condition = conditions[conditionIndex];
|
let condition = conditions[conditionIndex];
|
||||||
let sourceType = source && source.settings.type;
|
let sourceType = source && source.settings.type;
|
||||||
let sourceSubtype = source && source.settings.subtype;
|
let sourceSubtype = source && source.settings.subtype;
|
||||||
let describer = describeMeasurement(condition.measurementType, sourceType, sourceSubtype);
|
let describer = describeMeasurement(condition.measurementType, sourceType, sourceSubtype, undefined, user);
|
||||||
condition.value = describer.toStored(value);
|
condition.value = describer.toStored(value);
|
||||||
updatedDirtyInteractions.set(interactionIndex, true);
|
updatedDirtyInteractions.set(interactionIndex, true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ import { quack } from "protobuf-ts/pond";
|
||||||
import { or } from "utils/types";
|
import { or } from "utils/types";
|
||||||
import { clone, cloneDeep } from "lodash";
|
import { clone, cloneDeep } from "lodash";
|
||||||
import { Component } from "models";
|
import { Component } from "models";
|
||||||
import { describeMeasurement } from "pbHelpers/MeasurementDescriber";
|
|
||||||
import { extractGrainCable } from "pbHelpers/ComponentTypes";
|
|
||||||
|
|
||||||
export class CO2 {
|
export class CO2 {
|
||||||
public settings: pond.ComponentSettings = pond.ComponentSettings.create();
|
public settings: pond.ComponentSettings = pond.ComponentSettings.create();
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export class UnitMeasurement {
|
||||||
public static create(pb?: pond.UnitMeasurementsForComponent, user?: User): UnitMeasurement {
|
public static create(pb?: pond.UnitMeasurementsForComponent, user?: User): UnitMeasurement {
|
||||||
let my = new UnitMeasurement();
|
let my = new UnitMeasurement();
|
||||||
if (pb) {
|
if (pb) {
|
||||||
let describer = describeMeasurement(pb.type, pb.componentType);
|
let describer = describeMeasurement(pb.type, pb.componentType, undefined, undefined, user);
|
||||||
let values = pb.values;
|
let values = pb.values;
|
||||||
if (user) {
|
if (user) {
|
||||||
values = unitConversion(pb.values, pb.type, user);
|
values = unitConversion(pb.values, pb.type, user);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { pond, quack } from "protobuf-ts/pond";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import NewObjectInteraction from "./NewObjectInteraction";
|
import NewObjectInteraction from "./NewObjectInteraction";
|
||||||
import { Option } from "common/SearchSelect";
|
import { Option } from "common/SearchSelect";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
export interface Alert {
|
export interface Alert {
|
||||||
conditions: pond.InteractionCondition[];
|
conditions: pond.InteractionCondition[];
|
||||||
|
|
@ -20,10 +21,11 @@ interface Props {
|
||||||
|
|
||||||
export default function Alerts(props: Props){
|
export default function Alerts(props: Props){
|
||||||
const {alerts, addNew, permissions} = props
|
const {alerts, addNew, permissions} = props
|
||||||
|
const [{user}] = useGlobalState();
|
||||||
// const [openNewAlert, setOpenNewAlert] = useState(false)
|
// const [openNewAlert, setOpenNewAlert] = useState(false)
|
||||||
|
|
||||||
const readableCondition = (condition: pond.InteractionCondition) => {
|
const readableCondition = (condition: pond.InteractionCondition) => {
|
||||||
let describer = describeMeasurement(condition.measurementType);
|
let describer = describeMeasurement(condition.measurementType, undefined, undefined, undefined, user);
|
||||||
let type = describer.label();
|
let type = describer.label();
|
||||||
let comparison =
|
let comparison =
|
||||||
condition.comparison === quack.RelationalOperator.RELATIONAL_OPERATOR_EQUAL_TO
|
condition.comparison === quack.RelationalOperator.RELATIONAL_OPERATOR_EQUAL_TO
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { Component, Device, Interaction } from "models";
|
||||||
import { interactionResultText } from "pbHelpers/Interaction";
|
import { interactionResultText } from "pbHelpers/Interaction";
|
||||||
import { describeMeasurement } from "pbHelpers/MeasurementDescriber";
|
import { describeMeasurement } from "pbHelpers/MeasurementDescriber";
|
||||||
import { pond, quack } from "protobuf-ts/pond";
|
import { pond, quack } from "protobuf-ts/pond";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
export interface Control {
|
export interface Control {
|
||||||
|
|
@ -23,6 +24,7 @@ interface Props {
|
||||||
|
|
||||||
export default function Controls(props: Props){
|
export default function Controls(props: Props){
|
||||||
const { devices, controls, addNew, permissions } = props
|
const { devices, controls, addNew, permissions } = props
|
||||||
|
const [{user}] = useGlobalState();
|
||||||
const [deviceControls, setDeviceControls] = useState<Map<number, Control[]>>(new Map())
|
const [deviceControls, setDeviceControls] = useState<Map<number, Control[]>>(new Map())
|
||||||
const [openDeviceMenu, setOpenDeviceMenu] = useState(false)
|
const [openDeviceMenu, setOpenDeviceMenu] = useState(false)
|
||||||
const [anchor, setAnchor] = useState<null | HTMLElement>(null)
|
const [anchor, setAnchor] = useState<null | HTMLElement>(null)
|
||||||
|
|
@ -45,7 +47,7 @@ export default function Controls(props: Props){
|
||||||
let conditions: string = ""
|
let conditions: string = ""
|
||||||
let firstSource = control.sourceComponents[0]
|
let firstSource = control.sourceComponents[0]
|
||||||
control.conditions.forEach((condition, index) => {
|
control.conditions.forEach((condition, index) => {
|
||||||
let describer = describeMeasurement(condition.measurementType, firstSource.type(), firstSource.subType());
|
let describer = describeMeasurement(condition.measurementType, firstSource.type(), firstSource.subType(), undefined, user);
|
||||||
let type = describer.label();
|
let type = describer.label();
|
||||||
let comparison =
|
let comparison =
|
||||||
condition.comparison === quack.RelationalOperator.RELATIONAL_OPERATOR_EQUAL_TO
|
condition.comparison === quack.RelationalOperator.RELATIONAL_OPERATOR_EQUAL_TO
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ const useStyles = makeStyles((theme: Theme) => {
|
||||||
export default function NewObjectInteraction(props: Props){
|
export default function NewObjectInteraction(props: Props){
|
||||||
const { open, onClose, device, linkedComponents, componentDevices } = props
|
const { open, onClose, device, linkedComponents, componentDevices } = props
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const [{ as }] = useGlobalState();
|
const [{ as, user }] = useGlobalState();
|
||||||
const {openSnack} = useSnackbar();
|
const {openSnack} = useSnackbar();
|
||||||
const interactionsAPI = useInteractionsAPI();
|
const interactionsAPI = useInteractionsAPI();
|
||||||
const [newAlertComponentType, setNewAlertComponentType] = useState<quack.ComponentType>(
|
const [newAlertComponentType, setNewAlertComponentType] = useState<quack.ComponentType>(
|
||||||
|
|
@ -249,7 +249,7 @@ export default function NewObjectInteraction(props: Props){
|
||||||
const measurementTypeMenuItems = () => {
|
const measurementTypeMenuItems = () => {
|
||||||
return availableMeasurementTypes(newAlertComponentType).map(measurementType => (
|
return availableMeasurementTypes(newAlertComponentType).map(measurementType => (
|
||||||
<MenuItem key={measurementType} value={measurementType}>
|
<MenuItem key={measurementType} value={measurementType}>
|
||||||
{describeMeasurement(measurementType).label()}
|
{describeMeasurement(measurementType, undefined, undefined, undefined, user).label()}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
@ -531,7 +531,9 @@ export default function NewObjectInteraction(props: Props){
|
||||||
return describeMeasurement(
|
return describeMeasurement(
|
||||||
Measurement.boolean,
|
Measurement.boolean,
|
||||||
or(sink, Component.create()).settings.type,
|
or(sink, Component.create()).settings.type,
|
||||||
or(sink, Component.create()).settings.subtype
|
or(sink, Component.create()).settings.subtype,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -569,7 +569,11 @@ export default function Bins(props: Props) {
|
||||||
measurementType: quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE,
|
measurementType: quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE,
|
||||||
comparison: quack.RelationalOperator.RELATIONAL_OPERATOR_GREATER_THAN,
|
comparison: quack.RelationalOperator.RELATIONAL_OPERATOR_GREATER_THAN,
|
||||||
value: describeMeasurement(
|
value: describeMeasurement(
|
||||||
quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE
|
quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
user
|
||||||
).toStored(bin.settings.highTemp)
|
).toStored(bin.settings.highTemp)
|
||||||
}),
|
}),
|
||||||
componentLocation: quack.ComponentID.create({
|
componentLocation: quack.ComponentID.create({
|
||||||
|
|
|
||||||
|
|
@ -236,16 +236,16 @@ export function unitMeasurementSummary(
|
||||||
): Summary {
|
): Summary {
|
||||||
let vals: string[] = [];
|
let vals: string[] = [];
|
||||||
convertedMeasurement.values.forEach(val => {
|
convertedMeasurement.values.forEach(val => {
|
||||||
vals.push(val + describer.unit());
|
vals.push(val + convertedMeasurement.unit);
|
||||||
});
|
});
|
||||||
let v = vals.join(", ");
|
let v = vals.join(", ");
|
||||||
if (describer.enumerations().length > 0) {
|
if (describer.enumerations().length > 0) {
|
||||||
v = describer.enumerations()[parseFloat(vals[0])];
|
v = describer.enumerations()[parseFloat(vals[0])];
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
colour: describer.colour(),
|
colour: convertedMeasurement.colour,
|
||||||
label: describer.label(),
|
label: convertedMeasurement.label,
|
||||||
type: describer.type(),
|
type: convertedMeasurement.type,
|
||||||
value: v,
|
value: v,
|
||||||
error: convertedMeasurement.error
|
error: convertedMeasurement.error
|
||||||
};
|
};
|
||||||
|
|
@ -258,6 +258,8 @@ export function unitMeasurementSummaries(
|
||||||
): Summary[] {
|
): Summary[] {
|
||||||
let summaries: Summary[] = [];
|
let summaries: Summary[] = [];
|
||||||
measurements.measurementsFor.forEach(measurement => {
|
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);
|
let describer = describeMeasurement(measurement.type, compType, subtype);
|
||||||
summaries.push(unitMeasurementSummary(measurement, describer));
|
summaries.push(unitMeasurementSummary(measurement, describer));
|
||||||
});
|
});
|
||||||
|
|
@ -530,6 +532,7 @@ export function simpleLineChartData(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
console.log(lineData)
|
||||||
return lineData;
|
return lineData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -945,6 +948,15 @@ function getOverlayAreas(
|
||||||
return overlayAreas;
|
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(
|
function createInteractionLine(
|
||||||
componentType: quack.ComponentType,
|
componentType: quack.ComponentType,
|
||||||
subtype: number,
|
subtype: number,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Interaction, Component } from "models";
|
import { Interaction, Component, User } from "models";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { quack } from "protobuf-ts/quack";
|
import { quack } from "protobuf-ts/quack";
|
||||||
import { or, notNull } from "utils/types";
|
import { or, notNull } from "utils/types";
|
||||||
|
|
@ -172,7 +172,8 @@ export const interactionResultText = (interaction: Interaction, sink?: Component
|
||||||
export const interactionConditionText = (
|
export const interactionConditionText = (
|
||||||
source: Component | undefined,
|
source: Component | undefined,
|
||||||
condition: pond.IInteractionCondition,
|
condition: pond.IInteractionCondition,
|
||||||
and: boolean
|
and: boolean,
|
||||||
|
user?: User
|
||||||
) => {
|
) => {
|
||||||
let comparison = "is exactly";
|
let comparison = "is exactly";
|
||||||
switch (condition.comparison) {
|
switch (condition.comparison) {
|
||||||
|
|
@ -189,7 +190,7 @@ export const interactionConditionText = (
|
||||||
if (!condition.measurementType) return "Unknown " + comparison + " " + condition.value;
|
if (!condition.measurementType) return "Unknown " + comparison + " " + condition.value;
|
||||||
let sourceType = source && source.settings.type;
|
let sourceType = source && source.settings.type;
|
||||||
let sourceSubtype = source && source.settings.subtype;
|
let sourceSubtype = source && source.settings.subtype;
|
||||||
let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype);
|
let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype, undefined, user);
|
||||||
return (
|
return (
|
||||||
(and ? "and " : "") +
|
(and ? "and " : "") +
|
||||||
measurement.label() +
|
measurement.label() +
|
||||||
|
|
|
||||||
|
|
@ -694,11 +694,12 @@ export function describeMeasurement(
|
||||||
componentType: quack.ComponentType | null | undefined = quack.ComponentType
|
componentType: quack.ComponentType | null | undefined = quack.ComponentType
|
||||||
.COMPONENT_TYPE_INVALID,
|
.COMPONENT_TYPE_INVALID,
|
||||||
componentSubtype: number = 0,
|
componentSubtype: number = 0,
|
||||||
product?: pond.DeviceProduct
|
product?: pond.DeviceProduct,
|
||||||
|
user?: User
|
||||||
): MeasurementDescriber {
|
): MeasurementDescriber {
|
||||||
measurementType = measurementType
|
measurementType = measurementType
|
||||||
? measurementType
|
? measurementType
|
||||||
: quack.MeasurementType.MEASUREMENT_TYPE_INVALID;
|
: quack.MeasurementType.MEASUREMENT_TYPE_INVALID;
|
||||||
componentType = componentType ? componentType : quack.ComponentType.COMPONENT_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