使用NodeJS中另一个模块的属性

时间:2017-04-18 13:33:18

标签: javascript node.js

我有一个名为 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;

在另一个文件中,我必须检查不同的情况,例如,如果在夏天使用加热,我应该显示警告。该代码适用于北半球,但对于南半球来说是错误的,因为它在夏天(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'));
    })
...

我尝试做的是将['May', 'Jun']替换为myService.findingHeat(site, key)myService.seasons.AustraliaDefault,以便检测该区域是否不是夏天,加热费用是正常的。 有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您正尝试使用myService.findingHeatingSeason(report.site, report.cohort)myService.seasons.AustraliaDefault返回的季节对象替换数组public class SampleRecommender { public static void main(String[] ars) throws IOException, TasteException { DataModel dataModel = new FileDataModel(new File("E:\\Rakshit\\Recommender\\stackdata.csv")); UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, dataModel); UserBasedRecommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity); List<RecommendedItem> recommendations = recommender.recommend(3,3); for(RecommendedItem item : recommendations) { System.out.println(item); } } ,这可能会导致某些不一致。你能指定一下季节构造函数吗?