google code style

pull/2077/head
Isaac Connor 2017-10-16 15:16:33 -04:00
parent 7ceeef55fc
commit 9e1893311d
1 changed files with 31 additions and 69 deletions

View File

@ -1,37 +1,30 @@
<?php <?php
function getDateScale( $scales, $range, $minLines, $maxLines ) function getDateScale( $scales, $range, $minLines, $maxLines ) {
{ foreach ( $scales as $scale ) {
foreach ( $scales as $scale )
{
$align = isset($scale['align'])?$scale['align']:1; $align = isset($scale['align'])?$scale['align']:1;
$scaleRange = (int)($range/($scale['factor']*$align)); $scaleRange = (int)($range/($scale['factor']*$align));
//echo "S:".$scale['name'].", A:$align, SR:$scaleRange<br>"; //echo "S:".$scale['name'].", A:$align, SR:$scaleRange<br>";
if ( $scaleRange >= $minLines ) if ( $scaleRange >= $minLines ) {
{
$scale['range'] = $scaleRange; $scale['range'] = $scaleRange;
break; break;
} }
} }
if ( !isset($scale['range']) ) if ( !isset($scale['range']) ) {
{
$scale['range'] = (int)($range/($scale['factor']*$align)); $scale['range'] = (int)($range/($scale['factor']*$align));
} }
$scale['divisor'] = 1; $scale['divisor'] = 1;
while ( ($scale['range']/$scale['divisor']) > $maxLines ) while ( ($scale['range']/$scale['divisor']) > $maxLines ) {
{
$scale['divisor']++; $scale['divisor']++;
} }
$scale['lines'] = (int)($scale['range']/$scale['divisor']); $scale['lines'] = (int)($scale['range']/$scale['divisor']);
return( $scale ); return( $scale );
} }
function getYScale( $range, $minLines, $maxLines ) function getYScale( $range, $minLines, $maxLines ) {
{
$scale['range'] = $range; $scale['range'] = $range;
$scale['divisor'] = 1; $scale['divisor'] = 1;
while ( $scale['range']/$scale['divisor'] > $maxLines ) while ( $scale['range']/$scale['divisor'] > $maxLines ) {
{
$scale['divisor']++; $scale['divisor']++;
} }
$scale['lines'] = (int)(($scale['range']-1)/$scale['divisor'])+1; $scale['lines'] = (int)(($scale['range']-1)/$scale['divisor'])+1;
@ -39,11 +32,9 @@ function getYScale( $range, $minLines, $maxLines )
return( $scale ); return( $scale );
} }
function getSlotFrame( $slot ) function getSlotFrame( $slot ) {
{
$slotFrame = isset($slot['frame'])?$slot['frame']['FrameId']:1; $slotFrame = isset($slot['frame'])?$slot['frame']['FrameId']:1;
if ( false && $slotFrame ) if ( false && $slotFrame ) {
{
$slotFrame -= $monitor['PreEventCount']; $slotFrame -= $monitor['PreEventCount'];
if ( $slotFrame < 1 ) if ( $slotFrame < 1 )
$slotFrame = 1; $slotFrame = 1;
@ -51,10 +42,8 @@ function getSlotFrame( $slot )
return( $slotFrame ); return( $slotFrame );
} }
function parseFilterToTree( $filter ) function parseFilterToTree( $filter ) {
{ if ( count($filter['terms']) > 0 ) {
if ( count($filter['terms']) > 0 )
{
$postfixExpr = array(); $postfixExpr = array();
$postfixStack = array(); $postfixStack = array();
@ -73,29 +62,19 @@ function parseFilterToTree( $filter )
'or' => 4, 'or' => 4,
); );
for ( $i = 0; $i <= count($filter['terms']); $i++ ) for ( $i = 0; $i <= count($filter['terms']); $i++ ) {
{ if ( !empty($filter['terms'][$i]['cnj']) ) {
if ( !empty($filter['terms'][$i]['cnj']) ) while( true ) {
{ if ( !count($postfixStack) ) {
while( true )
{
if ( !count($postfixStack) )
{
$postfixStack[] = array( 'type'=>"cnj", 'value'=>$filter['terms'][$i]['cnj'], 'sqlValue'=>$filter['terms'][$i]['cnj']); $postfixStack[] = array( 'type'=>"cnj", 'value'=>$filter['terms'][$i]['cnj'], 'sqlValue'=>$filter['terms'][$i]['cnj']);
break; break;
} } elseif ( $postfixStack[count($postfixStack)-1]['type'] == 'obr' ) {
elseif ( $postfixStack[count($postfixStack)-1]['type'] == 'obr' )
{
$postfixStack[] = array( 'type'=>"cnj", 'value'=>$filter['terms'][$i]['cnj'], 'sqlValue'=>$filter['terms'][$i]['cnj']); $postfixStack[] = array( 'type'=>"cnj", 'value'=>$filter['terms'][$i]['cnj'], 'sqlValue'=>$filter['terms'][$i]['cnj']);
break; break;
} } elseif ( $priorities[$filter['terms'][$i]['cnj']] < $priorities[$postfixStack[count($postfixStack)-1]['value']] ) {
elseif ( $priorities[$filter['terms'][$i]['cnj']] < $priorities[$postfixStack[count($postfixStack)-1]['value']] )
{
$postfixStack[] = array( 'type'=>"cnj", 'value'=>$filter['terms'][$i]['cnj'], 'sqlValue'=>$filter['terms'][$i]['cnj']); $postfixStack[] = array( 'type'=>"cnj", 'value'=>$filter['terms'][$i]['cnj'], 'sqlValue'=>$filter['terms'][$i]['cnj']);
break; break;
} } else {
else
{
$postfixExpr[] = array_pop( $postfixStack ); $postfixExpr[] = array_pop( $postfixStack );
} }
} }
@ -157,23 +136,17 @@ function parseFilterToTree( $filter )
$sqlValue = $filter['terms'][$i]['attr']; $sqlValue = $filter['terms'][$i]['attr'];
break; break;
} }
if ( $dtAttr ) if ( $dtAttr ) {
{
$postfixExpr[] = array( 'type'=>"attr", 'value'=>$filter['terms'][$i]['attr'], 'sqlValue'=>$sqlValue, 'dtAttr'=>true ); $postfixExpr[] = array( 'type'=>"attr", 'value'=>$filter['terms'][$i]['attr'], 'sqlValue'=>$sqlValue, 'dtAttr'=>true );
} } else {
else
{
$postfixExpr[] = array( 'type'=>"attr", 'value'=>$filter['terms'][$i]['attr'], 'sqlValue'=>$sqlValue ); $postfixExpr[] = array( 'type'=>"attr", 'value'=>$filter['terms'][$i]['attr'], 'sqlValue'=>$sqlValue );
} }
} }
if ( isset($filter['terms'][$i]['op']) ) if ( isset($filter['terms'][$i]['op']) ) {
{ if ( empty($filter['terms'][$i]['op']) ) {
if ( empty($filter['terms'][$i]['op']) )
{
$filter['terms'][$i]['op' ]= '='; $filter['terms'][$i]['op' ]= '=';
} }
switch ( $filter['terms'][$i]['op' ]) switch ( $filter['terms'][$i]['op' ]) {
{
case '=' : case '=' :
case '!=' : case '!=' :
case '>=' : case '>=' :
@ -195,36 +168,25 @@ function parseFilterToTree( $filter )
$sqlValue = 'not in ('; $sqlValue = 'not in (';
break; break;
} }
while( true ) while( true ) {
{ if ( !count($postfixStack) ) {
if ( !count($postfixStack) )
{
$postfixStack[] = array( 'type'=>"op", 'value'=>$filter['terms'][$i]['op'], 'sqlValue'=>$sqlValue ); $postfixStack[] = array( 'type'=>"op", 'value'=>$filter['terms'][$i]['op'], 'sqlValue'=>$sqlValue );
break; break;
} } elseif ( $postfixStack[count($postfixStack)-1]['type'] == 'obr' ) {
elseif ( $postfixStack[count($postfixStack)-1]['type'] == 'obr' )
{
$postfixStack[] = array( 'type'=>"op", 'value'=>$filter['terms'][$i]['op'], 'sqlValue'=>$sqlValue ); $postfixStack[] = array( 'type'=>"op", 'value'=>$filter['terms'][$i]['op'], 'sqlValue'=>$sqlValue );
break; break;
} } elseif ( $priorities[$filter['terms'][$i]['op']] < $priorities[$postfixStack[count($postfixStack)-1]['value']] ) {
elseif ( $priorities[$filter['terms'][$i]['op']] < $priorities[$postfixStack[count($postfixStack)-1]['value']] )
{
$postfixStack[] = array( 'type'=>"op", 'value'=>$filter['terms'][$i]['op'], 'sqlValue'=>$sqlValue ); $postfixStack[] = array( 'type'=>"op", 'value'=>$filter['terms'][$i]['op'], 'sqlValue'=>$sqlValue );
break; break;
} } else {
else
{
$postfixExpr[] = array_pop( $postfixStack ); $postfixExpr[] = array_pop( $postfixStack );
} }
} }
} }
if ( isset($filter['terms'][$i]['val']) ) if ( isset($filter['terms'][$i]['val']) ) {
{
$valueList = array(); $valueList = array();
foreach ( preg_split( '/["\'\s]*?,["\'\s]*?/', preg_replace( '/^["\']+?(.+)["\']+?$/', '$1', $filter['terms'][$i]['val' ]) ) as $value ) foreach ( preg_split( '/["\'\s]*?,["\'\s]*?/', preg_replace( '/^["\']+?(.+)["\']+?$/', '$1', $filter['terms'][$i]['val' ]) ) as $value ) {
{ switch ( $filter['terms'][$i]['attr']) {
switch ( $filter['terms'][$i]['attr'])
{
case 'MonitorName': case 'MonitorName':
case 'Name': case 'Name':
case 'Cause': case 'Cause':