我有一个名为 myService.js 的文件,我在其中通过使用加热或冷却系统定义季节。它们是不同的,特别是在季节相反的南半球国家(例如澳大利亚):
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;
在另一个文件中,我必须检查不同的情况,例如,如果夏天使用暖气,我应该显示警告。该代码对于北半球工作正常,但对于南半球则错误,因为它检测到在夏季(五月、六月)使用供暖系统,但在这种特殊情况下,该地区是冬季。 这是第二个名为 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'));
})
...
我尝试做的是将 ['May', 'Jun']
替换为 myService.findingHeat(site, key)
或 myService.seasons .AustraliaDefault
,以便让它检测该地区是否不是夏季,并且有取暖费用是正常的。
有谁知道如何解决这个问题吗?
最佳答案
您正在尝试替换数组 ['July', 'Aug']
带有 myService.findingHeatingSeason(report.site, report.cohort)
返回的 Season 对象或myService.seasons.AustraliaDefault
这可能会导致一些不一致。您能否也指定您的 Season 构造函数?
关于javascript - 使用 NodeJS 中另一个模块的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43473722/