6c16d30dacb96063dbc72ae6b7bdc3772c23527b.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. BemsWebApplication.BoilerAnalysis = function(params, viewInfo) {
  2. "use strict";
  3. var initialized = false,
  4. shouldReload = false,
  5. datagrid = null,
  6. currentTabIndex = ko.observable(0),
  7. facilityViewModel = new BWA.CmFacilityViewModel(),
  8. dataSource;
  9. var m_Facility;
  10. var multiViewItems = [{
  11. template: 'mainCharts'
  12. }, {
  13. template: 'subCharts'
  14. }
  15. ];
  16. var facilityDataSource = BWA.db.createDataSource('CmFacility'),
  17. facilitiesForSearch = ko.observableArray(),
  18. facilityCodeForSearch = ko.observable(0),
  19. deferredForSearch = new $.Deferred();
  20. var visiblePopup = ko.observable(false);
  21. var dataCalorie = ko.observableArray(),
  22. dataAtfw = ko.observableArray(),
  23. dataTemperatureCalorie = ko.observableArray(),
  24. dataTemperatureElectricity = ko.observableArray()
  25. ;
  26. var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());
  27. //var timeBoxForSearch = BWA.SearchView.createDateTimeBox();
  28. // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  29. var timeBoxForSearch = BWA.SearchView.createDateTimeBox($G.TimeTypesForHourOnly, null, false);
  30. var chartEffi = BWA.Chart.Instance('chartEffiBO', 'dxChart'),
  31. chartAtfw = BWA.Chart.Instance('chartAtfwBO', 'dxChart'),
  32. chartCOP = BWA.Chart.Instance('chartCOPBO', 'dxChart'),
  33. chartFIRE = BWA.Chart.Instance('chartFIREBO', 'dxChart');
  34. var chartLayout = new BWA.ChartLayout({
  35. divs: [[{
  36. id: 'boilerDetail'
  37. }, {
  38. id: 'effi',
  39. chartId: 'chartEffiBO'
  40. }, {
  41. id: 'atfw',
  42. chartId: 'chartAtfwBO'
  43. }, {
  44. id: 'COP',
  45. chartId: 'chartCOPBO'
  46. }, {
  47. id: 'FIRE',
  48. chartId: 'chartFIREBO'
  49. }
  50. ]],
  51. multiViewOptions: {
  52. viewIndex: currentTabIndex,
  53. viewCount: 1
  54. }
  55. });
  56. var m = moment();
  57. dataCalorie([
  58. { DateTime: new Date(m.year(), m.month(), 1), Value: 50 },
  59. { DateTime: new Date(m.year(), m.month(), 2), Value: 50 },
  60. { DateTime: new Date(m.year(), m.month(), 3), Value: 60 },
  61. { DateTime: new Date(m.year(), m.month(), 4), Value: 80 },
  62. { DateTime: new Date(m.year(), m.month(), 5), Value: 100 },
  63. { DateTime: new Date(m.year(), m.month(), 6), Value: 40, },
  64. { DateTime: new Date(m.year(), m.month(), 7), Value: 120 },
  65. { DateTime: new Date(m.year(), m.month(), 31), Value: 120 }
  66. ]);
  67. // 추가 2015 04 20 hcLee ->
  68. var CODE = $Code,
  69. FuelType = CODE.FuelType,
  70. FT = CODE.FacilityType,
  71. FC = CODE.FacilityCode,
  72. F = CODE.Formula,
  73. TIT = CODE.TimeIntervalType;
  74. // 추가 2015 04 20 hcLee <-
  75. //dataMonthForBar(dataDayForBar());
  76. //dataDayForPie([
  77. // { FuelTypeName: '전기', Value: 320 },
  78. // { FuelTypeName: '가스', Value: 350 },
  79. // { FuelTypeName: '수도', Value: 360 },
  80. //]);
  81. //dataMonthForPie(dataDayForPie());
  82. function handleViewShown() {
  83. if (initialized === false) {
  84. var chartOption = BWA.ChartOptions.BoilerAnalysis;
  85. chartEffi = chartEffi(chartOption.getChartEffiOptions($Code.TimeType.HOUR));
  86. //chartAtfw = chartAtfw(chartOption.getChartAtfwOptions($Code.TimeType.HOUR));
  87. chartAtfw = chartAtfw(chartOption.getChart_2_Options($Code.TimeType.HOUR));
  88. //chartCOP = chartCOP(chartOption.getChartCOPOptions($Code.TimeType.HOUR));
  89. chartCOP = chartCOP(chartOption.getChart_3_Options($Code.TimeType.HOUR));
  90. //chartFIRE = chartFIRE(chartOption.getChartFIREOptions($Code.TimeType.HOUR));
  91. chartFIRE = chartFIRE(chartOption.getChart_4_Options($Code.TimeType.HOUR));
  92. initialized = true;
  93. }
  94. //hcLee 2016 07 12
  95. timeBoxForSearch.setDefaultDate();
  96. var eq = BWA.DataUtil.constructEqualFilter;
  97. facilityDataSource.filter([
  98. eq('SiteId', BWA.UserInfo.SiteId()),
  99. 'and',
  100. eq('FacilityTypeId', $Code.FacilityType.BOILER),
  101. //'or',
  102. //eq('FacilityTypeId', 8),
  103. ]);
  104. facilityDataSource.load().done(function(facilities) {
  105. facilitiesForSearch(facilities);
  106. if (_.isEmpty(facilities) === false) {
  107. var f = facilities[0];
  108. handleSelectedFacilityInSearchView(f);
  109. handleSearchInSearchView();
  110. var datagrid = $('#boilerDataGridViewInSearchView').dxDataGrid('instance');
  111. if (_.has(datagrid, 'selectRows')) {
  112. datagrid.selectRows(f);
  113. }
  114. }
  115. });
  116. }
  117. if (shouldReload) {
  118. //shouldReload = false;
  119. //dataSource.pageIndex(0);
  120. //dataSource.load();
  121. }
  122. function handleViewHidden() {
  123. //hideOverlay();
  124. // var dataGrid = $('#gridContainer').dxDataGrid('instance');
  125. // dataGrid.clearSelection();
  126. var paging = BWA.ChartLayout.Paging;
  127. paging.sideOverlayVisible(false);
  128. //paging.hideNextButton(true);
  129. //paging.hidePrevButton(true);
  130. $SearchView.visibleObservable(false); // hcLee 2015 03 23
  131. visiblePopup(false);
  132. }
  133. function handleViewShowing() {
  134. }
  135. function refreshList() {
  136. //dataSource.pageIndex(0);
  137. //dataSource.load();
  138. }
  139. var searchViewOptions = {
  140. searchViewItems: [
  141. { id: 'FacilityCode', ignoreValue: 0, defaultValue: 0, value: facilityCodeForSearch, dataSource: facilitiesForSearch },
  142. ],
  143. promiseDataInSearchView: deferredForSearch.promise()
  144. };
  145. function handleSelectedFacilityInSearchView(facility) {
  146. m_Facility = facility;
  147. return;
  148. }
  149. function handleSearchInSearchView(filter, searchViewItems) {
  150. //console.log(filter);
  151. //console.log(searchViewItems);
  152. if (m_Facility == null) return;
  153. visiblePopup(true);
  154. var f = m_Facility.toJS();
  155. facilityViewModel.fromJS(f);
  156. //var timeIntervalType = $Code.TimeIntervalType.QUARTERMIN;
  157. var timeIntervalType = timeBoxForSearch.type();
  158. var formula = $Code.Formula[$Code.FacilityType.BOILER];
  159. var formulaIds = _.values(formula);
  160. var date = timeBoxForSearch.getDate();
  161. //utils.toast.displayTime=1000000;
  162. //utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요');
  163. /*
  164. timeBoxForSearch.type($Code.TimeIntervalType.DAY);
  165. timeIntervalType = $Code.TimeIntervalType.DAY;
  166. date.startDate = new Date(2015, 0, 1);
  167. date.endDate = new Date(2015, 11, 31);*/
  168. // var startDate = moment().
  169. var promises = [];
  170. _.each(formulaIds, function (formulaId) {
  171. var p = formulaGet.apiGet({
  172. FacilityTypeId: f.FacilityTypeId,
  173. FacilityCode: f.FacilityCode,
  174. FormulaId: formulaId,
  175. TimeIntervalType: timeIntervalType,
  176. StartDate: date.startDate,
  177. EndDate: date.endDate
  178. });
  179. promises.push(p);
  180. });
  181. // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20 ->
  182. var commonParameters = {
  183. TimeIntervalType: timeIntervalType,
  184. StartDate: date.startDate,
  185. EndDate: date.endDate
  186. };
  187. var temperatureParameters = {
  188. FacilityTypeId: FT.OUTDOOR,
  189. FacilityCode: FC.OUTDOOR,
  190. FormulaId: F[FT.OUTDOOR].TEMPERATURE,
  191. };
  192. var humidityParameters = _.extend({}, temperatureParameters, {
  193. FormulaId: F[FT.OUTDOOR].HUMIDITY,
  194. });
  195. promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
  196. promises.push(formulaGet.apiGet(_.extend(humidityParameters, commonParameters)));
  197. $.when.apply(this, promises)
  198. .done(function (kcal, fueluse, effi, fo2, eo2, airfact, elecuse, fire, COP,
  199. //2016 03 05 추가
  200. syseffi, load, pump_kw, pump_hz,
  201. OUTTemp, OutHumi) {
  202. kcal = kcal[0];
  203. fueluse = fueluse[0];
  204. effi = effi[0];
  205. fo2 = fo2[0];
  206. eo2 = eo2[0];
  207. airfact = airfact[0];
  208. elecuse = elecuse[0];
  209. fire = fire[0];
  210. COP = COP[0];
  211. // chart 1
  212. var EffiDataArray = [];
  213. /* _.each(kcal, function (x) { // 보일러능력
  214. EffiDataArray.push({
  215. //DateTime: moment(x.DateTime).toDate(),
  216. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  217. kcal: x.Value
  218. });
  219. }); 2016 03 07 다시 제외 */
  220. _.each(fueluse, function (x) { //보일러연료사용량
  221. EffiDataArray.push({
  222. //DateTime: moment(x.DateTime).toDate(),
  223. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  224. m3: x.Value
  225. });
  226. });
  227. _.each(effi, function (x) { //보일러효율
  228. EffiDataArray.push({
  229. //DateTime: moment(x.DateTime).toDate(),
  230. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  231. effi: x.Value
  232. });
  233. });
  234. _.each(syseffi[0], function (x) {// 시스템효율
  235. EffiDataArray.push({
  236. //DateTime: moment(x.DateTime).toDate(),
  237. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  238. syseffi: x.Value
  239. });
  240. });
  241. _.each(elecuse, function (x) { // 보일러소비전력
  242. EffiDataArray.push({
  243. //DateTime: moment(x.DateTime).toDate(),
  244. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  245. elecuse: x.Value
  246. });
  247. });
  248. _.each(pump_kw[0], function (x) { // 펌프소비전력
  249. EffiDataArray.push({
  250. //DateTime: moment(x.DateTime).toDate(),
  251. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  252. pump_kw: x.Value
  253. });
  254. });
  255. var options = BWA.ChartOptions.BoilerAnalysis.getChartEffiOptions(timeBoxForSearch.type());
  256. options.dataSource = EffiDataArray;
  257. chartEffi().option(options);
  258. //chart2
  259. /*
  260. var AirDataArray = [];
  261. _.each(airfact, function (x) {
  262. AirDataArray.push({
  263. //DateTime: moment(x.DateTime).toDate(),
  264. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  265. airfact: x.Value
  266. });
  267. });
  268. _.each(fo2, function (x) {
  269. AirDataArray.push({
  270. //DateTime: moment(x.DateTime).toDate(),
  271. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  272. fo2: x.Value
  273. });
  274. });
  275. _.each(eo2, function (x) {
  276. AirDataArray.push({
  277. //DateTime: moment(x.DateTime).toDate(),
  278. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  279. eo2: x.Value
  280. });
  281. });
  282. options = BWA.ChartOptions.BoilerAnalysis.getChartAtfwOptions(timeBoxForSearch.type());
  283. options.dataSource = AirDataArray;
  284. chartAtfw().option(options);*/
  285. var dataArray = BWA.Chart.getRelationDataArrayOnDateTime(effi, load[0], 'effi', 'load');
  286. options = BWA.ChartOptions.BoilerAnalysis.getChart_2_Options(timeBoxForSearch.type());
  287. options.dataSource = dataArray;
  288. chartAtfw().option(options);
  289. //chart3
  290. var COPDataArray = [];
  291. /*
  292. _.each(COP, function (x) {
  293. COPDataArray.push({
  294. //DateTime: moment(x.DateTime).toDate(),
  295. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  296. COP: x.Value
  297. });
  298. });
  299. _.each(elecuse, function (x) {
  300. COPDataArray.push({
  301. //DateTime: moment(x.DateTime).toDate(),
  302. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  303. elecuse: x.Value
  304. });
  305. });
  306. _.each(fueluse, function (x) {
  307. COPDataArray.push({
  308. //DateTime: moment(x.DateTime).toDate(),
  309. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  310. m3: x.Value
  311. });
  312. });
  313. //chartCOP().option('dataSource', COPDataArray);
  314. options = BWA.ChartOptions.BoilerAnalysis.getChartCOPOptions(timeBoxForSearch.type());
  315. //chartCOP().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
  316. options.dataSource = COPDataArray;
  317. chartCOP().option(options); */
  318. _.each(pump_kw[0], function (x) {
  319. COPDataArray.push({
  320. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  321. pump_kw: x.Value
  322. });
  323. });
  324. _.each(pump_hz[0], function (x) {
  325. COPDataArray.push({
  326. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  327. pump_hz: x.Value
  328. });
  329. });
  330. options = BWA.ChartOptions.BoilerAnalysis.getChart_3_Options(timeBoxForSearch.type());
  331. options.dataSource = COPDataArray;
  332. chartCOP().option(options);
  333. //chart4
  334. var FIREDataArray = [];/*
  335. _.each(fire, function (x) {
  336. FIREDataArray.push({
  337. //DateTime: moment(x.DateTime).toDate(),
  338. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  339. fire: x.Value
  340. });
  341. });
  342. _.each(elecuse, function (x) {
  343. FIREDataArray.push({
  344. //DateTime: moment(x.DateTime).toDate(),
  345. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  346. elecuse: x.Value
  347. });
  348. });
  349. _.each(fueluse, function (x) {
  350. FIREDataArray.push({
  351. //DateTime: moment(x.DateTime).toDate(),
  352. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  353. m3: x.Value
  354. });
  355. });
  356. //chartFIRE().option('dataSource', FIREDataArray);
  357. options = BWA.ChartOptions.BoilerAnalysis.getChartFIREOptions(timeBoxForSearch.type());
  358. //chartFIRE().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
  359. options.dataSource = FIREDataArray;
  360. chartFIRE().option(options);
  361. */
  362. var maxValuecops = 0;
  363. _.each(load[0], function (x) {
  364. if (maxValuecops < x.Value) maxValuecops = x.Value;
  365. });
  366. FIREDataArray = BWA.Chart.mapNewWithConvertingDateTime(load[0], timeBoxForSearch.type());
  367. //_.each(OUTTemp[0], function (x) {
  368. // FIREDataArray.push({
  369. // DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  370. // Temperature: x.Value
  371. // });
  372. //});
  373. //_.each(OutHumi[0], function (x) {
  374. // FIREDataArray.push({
  375. // DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  376. // Humidity: x.Value
  377. // });
  378. //});
  379. options = BWA.ChartOptions.BoilerAnalysis.getChart_4_Options(timeBoxForSearch.type());
  380. //options.valueAxis[0].tickInterval = Math.round(maxValuecops / 5) + 1;
  381. options.dataSource = FIREDataArray;
  382. chartFIRE().option(options);
  383. visiblePopup(false);
  384. /* msgbox.
  385. $("#large-indicator").dxLoadIndicator({
  386. height: 60,
  387. width: 60
  388. });*/
  389. //chartTemperatureCalorie().option('dataSource', calories.concat(OUTtemperatures));
  390. //chartTemperatureElectricity2().option('dataSource', electricityDataArray.concat(OUTtemperatures));
  391. })
  392. .fail(function (error) {
  393. //alert(error);
  394. visiblePopup(false);
  395. });
  396. }
  397. var viewModel = $.extend(BWA.CommonView.create(
  398. params, viewInfo, searchViewOptions, ko.observable(null),
  399. handleViewShown, null, handleSearchInSearchView, undefined,
  400. chartLayout), {
  401. // facility: facilityViewModel,
  402. refreshList: refreshList,
  403. viewShowing: handleViewShowing,
  404. viewHidden: handleViewHidden, // hcLee 2015 06 19
  405. scrolling: { mode: 'infinite' },
  406. boilerDataGridOptions: {
  407. dataSource: facilitiesForSearch,
  408. columns: [
  409. { dataField: 'Name', caption: $G('facilityName'), width: '100%', alignment: 'left' }
  410. ],
  411. filterRow: {
  412. visible: true,
  413. showOperationChooser: false
  414. },
  415. selection: {
  416. mode: 'single'
  417. },
  418. rowClick: function(clickRow) {
  419. handleSelectedFacilityInSearchView(clickRow.data);
  420. }
  421. },
  422. contentReadyAction: function(e) {
  423. datagrid = e.component;
  424. }
  425. });
  426. viewModel.timeBoxForSearch = timeBoxForSearch;
  427. viewModel.currentTabIndex = currentTabIndex;
  428. viewModel.multiViewItems = [{
  429. facility: facilityViewModel,
  430. template: 'mainCharts'
  431. }, {
  432. template: 'subCharts'
  433. }
  434. ];
  435. $HourGlassPopup(viewModel, visiblePopup);
  436. return viewModel;
  437. };