Skip to content
Extraits de code Groupes Projets
Valider 64acd79f rédigé par mattpiwik's avatar mattpiwik
Parcourir les fichiers

- a few renaming, datatable updates, test files update

git-svn-id: http://dev.piwik.org/svn/trunk@833 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent e8d43ab8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -734,6 +734,7 @@ class Piwik_DataTable
* serialized DataTable contained in this DataTable.
* We save DataTable in serialized format in the Database.
* Each row of this returned PHP array will be a row in the DB table.
* At the end of the method execution, the dataTable may be truncated (if $maximum* parameters are set).
*
* The keys of the array are very important as they are used to define the DataTable
*
......@@ -771,7 +772,6 @@ class Piwik_DataTable
{
throw new Exception("Maximum recursion level of ".self::MAXIMUM_DEPTH_LEVEL_ALLOWED. " reached. You have probably set a DataTable_Row with an associated DataTable which belongs already to its parent hierarchy.");
}
if( !is_null($maximumRowsInDataTable) )
{
$filter = new Piwik_DataTable_Filter_AddSummaryRow($this, $maximumRowsInDataTable - 1);
......@@ -779,7 +779,7 @@ class Piwik_DataTable
// For each row, get the serialized row
// If it is associated to a sub table, get the serialized table recursively ;
// but returns all serialized tables and subtable in an array of 1 dimension!
// but returns all serialized tables and subtable in an array of 1 dimension
$aSerializedDataTable = array();
foreach($this->rows as $row)
{
......@@ -814,7 +814,7 @@ class Piwik_DataTable
*
* The function creates all the necessary DataTable_Row
*
* @param string Serialized string of a datatable
* @param string string of serialized datatable
* @return void
*/
public function addRowsFromSerializedArray( $stringSerialized )
......@@ -1000,14 +1000,17 @@ class Piwik_DataTable
$cleanRow = array();
foreach($array as $label => $row)
{
// TODO I think this requirement is not true anymore:
// we make sure that the label column is first in the list!
// important for the UI javascript mainly...
// important for the UI javascript mainly...
// array_merge doesn't work here as it reindex the numeric value
// see the test testMergeArray in PHP_Related.test.php
$cleanRow[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = null;
$cleanRow[Piwik_DataTable_Row::COLUMNS] = array('label' => $label) + $row;
if(!is_null($subtablePerLabel)
// some rows of this table don't have subtables
// (for examplecase of the campaign without keywords )
// (for example case of campaigns without keywords)
&& isset($subtablePerLabel[$label])
)
{
......
......@@ -43,7 +43,7 @@ class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter
protected function filter()
{
$filter = new Piwik_DataTable_Filter_Sort($this->table, $this->columnToSortByBeforeTruncating, 'desc');
$rows = $this->table->getRows();
$count = $this->table->getRowsCount();
$newRow = new Piwik_DataTable_Row();
......@@ -61,6 +61,7 @@ class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter
}
}
$newRow->addColumn('label', $this->labelSummaryRow);
$filter = new Piwik_DataTable_Filter_Limit($this->table, 0, $this->startRowToSummarize);
$this->table->addSummaryRow($newRow);
}
......
......@@ -35,7 +35,6 @@ class Piwik_DataTable_Filter_Limit extends Piwik_DataTable_Filter
$limit = -1;
}
$this->limit = $limit;
$this->filter();
}
......@@ -45,8 +44,10 @@ class Piwik_DataTable_Filter_Limit extends Piwik_DataTable_Filter
$rowsCount = $table->getRowsCount();
// we delete from 0 to offset
$table->deleteRowsOffset( 0, $this->offset );
if($this->offset > 0)
{
$table->deleteRowsOffset( 0, $this->offset );
}
// at this point the array has offset less elements. We delete from limit to the end
if( $this->limit >= 0 )
{
......
......@@ -75,6 +75,7 @@ class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer
break;
}
if(is_string($value)) $value = "'$value'";
elseif(is_array($value)) $value = var_export($value, true);
$columns[] = "'$column' => $value";
}
......@@ -87,10 +88,8 @@ class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer
$metadata = array();
foreach($row->getMetadata() as $name => $value)
{
if(is_string($value))
{
$value = "'$value'";
}
if(is_string($value)) $value = "'$value'";
elseif(is_array($value)) $value = var_export($value, true);
$metadata[] = "'$name' => $value";
}
$metadata = implode(", ", $metadata);
......
......@@ -107,16 +107,15 @@ class Piwik_DataTable_Row
foreach($this->getColumns() as $column => $value)
{
if(is_string($value)) $value = "'$value'";
elseif(is_array($value)) $value = var_export($value, true);
$columns[] = "'$column' => $value";
}
$columns = implode(", ", $columns);
$metadata = array();
foreach($this->getMetadata() as $name => $value)
{
if(is_string($value))
{
$value = "'$value'";
}
if(is_string($value)) $value = "'$value'";
elseif(is_array($value)) $value = var_export($value, true);
$metadata[] = "'$name' => $value";
}
$metadata = implode(", ", $metadata);
......@@ -332,20 +331,39 @@ class Piwik_DataTable_Row
{
foreach($rowToSum->getColumns() as $name => $value)
{
if($name != 'label'
&& Piwik::isNumeric($value))
if($name != 'label')
{
$current = $this->getColumn($name);
if($current === false)
if(Piwik::isNumeric($value))
{
$current = 0;
$current = $this->getColumn($name);
if($current === false)
{
$current = 0;
}
$this->setColumn( $name, $current + $value);
}
elseif(is_array($value))
{
$current = $this->getColumn($name);
$newValue = array();
if($current == false)
{
$newValue = $value;
}
else
{
$newValue = $current;
foreach($value as $arrayIndex => $arrayValue)
{
$newValue[$arrayIndex] += $arrayValue;
}
}
$this->setColumn($name, $newValue);
}
$this->setColumn( $name, $current + $value);
}
}
}
/**
* Helper function to test if two rows are equal.
*
......@@ -366,7 +384,6 @@ class Piwik_DataTable_Row
uksort($cols1, 'strnatcasecmp');
uksort($cols2, 'strnatcasecmp');
if($cols1 != $cols2)
{
return false;
......
Following up show all columns new UI element
====
- passe en année, actions puis pages => c'est vide !!!
- pages columns: first should be unique page views, sorted by unique pageviews
- exclude all population doesn't work for actions
- post 29 There seems not to be a way to export the pages information widget. I wanted to download the entry pages to see where my visitors entered my site from, but there is no option to do so.
......
......@@ -72,7 +72,6 @@ require_once 'Zend/Db/Table.php';
require_once 'FrontController.php';
require_once 'Config.php';
require_once 'Timer.php';
require_once 'API/APIable.php';
require_once 'Access.php';
require_once 'Log.php';
require_once 'core/Piwik.php';
......
......@@ -255,7 +255,8 @@ class Test_Piwik_DataTable extends UnitTestCase
'test_float3'=> 1.5,
'test_stringint'=> "145",
"test" => 'string fake',
'super'=>array('this column has an array value, amazing')
'super'=>array('this column has an array string that will be 0 when algorithm sums the value'),
'integerArrayToSum'=>array( 1=>1, 2=>10.0),
);
$metadata = array('logo'=> 'piwik.png',
'super'=>array('this column has an array value, amazing'));
......@@ -271,23 +272,22 @@ class Test_Piwik_DataTable extends UnitTestCase
'test_float2'=> 14.5,
'test_stringint'=> "5",
0925824 => 'toto',
'super'=>array('this column has geagaean array value, amazing'));
'super'=>array('this column has geagaean array value, amazing'),
'integerArrayToSum'=>array( 1=> 5, 2=>5.5),
);
$finalRow = new Piwik_DataTable_Row( array(Piwik_DataTable_Row::COLUMNS => $columns2));
$finalRow->sumRow($row1);
$columnsWanted = array('test_int'=> 150,
'test_float'=> 150.0,
'test_float2'=> 14.5,
'test_float3'=> 1.5,
'test_stringint'=> "150", //add also strings!!
'super'=>array('this column has geagaean array value, amazing'),
'test_stringint'=> 150, //add also strings!!
'super'=>array(0),
'integerArrayToSum' => array( 1=> 6, 2=>15.5),
0925824 => 'toto',
);
$rowWanted = new Piwik_DataTable_Row( array(Piwik_DataTable_Row::COLUMNS => $columnsWanted));
$this->assertTrue( Piwik_DataTable_Row::isEqual($rowWanted, $finalRow));
}
......
......@@ -24,6 +24,51 @@ class Test_PHP_Related extends UnitTestCase
{
}
// conclusion:
// - it's ok to have big holes in your array index values
// - obvious: it's not ok to index array by strings when you can do magic and index with int
function oldtest_memoryUsageArrayIncreasingIndexOrJumps()
{
ini_set('memory_limit','200M');
Piwik::createConfigObject();
Piwik::createLogObject();
//test array[0] array[1] array[2]
//VS
// test array[0] array[100] array[200]
// same memory usage? hash
echo "start ". __FUNCTION__ . "<br>";
Piwik::printMemoryUsage();
$timer = new Piwik_Timer();
$testId = 2;
if($testId == 1)
{
echo "start incrementing index<br>";
$array = array();
for($i = 0; $i<1000000;$i++) {
$array[$i] = 1;
}
}
elseif($testId == 2)
{
echo "start indexing by strings<br>";
$array = array();
for($i = 0; $i<1000000;$i++) {
$array[$i."_".$i] = 1;
}
}
elseif($testId == 3)
{
echo "start jumping index<br>";
for($i = 0; $i<1000000;$i++) {
$array[$i*100] = 1;
}
}
echo $timer . "<br>";
echo "size serialized:". Piwik::getPrettySizeFromBytes(strlen(serialize($array))). "<br>";
Piwik::printMemoryUsage();
echo "end ". __FUNCTION__ . "<br>";
}
function test_versionTrailingZero()
{
$this->assertTrue(version_compare('0.1','0.01') == 0);
......@@ -75,9 +120,7 @@ class Test_PHP_Related extends UnitTestCase
public function test_staticAttr()
{
// use this trick to read the static attribute of the class
// $class::$methodsNotToPublish doesn't work
$vars = get_class_vars("test_staticAttr");
$this->assertEqual( $vars['a'], 'testa' );
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter