Now, maybe it is because I am tired, but in the last hour I had put myself in a loop-vortex trying to arrange an array in a different way (array_column(), array_map(), and a handful of foreach() and if() ) - and the result of this vortex were loops so confusing that I can not see the trees from the forest anymore, and frankly - I am ashamed to even post the spaghetti code that I have tried :-).
The array looks like this :
array (
0 =>
array (
0 => '29',
1 => '0m9-cart-main-app',
2 => '2108',
3 => '9',
),
1 =>
array (
0 => '16',
1 => '0m9-safe-box-server',
2 => '2017',
3 => '12',
),
2 =>
array (
0 => '2',
1 => '0m9art-main-app-nodejs',
2 => '2017',
3 => '2',
),
3 =>
array (
0 => '1',
1 => '0m9art-server-golang',
2 => '2017',
3 => '4',
),
4 =>
array (
0 => '17',
1 => '0m9panel',
2 => '2017',
3 => '7',
),
5 =>
array (
0 => '3',
1 => 'moli-server',
2 => '2017',
3 => '3',
),
6 =>
array (
0 => '2',
1 => 'igcc',
2 => '2017',
3 => '11',
),
7 =>
array (
0 => '26',
1 => '0m9-cart-main-app',
2 => '2108',
3 => '10',
),
8 =>
array (
0 => '18',
1 => '0m9-safe-box-python-app',
2 => '2108',
3 => '12',
),
9 =>
array (
0 => '1',
1 => '0m9art-evergreen-android-app',
2 => '2108',
3 => '5',
), ......
The array goes on ( about 700 lines ) where array[0] = count , array[1] = name,array[2] = year,array[3] = month
it's basically an aggregation of all commits in all git repositories of a single person and the goal is to have an approximation of per-project workload distribution each month ..
what I need is to know for each MONTH of YEAR what is the approximate percentage of NAME-COUNT ( repos-commits) from total MONTH-COUNT-OF-ALL-NAMES (monthly overall commits ).
so , I am sure there is an elegant one-liner to solve this horrible array, but I just can not seem to be able to do that anymore..
EDIT I
I am pretty sure that what I have done will only confuse everyone more, but since comments have asked - here are some of my tries in rearranging the array :
the array is originated from a csv , so
$csv = array_map('str_getcsv', file('git_stati.csv'));
give the original array posted above..
`
// try I
foreach($csv as $line){
$i=1;
// $r_date[] = $line[2] . $line[3] ;
$r_date = $line[2] .'-'. $line[3] ;
$r_dater[$r_date.'-'.$line[1] ] = $line[0] ;
$r_new[$line[1]]= $line[0] ;
$i++;
}
`// try II
foreach($csv as $line){
if ( $line[2] == '2018' ){
$name[] = $line[1] ;
$count[$line[1] ] += $line[0];
}
if ( $line[2] == '2017' ){
$name[] = $line[1] ;
$count[$line[1] ] += $line[0];
}
}
// try III
// foreach($r_dater as $key => $val) {
// if(substr($key, 0, 6) == '2018-9'){
// $str2 = substr($key, 7);
// $special_items[$key] = $val;
// $repo_r[$str2]= $val;
// }
// }
// other failed confusing trials ...
highlight_string("<?php\n\$data =\n". var_export($r_dater, true) . ";\n?>");
EDIT II
it's basically an aggregation of all commits in all git repositories of a single person and the goal is to have an approximation of per-project workload distribution each month ..
what I need is to know for each MONTH of YEAR what is the approximate percentage of NAME-COUNT ( repos-commits) from total MONTH-COUNT-OF-ALL-NAMES (monthly overall commits ).
For the example array, the desired output is something like :
'2018-09 =>
array (
'repo_name' => '0m9-cart-main-app',
'commits' => 29,
'% of total commits for 2018-09 => 'x.xx%',
),
MONTH-COUNT-OF-ALL-NAMESbe computed per year?