Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
views_aggregator
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
views_aggregator
Commits
2539ac53
Commit
2539ac53
authored
9 years ago
by
Rik de Boer
Browse files
Options
Downloads
Patches
Plain Diff
Add Percentage aggregation function to views_aggregator_more_functions
parent
97e9a840
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
views_aggregator_functions.inc
+2
-2
2 additions, 2 deletions
views_aggregator_functions.inc
views_aggregator_more_functions/views_aggregator_more_functions.module
+38
-0
38 additions, 0 deletions
...tor_more_functions/views_aggregator_more_functions.module
with
40 additions
and
2 deletions
views_aggregator_functions.inc
+
2
−
2
View file @
2539ac53
...
...
@@ -187,7 +187,7 @@ function views_aggregator_group_and_compress($view_results, $field_handler, $cas
* @param array $groups
* an array of groups of rows, each group indexed by group value
* @param object $field_handler
* the handler for the view column to find the
minimum
in
* the handler for the view column to find the
average
in
* @param int $precision_group
* the number of decimals, if specified
* @param int $precision_column
...
...
@@ -389,7 +389,7 @@ function views_aggregator_expression($groups, $field_handler, $group_exp = NULL,
$value
=
$math
->
evaluate
(
$expression
);
}
}
// Should we call number_format($value, $precision, $decimal, $separator)
// Should we call
:
number_format($value, $precision, $decimal, $separator)
?
$values
[
'column'
]
=
$value
;
return
$values
;
}
...
...
This diff is collapsed.
Click to expand it.
views_aggregator_more_functions/views_aggregator_more_functions.module
+
38
−
0
View file @
2539ac53
...
...
@@ -16,6 +16,11 @@ function views_aggregator_more_functions_views_aggregation_functions_info() {
'column'
=>
NULL
,
'is_renderable'
=>
TRUE
,
),
'views_aggregator_percentage'
=>
array
(
'group'
=>
t
(
'Percentage'
),
'column'
=>
t
(
'100%'
),
'is_renderable'
=>
TRUE
),
);
return
$functions
;
}
...
...
@@ -35,4 +40,37 @@ function views_aggregator_group_seq_number($groups, $field_handler = NULL, $star
$values
[
$group
]
=
$count
++
;
}
return
$values
;
}
/**
* Aggregates a field group total as the percentage of the column total.
*
* @param array $groups
* an array of groups of rows, each group indexed by group value
* @param object $field_handler
* the handler for the view column to calculate percentages in
*
* @return array
* an array of values, one for each group and one for the column (always 100%)
*/
function
views_aggregator_percentage
(
$groups
,
$field_handler
,
$arg_group
,
$arg_column
)
{
$values
=
array
();
$sum_column
=
0.0
;
foreach
(
$groups
as
$group
=>
$rows
)
{
$sum
=
0.0
;
foreach
(
$rows
as
$num
=>
$row
)
{
// Do not count empty or non-numeric cells.
$cell
=
vap_num
(
views_aggregator_get_cell
(
$field_handler
,
$num
,
FALSE
));
if
(
$cell
!==
FALSE
)
{
$sum
+=
$cell
;
}
}
$values
[
$group
]
=
$sum
;
$sum_column
+=
$sum
;
}
foreach
(
$groups
as
$group
=>
$rows
)
{
$values
[
$group
]
=
100
*
$values
[
$group
]
/
$sum_column
;
}
$values
[
'column'
]
=
100
;
return
$values
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment