Blame view

js/app/views/StatisticalPlug.js 6.48 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
  * Project      :  AMDA-NG
  * Name         : statisticalPlug.js
  * @plugin 	  amdaUI.StatisticalPlug
  * @extends 	  Ext.util.Observable 
  * @ptype 	 	  statisticalPlugin
  * @brief		  Statistical info in Time Table Module UI (View)
  * @author Myriam
  * @version $Id: StatisticalPlug.js 1237 2013-02-12 15:42:14Z myriam $
  ********************************************************************************
  *    FT Id     :   Date   : Name - Description
  *******************************************************************************
  *  :           :08/06/2011: Myriam - Migration extjs4
  */


Ext.define('amdaUI.StatisticalPlug', {
	extend: 'Ext.util.Observable',
	alias: 'plugin.statisticalPlugin',
	
	win : null,
		
 	constructor: function(config) { 
        Ext.apply(this, config);  
        this.callParent(arguments);
	},
 	
	init: function(cmp) {
	    this.hostCmp = cmp;    
	    this.hostCmp.on({
		info: this.onInfo,
		refresh: this.refresh,		 
		scope: this});
	},
	
	onDestroy : function() {
	        this.win = null;   
	},
	
	refresh: function() {
		this.statTT();
		/*if (this.form) {
			this.form.getForm().setValues({min: this.min, max: this.max, mean:this.mean, stdev: this.stdev,
				median: this.median, density: this.density });
		}*/
	},

0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
48
	onInfo: function(type) {
16035364   Benjamin Renard   First commit
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
	        if (!this.win) {	   
		    this.win = new Ext.Window({			
			    id: 'statistical-win',
			    width: 370, 
			    height: 140,
			    x: 420, y: 330,
			    baseCls:'x-panel',	 
			    title: 'Statistical info',
			    layout: 'fit',
			    constrain: true,
			    ghost: false,
			    renderTo: this.hostCmp.id,
				tools: [
				         {
				        	type:'help',
				        	qtip: 'Help on Statistical info',
				        	handler: function(event, toolEl, panel){
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
66
67
                                                                                                                        
				        		AmdaAction.getInfo({name : 'statisticalHelp'+type}, function(res,e) {					    					   
16035364   Benjamin Renard   First commit
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
								    if (res.success) myDesktopApp.infoMsg(res.result);
							 });  
				        	}
				         }
					],
			    items: this.getFormConfig(),
			    getConstrainVector: function(constrainTo){
					var me = this;
			        if (me.constrain || me.constrainHeader) {
			            constrainTo = constrainTo || (me.floatParent && me.floatParent.getTargetEl()) || me.container || me.el.getScopeParent();
			            return (me.constrainHeader ? me.header.el : me.el).getConstrainVector(constrainTo);
			        }
			    }
		    });
		    this.win.on('destroy', this.onDestroy, this);
		    this.win.show();
		}
	//    this.hostCmp.add(this.win);	    
	    this.refresh();
	},
	
	/**
	 * calculation method of statical values 
	 */
	statTT: function(){
	    if (this.win) {
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
94
                              var type =this.hostCmp[0]['id'];
16035364   Benjamin Renard   First commit
95
	    	var me = this;
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
96
	    	AmdaAction.getTTCacheStatistics({name : type }, function (result, e) {
16035364   Benjamin Renard   First commit
97
98
99
100
101
102
103
104
105
106
	    		if (!result || !result.success)
	    		{
	    			if (result.message)
	        			myDesktopApp.errorMsg(result.message);
	        		else
	        			myDesktopApp.errorMsg('Unknown error during statistics calculation');
	        		return;
	    		}
	    		
	    		// format min value
b6dff325   Elena.Budnik   #6898 : stat info...
107
	    		me.min = me.format_unit(result.result.minDuration) + " (-- " + (result.result.minDurationIndex+1) + ")";
16035364   Benjamin Renard   First commit
108
	    	    // format max value
b6dff325   Elena.Budnik   #6898 : stat info...
109
	    		me.max = me.format_unit(result.result.maxDuration) + " (-- " + (result.result.maxDurationIndex+1) + ")";    	    
16035364   Benjamin Renard   First commit
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
	    	    // format mean value
	    	    me.mean = me.format_unit(result.result.mean);
	    	    // format Stdev value
	    	    me.stdev = me.format_unit(result.result.stdev);
	    	    // format median value
	    	    me.median = me.format_unit(result.result.median);
	    	    // format density value
	    	    me.density = (result.result.density*100).toFixed(2) + " %";
	    	    
	    	    if (me.form) {
	    	    	me.form.getForm().setValues({min: me.min, max: me.max, mean:me.mean, stdev: me.stdev,
	    				median: me.median, density: me.density });
	    		}
	    	});
	    }
	},
	
	format_unit: function(unit) {
		if ( unit < 60 ) var string_unit = unit.toFixed(2) + " sec";
	    else if ((unit >= 60) && ( unit < 3600)) var string_unit = (unit/60).toFixed(2) + " min";
	    else if ((unit >= 3600) && ( unit < 86400)) var string_unit = (unit/3600).toFixed(2) + " hour";
	    else if ( unit >= 86400 ) var string_unit = (unit/86400).toFixed(2) + " day";
	    return string_unit;
	},	
	
	getFormConfig: function(){
	    this.form = new Ext.form.FormPanel( {
	    	frame: true, buttonAlign: 'center', flex: 1,
	    	fieldDefaults: {
                labelWidth: 50
            },
            items: [{
                xtype : 'container',
                layout:'anchor',
                items: [	
      	          {			            	        	        	  
      	        	  xtype: 'fieldcontainer',
      	        	  layout: 'hbox',
      	        	  fieldLabel:'Min',
      	        	  items: [
  	        	          {xtype:'textfield', name:'min', value: this.min, width: 100},
  	        	          {xtype:'splitter', width: 20},
  	        	          {xtype:'displayfield', value: 'Max:', width: 40},
  	        	          {xtype:'splitter', width: 13},
  	        	          {xtype:'textfield', name:'max', value: this.max, width: 100}
      	        	  ]
      	          },
      	          {			            	        	        	  
      	        	  xtype: 'fieldcontainer',
      	        	  layout: 'hbox',
      	        	  fieldLabel:'Mean',
      	        	  items: [
  	        	          {xtype:'textfield', name: 'mean', value: this.mean, width: 100},
  	        	          {xtype:'splitter', width: 20},
  	        	          {xtype:'displayfield', value: 'St.dev:', width: 50},
  	        	          {xtype:'splitter', width: 2},
  	        	          {xtype:'textfield', name: 'stdev', value: this.stdev, width: 100}
      	        	  ]
      	          },	        	          
      	          {			            	        	        	  
      	        	  xtype: 'fieldcontainer',
      	        	  layout: 'hbox',
      	        	  fieldLabel:'Median',
      	        	  items: [
  	        	          {xtype:'textfield', name: 'median', value: this.median, width: 100},
  	        	          {xtype:'splitter', width: 20},
  	        	          {xtype:'displayfield', value: 'Density:', width: 52},
  	        	          {xtype:'textfield', name: 'density', value: this.density, width: 100}
      	        	  ]
      	          }
      	          
      	         ]
            }]
	    });
	    return this.form;
	}    
		
});