BemsWebApplication.HeatExchangerAnalysis = 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 chartEffi = BWA.Chart.Instance('chartEffiHEA', 'dxChart'), chartAV = BWA.Chart.Instance('chartAVHEA', 'dxChart'), chartPump = BWA.Chart.Instance('chartPumpHEA', 'dxChart'), chartATF = BWA.Chart.Instance('chartATFHEA', 'dxChart'); var chartLayout = new BWA.ChartLayout({ divs: [[{ id: 'HeatExchangerDetail' }, { id: 'Effi', chartId: 'chartEffiHEA' }, { id: 'AV', chartId: 'chartAVHEA' }, { id: 'Pump', chartId: 'chartPumpHEA' }, { id: 'ATF', chartId: 'chartATFHEA' } ]], multiViewOptions: { viewIndex: currentTabIndex, viewCount: 1 } }); // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 // 팝업창뷰 보이기 속성 제어용 변수 선언 var DataGridPopup_Visible = ko.observable(false); // 그래프 출력 이후 엑셀출력을 위한 팝업창을 위해 임시 저장용 배열 선언 var dataArrayresult = ko.observableArray(); // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 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.HeatExchangerAnalysis; //chartEffi = chartEffi(chartOption.getChartEffiOptions($Code.TimeType.HOUR)); chartEffi = chartEffi(chartOption.getChart_1_Options($Code.TimeType.HOUR)); //chartAV = chartAV(chartOption.getChartAVOptions($Code.TimeType.HOUR)); chartAV = chartAV(chartOption.getChart_2_Options($Code.TimeType.HOUR)); chartPump = chartPump(chartOption.getChart_3_Options($Code.TimeType.HOUR)); //chartATF = chartATF(chartOption.getChartATFOptions($Code.TimeType.HOUR)); chartATF = chartATF(chartOption.getChart_4_Options($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.EARTH) ]); facilityDataSource.load().done(function(facilities) { facilitiesForSearch(facilities); if (_.isEmpty(facilities) === false) { var f = facilities[0]; handleSelectedFacilityInSearchView(f); handleSearchInSearchView(); var datagrid = $('#HeatExchangerDataGridViewInSearchView').dxDataGrid('instance'); if (_.has(datagrid, 'selectRows')) { datagrid.selectRows(f); } } }); } if (shouldReload) { //shouldReload = false; //dataSource.pageIndex(0); //dataSource.load(); } function handleViewHidden() { var paging = BWA.ChartLayout.Paging; paging.sideOverlayVisible(false); $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) { 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.HEAT_EXCHANGER]; var formula = $Code.Formula[$Code.FacilityType.EARTH]; var formulaIds = _.values(formula); var date = timeBoxForSearch.getDate(); /* timeBoxForSearch.type($Code.TimeIntervalType.DAY); timeIntervalType = $Code.TimeIntervalType.DAY; date.startDate = new Date(2015, 0, 1); date.endDate = new Date(2015, 11, 31); */ //utils.toast.displayTime=1000000; //utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요'); // 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); }); // 외기 온도 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 (effi, r_effi, elec, s_water_temp, r_water_temp, sw, lift, atf, OUTtemperatures) { effi = effi[0]; r_effi = r_effi[0]; elec = elec[0]; s_water_temp = s_water_temp[0]; r_water_temp = r_water_temp[0]; sw = sw[0]; lift = lift[0]; atf = atf[0]; */ $.when.apply(this, promises) //.done(function (cop, load, in_temp, out_temp, kw, OUTtemperatures, humidities) { .done(function (cop, load, in_temp, out_temp, kw, green, OUTtemperatures, humidities) { cop = cop[0]; load = load[0]; in_temp = in_temp[0]; out_temp = out_temp[0]; kw = kw[0]; // chart 1 //var EffiDataArray = []; var maxValuecops = 0; _.each(cop, function (x) { if (maxValuecops < x.Value) maxValuecops = x.Value; }); var EffiDataArray = BWA.Chart.mapNewWithConvertingDateTime(cop, timeBoxForSearch.type()); _.each(OUTtemperatures[0], function (x) { EffiDataArray.push({ DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), Temperature: x.Value }); }); _.each(humidities[0], function (x) { EffiDataArray.push({ DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), Humidity: x.Value }); }); var options = BWA.ChartOptions.HeatExchangerAnalysis.getChart_1_Options(timeBoxForSearch.type()); options.valueAxis[0].tickInterval = Math.round(maxValuecops / 5) + 1; options.dataSource = EffiDataArray; chartEffi().option(options); /* _.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(r_effi, function (x) { EffiDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), r_effi: x.Value }); }); _.each(elec, function (x) { EffiDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), elec: x.Value }); }); //chartEffi().option('dataSource', EffiDataArray); var options = BWA.ChartOptions.HeatExchangerAnalysis.getChartEffiOptions(timeBoxForSearch.type()); //chartEffi().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.dataSource = EffiDataArray; chartEffi().option(options); */ //chart2 /* var AVDataArray = []; _.each(s_water_temp, function (x) { AVDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), s_water_temp: x.Value }); }); _.each(r_water_temp, function (x) { AVDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), r_water_temp: x.Value }); }); _.each(elec, function (x) { AVDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), elec: x.Value }); }); //chartAV().option('dataSource', AVDataArray); options = BWA.ChartOptions.HeatExchangerAnalysis.getChartAVOptions(timeBoxForSearch.type()); chartAV().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.dataSource = AVDataArray; chartAV().option(options); */ var dataArray = BWA.Chart.getRelationDataArrayOnDateTime(cop, load, 'cop', 'load'); var options = BWA.ChartOptions.HeatExchangerAnalysis.getChart_2_Options(timeBoxForSearch.type()); //chartElectricityLoadRate().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.dataSource = dataArray; chartAV().option(options); //chart3 /* var PumpDataArray = []; _.each(sw, function (x) { PumpDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), sw: x.Value }); }); _.each(lift, function (x) { PumpDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), lift: x.Value }); }); _.each(elec, function (x) { PumpDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), elec: x.Value }); }); //chartPump().option('dataSource', PumpDataArray); options = BWA.ChartOptions.HeatExchangerAnalysis.getChartPumpOptions(timeBoxForSearch.type()); //chartPump().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.dataSource = PumpDataArray; chartPump().option(options); */ var maxValuecops = 0; _.each(load, function (x) { if (maxValuecops < x.Value) maxValuecops = x.Value; }); EffiDataArray = BWA.Chart.mapNewWithConvertingDateTime(load, timeBoxForSearch.type()); //_.each(OUTtemperatures[0], function (x) { // EffiDataArray.push({ // DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), // Temperature: x.Value // }); //}); //_.each(humidities[0], function (x) { // EffiDataArray.push({ // DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), // Humidity: x.Value // }); //}); var options = BWA.ChartOptions.HeatExchangerAnalysis.getChart_3_Options(timeBoxForSearch.type()); //options.valueAxis[0].tickInterval = Math.round(maxValuecops / 5) + 1; options.dataSource = EffiDataArray; chartPump().option(options); //chart4 /* var maxValue = 0; var ATFDataArray = []; _.each(atf, function (x) { ATFDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), atf: x.Value }); if (maxValue < x.Value) maxValue = x.Value; }); _.each(OUTtemperatures[0], function (x) { ATFDataArray.push({ //DateTime: moment(x.DateTime).toDate(), DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), temp: x.Value }); }); //chartATF().option('dataSource', ATFDataArray); options = BWA.ChartOptions.HeatExchangerAnalysis.getChartATFOptions(timeBoxForSearch.type()); //chartATF().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결) options.valueAxis[0].tickInterval = Math.round(maxValue / 5) + 1; options.dataSource = ATFDataArray; chartATF().option(options); */ var DataArray_temp = [], DataArray_temp1 = [], DataArray_temp2 = [], DataArray_temp3 = []; EffiDataArray = BWA.Chart.mapNewWithConvertingDateTime(kw, timeBoxForSearch.type()); DataArray_temp = BWA.Chart.mapNewWithConvertingDateTime(kw, timeBoxForSearch.type()); _.each(in_temp, function (x) { EffiDataArray.push({ DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), in_temp: x.Value }); }); _.each(out_temp, function (x) { EffiDataArray.push({ DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), out_temp: x.Value }); }); _.each(in_temp, function (x) { DataArray_temp1.push({ DateTime: BWA.Chart.getCustermTimeArgumentAxisString($Code.TimeType.QUARTERMIN, moment(x.DateTime).toDate()), in_temp: x.Value }); }); _.each(out_temp, function (x) { DataArray_temp2.push({ DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()), out_temp: x.Value }); }); var array_length_size = Math.max(DataArray_temp.length, DataArray_temp1.length, DataArray_temp2.length); // 크기가 동일한 경우에만 허용함 (예외 방어용) if (DataArray_temp.length == DataArray_temp1.length && DataArray_temp1.length == DataArray_temp2.length) { for (var i = 0; i < array_length_size; i++) { DataArray_temp3.push( { DateTime: DataArray_temp1[i].DateTime, 'kw': DataArray_temp[i].Value, 'in_temp': DataArray_temp1[i].in_temp, 'out_temp': DataArray_temp2[i].out_temp, }); } } var options = BWA.ChartOptions.HeatExchangerAnalysis.getChart_4_Options(timeBoxForSearch.type()); //options.valueAxis[0].tickInterval = Math.round(maxValuecops / 5) + 1; options.dataSource = EffiDataArray; // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 dataArrayresult = DataArray_temp3; chartATF().option(options); visiblePopup(false); }) .fail(function (error) { visiblePopup(false); }); } // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 function DataGridPopup_ButtonClick() { DataGridPopup_Visible(true); } function handlePopupShown() { // 데이타소스 업데이트 $("#HeatExchangerDataGrid_Container").dxDataGrid("instance").option("dataSource", dataArrayresult); // 팝업창 갱신 DataGridPopup_Visible(true); } 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' }, HeatExchangerDataGridOptions: { 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; } // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 , HeatExchangerDataGridPopup_ButtonClicked: DataGridPopup_ButtonClick // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 }); // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 viewModel.HeatExchangerDataGridPopupOptions = { width: '480px', height: '750px', // cyim 2017.05.30 : 테스트 결과 Devextreme 버그임. px 로 지정하면 초기 출력시 정확하게 가운데에 있지만, auto 설정시 화면아래에 위치하게 됨 contentTemplate: "content", showTitle: true, title: "도표", visible: DataGridPopup_Visible, dragEnabled: true, closeOnOutsideClick: true, shownAction: handlePopupShown, animation: window.utils.popup.createAnimation() }; // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 viewModel.timeBoxForSearch = timeBoxForSearch; viewModel.currentTabIndex = currentTabIndex; viewModel.multiViewItems = [{ facility: facilityViewModel, template: 'mainCharts' }, { template: 'subCharts' } ]; $HourGlassPopup(viewModel, visiblePopup); // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 viewModel.HeatExchangerDataGridOptions1 = { dataSource: dataArrayresult, paging: { pageSize: 17 }, columns: [ { dataField: 'DateTime', caption: "날짜", width: '31%', alignment: 'center', },// dataType: 'date', format: 'yyyy-MM-dd HH:mm' }, { dataField: 'kw', caption: "소비전력", width: '23%', alignment: 'center', format: 'fixedPoint', precision: 2 }, { dataField: 'in_temp', caption: "공급온도", width: '23%', alignment: 'center', format: 'fixedPoint', precision: 2 }, { dataField: 'out_temp', caption: "환수온도", width: '23%', alignment: 'center', format: 'fixedPoint', precision: 2 } ], // 엑셀 출력 "export": { enabled: true, fileName: '지열시스템 성능분석' } }; // 2018.08.21 : 그리드 도표 작업 : 팝업창 추가 return viewModel; };