1<?php
2/**
3 * ThunderSnarf
4 *
5 * @author Ricardo H.F. Sette P. <ricardohfsp@gmail.com>
6 * @link http://www.freebsdbrasil.com.br/
7 * @copyright Copyright &copy; 2010 - FreeBSD Brasil LTDA
8 * @license licença GNU/GPL v2.0 http://www.gnu.org/licenses/gpl-2.0.html
9 */
10?>
11<?php
12$this->breadcrumbs=array(
13	'Resumo'=>array('index'),
14	'Informações',
15);
16function formatBytes($bytes, $precision = 2) {
17    $units = array('B', 'KB', 'MB', 'GB', 'TB');
18
19    $bytes = max($bytes, 0);
20    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
21    $pow = min($pow, count($units) - 1);
22
23    $bytes /= pow(1024, $pow);
24
25    return round($bytes, $precision) . '' . $units[$pow];
26}
27
28Yii::app()->clientScript->registerScript('search', "
29$('.search-button').click(function(){
30	$('.search-form').toggle();
31	return false;
32});
33$('.search-form form').submit(function(){
34	$.fn.yiiGridView.update('resumo-grid', {
35		data: $(this).serialize()
36	});
37	return false;
38});
39");
40?>
41
42<h1>Resumo por Data</h1><?php echo CHtml::link('Filtro','#',array('class'=>'search-button')); ?>
43<?php echo CHtml::dropDownList(
44				'pageSize',
45				Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),
46				array(5=>'5 por página',20=>'20 por página',50=>'50 por página',100=>'100 por página'),
47	            array('class'=>'change-pagesize','style'=>'margin-left:10px')
48			);
49?>
50<?php echo CHtml::dropDownList(
51				'tipoTrafego',
52				isset($_GET['tipoTrafego'])?$_GET['tipoTrafego']:'',
53				array('E'=>'Somente Estático','D'=>'Somente Dinâmico'),
54				array('empty'=>'Estáticos e Dinâmicos','class'=>'change-tipoTrafego')
55			);
56?>
57<?php echo CHtml::dropDownList(
58				'periodo',
59				isset($_GET['periodo'])?$_GET['periodo']:'',
60				array('S'=>'Semanal','M'=>'Mensal'),
61				array('empty'=>'Diário','class'=>'change-periodo')
62			);
63?>
64
65<div class="search-form" style="display:none">
66<?php $this->renderPartial('_search',array(
67	'model'=>$model,
68)); ?>
69</div><!-- search-form -->
70
71<?php
72if(isset($_GET['eficienciaDynamic']) AND $_GET['eficienciaDynamic']=='2')
73	$valorEficienciaDynamic = '$data->hit_dynamic>0 ? \'<b>\'.number_format(((100*$data->hit_dynamic)/($data->hit_dynamic + $data->miss_dynamic)),2,",","").\'%</b>\' : \'<b>0%</b>\'';
74else
75	$valorEficienciaDynamic = '$data->cache_dynamic>0 ? \'<b>\'.number_format(((100*$data->cache_dynamic)/($data->cache_dynamic + $data->traffic_dynamic)),2,",","").\'%</b>\' : \'<b>0%</b>\'';
76
77if(isset($_GET['eficienciaStatic']) AND $_GET['eficienciaStatic']=='2')
78	$valorEficienciaStatic = '$data->hit_static>0 ? \'<b>\'.number_format(((100*$data->hit_static)/($data->hit_static + $data->miss_static)),2,",","").\'%</b>\' : \'<b>0%</b>\'';
79else
80	$valorEficienciaStatic = '$data->cache_static>0 ? \'<b>\'.number_format(((100*$data->cache_static)/($data->cache_static + $data->traffic_static)),2,",","").\'%</b>\' : \'<b>0%</b>\'';
81
82
83if(isset($_GET['periodo']) AND $_GET['periodo']=="S"){//semanal
84	$array_data_id = array(
85		'name'=>'id_data_week',
86		'value'=>'$data->id_data_week',
87	);
88}else if(isset($_GET['periodo']) AND $_GET['periodo']=="M"){//mensal
89	$array_data_id = array(
90		'name'=>'id_data_month',
91		'value'=>'$data->id_data_month',
92	);
93}else{
94	$array_data_id = array(
95		'name'=>'id_data',
96		'value'=>'CHtml::link(CHtml::encode(substr($data->id_data,6,2)."/".substr($data->id_data,4,2)."/".substr($data->id_data,0,4)), array("view", "id_data"=>$data->id_data))',
97		'type'=>'html'
98	);
99}
100
101$colunasCGridView = array(
102	$array_data_id,
103	array(
104        'name'=>'cache_static',
105        'value'=>'formatBytes($data->cache_static)',
106    ),
107	array(
108        'name'=>'traffic_static',
109        'value'=>'formatBytes($data->traffic_static)',
110    ),
111	array(
112        'name'=>'Total',
113        'value'=>'formatBytes($data->cache_static + $data->traffic_static)',
114    ),
115	'hit_static',
116	'miss_static',
117	array(
118        'name'=>'Total',
119        'value'=>'$data->hit_static + $data->miss_static',
120    ),
121	array(
122        'header'=>CHtml::label('Eficiência E',false,array("title"=>"Eficiencia Estática")).CHtml::dropDownList(
123						"eficienciaStatic",
124						isset($_GET['eficienciaStatic']) ? $_GET['eficienciaStatic'] : '1',
125						array("1"=>"Cache","2"=>"Hit"),
126			            array("class"=>"change-eficienciaStatic")
127					),
128        'value'=>$valorEficienciaStatic,
129		'type'=>'html'
130    ),
131	array(
132        'name'=>'cache_dynamic',
133        'value'=>'formatBytes($data->cache_dynamic)',
134    ),
135	array(
136        'name'=>'traffic_dynamic',
137        'value'=>'formatBytes($data->traffic_dynamic)',
138    ),
139	array(
140        'name'=>'Total',
141        'value'=>'formatBytes($data->cache_dynamic + $data->traffic_dynamic)',
142    ),
143	'hit_dynamic',
144	'miss_dynamic',
145	array(
146        'name'=>'Total',
147        'value'=>'$data->hit_dynamic + $data->miss_dynamic',
148    ),
149	array(
150        'header'=>CHtml::label('Eficiência D',false,array("title"=>"Eficiencia Dinâmica")).CHtml::dropDownList(
151						"eficienciaDynamic",
152						isset($_GET['eficienciaDynamic']) ? $_GET['eficienciaDynamic'] : '1',
153						array("1"=>"Cache","2"=>"Hit"),
154			            array("class"=>"change-eficienciaDynamic")
155					),
156        'value'=>$valorEficienciaDynamic,
157		'type'=>'html'
158    ),
159	array(
160    	'header'=>CHtml::label("Nro Reqs",false,array("title"=>"Número de Requisições")),
161    	'name'=>'requested',
162    	'value'=>'$data->requested',
163    ),
164);
165if(isset($_GET["tipoTrafego"]) and $_GET["tipoTrafego"]=="E"){
166	unset($colunasCGridView[8]);
167	unset($colunasCGridView[9]);
168	unset($colunasCGridView[10]);
169	unset($colunasCGridView[11]);
170	unset($colunasCGridView[12]);
171	unset($colunasCGridView[13]);
172	unset($colunasCGridView[14]);
173}else if(isset($_GET["tipoTrafego"]) and $_GET["tipoTrafego"]=="D"){
174	unset($colunasCGridView[1]);
175	unset($colunasCGridView[2]);
176	unset($colunasCGridView[3]);
177	unset($colunasCGridView[4]);
178	unset($colunasCGridView[5]);
179	unset($colunasCGridView[6]);
180	unset($colunasCGridView[7]);
181}else{
182	unset($colunasCGridView[3]);
183	unset($colunasCGridView[6]);
184	unset($colunasCGridView[10]);
185	unset($colunasCGridView[13]);
186}
187$this->widget('zii.widgets.grid.CGridView', array(
188	'id'=>'resumo-grid',
189	'dataProvider'=>$model->search(),
190	//'filter'=>$model,
191	'summaryText'=>'Exibindo {start} até {end} de {count} resultado(s).',
192	'columns'=>$colunasCGridView,
193)); ?>
194<?php Yii::app()->clientScript->registerScript('initPageSize',<<<EOD
195    $('.change-pagesize').bind('change', function() {
196        $.fn.yiiGridView.update('resumo-grid',{ data:{ pageSize: $(this).val() }});
197    });
198EOD
199,CClientScript::POS_READY); ?>
200<?php Yii::app()->clientScript->registerScript('tipoTrafego',<<<EOD
201    $('.change-tipoTrafego').bind('change', function() {
202        $.fn.yiiGridView.update('resumo-grid',{ data:{ tipoTrafego: $(this).val() }});
203    });
204EOD
205,CClientScript::POS_READY); ?>
206<?php Yii::app()->clientScript->registerScript('periodo',<<<EOD
207    $('.change-periodo').bind('change', function() {
208        $.fn.yiiGridView.update('resumo-grid',{ data:{ periodo: $(this).val() }});
209    });
210EOD
211,CClientScript::POS_READY); ?>
212<?php Yii::app()->clientScript->registerScript('eficienciaDynamic',<<<EOD
213    $('.change-eficienciaDynamic').live('change', function() {
214        $.fn.yiiGridView.update('resumo-grid',{ data:{ eficienciaDynamic: $(this).val() }});
215    });
216EOD
217,CClientScript::POS_READY); ?>
218<?php Yii::app()->clientScript->registerScript('eficienciaStatic',<<<EOD
219    $('.change-eficienciaStatic').live('change', function() {
220        $.fn.yiiGridView.update('resumo-grid',{ data:{ eficienciaStatic: $(this).val() }});
221    });
222EOD
223,CClientScript::POS_READY); ?>