Skip to content

Commit

Permalink
Fixes isActive formula
Browse files Browse the repository at this point in the history
Sends a global min/max date value based on selected date range for the isActive formula

Fixes wrong data context name being sent to create map
  • Loading branch information
eireland committed Jan 26, 2024
1 parent ee77717 commit ad1e49e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { AttributeFilter } from "./attribute-filter";
import { InfoModal } from "./info-modal";
import { useStateContext } from "../hooks/use-state";
import { adjustStationDataset, getWeatherStations } from "../utils/getWeatherStations";
import { addNotificationHandler, createStationsDataset } from "../utils/codapHelpers";
import { addNotificationHandler, createStationsDataset, guaranteeGlobal } from "../utils/codapHelpers";
import InfoIcon from "../assets/images/icon-info.svg";
import { useCODAPApi } from "../hooks/use-codap-api";
import { dataTypeStore } from "../utils/noaaDataTypes";
import { composeURL, formatData } from "../utils/noaaApiHelper";
import { IDataType } from "../types";
import { StationDSName } from "../constants";
import { StationDSName, globalMaxDate, globalMinDate } from "../constants";
import { geoLocSearch } from "../utils/geonameSearch";
import { DataReturnWarning } from "./data-return-warning";

Expand All @@ -37,7 +37,6 @@ export const App = () => {
useEffect(() => {
initializePlugin({pluginName: kPluginName, version: kVersion, dimensions: kInitialDimensions});


const stationSelectionHandler = async(req: any) =>{
if (req.values.operation === "selectCases") {
const result = req.values.result;
Expand All @@ -63,9 +62,13 @@ export const App = () => {
}, []);

useEffect(() => {
const minDate = state.startDate || new Date( -5364662060);
const maxDate = state.endDate || new Date(Date.now());
adjustStationDataset(weatherStations); //change max data to "present"
createStationsDataset(weatherStations); //send weather station data to CODAP
},[weatherStations]);
guaranteeGlobal(globalMinDate, Number(minDate)/1000);
guaranteeGlobal(globalMaxDate, Number(maxDate)/1000);
},[state.endDate, state.startDate, weatherStations]);

const handleOpenInfo = () => {
setState(draft => {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const kWeatherStationCollectionAttrs = [
name: "isActive",
formula: `(number(maxdate="present"
? date()
: date(split(maxdate,'-',1), split(maxdate, ""-", 2), split(maxdate, "-", 3))) - wxMinDate)>0 and wxMaxDate-number(date(split(mindate,"-",1), split(mindate, "-", 2), split(mindate, "-", 3)))>0`,
: date(split(maxdate,'-',1), split(maxdate, "-", 2), split(maxdate, "-", 3))) - wxMinDate)>0 and wxMaxDate-number(date(split(mindate,"-",1), split(mindate, "-", 2), split(mindate, "-", 3)))>0`,
description: "whether the station was active in the Weather Plugin's requested date range",
_categoryMap: {
__order: [
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/use-codap-api.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Attribute, Collection, DataContext, IDataType, IItem } from "../types";
import { IResult, codapInterface, createItems, getDataContext } from "@concord-consortium/codap-plugin-api";
import { DSCollection1, DSCollection2, DSName, kStationsCollectionName } from "../constants";
import { DSCollection1, DSCollection2, DSName, kStationsDatasetName } from "../constants";
import { useStateContext } from "./use-state";
import { useEffect } from "react";
import { createMap, selectStations } from "../utils/codapHelpers";
Expand All @@ -11,7 +11,7 @@ export const useCODAPApi = () => {
useEffect(() => {
if (state.weatherStation && state.isMapOpen) {
const zoom = state.zoomMap ? 7 : null;
createMap(kStationsCollectionName, {width: 500, height: 350}, [state.weatherStation.latitude, state.weatherStation.longitude], zoom);
createMap(kStationsDatasetName, {width: 500, height: 350}, [state.weatherStation.latitude, state.weatherStation.longitude], zoom);
selectStations([state.weatherStation.name]);
}
}, [state.isMapOpen, state.weatherStation, state.zoomMap]);
Expand Down

0 comments on commit ad1e49e

Please sign in to comment.