|
3 | 3 | Object.defineProperty(exports, "__esModule", {
|
4 | 4 | value: true
|
5 | 5 | });
|
6 |
| -exports.summarizeTimeSteps = exports.getTestableItems = exports.default = exports.Y_AXIS_RANGE_MODE_DETAILS = exports.Y_AXIS_RANGE_MODES = exports.TabComponentPropTypes = exports.TIME_STEPS = exports.TIME_SERIES_VIEWER_STATUS_TITLES = exports.DEFAULT_STATE = void 0; |
| 6 | +exports.summarizeTimeSteps = exports.getTestableItems = exports.default = exports.Y_AXIS_RANGE_MODE_DETAILS = exports.Y_AXIS_RANGE_MODES = exports.TabComponentPropTypes = exports.TIME_STEPS = exports.TIME_SERIES_VIEWER_STATUS_TITLES = exports.POINTS_PERFORMANCE_LIMIT = exports.DEFAULT_STATE = void 0; |
7 | 7 | var _react = _interopRequireWildcard(require("react"));
|
8 | 8 | var _propTypes = _interopRequireWildcard(require("prop-types"));
|
9 | 9 | var _moment = _interopRequireDefault(require("moment"));
|
@@ -53,6 +53,7 @@ const TIME_SERIES_VIEWER_STATUS_TITLES = exports.TIME_SERIES_VIEWER_STATUS_TITLE
|
53 | 53 | ERROR: null,
|
54 | 54 | READY: null
|
55 | 55 | };
|
| 56 | +const POINTS_PERFORMANCE_LIMIT = exports.POINTS_PERFORMANCE_LIMIT = 250000; |
56 | 57 |
|
57 | 58 | // List of common date-time variable names to verify against
|
58 | 59 | // The variables file ultimately controls the datetime variable that will
|
@@ -146,6 +147,7 @@ const DEFAULT_STATE = exports.DEFAULT_STATE = {
|
146 | 147 | dataFetches: {},
|
147 | 148 | dataFetchProgress: 0,
|
148 | 149 | variables: {},
|
| 150 | + pointTotal: 0, |
149 | 151 | product: {
|
150 | 152 | productCode: null,
|
151 | 153 | productName: null,
|
@@ -297,9 +299,104 @@ const summarizeTimeSteps = function (steps) {
|
297 | 299 | const plural = pluralize ? 's' : '';
|
298 | 300 | return "".concat(value, " ").concat(intervals[breakIdx]).concat(plural);
|
299 | 301 | };
|
| 302 | +exports.summarizeTimeSteps = summarizeTimeSteps; |
| 303 | +const getPositionCount = (sitesArray, siteCodeToExclude) => { |
| 304 | + let total = 0; |
| 305 | + sitesArray.forEach(site => { |
| 306 | + if (site.siteCode !== siteCodeToExclude) { |
| 307 | + total += site.positions.length; |
| 308 | + } |
| 309 | + }); |
| 310 | + return total; |
| 311 | +}; |
| 312 | + |
| 313 | +// yearMonth param is in the format of 'yyyy-mm' which is |
| 314 | +// a typical dateRange item |
| 315 | +const getLastDayInMonth = yearMonth => { |
| 316 | + const date = new Date("".concat(yearMonth, "-01T00:00:00Z")); |
| 317 | + date.setUTCMonth(date.getUTCMonth() + 1); |
| 318 | + date.setUTCSeconds(date.getUTCSeconds() - 1); |
| 319 | + return date.getUTCDate(); |
| 320 | +}; |
| 321 | +const getTotalHoursCustom = (startDate, endDate) => { |
| 322 | + const date1 = new Date("".concat(startDate, "-01T00:00:00Z")); |
| 323 | + const lastDay = getLastDayInMonth(endDate); |
| 324 | + const date2 = new Date("".concat(endDate, "-").concat(lastDay, "T23:59:59Z")); |
| 325 | + return Math.round((date2.getTime() - date1.getTime()) / 1000 / 60 / 60); |
| 326 | +}; |
| 327 | +const getTotalHours = state => { |
| 328 | + const date1 = new Date("".concat(state.selection.dateRange[0], "-01T00:00:00Z")); |
| 329 | + let date2; |
| 330 | + if (state.selection.continuousDateRange.length === 1) { |
| 331 | + const lastDay = getLastDayInMonth(state.selection.continuousDateRange[0]); |
| 332 | + date2 = new Date("".concat(state.selection.continuousDateRange[0], "-").concat(lastDay, "T23:59:59Z")); |
| 333 | + } else if (state.selection.dateRange.length === 2) { |
| 334 | + const lastDay = getLastDayInMonth(state.selection.dateRange[1]); |
| 335 | + date2 = new Date("".concat(state.selection.dateRange[1], "-").concat(lastDay, "T23:59:59Z")); |
| 336 | + } else { |
| 337 | + // eslint-disable-next-line no-console |
| 338 | + console.error('Unknown date range'); |
| 339 | + } |
| 340 | + return Math.round((date2.getTime() - date1.getTime()) / 1000 / 60 / 60); |
| 341 | +}; |
| 342 | +const getPointsPerHour = (state, currentTimeStep) => { |
| 343 | + const secondsInHour = 3600; |
| 344 | + const timeStep = currentTimeStep === 'auto' ? state.selection.autoTimeStep : currentTimeStep; |
| 345 | + const timeStepSeconds = TIME_STEPS[timeStep].seconds; |
| 346 | + return secondsInHour / timeStepSeconds; |
| 347 | +}; |
| 348 | +const calcPointTotal = data => { |
| 349 | + if (!data) { |
| 350 | + return 0; |
| 351 | + } |
| 352 | + let varsAndPositions = 0; |
| 353 | + if (data.length > 0 && data[0].length > 1) { |
| 354 | + // first array position is dateTime. Count items after it |
| 355 | + varsAndPositions = data[0].length - 1; |
| 356 | + } |
| 357 | + return data.length * varsAndPositions; |
| 358 | +}; |
| 359 | +const calcPredictedPointsByTimeStep = (state, timeStep) => { |
| 360 | + if (!state.selection.autoTimeStep) return 0; |
| 361 | + |
| 362 | + // formula: points per hour (seconds in hour / Time Step seconds) |
| 363 | + // x hours (months selected converted to hours) x positions * variables |
| 364 | + // using seconds for points per hour since that is what TIME_STEPS has. |
| 365 | + const positions = getPositionCount(state.selection.sites); |
| 366 | + const pointPerHour = getPointsPerHour(state, timeStep); |
| 367 | + const variables = state.selection.variables.length === 0 ? 1 : state.selection.variables.length; |
| 368 | + const totalHours = getTotalHours(state); |
| 369 | + return pointPerHour * totalHours * positions * variables; |
| 370 | +}; |
| 371 | +const calcPredictedPointsForNewPosition = (state, numPositionsOverride) => { |
| 372 | + if (!state.selection.autoTimeStep) return 0; |
| 373 | + const positions = numPositionsOverride !== null && numPositionsOverride !== void 0 ? numPositionsOverride : getPositionCount(state.selection.sites) + 1; |
| 374 | + const pointPerHour = getPointsPerHour(state, state.selection.timeStep); |
| 375 | + const variables = state.selection.variables.length === 0 ? 1 : state.selection.variables.length; |
| 376 | + const totalHours = getTotalHours(state); |
| 377 | + return pointPerHour * totalHours * positions * variables; |
| 378 | +}; |
| 379 | +const calcPredictedPointsForNewVariable = state => { |
| 380 | + if (!state.selection.autoTimeStep) return 0; |
| 381 | + const positions = getPositionCount(state.selection.sites); |
| 382 | + const pointPerHour = getPointsPerHour(state, state.selection.timeStep); |
| 383 | + const totalHours = getTotalHours(state); |
| 384 | + const variables = state.selection.variables.length === 0 ? 1 : state.selection.variables.length + 1; |
| 385 | + return pointPerHour * totalHours * positions * variables; |
| 386 | +}; |
| 387 | + |
| 388 | +// note that the dates are not JS dates but from dateRange and should be |
| 389 | +// in the format of 'yyyy-mm'. |
| 390 | +const calcPredictedPointsByDateRange = (state, startDate, endDate) => { |
| 391 | + if (!state.selection.autoTimeStep) return 0; |
| 392 | + const positions = getPositionCount(state.selection.sites); |
| 393 | + const pointPerHour = getPointsPerHour(state, state.selection.timeStep); |
| 394 | + const variables = state.selection.variables.length === 0 ? 1 : state.selection.variables.length; |
| 395 | + const totalHours = getTotalHoursCustom(startDate, endDate); |
| 396 | + return pointPerHour * totalHours * positions * variables; |
| 397 | +}; |
300 | 398 |
|
301 | 399 | // Array offsets and validators for use when splitting a data file URL
|
302 |
| -exports.summarizeTimeSteps = summarizeTimeSteps; |
303 | 400 | const DATA_FILE_PARTS = {
|
304 | 401 | POSITION_H: {
|
305 | 402 | offset: 6,
|
@@ -1144,6 +1241,7 @@ const reducer = (state, action) => {
|
1144 | 1241 | return softFail('Current selection of dates/sites/positions/variables does not have any valid numeric data.');
|
1145 | 1242 | }
|
1146 | 1243 | newState.graphData = action.graphData;
|
| 1244 | + newState.pointTotal = calcPointTotal(action.graphData.data); |
1147 | 1245 | newState.status = _constants.TIME_SERIES_VIEWER_STATUS.READY;
|
1148 | 1246 | return newState;
|
1149 | 1247 |
|
@@ -1218,6 +1316,22 @@ const reducer = (state, action) => {
|
1218 | 1316 | case 'fetchDataFileSucceeded':
|
1219 | 1317 | newState.product.sites[action.siteCode].positions[action.position].data[action.month][action.downloadPkg][action.timeStep][action.table].status = FETCH_STATUS.SUCCESS;
|
1220 | 1318 | newState.product.sites[action.siteCode].positions[action.position].data[action.month][action.downloadPkg][action.timeStep][action.table].series = action.series;
|
| 1319 | + /* uncomment for troubleshooting to get number of points downloaded |
| 1320 | + try { |
| 1321 | + if (!newState.product.pointTotal || isNaN(newState.product.pointTotal)) { |
| 1322 | + newState.product.pointTotal = 0; |
| 1323 | + } |
| 1324 | + newState.product.pointTotal += action.series.endDateTime.data.length; |
| 1325 | + console.log("newState", newState); |
| 1326 | + // console.log("action", action); |
| 1327 | + console.log("fetchDataFileSucceeded - pointTotal", newState.product.pointTotal); |
| 1328 | + // console.log("newState.selection.continuousDateRange.length", |
| 1329 | + // newState.selection.continuousDateRange.length); |
| 1330 | + } catch (error) { |
| 1331 | + console.log("my derpy code crashed", action); |
| 1332 | + } |
| 1333 | + */ |
| 1334 | + |
1221 | 1335 | return newState;
|
1222 | 1336 |
|
1223 | 1337 | // Core Selection Actions
|
@@ -1819,6 +1933,9 @@ const Provider = props => {
|
1819 | 1933 | token: masterFetchToken,
|
1820 | 1934 | fetches: dataActions
|
1821 | 1935 | });
|
| 1936 | + // this is the point where we can capture the user fetch criteria |
| 1937 | + // eslint-disable-next-line no-console |
| 1938 | + // console.log('Fetching data', state, dataFetches); |
1822 | 1939 | (0, _rxUtil.forkJoinWithProgress)(dataFetches).pipe((0, _rxjs.mergeMap)(_ref => {
|
1823 | 1940 | let [finalResult, progress] = _ref;
|
1824 | 1941 | return (0, _rxjs.merge)(progress.pipe((0, _rxjs.tap)(value => dispatch({
|
@@ -1906,7 +2023,12 @@ Provider.defaultProps = {
|
1906 | 2023 | const TimeSeriesViewerContext = {
|
1907 | 2024 | Provider,
|
1908 | 2025 | useTimeSeriesViewerState,
|
1909 |
| - TimeSeriesViewerPropTypes |
| 2026 | + TimeSeriesViewerPropTypes, |
| 2027 | + calcPredictedPointsForNewPosition, |
| 2028 | + calcPredictedPointsByTimeStep, |
| 2029 | + calcPredictedPointsForNewVariable, |
| 2030 | + calcPredictedPointsByDateRange, |
| 2031 | + getPositionCount |
1910 | 2032 | };
|
1911 | 2033 | var _default = exports.default = TimeSeriesViewerContext; // Additional items exported for unit testing
|
1912 | 2034 | const getTestableItems = () => process.env.NODE_ENV !== 'test' ? {} : {
|
|
0 commit comments