BemsWebApplication.IceStoreAirAnalysis = function(params, viewInfo) { "use strict"; var initialized = false, shouldReload = false, datagrid = null, currentTabIndex = ko.observable(0), facilityViewModel = new BWA.CmFacilityViewModel(), dataSource; var m_Facility; var multiViewItems = [{ template: 'mainCharts' }, { template: 'subCharts' } ]; var facilityDataSource = BWA.db.createDataSource('CmFacility'), facilitiesForSearch = ko.observableArray(), facilityCodeForSearch = ko.observable(0), deferredForSearch = new $.Deferred(); var visiblePopup = ko.observable(false); var dataCalorie = ko.observableArray(), dataAtfw = ko.observableArray(), dataTemperatureCalorie = ko.observableArray(), dataTemperatureElectricity = ko.observableArray() ; var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId()); //var timeBoxForSearch = BWA.SearchView.createDateTimeBox(); // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다 var timeBoxForSearch = BWA.SearchView.createDateTimeBox($G.TimeTypesForHourOnly, null, false); var chartCOP = BWA.Chart.Instance('chartCOPISA', 'dxChart'), chartCOPout = BWA.Chart.Instance('chartCOPoutISA', 'dxChart'), chartStoreLoad = BWA.Chart.Instance('chartStoreLoadISA', 'dxChart'), chartCOPLoad = BWA.Chart.Instance('chartCOPLoadISA', 'dxChart'); /* chartColdCOP = BWA.Chart.Instance('chartColdCOPISA', 'dxChart'), chartKCAL = BWA.Chart.Instance('chartKCALISA', 'dxChart'), chartEffi = BWA.Chart.Instance('chartEffiISA', 'dxChart'), chartApproch = BWA.Chart.Instance('chartApprochISA', 'dxChart'); */ var chartLayout = new BWA.ChartLayout({ divs: [[{ id: 'IceStoreAirDetail' }, { id: 'COP', chartId: 'chartCOPISA' }, { id: 'COPout', chartId: 'chartCOPoutISA' }, { id: 'StoreLoad', chartId: 'chartStoreLoadISA' }, { id: 'COPLoad', chartId: 'chartCOPLoadISA' }, { id: 'ColdCOP', chartId: 'chartColdCOPISA' }, { id: 'KCAL', chartId: 'chartKCALISA' }, { id: 'Effi', chartId: 'chartEffiISA' }, { id: 'Approch', chartId: 'chartApprochISA' } ] ], multiViewOptions: { viewIndex: currentTabIndex, //viewCount: 2 원래는2개, viewCount: 1 } }); var m = moment(); dataCalorie([ { DateTime: new Date(m.year(), m.month(), 1), Value: 50 }, { DateTime: new Date(m.year(), m.month(), 2), Value: 50 }, { DateTime: new Date(m.year(), m.month(), 3), Value: 60 }, { DateTime: new Date(m.year(), m.month(), 4), Value: 80 }, { DateTime: new Date(m.year(), m.month(), 5), Value: 100 }, { DateTime: new Date(m.year(), m.month(), 6), Value: 40, }, { DateTime: new Date(m.year(), m.month(), 7), Value: 120 }, { DateTime: new Date(m.year(), m.month(), 31), Value: 120 } ]); // 추가 2015 04 20 hcLee -> var CODE = $Code, FuelType = CODE.FuelType, FT = CODE.FacilityType, FC = CODE.FacilityCode, F = CODE.Formula, TIT = CODE.TimeIntervalType; // 추가 2015 04 20 hcLee <- //dataMonthForBar(dataDayForBar()); //dataDayForPie([ // { FuelTypeName: '전기', Value: 320 }, // { FuelTypeName: '가스', Value: 350 }, // { FuelTypeName: '수도', Value: 360 }, //]); //dataMonthForPie(dataDayForPie()); function handleViewShown() { if (initialized === false) { var chartOption = BWA.ChartOptions.IceStoreAirAnalysis; chartCOP = chartCOP(chartOption.getChartCOPOptions($Code.TimeType.HOUR)); chartCOPout = chartCOPout(chartOption.getChartCOPoutOptions($Code.TimeType.HOUR)); chartStoreLoad = chartStoreLoad(chartOption.getChartStoreLoadOptions($Code.TimeType.HOUR)); chartCOPLoad = chartCOPLoad(chartOption.getChartCOPOptions2($Code.TimeType.HOUR)); /* chartColdCOP = chartColdCOP(chartOption.getChartColdCOPOptions($Code.TimeType.HOUR)); chartKCAL = chartKCAL(chartOption.getChartKCALOptions($Code.TimeType.HOUR)); chartEffi = chartEffi(chartOption.getChartEffiOptions($Code.TimeType.HOUR)); chartApproch = chartApproch(chartOption.getChartApprochOptions($Code.TimeType.HOUR));*/ initialized = true; } //hcLee 2016 07 12 timeBoxForSearch.setDefaultDate(); var eq = BWA.DataUtil.constructEqualFilter; facilityDataSource.filter([ eq('SiteId', BWA.UserInfo.SiteId()), 'and', eq('FacilityTypeId', $Code.FacilityType.ICESTOREAIR) ]); facilityDataSource.load().done(function(facilities) { facilitiesForSearch(facilities); if (_.isEmpty(facilities) === false) { var f = facilities[0]; handleSelectedFacilityInSearchView(f); handleSearchInSearchView(); var datagrid = $('#IceStoreAirDataGridViewInSearchView').dxDataGrid('instance'); if (_.has(datagrid, 'selectRows')) { datagrid.selectRows(f); } } }); } if (shouldReload) { //shouldReload = false; //dataSource.pageIndex(0); //dataSource.load(); } function handleViewHidden() { //hideOverlay(); // var dataGrid = $('#gridContainer').dxDataGrid('instance'); // dataGrid.clearSelection(); var paging = BWA.ChartLayout.Paging; paging.sideOverlayVisible(false); //paging.hideNextButton(true); //paging.hidePrevButton(true); $SearchView.visibleObservable(false); // hcLee 2015 03 23 visiblePopup(false); } function handleViewShowing() { } function refreshList() { //dataSource.pageIndex(0); //dataSource.load(); } var searchViewOptions = { searchViewItems: [ { id: 'FacilityCode', ignoreValue: 0, defaultValue: 0, value: facilityCodeForSearch, dataSource: facilitiesForSearch }, ], promiseDataInSearchView: deferredForSearch.promise() }; function handleSelectedFacilityInSearchView(facility) { m_Facility = facility; return; } function handleSearchInSearchView(filter, searchViewItems) { //console.log(filter); //console.log(searchViewItems); if (m_Facility == null) return; visiblePopup(true); var f = m_Facility.toJS(); facilityViewModel.fromJS(f); //var timeIntervalType = $Code.TimeIntervalType.QUARTERMIN; var timeIntervalType = timeBoxForSearch.type(); var formula = $Code.Formula[$Code.FacilityType.ICESTOREAIR]; var formulaIds = _.values(formula); var date = timeBoxForSearch.getDate(); // var startDate = moment(). var promises = []; _.each(formulaIds, function (formulaId) { var p = formulaGet.apiGet({ FacilityTypeId: f.FacilityTypeId, FacilityCode: f.FacilityCode, FormulaId: formulaId, TimeIntervalType: timeIntervalType, StartDate: date.startDate, EndDate: date.endDate }); promises.push(p); }); // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20 -> var commonParameters = { //TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN, TimeIntervalType: timeIntervalType, StartDate: date.startDate, EndDate: date.endDate }; var temperatureParameters = { FacilityTypeId: FT.OUTDOOR, FacilityCode: FC.OUTDOOR, FormulaId: F[FT.OUTDOOR].TEMPERATURE, }; var humidityParameters = _.extend({}, temperatureParameters, { FormulaId: F[FT.OUTDOOR].HUMIDITY, }); promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters))); promises.push(formulaGet.apiGet(_.extend(humidityParameters, commonParameters))); $.when.apply(this, promises) .done(function (cold_av, effi, load, cold_kcal, vline_kcal, elec, sw, COP, input_temp, out_temp, h_temp, approch, kcal, // 2016 02 29 추가 cop1, cop2, load1, load2, OUTtemperatures, humidities) { // done의 리턴 파라메터는 정해져 있다 2015 04 20, 끝에 2개 (OUTtemperatures, humidities)추가 cold_av = cold_av[0]; effi = effi[0]; load = load[0]; cold_kcal = cold_kcal[0]; vline_kcal = vline_kcal[0]; elec = elec[0]; sw = sw[0]; COP = COP[0]; input_temp = input_temp[0]; out_temp = out_temp[0]; h_temp = h_temp[0]; approch = approch[0]; kcal = kcal[0]; cop1 = cop1[0]; cop2 = cop2[0]; load1 = load1[0]; load2 = load2[0]; // chart 1 var COPDataArray = []; _.each(COP, function (x) { COPDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), cop: x.Value }); }); /* _.each(cold_av, function (x) { COPDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), cold_av: x.Value }); });*/ //2016 02 29 대구은행현장제외 _.each(elec, function (x) { COPDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), elec: x.Value }); }); //chartCOP().option('dataSource', COPDataArray); var options = BWA.ChartOptions.IceStoreAirAnalysis.getChartCOPOptions(timeBoxForSearch.type()); //chartCOP().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.dataSource = COPDataArray; chartCOP().option(options); //chart2 var COPoutDataArray = []; var maxValue = 0; /* _.each(COP, function (x) { 2016 02 29 대구은행현장은 축열량으로 변경 COPoutDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), cop: x.Value }); if (maxValue < x.Value) maxValue = x.Value; }); */ // 2016 02 29 대구은행현장은 축열량으로 변경 _.each(kcal, function (x) { COPoutDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), kcal: x.Value }); if (maxValue < x.Value) maxValue = x.Value; }); //_.each(OUTtemperatures[0], function (x) { // COPoutDataArray.push({ // //DateTime: moment(x.DateTime).toDate(), // DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), // temp: x.Value // }); //}); //_.each(humidities[0], function (x) { // COPoutDataArray.push({ // //DateTime: moment(x.DateTime).toDate(), // DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), // hum: x.Value // }); //}); // 2016 02 29 대구은행현장은 축열량으로 변경 //options = BWA.ChartOptions.IceStoreAirAnalysis.getChartCOPoutOptions(timeBoxForSearch.type()); options = BWA.ChartOptions.IceStoreAirAnalysis.getChartKCALoutOptions(timeBoxForSearch.type()); //chartCOPout().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) //options.valueAxis[0].tickInterval = Math.round(maxValue / 5) + 1; options.dataSource = COPoutDataArray; chartCOPout().option(options); //chart3 /* var dataArray = BWA.Chart.getRelationDataArrayOnDateTime( kcal, load, 'kcal', 'load'); options = BWA.ChartOptions.IceStoreAirAnalysis.getChartStoreLoadOptions(timeBoxForSearch.type()); options.dataSource = dataArray; chartStoreLoad().option(options); 2016 02 29 대구은행현장 */ var dataArray = BWA.Chart.getRelationDataArrayOnDateTime( kcal, load1, 'kcal', 'load1'); var dataArray2 = BWA.Chart.getRelationDataArrayOnDateTime( kcal, load2, 'kcal', 'load2'); _.each(dataArray2, function (x) { dataArray.push(x); }); options = BWA.ChartOptions.IceStoreAirAnalysis.getChartStoreLoadOptions(timeBoxForSearch.type()); options.dataSource = dataArray; chartStoreLoad().option(options); //chart 4 /* dataArray = BWA.Chart.getRelationDataArrayOnDateTime( COP, load, 'cop', 'load'); options = BWA.ChartOptions.IceStoreAirAnalysis.getChartCOPLoadOptions(timeBoxForSearch.type()); options.dataSource = dataArray; chartCOPLoad().option(options); 2016 02 29 대구은행현장*/ dataArray = []; _.each(cop1, function (x) { dataArray.push({ DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), cop1: x.Value }); }); _.each(cop2, function (x) { dataArray.push({ DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), cop2: x.Value }); }); _.each(kcal, function (x) { dataArray.push({ DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), kcal : x.Value }); }); var options = BWA.ChartOptions.IceStoreAirAnalysis.getChartCOPOptions2(timeBoxForSearch.type()); options.dataSource = dataArray; chartCOPLoad().option(options); //2016 02 29 // visiblePopup(false); return; //chart5 var ColdCOPDataArray = []; _.each(input_temp, function (x) { ColdCOPDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), temp: x.Value }); }); _.each(COP, function (x) { ColdCOPDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), cop: x.Value }); }); _.each(load, function (x) { ColdCOPDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), load: x.Value }); }); //chartColdCOP().option('dataSource', ColdCOPDataArray); options = BWA.ChartOptions.IceStoreAirAnalysis.getChartColdCOPOptions(timeBoxForSearch.type()); //chartColdCOP().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.dataSource = ColdCOPDataArray; chartColdCOP().option(options); //chart6 var KCALDataArray = []; _.each(cold_kcal, function (x) { KCALDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), cold_kcal: x.Value }); }); _.each(vline_kcal, function (x) { KCALDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), vline_kcal: x.Value }); }); //chartKCAL().option('dataSource', KCALDataArray); options = BWA.ChartOptions.IceStoreAirAnalysis.getChartKCALOptions(timeBoxForSearch.type()); //chartKCAL().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.dataSource = KCALDataArray; chartKCAL().option(options); //chart7 var EffiDataArray = []; _.each(effi, function (x) { EffiDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), effi: x.Value }); }); _.each(sw, function (x) { EffiDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), sw: x.Value }); }); //chartEffi().option('dataSource', EffiDataArray); options = BWA.ChartOptions.IceStoreAirAnalysis.getChartEffiOptions(timeBoxForSearch.type()); //chartEffi().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.dataSource = EffiDataArray; chartEffi().option(options); //chart8 var ApproDataArray = []; _.each(approch, function (x) { ApproDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), approch: x.Value }); }); _.each(h_temp, function (x) { ApproDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), h_temp: x.Value }); }); _.each(input_temp, function (x) { ApproDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), in_temp: x.Value }); }); _.each(out_temp, function (x) { ApproDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), out_temp: x.Value }); }); //chartApproch().option('dataSource', ApproDataArray); options = BWA.ChartOptions.IceStoreAirAnalysis.getChartApprochOptions(timeBoxForSearch.type()); //chartApproch().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.dataSource = ApproDataArray; chartApproch().option(options); /* //chart3 var COPDataArray = []; _.each(COP, function (x) { COPDataArray.push({ DateTime: moment(x.DateTime).toDate(), COP: x.Value }); }); _.each(elecuse, function (x) { COPDataArray.push({ DateTime: moment(x.DateTime).toDate(), elecuse: x.Value }); }); _.each(fueluse, function (x) { COPDataArray.push({ DateTime: moment(x.DateTime).toDate(), m3: x.Value }); }); chartCOP().option('dataSource', COPDataArray); //chart4 var FIREDataArray = []; _.each(fire, function (x) { FIREDataArray.push({ DateTime: moment(x.DateTime).toDate(), fire: x.Value }); }); _.each(elecuse, function (x) { FIREDataArray.push({ DateTime: moment(x.DateTime).toDate(), elecuse: x.Value }); }); _.each(fueluse, function (x) { FIREDataArray.push({ DateTime: moment(x.DateTime).toDate(), m3: x.Value }); }); chartFIRE().option('dataSource', FIREDataArray); */ visiblePopup(false); /* msgbox. $("#large-indicator").dxLoadIndicator({ height: 60, width: 60 });*/ //chartTemperatureCalorie().option('dataSource', calories.concat(OUTtemperatures)); //chartTemperatureElectricity2().option('dataSource', electricityDataArray.concat(OUTtemperatures)); }) .fail(function (error) { //alert(error); visiblePopup(false); }); } var viewModel = $.extend(BWA.CommonView.create( params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView, undefined, chartLayout), { // facility: facilityViewModel, refreshList: refreshList, viewHidden: handleViewHidden, // hcLee 2015 06 03 viewShowing: handleViewShowing, scrolling: { mode: 'infinite' }, IceStoreAirDataGridOptions: { dataSource: facilitiesForSearch, columns: [ { dataField: 'Name', caption: $G('facilityName'), width: '100%', alignment: 'left' } ], filterRow: { visible: true, showOperationChooser: false }, selection: { mode: 'single' }, rowClick: function(clickRow) { handleSelectedFacilityInSearchView(clickRow.data); } }, contentReadyAction: function(e) { datagrid = e.component; } }); viewModel.timeBoxForSearch = timeBoxForSearch; viewModel.currentTabIndex = currentTabIndex; viewModel.multiViewItems = [{ facility: facilityViewModel, template: 'mainCharts' }, { template: 'subCharts' } ]; $HourGlassPopup(viewModel, visiblePopup); return viewModel; };