e30ab5ec9b7bb229c70a9e13f0e3af061d1bc7ad.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. BemsWebApplication.ElecAnalysis = 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. var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());
  26. var timeBoxForSearch = BWA.SearchView.createDateTimeBox();
  27. var chartElec1 = BWA.Chart.Instance('chartElec1EA', 'dxChart'),
  28. chartElec2 = BWA.Chart.Instance('chartElec2EA', 'dxChart'),
  29. chartLoad = BWA.Chart.Instance('chartLoadEA', 'dxChart');
  30. var chartLayout = new BWA.ChartLayout({
  31. divs: [{
  32. id: 'ElecDetail'
  33. }, {
  34. id: 'elec1',
  35. chartId: 'chartElec1EA'
  36. }, {
  37. id: 'elec2',
  38. chartId: 'chartElec2EA'
  39. }, {
  40. id: 'load',
  41. chartId: 'chartLoadEA'
  42. }
  43. ],
  44. multiViewOptions: {
  45. viewIndex: currentTabIndex,
  46. viewCount: 1
  47. }
  48. });
  49. var m = moment();
  50. dataCalorie([
  51. { DateTime: new Date(m.year(), m.month(), 1), Value: 50 },
  52. { DateTime: new Date(m.year(), m.month(), 2), Value: 50 },
  53. { DateTime: new Date(m.year(), m.month(), 3), Value: 60 },
  54. { DateTime: new Date(m.year(), m.month(), 4), Value: 80 },
  55. { DateTime: new Date(m.year(), m.month(), 5), Value: 100 },
  56. { DateTime: new Date(m.year(), m.month(), 6), Value: 40, },
  57. { DateTime: new Date(m.year(), m.month(), 7), Value: 120 },
  58. { DateTime: new Date(m.year(), m.month(), 31), Value: 120 }
  59. ]);
  60. // 추가 2015 04 20 hcLee ->
  61. var CODE = $Code,
  62. FuelType = CODE.FuelType,
  63. FT = CODE.FacilityType,
  64. FC = CODE.FacilityCode,
  65. F = CODE.Formula,
  66. TIT = CODE.TimeIntervalType;
  67. // 추가 2015 04 20 hcLee <-
  68. //dataMonthForBar(dataDayForBar());
  69. //dataDayForPie([
  70. // { FuelTypeName: '전기', Value: 320 },
  71. // { FuelTypeName: '가스', Value: 350 },
  72. // { FuelTypeName: '수도', Value: 360 },
  73. //]);
  74. //dataMonthForPie(dataDayForPie());
  75. function handleViewShown() {
  76. if (initialized === false) {
  77. var chartOption = BWA.ChartOptions.ElecAnalysis;
  78. chartElec1 = chartElec1(chartOption.getChartElec1Options($Code.TimeType.DAY));
  79. chartElec2 = chartElec2(chartOption.getChartElec2Options($Code.TimeType.DAY));
  80. chartLoad = chartLoad(chartOption.getChartLoadOptions($Code.TimeType.DAY));
  81. initialized = true;
  82. }
  83. var eq = BWA.DataUtil.constructEqualFilter;
  84. facilityDataSource.filter([
  85. eq('SiteId', BWA.UserInfo.SiteId()),
  86. 'and',
  87. eq('FacilityTypeId', $Code.FacilityType.ELECTRICITY)
  88. ]);
  89. facilityDataSource.load().done(function (facilities) {
  90. facilitiesForSearch(facilities);
  91. if (_.isEmpty(facilities) === false) {
  92. var f = facilities[0];
  93. handleSelectedFacilityInSearchView(f);
  94. handleSearchInSearchView();
  95. var datagrid = $('#elecDataGridViewInSearchView').dxDataGrid('instance');
  96. if (_.has(datagrid, 'selectRows')) {
  97. datagrid.selectRows(f);
  98. }
  99. }
  100. });
  101. }
  102. if (shouldReload) {
  103. //shouldReload = false;
  104. //dataSource.pageIndex(0);
  105. //dataSource.load();
  106. }
  107. function handleViewHidden() {
  108. var paging = BWA.ChartLayout.Paging;
  109. paging.sideOverlayVisible(false);
  110. $SearchView.visibleObservable(false); // hcLee 2015 03 23
  111. visiblePopup(false);
  112. }
  113. function handleViewShowing() {
  114. }
  115. function refreshList() {
  116. //dataSource.pageIndex(0);
  117. //dataSource.load();
  118. }
  119. var searchViewOptions = {
  120. searchViewItems: [
  121. { id: 'FacilityCode', ignoreValue: 0, defaultValue: 0, value: facilityCodeForSearch, dataSource: facilitiesForSearch },
  122. ],
  123. promiseDataInSearchView: deferredForSearch.promise()
  124. };
  125. function handleSelectedFacilityInSearchView(facility) {
  126. m_Facility = facility;
  127. return;
  128. }
  129. function handleSearchInSearchView(filter, searchViewItems) {
  130. if (m_Facility == null) return;
  131. visiblePopup(true);
  132. $("#large-indicator").dxLoadIndicator({
  133. height: 60,
  134. width: 60
  135. });
  136. var f = m_Facility.toJS();
  137. facilityViewModel.fromJS(f);
  138. var timeIntervalType = $Code.TimeIntervalType.DAY;
  139. //var timeIntervalType = timeBoxForSearch.type();
  140. var formula = $Code.Formula[$Code.FacilityType.ELECTRICITY];
  141. var formulaIds = _.values(formula);
  142. var date = timeBoxForSearch.getDate();
  143. //utils.toast.displayTime=1000000;
  144. //utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요');
  145. // var startDate = moment().
  146. var promises = [];
  147. _.each(formulaIds, function (formulaId) {
  148. var p = formulaGet.apiGet({
  149. FacilityTypeId: f.FacilityTypeId,
  150. FacilityCode: f.FacilityCode,
  151. FormulaId: formulaId,
  152. TimeIntervalType: timeIntervalType,
  153. StartDate: date.startDate,
  154. EndDate: date.endDate
  155. });
  156. promises.push(p);
  157. });
  158. /*
  159. // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20 ->
  160. var commonParameters = {
  161. TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
  162. StartDate: date.startDate,
  163. EndDate: date.endDate
  164. };
  165. var temperatureParameters = {
  166. FacilityTypeId: FT.OUTDOOR,
  167. FacilityCode: FC.OUTDOOR,
  168. FormulaId: F[FT.OUTDOOR].TEMPERATURE,
  169. };
  170. promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
  171. */ // 보일러는 필요 없다
  172. $.when.apply(this, promises)
  173. .done(function (total, contract, target, week_avg, current, load, avg, day_max) {
  174. contract = contract[0];
  175. target = target[0];
  176. week_avg = week_avg[0];
  177. current = current[0];
  178. load = load[0];
  179. avg = avg[0];
  180. day_max = day_max[0];
  181. // chart 1
  182. var DataArray1 = [];
  183. _.each(contract, function (x) {
  184. DataArray1.push({
  185. DateTime: moment(x.DateTime).toDate(),
  186. contract: x.Value
  187. });
  188. });
  189. _.each(target, function (x) {
  190. DataArray1.push({
  191. DateTime: moment(x.DateTime).toDate(),
  192. target: x.Value
  193. });
  194. });
  195. _.each(current, function (x) {
  196. DataArray1.push({
  197. DateTime: moment(x.DateTime).toDate(),
  198. current: x.Value
  199. });
  200. });
  201. _.each(week_avg, function (x) {
  202. DataArray1.push({
  203. DateTime: moment(x.DateTime).toDate(),
  204. week_avg: x.Value
  205. });
  206. });
  207. chartElec1().option('dataSource', DataArray1);
  208. chartElec2().option('dataSource', DataArray1);
  209. //chart2
  210. var LoadDataArray = [];
  211. _.each(load, function (x) {
  212. LoadDataArray.push({
  213. DateTime: moment(x.DateTime).toDate(),
  214. load: x.Value
  215. });
  216. });
  217. _.each(avg, function (x) {
  218. LoadDataArray.push({
  219. DateTime: moment(x.DateTime).toDate(),
  220. avg: x.Value
  221. });
  222. });
  223. _.each(day_max, function (x) {
  224. LoadDataArray.push({
  225. DateTime: moment(x.DateTime).toDate(),
  226. day_max: x.Value
  227. });
  228. });
  229. chartLoad().option('dataSource', LoadDataArray);
  230. visiblePopup(false);
  231. /* msgbox.
  232. $("#large-indicator").dxLoadIndicator({
  233. height: 60,
  234. width: 60
  235. });*/
  236. //chartTemperatureCalorie().option('dataSource', calories.concat(OUTtemperatures));
  237. //chartTemperatureElectricity2().option('dataSource', electricityDataArray.concat(OUTtemperatures));
  238. })
  239. .fail(function (error) {
  240. //alert(error);
  241. visiblePopup(false);
  242. });
  243. }
  244. var viewModel = $.extend(BWA.CommonView.create(
  245. params, viewInfo, searchViewOptions, ko.observable(null),
  246. handleViewShown, null, handleSearchInSearchView, undefined,
  247. chartLayout), {
  248. // facility: facilityViewModel,
  249. refreshList: refreshList,
  250. viewHidden: handleViewHidden, // hcLee 2015 06 03
  251. viewShowing: handleViewShowing,
  252. scrolling: { mode: 'infinite' },
  253. elecDataGridOptions: {
  254. dataSource: facilitiesForSearch,
  255. columns: [
  256. { dataField: 'Name', caption: $G('facilityName'), width: '100%', alignment: 'left' }
  257. ],
  258. filterRow: {
  259. visible: true,
  260. showOperationChooser: false
  261. },
  262. selection: {
  263. mode: 'single'
  264. },
  265. rowClick: function (clickRow) {
  266. handleSelectedFacilityInSearchView(clickRow.data);
  267. }
  268. },
  269. contentReadyAction: function (e) {
  270. datagrid = e.component;
  271. }
  272. });
  273. viewModel.popupOptions = {
  274. width: 300,
  275. height: 100,
  276. contentTemplate: "info",
  277. showTitle: false,
  278. title: "메세지",
  279. visible: visiblePopup,
  280. dragEnabled: false,
  281. shading: false,
  282. closeOnOutsideClick: false
  283. };
  284. viewModel.timeBoxForSearch = timeBoxForSearch;
  285. viewModel.currentTabIndex = currentTabIndex;
  286. viewModel.multiViewItems = [{
  287. facility: facilityViewModel,
  288. template: 'mainCharts'
  289. }, {
  290. template: 'subCharts'
  291. }
  292. ];
  293. return viewModel;
  294. };