我有这个文件叫myService.js其中我通过使用加热或冷却系统定义季节。他们是不同的尤其是在南半球的国家(如澳大利亚),其中季节是相反的情况:使用来自NodeJS中另一个模块的属性
const myService= {};
const yearTimes = {
JapanDefault: {
heat: new YearTime('heat', 'Sep', 15, 'Mar', 1),
cool: new YearTime('cool', 'Mar', 14, 'Sep', 14)
},
AustraliaDefault: {
heat: new YearTime('heat', 'Jul', 1, 'Aug', 31),
cool: new YearTime('cool', 'Sep', 1, 'Mar', 1)
}
};
myService.gettingAnalysis = function (site, Key) {
return Promise.all([
myService.findingHeat(site, Key),
myService.findingCool(site, Key)
]).spread(function (heat, cool) {
return { heating: heating, cooling: cooling };
});
};
myService.findingHeat = function (site, Key) {
return Promise.resolve(YearTime[Key] && YearTime[Key]['heat'] || defaults['heating']);
};
module.exports = myService;
在另一个文件中,我必须检查是否有不同的情况,比如我应该给一个警告,如果有使用在夏天加热。该规范对北半球工作正常,但对于南半球来说是错误的,因为它发现它在夏季(5月,6月)使用加热系统,但在该特定情况下,该地区是冬季。 这就是所谓的Breakdown.js第二个文件:
const _ = require('underscore');
const util = require('util');
const stats = require('simple-statistics');
const myService = require('./myService');
const SUM = 10;
...
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(['May', 'Jun'], function (monthLabel) {
const summerIndex = _.indexOf(model.xAxisLabels, monthLabel);
const heatingSummerCost = heatingSeries.data[summerIndex];
if (heatingSummerCost > (totalAccounts * SUM)) {
return {
month: monthLabel,
cost: heatingSummerCost,
accounts: totalAccounts
};
}
}));
this.should(!warnings.length, util.format('heating in summer recommended'));
})
...
我试图做是为了使检测如果不是夏天在这方面与myService.findingHeat(site, key)
或myService.seasons.AustraliaDefault
更换['May', 'Jun']
,它是正常有加热成本。 有没有人有任何想法如何解决这个问题?
是:https://pastebin.com/DaaVAmMv –
根据季节的实施['7月','8月']是本赛季的开始月份和结束月份,不是吗?所以你将不得不创建一个返回[season.startMonth,season.endMonth]的方法。此外,'findingHeatingSeason'返回Promise.resolve,因此您将得到'myService.findingHeatingSeason(report.site,report.cohort).then(function(data){console.log(data)})'的响应。 – Harish
是的,你是对的。他们是开始的月份和结束月份。在这种情况下,他们之间没有其他月份,但在一般情况下可能会有。所以我认为返回一个数组containsig应该是解决方案 –