123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- BemsWebApplication.ElecAnalysis = 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();
- var chartElec1 = BWA.Chart.Instance('chartElec1EA', 'dxChart'),
- chartElec2 = BWA.Chart.Instance('chartElec2EA', 'dxChart'),
- chartLoad = BWA.Chart.Instance('chartLoadEA', 'dxChart');
- var chartLayout = new BWA.ChartLayout({
- divs: [{
- id: 'ElecDetail'
- }, {
- id: 'elec1',
- chartId: 'chartElec1EA'
- }, {
- id: 'elec2',
- chartId: 'chartElec2EA'
- }, {
- id: 'load',
- chartId: 'chartLoadEA'
- }
- ],
- multiViewOptions: {
- viewIndex: currentTabIndex,
- 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.ElecAnalysis;
- chartElec1 = chartElec1(chartOption.getChartElec1Options($Code.TimeType.DAY));
- chartElec2 = chartElec2(chartOption.getChartElec2Options($Code.TimeType.DAY));
- chartLoad = chartLoad(chartOption.getChartLoadOptions($Code.TimeType.DAY));
- initialized = true;
- }
- var eq = BWA.DataUtil.constructEqualFilter;
- facilityDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- eq('FacilityTypeId', $Code.FacilityType.ELECTRICITY)
- ]);
- facilityDataSource.load().done(function (facilities) {
- facilitiesForSearch(facilities);
- if (_.isEmpty(facilities) === false) {
- var f = facilities[0];
- handleSelectedFacilityInSearchView(f);
- handleSearchInSearchView();
- var datagrid = $('#elecDataGridViewInSearchView').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);
- $("#large-indicator").dxLoadIndicator({
- height: 60,
- width: 60
- });
- var f = m_Facility.toJS();
- facilityViewModel.fromJS(f);
- var timeIntervalType = $Code.TimeIntervalType.DAY;
- //var timeIntervalType = timeBoxForSearch.type();
- var formula = $Code.Formula[$Code.FacilityType.ELECTRICITY];
- var formulaIds = _.values(formula);
- var date = timeBoxForSearch.getDate();
- //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);
- });
- /*
- // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20 ->
- var commonParameters = {
- TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
- StartDate: date.startDate,
- EndDate: date.endDate
- };
- var temperatureParameters = {
- FacilityTypeId: FT.OUTDOOR,
- FacilityCode: FC.OUTDOOR,
- FormulaId: F[FT.OUTDOOR].TEMPERATURE,
- };
- promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
- */ // 보일러는 필요 없다
- $.when.apply(this, promises)
- .done(function (total, contract, target, week_avg, current, load, avg, day_max) {
- contract = contract[0];
- target = target[0];
- week_avg = week_avg[0];
- current = current[0];
- load = load[0];
- avg = avg[0];
- day_max = day_max[0];
- // chart 1
- var DataArray1 = [];
- _.each(contract, function (x) {
- DataArray1.push({
- DateTime: moment(x.DateTime).toDate(),
- contract: x.Value
- });
- });
- _.each(target, function (x) {
- DataArray1.push({
- DateTime: moment(x.DateTime).toDate(),
- target: x.Value
- });
- });
- _.each(current, function (x) {
- DataArray1.push({
- DateTime: moment(x.DateTime).toDate(),
- current: x.Value
- });
- });
- _.each(week_avg, function (x) {
- DataArray1.push({
- DateTime: moment(x.DateTime).toDate(),
- week_avg: x.Value
- });
- });
- chartElec1().option('dataSource', DataArray1);
- chartElec2().option('dataSource', DataArray1);
- //chart2
- var LoadDataArray = [];
- _.each(load, function (x) {
- LoadDataArray.push({
- DateTime: moment(x.DateTime).toDate(),
- load: x.Value
- });
- });
- _.each(avg, function (x) {
- LoadDataArray.push({
- DateTime: moment(x.DateTime).toDate(),
- avg: x.Value
- });
- });
- _.each(day_max, function (x) {
- LoadDataArray.push({
- DateTime: moment(x.DateTime).toDate(),
- day_max: x.Value
- });
- });
- chartLoad().option('dataSource', LoadDataArray);
- 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' },
- elecDataGridOptions: {
- 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.popupOptions = {
- width: 300,
- height: 100,
- contentTemplate: "info",
- showTitle: false,
- title: "메세지",
- visible: visiblePopup,
- dragEnabled: false,
- shading: false,
- closeOnOutsideClick: false
- };
- viewModel.timeBoxForSearch = timeBoxForSearch;
- viewModel.currentTabIndex = currentTabIndex;
- viewModel.multiViewItems = [{
- facility: facilityViewModel,
- template: 'mainCharts'
- }, {
- template: 'subCharts'
- }
- ];
- return viewModel;
- };
|