var underscore = angular.module('underscore', []); underscore.factory('_', function() { return window._; // assumes underscore has already been loaded on the page }); //angular.module('webApp', ['underscore','ui.bootstrap']) //.controller('calDenki', function ($scope, $http, $filter, _) { angular.module('webApp', ['ui.bootstrap']) .controller('calDenki', function ($scope, $http, $filter) { $scope.powerCompanies = [ {name: '北海道電力', url:['http://www.hepco.co.jp/userate/price/unitprice/unitprice01.html'],steps:[[0,19.88],[120,26.06],[300,29.46]]}, {name: '東北電力', url:['http://www.tohoku-epco.co.jp/dprivate/unit/index.html'],steps:[[0,18.24],[120,24.87],[300,28.75]]}, {name: '東京電力', url: 'http://www.tepco.co.jp/e-rates/individual/basic/charge/charge01-j.html', prices:{ '10A':{color:'赤',price:273.00}, '15A':{color:'桃',price:409.50}, '20A':{color:'黄',price:546.00}, '30A':{color:'緑',price:819.00}, '40A':{color:'灰',price:1092.00}, '50A':{color:'茶',price:1365.00}, '60A':{color:'紫',price:1638.00} }, steps:[[0,19.43],[120,25.91],[300,29.93]], discount: 54, }, {name: '中部電力', url: ['http://www.chuden.co.jp/ryokin/shikumi/shi_keiyaku/kei_ryokin/keisan/', 'http://www.chuden.co.jp/ryokin/home_menu/home_basic/hba_timeplan/'], prices:{ '10A':{color:'赤',price:280.80}, '15A':{color:'桃',price:421.20}, '20A':{color:'黄',price:561.60}, '30A':{color:'緑',price:842.40}, '40A':{color:'灰',price:1123.20}, '50A':{color:'茶',price:1404.00}, '60A':{color:'紫',price:1684.80} }, steps:[[0,20.68],[120,25.08],[300,27.97]], night:{90:24.16,night:13.45}, minimum: 253.80, discount: 54, surcharge: 0.69, recycle: 0.75, solor: 0.03 }, {name: '北陸電力',url:['http://www.rikuden.co.jp/ryokin/minsei.html'],steps:[[0,17.44],[120,21.25],[300,22.94]], minimum: 177.44}, {name: '関西電力', url:['http://www.kepco.co.jp/home/ryoukin/'],steps:[[0,20.84],[120,27.27],[300,31.09]]}, {name: '中国電力', url:['http://www.energia.co.jp/elec/h_menu/pricelist/pricelist1.html'],steps:[[0,20.34],[120,26.90],[300,28.98]]}, {name: '四国電力', url:['http://www.yonden.co.jp/ryoukin/'],steps:[[0,20.00],[120,26.50],[300,29.95]]}, {name: '九州電力', url:['http://www.kyuden.co.jp/rate_mein-menu_4_2_h26_5.html'],steps:[[0,17.13],[120,22.63],[300,25.57]]}, {name: '沖縄電力', url:['http://www.okiden.co.jp/service/individual/menu_specific.html'],steps:[[0,22.49],[120,27.93],[300,29.07]]} ]; $scope.presetCompany = $scope.powerCompanies[2]; $scope.setCompany = function(num){ $scope.presetCompany = $scope.powerCompanies[num]; } $scope.presets = [ {id:0, name:'テレビ',watt:60, idlewatt:1, hours:3}, {id:1, name:'DVD・HDプレイヤー',watt:60, idlewatt:1, hours:3}, {id:2, name:'冷蔵庫 40L(単身)',watt:60, idlewatt:1, hours:24}, {id:3, name:'冷蔵庫 80L(家庭)',watt:60, idlewatt:1, hours:24}, {id:4, name:'洗濯・乾燥機', watt:60, idlewatt:1, hours:1}, {id:5, name:'パソコン(デスクトップ)',watt:150, idlewatt:1, hours:3}, {id:6, name:'パソコン(ノート)',watt:100, idlewatt:1, hours:3}, {id:7, name:'エアコン',watt:100, idlewatt:1, hours:4}, {id:8, name:'こたつ',watt:100, idlewatt:1, hours:3}, {id:9, name:'電気ストーブ',watt:100, idlewatt:1, hours:3}, {id:10, name:'空気清浄機',watt:100, idlewatt:1, hours:6}, {id:11, name:'掃除機',watt:100, idlewatt:1, hours:0.5}, {id:12, name:'扇風機',watt:50, idlewatt:1, hours:3}, {id:13, name:'ドライヤー',watt:1200, idlewatt:1, hours:1}, {id:14, name:'照明(8畳LED)',watt:100, idlewatt:1, hours:6}, {id:15, name:'電子レンジ',watt:1200, idlewatt:1, hours:0.5}, {id:16, name:'IH',watt:100, idlewatt:1, hours:1}, {id:16, name:'自動食器洗い機',watt:1300, idlewatt:1, hours:0.5}]; $scope.selectedPreset = {}; $scope.$watch('selectedPreset', function(){ $scope.selectedPreset.amount = $scope.selectedPreset.amount||1; }) $scope.myPresets = [{name:"単身世帯",indexs:[{id:0,amount:1},{id:2,amount:1},{id:15,amount:1}]}, {name:"二人世帯",indexs:[{id:0,amount:1},{id:3,amount:1},{id:11,amount:1},{id:15,amount:1},{id:16,amount:1}]}, {name:"四人世帯",indexs:[{id:0,amount:1},{id:2,amount:1},{id:9,amount:1},{id:11,amount:1},{id:15,amount:1},{id:16,amount:1}]} ] $scope.setPreset = function(num){ $scope.devices = []; $scope.myPresets[num].indexs.map(function(idx){ var found = $filter('getById')($scope.presets, idx.id); if(found) { found.amount = idx.amount; $scope.devices.push(found); } }) } $scope.devices = [ {name:'テレビ',watt:60, amount:1, hours:3}, {name:'パソコン(デスクトップ)',watt:100, amount:1, hours:6}, ]; $scope.deviceMng = { add: function(dev){ if(dev.watt && dev.amount && dev.hours) /* var base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var len = base.length; dev.id = Math.floor(Math.random()*10000); */ $scope.devices.push(dev); $scope.selectedPreset = {}; }, del: function(num){if($scope.devices[num]) $scope.devices.splice(num,1)} }; $scope.downLoadCSV = function(){ window.open( "data:text/csv;charset=utf-8," + escape(JSON.stringify($scope.devices)));; // 計算結果も // "=IF(A2=B2,""PASS"", ""FAIL"")" } $scope.total = {}; $scope.$watch('devices', function(){ $scope.total.watt = function(){ return $scope.devices.map(function(dev){return dev.watt*dev.amount*dev.hours}) .reduce(function(previousValue, currentValue, index, array){ return previousValue + currentValue; },0)}() },true) /* $scope.$watchCollection('devices', function(){ $scope.total.watt = function(){ return $scope.devices.map(function(dev){return dev.watt*dev.amount*dev.hours}) .reduce(function(previousValue, currentValue, index, array){ return previousValue + currentValue; },0)}() })*/ $scope.$watchCollection('[total.watt, presetCompany]', function(){ function price(watt){ var watt = Math.round(watt / 1000); var result = $scope.presetCompany.steps.map(function(price){ if(watt > price[0]) return price[1]; return 0; }) return Math.max.apply(null,result)*watt; } $scope.total.charge = price($scope.total.watt); $scope.total.monthCharge = price($scope.total.watt*365/12); $scope.total.yearCharge = $scope.total.monthCharge*12; },true) }) .directive('presetOption', function() { return { replace : true, restrict: 'AEC', transclude: true, template: '
' + '
' + '
W
' + '
' + '
H
' + '
' }; }) .directive('deviceTable', function() { return { replace : true, restrict: 'AEC', transclude: true, template: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
デバイス名消費電力(W)台数時間(H)小計
{{device.watt * device.amount * device.hours}}
総計{{total.watt}}
' }; }) .directive('companyProfile', function() { return { replace : true, restrict: 'AEC', template: '
住所
愛知県あま市下萱津坪井36−1
' }; }) .filter('sumByKey', function () { return function (data, key) { if (typeof (data) === 'undefined' || typeof (key) === 'undefined') { return 0; } var sum = 0; for (var i = data.length - 1; i >= 0; i--) { sum += Number(data[i][key]); } return sum; } }) .filter('getById', function() { return function(items, id) { var result; items.map(function(item){ if(item.id == id) { result = item; } }) return result; } });