I have two files:
myService.js
const Season = require('./season');
const myService = module.exports = {};
const defaults = {
heating: new Season('heating', 'October', 15, 'March', 1),
cooling: new Season('cooling', 'April', 15, 'September', 15)
};
const seasons = {
AustraliaDefault: {
heating: new Season('heating', 'July', 1, 'August', 31),
cooling: new Season('cooling', 'September', 1, 'March', 1)
}
};
myService.gettingSeasonalityAnalysis = function (site, cohortKey) {
return Promise.all([
myService.findingHeatingSeason(site, cohortKey),
myService.findingCoolingSeason(site, cohortKey)
]).spread(function (heating, cooling) {
return { heating: heating, cooling: cooling };
});
};
myService.findingHeatingSeason = function (site, cohortKey) {
return Promise.resolve(seasons[cohortKey] && seasons[cohortKey]['heating'] || defaults['heating']);
};
myService.findingCoolingSeason = function (site, cohortKey) {
return Promise.resolve(seasons[cohortKey] && seasons[cohortKey]['cooling'] || defaults['cooling']);
};
and Breakdown.js
...
const myService = require('../../myService');
...
const summerMonthRegex = {
'default': /^may|jun|jul|aug|sep/i,
south: /^dec|jan|feb/i
};
...
check('must not indicate heating in summer', function (report) {
const model = report.findSection('Breakdown').model;
const heatingSeries = _.findWhere(model.series, { name: 'Space heating' });
if (!heatingSeries || model.series.length === 1) {
return;
}
const totalAccounts = _.size(report.asModel().accountNumbers);
// TODO: "summer" varies per cohort
const warnings = _.compact(_.map(['July', 'Aug'], function (monthLabel) {
const summerIndex = _.indexOf(model.xAxisLabels, monthLabel);
const heatingSummerCost = heatingSeries.data[summerIndex];
if (heatingSummerCost > (totalAccounts * MAX_BASE_CHARGE)) {
return {
month: monthLabel,
cost: heatingSummerCost,
accounts: totalAccounts
};
}
}));
this.should(!warnings.length, util.format('breakdown chart indicates heating (%s) in summer (%s) in %d account(s)', _.pluck(warnings, 'cost'), _.pluck(warnings, 'month'), totalAccounts));
}),
The first file must describe the seasons(summer, winter) which are different between northern and southern hemisphere. I must call somehow myService in Breakdown . If it is let as default, it will detect that there is use of heating in summer (because in default in takes the northern hemisphere seasons) but it must be able to check for which one to compute it.
What I've tried is to import myService into Breakdown and instead of mapping ['July', 'Aug'] to use myService.findingHeatingSeason or myService.Seasons and others but it doesn't work. It lets them as undefined no matter what method I use.
Any suggestions?
via migea
No comments:
Post a Comment