2017-04-18 8 views
1

私はこのファイルを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と呼ばれるこの2番目のファイルである:

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']を交換しました暖房費がかかると正常です。 これを解決する方法を知っている人はいますか?

答えて

1

アレイ['July', 'Aug']を、myService.findingHeatingSeason(report.site, report.cohort)またはmyService.seasons.AustraliaDefaultによって返されたシーズンのオブジェクトに置き換えようとしていますが、これによって矛盾が生じる可能性があります。シーズンのコンストラクタも指定できますか?

+0

はい:https://pastebin.com/DaaVAmMv –

+2

シーズンの実装['July'、 'Aug']は、シーズンのstartMonthとendMonthですが、そうではありませんか?したがって、[season.startMonth、season.endMonth]を返すメソッドを作成する必要があります。また、 'findingHeatingSeason'はPromise.resolveを返して、' myService.findingHeatingSeason(report.site、report.cohort).then(function(data){console.log(data)}) 'というレスポンスを返します。 – Harish

+1

はい、そうです。彼らはstartMonthとendMonthです。この場合、それらの間に他の月はありませんが、一般的なケースでは可能性があります。だから私はその月が解決策でなければならない配列を返すことを考えている –

関連する問題