Skip to content

Commit

Permalink
Replace isMultiRun with hasMultiRuns
Browse files Browse the repository at this point in the history
  • Loading branch information
eyvorchuk committed Jun 3, 2024
1 parent dce958a commit 0996b52
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Accordion from "../../guidance-tools/Accordion";
import { BootstrapTable, TableHeaderColumn } from "react-bootstrap-table";
import { MEVSummary } from "../MEVSummary/MEVSummary";
import { filteredDatasetSummaryPanelLabel } from "../../guidance-content/info/InformationItems";
import { isMultiRun } from "../../map-controllers/map-helpers";
import { hasMultiRuns } from "../../map-controllers/map-helpers";

import _ from "lodash";
import { HalfWidthCol } from "../../layout/rb-derived-components";
Expand Down Expand Up @@ -46,7 +46,7 @@ export default class FilteredDatasetsSummary extends React.Component {
};

const keyedData = this.props.meta.map(metaToKeyedData);
if (this.props.meta.length && !isMultiRun(this.props.meta)) {
if (this.props.meta.length && !hasMultiRuns(this.props.meta)) {
// Remove run in cases where there is only one run
keyedData.forEach((el) => (el.key = el.key.split(" ")[1]));
}
Expand All @@ -56,7 +56,7 @@ export default class FilteredDatasetsSummary extends React.Component {
if (
keyedComparandData &&
this.props.comparandMeta.length &&
!isMultiRun(this.props.comparandMeta)
!hasMultiRuns(this.props.comparandMeta)
) {
keyedComparandData.forEach((el) => (el.key = el.key.split(" ")[1]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
updateLayerSimpleState,
updateLayerTime,
getDatasetIdentifiers,
isMultiRun,
hasMultiRuns,
} from "../map-helpers.js";

import styles from "../MapController.module.css";
Expand All @@ -70,7 +70,7 @@ export default class DualMapController extends React.Component {
run: undefined,
start_date: undefined,
end_date: undefined,
multi_run: false,
has_multi_runs: false,

raster: {
variableId: undefined, // formerly 'variable'
Expand Down Expand Up @@ -130,7 +130,7 @@ export default class DualMapController extends React.Component {
// (aside from variable_id) display the same dataspec.

const { start_date, end_date, ensemble_member } = dataSpec;
const multi_run = isMultiRun(props.meta);
const has_multi_runs = hasMultiRuns(props.meta);

const rasterScalarParams = scalarParams.bind(null, props.variable_id);
const rasterParamsPromise = getTimeParametersPromise(dataSpec, props.meta)
Expand Down Expand Up @@ -176,7 +176,7 @@ export default class DualMapController extends React.Component {
run: ensemble_member,
start_date,
end_date,
multi_run,
has_multi_runs,
raster: rasterParams,
isoline: isolineParams,
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
scalarParams,
selectRasterPalette,
getTimeParametersPromise,
isMultiRun,
hasMultiRuns,
} from "../map-helpers.js";

import styles from "../MapController.module.css";
Expand All @@ -71,7 +71,7 @@ export default class PrecipMapController extends React.Component {
run: undefined,
start_date: undefined,
end_date: undefined,
multi_run: false,
has_multi_runs: false,

raster: {
variableId: undefined, // formerly 'variable'
Expand Down Expand Up @@ -116,7 +116,7 @@ export default class PrecipMapController extends React.Component {
// timestamp is determined at render time and passed to the viewer component.

const { start_date, end_date, ensemble_member } = dataSpec;
const multi_run = isMultiRun(props.meta);
const has_multi_runs = hasMultiRuns(props.meta);

const rasterScalarParams = scalarParams.bind(null, props.variable_id);
const rasterParamsPromise = getTimeParametersPromise(dataSpec, props.meta)
Expand Down Expand Up @@ -150,7 +150,7 @@ export default class PrecipMapController extends React.Component {
run: ensemble_member,
start_date,
end_date,
multi_run,
has_multi_runs,
raster: rasterParams,
annotated: annotatedParams,
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
getTimeParametersPromise,
scalarParams,
getDatasetIdentifiers,
isMultiRun,
hasMultiRuns,
} from "../map-helpers.js";

import styles from "../MapController.module.css";
Expand Down Expand Up @@ -74,7 +74,7 @@ export default class SingleMapController extends React.Component {
run: undefined,
start_date: undefined,
end_date: undefined,
multi_run: false,
has_multi_runs: false,

raster: {
variableId: undefined, // formerly 'variable'
Expand Down Expand Up @@ -104,7 +104,7 @@ export default class SingleMapController extends React.Component {
// is passed to the viewer component.

const { start_date, end_date, ensemble_member } = dataSpec;
const multi_run = isMultiRun(props.meta);
const has_multi_runs = hasMultiRuns(props.meta);

const rasterScalarParams = scalarParams.bind(null, props.variable_id);
const rasterParamsPromise = getTimeParametersPromise(dataSpec, props.meta)
Expand All @@ -123,7 +123,7 @@ export default class SingleMapController extends React.Component {
run: ensemble_member,
start_date,
end_date,
multi_run,
has_multi_runs,
raster: params,
}));
});
Expand Down
7 changes: 4 additions & 3 deletions src/components/map-controllers/map-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ export function selectIsolinePalette(params) {
**************************************************************************/

// TODO: https://github.com/pacificclimate/climate-explorer-frontend/issues/118
export function currentDataSpec({ run, start_date, end_date, multi_run }) {
export function currentDataSpec({ run, start_date, end_date, has_multi_runs }) {
// Return encoding of currently selected dataspec.
// If the model that this dataspec comes from only has one run, then only the start_date-end_date
// portion is displayed in labels
return multi_run
return has_multi_runs
? `${run} ${start_date}-${end_date}`
: `${start_date}-${end_date}`;
}

export function isMultiRun(meta) {
export function hasMultiRuns(meta) {
// Check if there are multiple runs making up the datasets for the given model (e.g. CMIP5 MIROC5 has r1i1p1 and r3i1p1).
let ids = meta.map(
(el) => `${el.ensemble_member} ${el.start_date}-${el.end_date}`,
Expand All @@ -194,6 +194,7 @@ export function isMultiRun(meta) {
_.sortBy(ids, (item) => item),
(item) => item,
);
// Check if first run is the same as last run
return ids[0].split(" ")[0] != ids[ids.length - 1].split(" ")[0];
}

Expand Down

0 comments on commit 0996b52

Please sign in to comment.