Commit 0af389b7 authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

New functions: calculate daily or monthly min/max

These functions wrap the logic of the two functions that calculate the
minimum or maximum observation values for an interval delimited by
calendar dates as well as delimited by calendar months
parent f4bc5f52
......@@ -105,6 +105,102 @@ const calculateAverageOfObservationValuesWithinMonthInterval = function (
);
};
/**
* Calculate the minimum of observation values within a time interval delimited by a start date and end date. The time interval may be daily or monthly
* @param {Array} obsNestedArr A 1*N array that contains N nested arrays of observations (timestamp + value)
* @param {String} samplingRate The sampling rate of observations as a string, e.g. "15min", "60min"
* @param {Array} uniqueCalendarDatesOrMonthsArr A 1*N array of unique calendar dates or calendar months strings
* @param {String} aggregationInterval The aggregation interval as a string e.g. "daily", "monthly"
* @returns {Array} A 1*N array that contains N nested arrays of minimum values
*/
const calculateMinimumObservationValuesWithinInterval = function (
obsNestedArr,
samplingRate,
uniqueCalendarDatesOrMonthsArr,
aggregationInterval
) {
// Calculate minimum values of observations - daily
// Note the use of the two nested `map` methods
if (aggregationInterval === "daily") {
return uniqueCalendarDatesOrMonthsArr.map((uniqueCalendarDatesArr, i) =>
uniqueCalendarDatesArr.map((uniqueCalendarDate) =>
calculateMinimumObservationValuesWithinDatesInterval(
extractObservationValuesWithinDatesInterval(
obsNestedArr[i],
samplingRate,
uniqueCalendarDate,
uniqueCalendarDate
)
)
)
);
}
// Calculate minimum values of observations - monthly
// Note the use of the two nested `map` methods
if (aggregationInterval === "monthly") {
return uniqueCalendarDatesOrMonthsArr.map((uniqueCalendarMonthsArr, i) =>
uniqueCalendarMonthsArr.map((uniqueCalendarMonth) =>
calculateMinimumObservationValuesWithinMonthInterval(
extractObservationValuesWithinMonthInterval(
obsNestedArr[i],
samplingRate,
uniqueCalendarMonth
)
)
)
);
}
};
/**
* Calculate the maximum of observation values within a time interval delimited by a start date and end date. The time interval may be daily or monthly
* @param {Array} obsNestedArr A 1*N array that contains N nested arrays of observations (timestamp + value)
* @param {String} samplingRate The sampling rate of observations as a string, e.g. "15min", "60min"
* @param {Array} uniqueCalendarDatesOrMonthsArr A 1*N array of unique calendar dates or calendar months strings
* @param {String} aggregationInterval The aggregation interval as a string e.g. "daily", "monthly"
* @returns {Array} A 1*N array that contains N nested arrays of maximum values
*/
const calculateMaximumObservationValuesWithinInterval = function (
obsNestedArr,
samplingRate,
uniqueCalendarDatesOrMonthsArr,
aggregationInterval
) {
// Calculate maximum values of observations - daily
// Note the use of the two nested `map` methods
if (aggregationInterval === "daily") {
return uniqueCalendarDatesOrMonthsArr.map((uniqueCalendarDatesArr, i) =>
uniqueCalendarDatesArr.map((uniqueCalendarDate) =>
calculateMaximumObservationValuesWithinDatesInterval(
extractObservationValuesWithinDatesInterval(
obsNestedArr[i],
samplingRate,
uniqueCalendarDate,
uniqueCalendarDate
)
)
)
);
}
// Calculate maximum values of observations - monthly
// Note the use of the two nested `map` methods
if (aggregationInterval === "monthly") {
return uniqueCalendarDatesOrMonthsArr.map((uniqueCalendarMonthsArr, i) =>
uniqueCalendarMonthsArr.map((uniqueCalendarMonth) =>
calculateMaximumObservationValuesWithinMonthInterval(
extractObservationValuesWithinMonthInterval(
obsNestedArr[i],
samplingRate,
uniqueCalendarMonth
)
)
)
);
}
};
/**
* Calculate the sum of observation values within a time interval delimited by a start date and end date. The time interval may be daily or monthly
* @param {Array} obsNestedArr A 1*N array that contains N nested arrays of observations (timestamp + value)
......@@ -202,6 +298,8 @@ const calculateAverageOfObservationValuesWithinInterval = function (
};
export {
calculateMinimumObservationValuesWithinInterval,
calculateMaximumObservationValuesWithinInterval,
calculateSumOfObservationValuesWithinInterval,
calculateAverageOfObservationValuesWithinInterval,
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment