Skip to content

Commit

Permalink
refactor: dimensionless observation units
Browse files Browse the repository at this point in the history
When an observation variable is dimensionless, display the units as 'dimensionless', rather than an empty string. Convert 'dimensionless' back to an empty string when we parse the uploaded CSV.
  • Loading branch information
eatyourgreens committed Apr 24, 2024
1 parent deb0c5f commit 7340c9a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
6 changes: 5 additions & 1 deletion frontend-v2/src/features/data/Data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { DataGrid } from '@mui/x-data-grid';
import LoadDataStepper from "./LoadDataStepper";
import useDataset from "../../hooks/useDataset";

function displayUnitSymbol(symbol: string | undefined) {
return symbol === '' ? 'dimensionless' : symbol;
}

const Data:FC = () => {
const [tab, setTab] = useState(0);
const projectId = useSelector(
Expand Down Expand Up @@ -82,7 +86,7 @@ const Data:FC = () => {
'Time': row.time,
'Time Unit': row.timeUnit?.symbol,
'Observation': row.value,
'Observation Unit': row.unit?.symbol,
'Observation Unit': displayUnitSymbol(row.unit?.symbol),
'Observation ID': row.label,
'Observation Variable': row.qname,
Group: groupId,
Expand Down
24 changes: 19 additions & 5 deletions frontend-v2/src/features/data/MapObservations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ interface IMapObservations {
firstTime: boolean;
}

function displayUnitSymbol(symbol: string | undefined) {
return symbol === '' ? 'dimensionless' : symbol;
}

const MapObservations: FC<IMapObservations> = ({state}: IMapObservations) => {
const [unitsAreFixed, setUnitsAreFixed] = useState(true);
const projectId = useSelector(
Expand Down Expand Up @@ -172,25 +176,35 @@ const MapObservations: FC<IMapObservations> = ({state}: IMapObservations) => {
onChange={handleObservationChange(obsId)}
>
{compatibleVariables?.map((variable) => (
<MenuItem key={variable.name} value={variable.qname}>{variable.name}</MenuItem>
<MenuItem
key={variable.name}
value={variable.qname}
>
{variable.name}
</MenuItem>
))}
</Select>
</FormControl>
</TableCell>
<TableCell>
{unitsAreFixed ?
selectedUnitSymbol :
displayUnitSymbol(selectedUnitSymbol) :
<FormControl fullWidth>
<InputLabel id={`select-unit-${obsId}-label`}>Units</InputLabel>
<Select
labelId={`select-unit-${obsId}-label`}
id={`select-unit-${obsId}`}
label='Units'
value={selectedUnitSymbol || ''}
value={displayUnitSymbol(selectedUnitSymbol)}
onChange={handleUnitChange(obsId)}
>
{compatibleUnits?.map((unit) => (
<MenuItem key={unit.symbol} value={unit.symbol}>{unit.symbol}</MenuItem>
<MenuItem
key={unit.id}
value={displayUnitSymbol(unit.symbol)}
>
{displayUnitSymbol(unit.symbol)}
</MenuItem>
))}
</Select>
</FormControl>
Expand Down Expand Up @@ -235,7 +249,7 @@ const MapObservations: FC<IMapObservations> = ({state}: IMapObservations) => {
<TableRow key={index}>
<TableCell>{obsId}</TableCell>
<TableCell>{observation}</TableCell>
<TableCell>{obsUnit}</TableCell>
<TableCell>{displayUnitSymbol(obsUnit)}</TableCell>
<TableCell>{obsVariable}</TableCell>
</TableRow>
)
Expand Down
3 changes: 2 additions & 1 deletion pkpdapp/pkpdapp/utils/data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ def convert_percent_to_dim(x):
"percent" in xl or
"fraction" in xl or
"ratio" in xl or
"%" in xl
"%" in xl or
"dimensionless" in xl
):
return ""
else:
Expand Down

0 comments on commit 7340c9a

Please sign in to comment.