angular-nav-thresholds
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -6,13 +6,9 @@ (function (angular) { | ||
var versionDateFormat = "YYYY-MM-DD"; | ||
var config = { | ||
versionDateFormat: versionDateFormat | ||
var versions = [{ "version": 1, "date": "2016-01-01", "coefficients": { "product:2-reconst-syg": { "wastage": 1.1, "coverage": 0.87 }, "product:5-reconst-syg": { "wastage": 1.1, "coverage": 0.87 }, "product:ad-syg": { "wastage": 1.05, "coverage": 0.87 }, "product:bcg": { "wastage": 2, "coverage": 0.9, "doses": 1 }, "product:bcg-syg": { "coverage": 0.87 }, "product:diluent-bcg": {}, "product:diluent-mv": {}, "product:diluent-yf": {}, "product:hep-b": { "wastage": 1.3333333333333333, "coverage": 0.9, "doses": 1 }, "product:hpv": { "wastage": 1.1, "coverage": 0.9, "doses": 2 }, "product:ipv": { "wastage": 1.05, "coverage": 0.87, "doses": 1 }, "product:mv": { "wastage": 1.4285714285714286, "coverage": 0.9, "doses": 1 }, "product:opv": { "wastage": 1.3333333333333333, "coverage": 0.9, "doses": 4 }, "product:pcv": { "wastage": 1.05, "coverage": 0.87, "doses": 3 }, "product:penta": { "wastage": 1.3333333333333333, "coverage": 0.87, "doses": 3 }, "product:rota": { "wastage": 1.05, "coverage": 0.87, "doses": 3 }, "product:safety-boxes": { "wastage": 1.05 }, "product:td": { "wastage": 1.3333333333333333, "coverage": 0.87, "doses": 2 }, "product:yf": { "wastage": 1.4285714285714286, "coverage": 0.9, "doses": 1 } } }]; | ||
var defaultCoefficients = { | ||
versions: versions | ||
}; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
// TODO: replace with Array#find ponyfill | ||
var find = function find(list, match) { | ||
function find(list, match) { | ||
for (var i = 0; i < list.length; i++) { | ||
@@ -24,4 +20,88 @@ if (match(list[i])) { | ||
return undefined; | ||
} | ||
function somethingIsWrong(msg) { | ||
if (console) { | ||
console.warn("angular-nav-thresholds: " + msg); | ||
} | ||
// TODO: log it to Google Analytics (#28) | ||
} | ||
var versionDateFormat = "YYYY-MM-DD"; | ||
var config = { | ||
versionDateFormat: versionDateFormat | ||
}; | ||
var formulae = { | ||
'product:bcg': 'regular', | ||
'product:mv': 'regular', | ||
'product:yf': 'regular', | ||
'product:opv': 'regular', | ||
'product:td': 'regular', | ||
'product:penta': 'regular', | ||
'product:hep-b': 'regular', | ||
'product:pcv': 'regular', | ||
'product:ipv': 'regular', | ||
'product:rota': 'regular', | ||
'product:hpv': 'regular', | ||
'product:ad-syg': 'adSyg', | ||
'product:bcg-syg': 'bcg', | ||
'product:5-reconst-syg': 'fiveReconst', | ||
'product:2-reconst-syg': 'twoReconst', | ||
'product:safety-boxes': 'safetyBoxes', | ||
'product:diluent-bcg': 'diluentBcg', | ||
'product:diluent-yf': 'diluentYf', | ||
'product:diluent-mv': 'diluentMv' | ||
}; | ||
var calculator = {}; | ||
calculator.regular = function (allocations, coefficient, targetPopulation) { | ||
return targetPopulation * coefficient.doses * coefficient.coverage * coefficient.wastage; | ||
}; | ||
calculator.adSyg = function (allocations) { | ||
return allocations['product:penta'] + allocations['product:mv'] + allocations['product:yf'] + allocations['product:hep-b'] + allocations['product:td'] + allocations['product:pcv'] + allocations['product:ipv'] + allocations['product:hpv']; | ||
}; | ||
calculator.bcg = function (allocations) { | ||
return allocations['product:bcg']; | ||
}; | ||
calculator.fiveReconst = function (allocations, coefficient) { | ||
return (allocations['product:mv'] + allocations['product:yf']) / 10 * coefficient.wastage; | ||
}; | ||
calculator.twoReconst = function (allocations, coefficient) { | ||
return allocations['product:bcg'] / 20 * coefficient.wastage; | ||
}; | ||
calculator.safetyBoxes = function (allocations, coefficient) { | ||
return (allocations['product:ad-syg'] + allocations['product:bcg-syg'] + allocations['product:5-reconst-syg'] + allocations['product:2-reconst-syg']) / 100 * coefficient.wastage; | ||
}; | ||
calculator.diluentBcg = function (allocations) { | ||
return allocations['product:bcg']; | ||
}; | ||
calculator.diluentYf = function (allocations) { | ||
return allocations['product:yf']; | ||
}; | ||
calculator.diluentMv = function (allocations) { | ||
return allocations['product:mv']; | ||
}; | ||
var calculateForProduct = function calculateForProduct(monthlyTargetPopulations, coefficients, allocations, productId) { | ||
var coefficient = coefficients[productId]; | ||
var monthlyTargetPopulation = monthlyTargetPopulations[productId]; | ||
allocations[productId] = 0; | ||
if (typeof monthlyTargetPopulation !== 'undefined' && coefficient) { | ||
allocations[productId] = calculator[formulae[productId]](allocations, coefficient, monthlyTargetPopulation / 4); | ||
} | ||
return allocations; | ||
}; | ||
var calculateWeeklyLevels = (function (monthlyTargetPopulations, coefficients) { | ||
return Object.keys(formulae).reduce(calculateForProduct.bind(null, monthlyTargetPopulations, coefficients), {}); | ||
}); | ||
var isVersion = function isVersion(date, version) { | ||
@@ -33,6 +113,2 @@ var momentDate = moment().isoWeekYear(date.year).isoWeek(date.week).isoWeekday(1).startOf('day'); | ||
var isId = function isId(id, item) { | ||
return item._id === id; | ||
}; | ||
var getFactor = function getFactor(versions, date) { | ||
@@ -48,54 +124,97 @@ var reverseVersions = versions.slice(0).reverse(); | ||
var getFactors = function getFactors(stockCount, location) { | ||
// centralized for whenever we implement #16 | ||
var somethingIsWrong = function somethingIsWrong() { | ||
return undefined; | ||
}; | ||
var getCoefficients = function getCoefficients(productCoefficients, date) { | ||
if (!(productCoefficients && productCoefficients.versions && productCoefficients.versions.length)) { | ||
throw new Error('missing productCoefficients or productCoefficients.versions'); | ||
} | ||
var getWeeklyLevels = function getWeeklyLevels() { | ||
if (!(location.allocations && location.allocations.length)) { | ||
somethingIsWrong(); | ||
} | ||
var version = getFactor(productCoefficients.versions, date); | ||
if (!(version && version.coefficients)) { | ||
throw new Error('cannot find version of coefficients for date ' + date); | ||
} | ||
return version.coefficients; | ||
}; | ||
var allocations = getFactor(location.allocations, stockCount.date); | ||
return allocations && allocations.weeklyLevels; | ||
}; | ||
var getWeeksOfStock = function getWeeksOfStock(location, date) { | ||
if (!(location.plans && location.plans.length)) { | ||
throw new Error('missing plans on location ' + location._id); | ||
} | ||
var getWeeksOfStock = function getWeeksOfStock() { | ||
if (!(location.plans && location.plans.length)) { | ||
somethingIsWrong(); | ||
} | ||
var plans = getFactor(location.plans, date); | ||
if (!(plans && plans.weeksOfStock)) { | ||
throw new Error('cannot find version of weeksOfStock for location ' + location._id + ' and date ' + date); | ||
} | ||
return plans.weeksOfStock; | ||
}; | ||
var plans = getFactor(location.plans, stockCount.date); | ||
return plans && plans.weeksOfStock; | ||
}; | ||
var getTargetPopulations = function getTargetPopulations(location, date) { | ||
if (location.targetPopulations && location.targetPopulations.length) { | ||
var targetPopulations = getFactor(location.targetPopulations, date); | ||
var getMonthlyTargetPopulations = function getMonthlyTargetPopulations() { | ||
var monthlyTargetPopulations = void 0; | ||
if (location.targetPopulations) { | ||
if (!location.targetPopulations.length) { | ||
somethingIsWrong(); | ||
} | ||
return { | ||
version: targetPopulations.version, | ||
monthlyTargetPopulations: targetPopulations && targetPopulations.monthlyTargetPopulations | ||
}; | ||
} | ||
var targetPopulations = getFactor(location.targetPopulations, stockCount.date); | ||
monthlyTargetPopulations = targetPopulations && targetPopulations.monthlyTargetPopulations; | ||
} else { | ||
// For backwards compatibility with the old style location docs, | ||
// since we have no control about when the dashboards are going | ||
// to replicate the new location docs | ||
if (!(location.targetPopulation && location.targetPopulation.length)) { | ||
somethingIsWrong(); | ||
} | ||
monthlyTargetPopulations = location.targetPopulation; | ||
} | ||
return monthlyTargetPopulations; | ||
}; | ||
// For backwards compatibility to version before introducing `targetPopulations`, | ||
// since we have no control about when the dashboards are going | ||
// to replicate the new location docs | ||
if (!(location.targetPopulation && Object.keys(location.targetPopulation).length)) { | ||
return { | ||
version: 1 | ||
}; | ||
} | ||
return { | ||
weeksOfStock: getWeeksOfStock(), | ||
weeklyLevels: getWeeklyLevels(), | ||
targetPopulations: getMonthlyTargetPopulations() | ||
version: 1, | ||
monthlyTargetPopulations: location.targetPopulation | ||
}; | ||
}; | ||
var getWeeklyLevels = function getWeeklyLevels(location, date) { | ||
if (!(location.allocations && location.allocations.length)) { | ||
throw new Error('missing allocations on location ' + location._id); | ||
} | ||
var allocations = getFactor(location.allocations, date); | ||
if (!(allocations && allocations.weeklyLevels)) { | ||
throw new Error('cannot find version of weeklyLevels for location ' + location._id + ' and date ' + date); | ||
} | ||
return allocations.weeklyLevels; | ||
}; | ||
var getFactors = (function (location, productCoefficients, date) { | ||
var weeksOfStock = getWeeksOfStock(location, date); | ||
var _getTargetPopulations = getTargetPopulations(location, date), | ||
version = _getTargetPopulations.version, | ||
monthlyTargetPopulations = _getTargetPopulations.monthlyTargetPopulations; | ||
// For backwards compatibility to version before introducing `targetPopulations`, | ||
// since for that version `weeklyAllocations` were not always calculated | ||
// based on target population | ||
if (version === 1) { | ||
return { | ||
weeklyLevels: getWeeklyLevels(location, date), | ||
weeksOfStock: weeksOfStock, | ||
monthlyTargetPopulations: monthlyTargetPopulations | ||
}; | ||
} | ||
var coefficients = getCoefficients(productCoefficients, date); | ||
var weeklyLevels = calculateWeeklyLevels(monthlyTargetPopulations, coefficients); | ||
return { | ||
weeklyLevels: weeklyLevels, | ||
weeksOfStock: weeksOfStock, | ||
monthlyTargetPopulations: monthlyTargetPopulations | ||
}; | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var ThresholdsService = function () { | ||
@@ -114,2 +233,4 @@ function ThresholdsService($q, smartId, lgasService, statesService) { | ||
// That param is only used for zones. | ||
// | ||
// Passing the coefficientVersions as a param so that it can be adapted later to use the database doc | ||
@@ -121,37 +242,52 @@ | ||
var requiredStateStoresAllocation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var productCoefficients = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : defaultCoefficients; | ||
if (!(stockCount && stockCount.date)) { | ||
return; | ||
if (!stockCount) { | ||
var locationId = location && location._id ? location._id : 'with unknown id'; | ||
return somethingIsWrong('missing mandatory param stock count for location ' + locationId); | ||
} | ||
if (!stockCount.date) { | ||
return somethingIsWrong('missing date on stock count ' + stockCount._id); | ||
} | ||
if (!(location && location.level)) { | ||
return; | ||
if (!location) { | ||
var stockCountId = stockCount && stockCount._id ? stockCount._id : 'with unknown id'; | ||
return somethingIsWrong('missing mandatory param location for stock count ' + stockCountId); | ||
} | ||
if (!location.level) { | ||
return somethingIsWrong('missing level on location ' + location._id); | ||
} | ||
if (!(products && products.length)) { | ||
return; | ||
return somethingIsWrong('missing mandatory param products'); | ||
} | ||
var _getFactors = getFactors(stockCount, location), | ||
weeklyLevels = _getFactors.weeklyLevels, | ||
weeksOfStock = _getFactors.weeksOfStock, | ||
targetPopulations = _getFactors.targetPopulations; | ||
if (!(weeklyLevels && weeksOfStock)) { | ||
var locationFactors = void 0; | ||
try { | ||
locationFactors = getFactors(location, productCoefficients, stockCount.date); | ||
} catch (e) { | ||
somethingIsWrong(e.message); | ||
return; | ||
} | ||
return Object.keys(weeklyLevels).reduce(function (index, productId) { | ||
index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) { | ||
var level = weeklyLevels[productId] * weeksOfStock[threshold]; | ||
var product = find(products, isId.bind(null, productId)); | ||
var _locationFactors = locationFactors, | ||
weeksOfStock = _locationFactors.weeksOfStock, | ||
weeklyLevels = _locationFactors.weeklyLevels, | ||
monthlyTargetPopulations = _locationFactors.monthlyTargetPopulations; | ||
// Default rounding used in VSPMD and highest possible presentation | ||
var presentation = 20; | ||
if (product && product.presentation) { | ||
// TODO: product presentations should be ints, not strings | ||
presentation = parseInt(product.presentation, 10); | ||
} | ||
return products.reduce(function (index, product) { | ||
var productId = product._id; | ||
var weeklyLevel = weeklyLevels[productId]; | ||
// Default rounding used in VSPMD and highest possible presentation | ||
var presentation = 20; | ||
if (product && product.presentation) { | ||
// TODO: product presentations should be ints, not strings | ||
presentation = parseInt(product.presentation, 10); | ||
} | ||
index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) { | ||
var level = weeklyLevel * weeksOfStock[threshold]; | ||
var roundedLevel = Math.ceil(level / presentation) * presentation; | ||
@@ -167,5 +303,7 @@ productThresholds[threshold] = roundedLevel; | ||
if (targetPopulations) { | ||
// old (and new?) zone docs have no target population doc | ||
index[productId].targetPopulation = targetPopulations[productId]; | ||
index[productId].weeklyLevel = weeklyLevel; | ||
if (monthlyTargetPopulations) { | ||
// old zone docs have no target population | ||
index[productId].targetPopulation = monthlyTargetPopulations[productId]; | ||
} | ||
@@ -181,2 +319,8 @@ | ||
var productCoefficients = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultCoefficients; | ||
var isId = function isId(id, item) { | ||
return item._id === id; | ||
}; | ||
// TODO: make it work for zones too. | ||
@@ -217,3 +361,3 @@ // For making it work with zones, we need to take into account the amount of stock | ||
var location = find(promisesRes[item.type], isId.bind(null, key)); | ||
item.thresholds = _this.calculateThresholds(location, item, products); | ||
item.thresholds = _this.calculateThresholds(location, item, products, null, productCoefficients); | ||
delete item.type; | ||
@@ -220,0 +364,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
!function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}e="default"in e?e.default:e;var a="YYYY-MM-DD",n={versionDateFormat:a},r=function(){function e(e,t){for(var a=0;a<t.length;a++){var n=t[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,a,n){return a&&e(t.prototype,a),n&&e(t,n),t}}(),o=function(e,t){for(var a=0;a<e.length;a++)if(t(e[a]))return e[a]},i=function(e,t){var a=moment().isoWeekYear(e.year).isoWeek(e.week).isoWeekday(1).startOf("day"),r=moment(t.date,n.versionDateFormat).startOf("isoWeek").startOf("day");return a.isSameOrAfter(r)},l=function(e,t){return t._id===e},s=function(e,t){var a=e.slice(0).reverse(),n=o(a,i.bind(null,t));return n?n:e[0]},u=function(e,t){var a=function(){},n=function(){t.allocations&&t.allocations.length||a();var n=s(t.allocations,e.date);return n&&n.weeklyLevels},r=function(){t.plans&&t.plans.length||a();var n=s(t.plans,e.date);return n&&n.weeksOfStock},o=function(){var n=void 0;if(t.targetPopulations){t.targetPopulations.length||a();var r=s(t.targetPopulations,e.date);n=r&&r.monthlyTargetPopulations}else t.targetPopulation&&t.targetPopulation.length||a(),n=t.targetPopulation;return n};return{weeksOfStock:r(),weeklyLevels:n(),targetPopulations:o()}},c=function(){function e(a,n,r,o){t(this,e),this.$q=a,this.smartId=n,this.lgasService=r,this.statesService=o}return r(e,[{key:"calculateThresholds",value:function(e,t,a){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(t&&t.date&&e&&e.level&&a&&a.length){var r=u(t,e),i=r.weeklyLevels,s=r.weeksOfStock,c=r.targetPopulations;if(i&&s)return Object.keys(i).reduce(function(t,r){return t[r]=Object.keys(s).reduce(function(t,u){var c=i[r]*s[u],f=o(a,l.bind(null,r)),v=20;f&&f.presentation&&(v=parseInt(f.presentation,10));var d=Math.ceil(c/v)*v;return t[u]=d,"zone"===e.level&&n[r]&&(t[u]+=n[r]),t},{}),c&&(t[r].targetPopulation=c[r]),t},{})}}},{key:"getThresholdsFor",value:function(e,t){var a=this,n="zone:?state:?lga",r={},i={};r=e.reduce(function(e,t){var r=t.location;if(!r)return e;var o=a.smartId.idify(r,n);return e[o]={date:t.date},r.lga?(i.lga||(i.lga=a.lgasService.list()),e[o].type="lga"):r.state&&(i.state||(i.state=a.statesService.list()),e[o].type="state"),e},{});var s=function(e){return Object.keys(r).forEach(function(n){var i=r[n],s=o(e[i.type],l.bind(null,n));i.thresholds=a.calculateThresholds(s,i,t),delete i.type}),r};return this.$q.all(i).then(s)}}]),e}();c.$inject=["$q","smartId","lgasService","statesService"],e.module("angularNavThresholds",["angularNavData","ngSmartId"]).service("thresholdsService",c)}(angular); | ||
!function(e){"use strict";function t(e,t){for(var r=0;r<e.length;r++)if(t(e[r]))return e[r]}function r(e){console&&console.warn("angular-nav-thresholds: "+e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}e="default"in e?e.default:e;var n=[{version:1,date:"2016-01-01",coefficients:{"product:2-reconst-syg":{wastage:1.1,coverage:.87},"product:5-reconst-syg":{wastage:1.1,coverage:.87},"product:ad-syg":{wastage:1.05,coverage:.87},"product:bcg":{wastage:2,coverage:.9,doses:1},"product:bcg-syg":{coverage:.87},"product:diluent-bcg":{},"product:diluent-mv":{},"product:diluent-yf":{},"product:hep-b":{wastage:1.3333333333333333,coverage:.9,doses:1},"product:hpv":{wastage:1.1,coverage:.9,doses:2},"product:ipv":{wastage:1.05,coverage:.87,doses:1},"product:mv":{wastage:1.4285714285714286,coverage:.9,doses:1},"product:opv":{wastage:1.3333333333333333,coverage:.9,doses:4},"product:pcv":{wastage:1.05,coverage:.87,doses:3},"product:penta":{wastage:1.3333333333333333,coverage:.87,doses:3},"product:rota":{wastage:1.05,coverage:.87,doses:3},"product:safety-boxes":{wastage:1.05},"product:td":{wastage:1.3333333333333333,coverage:.87,doses:2},"product:yf":{wastage:1.4285714285714286,coverage:.9,doses:1}}}],a={versions:n},s="YYYY-MM-DD",c={versionDateFormat:s},i={"product:bcg":"regular","product:mv":"regular","product:yf":"regular","product:opv":"regular","product:td":"regular","product:penta":"regular","product:hep-b":"regular","product:pcv":"regular","product:ipv":"regular","product:rota":"regular","product:hpv":"regular","product:ad-syg":"adSyg","product:bcg-syg":"bcg","product:5-reconst-syg":"fiveReconst","product:2-reconst-syg":"twoReconst","product:safety-boxes":"safetyBoxes","product:diluent-bcg":"diluentBcg","product:diluent-yf":"diluentYf","product:diluent-mv":"diluentMv"},u={};u.regular=function(e,t,r){return r*t.doses*t.coverage*t.wastage},u.adSyg=function(e){return e["product:penta"]+e["product:mv"]+e["product:yf"]+e["product:hep-b"]+e["product:td"]+e["product:pcv"]+e["product:ipv"]+e["product:hpv"]},u.bcg=function(e){return e["product:bcg"]},u.fiveReconst=function(e,t){return(e["product:mv"]+e["product:yf"])/10*t.wastage},u.twoReconst=function(e,t){return e["product:bcg"]/20*t.wastage},u.safetyBoxes=function(e,t){return(e["product:ad-syg"]+e["product:bcg-syg"]+e["product:5-reconst-syg"]+e["product:2-reconst-syg"])/100*t.wastage},u.diluentBcg=function(e){return e["product:bcg"]},u.diluentYf=function(e){return e["product:yf"]},u.diluentMv=function(e){return e["product:mv"]};var d=function(e,t,r,o){var n=t[o],a=e[o];return r[o]=0,"undefined"!=typeof a&&n&&(r[o]=u[i[o]](r,n,a/4)),r},l=function(e,t){return Object.keys(i).reduce(d.bind(null,e,t),{})},g=function(e,t){var r=moment().isoWeekYear(e.year).isoWeek(e.week).isoWeekday(1).startOf("day"),o=moment(t.date,c.versionDateFormat).startOf("isoWeek").startOf("day");return r.isSameOrAfter(o)},f=function(e,r){var o=e.slice(0).reverse(),n=t(o,g.bind(null,r));return n?n:e[0]},p=function(e,t){if(!(e&&e.versions&&e.versions.length))throw new Error("missing productCoefficients or productCoefficients.versions");var r=f(e.versions,t);if(!r||!r.coefficients)throw new Error("cannot find version of coefficients for date "+t);return r.coefficients},v=function(e,t){if(!e.plans||!e.plans.length)throw new Error("missing plans on location "+e._id);var r=f(e.plans,t);if(!r||!r.weeksOfStock)throw new Error("cannot find version of weeksOfStock for location "+e._id+" and date "+t);return r.weeksOfStock},y=function(e,t){if(e.targetPopulations&&e.targetPopulations.length){var r=f(e.targetPopulations,t);return{version:r.version,monthlyTargetPopulations:r&&r.monthlyTargetPopulations}}return e.targetPopulation&&Object.keys(e.targetPopulation).length?{version:1,monthlyTargetPopulations:e.targetPopulation}:{version:1}},h=function(e,t){if(!e.allocations||!e.allocations.length)throw new Error("missing allocations on location "+e._id);var r=f(e.allocations,t);if(!r||!r.weeklyLevels)throw new Error("cannot find version of weeklyLevels for location "+e._id+" and date "+t);return r.weeklyLevels},w=function(e,t,r){var o=v(e,r),n=y(e,r),a=n.version,s=n.monthlyTargetPopulations;if(1===a)return{weeklyLevels:h(e,r),weeksOfStock:o,monthlyTargetPopulations:s};var c=p(t,r),i=l(s,c);return{weeklyLevels:i,weeksOfStock:o,monthlyTargetPopulations:s}},m=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}(),k=function(){function e(t,r,n,a){o(this,e),this.$q=t,this.smartId=r,this.lgasService=n,this.statesService=a}return m(e,[{key:"calculateThresholds",value:function(e,t,o){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:a;if(!t){var c=e&&e._id?e._id:"with unknown id";return r("missing mandatory param stock count for location "+c)}if(!t.date)return r("missing date on stock count "+t._id);if(!e){var i=t&&t._id?t._id:"with unknown id";return r("missing mandatory param location for stock count "+i)}if(!e.level)return r("missing level on location "+e._id);if(!o||!o.length)return r("missing mandatory param products");var u=void 0;try{u=w(e,s,t.date)}catch(e){return void r(e.message)}var d=u,l=d.weeksOfStock,g=d.weeklyLevels,f=d.monthlyTargetPopulations;return o.reduce(function(t,r){var o=r._id,a=g[o],s=20;return r&&r.presentation&&(s=parseInt(r.presentation,10)),t[o]=Object.keys(l).reduce(function(t,r){var c=a*l[r],i=Math.ceil(c/s)*s;return t[r]=i,"zone"===e.level&&n[o]&&(t[r]+=n[o]),t},{}),t[o].weeklyLevel=a,f&&(t[o].targetPopulation=f[o]),t},{})}},{key:"getThresholdsFor",value:function(e,r){var o=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:a,s=function(e,t){return t._id===e},c="zone:?state:?lga",i={},u={};i=e.reduce(function(e,t){var r=t.location;if(!r)return e;var n=o.smartId.idify(r,c);return e[n]={date:t.date},r.lga?(u.lga||(u.lga=o.lgasService.list()),e[n].type="lga"):r.state&&(u.state||(u.state=o.statesService.list()),e[n].type="state"),e},{});var d=function(e){return Object.keys(i).forEach(function(a){var c=i[a],u=t(e[c.type],s.bind(null,a));c.thresholds=o.calculateThresholds(u,c,r,null,n),delete c.type}),i};return this.$q.all(u).then(d)}}]),e}();k.$inject=["$q","smartId","lgasService","statesService"],e.module("angularNavThresholds",["angularNavData","ngSmartId"]).service("thresholdsService",k)}(angular); |
@@ -77,3 +77,3 @@ { | ||
], | ||
"version": "2.3.0" | ||
"version": "2.4.0" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
35918
304
1