Changeset 1462
- Timestamp:
- 11/04/15 09:30:22 (9 years ago)
- Location:
- trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Stat.pm
r1453 r1462 44 44 lastStatId => { }, 45 45 aggregateFunction => { 46 can_values => sub { qw(sum) }, 47 } 46 can_values => sub { qw(sum avg count) }, 47 }, 48 nullValue => { }, 48 49 } 49 50 ) … … 63 64 my $reffiltered = undef; 64 65 66 my $op = $self->_get_attributes('aggregateFunction'); 65 67 if (my $attr = $self->base->attribute($otype, $attribute)) { 66 68 if (my $obj = $attr->reference) { … … 72 74 } 73 75 } 74 if ($self->_get_attributes('refall') && $attr->has_values_list ) {76 if ($self->_get_attributes('refall') && $attr->has_values_list && !$op) { 75 77 foreach ($attr->can_values) { 76 78 if ($reffiltered && !$reffiltered->{$_}) { … … 93 95 my %results = $self->base->attributes_summary_by_object($otype, $attribute); 94 96 95 my $op = $self->_get_attributes('aggregateFunction'); 97 my $nullValue = $self->_get_attributes('nullValue'); 98 my %aggdata; 96 99 foreach my $id (keys %results) { 97 100 $filtered{ $id } or next; 98 101 foreach (@{ $results{ $id }}) { 99 if ($reffiltered && !$reffiltered->{$_}) { 102 next unless (defined($_) || $nullValue); 103 if ($_ && $reffiltered && !$reffiltered->{$_}) { 100 104 next; 101 105 } 106 $_ ||= '(none)'; 102 107 if ($op) { 103 if ($op eq 'sum') { 104 $stats{$id} ||= 0; 105 $stats{$id} += $_; 106 } 108 push(@{$aggdata{$id}}, $_); 107 109 } else { 108 110 $stats{ $_ } ||= 0; 109 111 $stats{ $_ }++; 112 } 113 } 114 } 115 if ($op) { 116 foreach my $key (keys %aggdata) { 117 if ($op eq 'sum') { 118 my $sum = 0; 119 $sum += $_ foreach (@{ $aggdata{$key} }); 120 $stats{ $key } = $sum; 121 } 122 elsif ($op eq 'count') { 123 $stats{ $key } = scalar(@{ $aggdata{$key} }); 124 } 125 elsif ($op eq 'average') { 126 my $sum = 0; 127 $sum += $_ foreach (@{ $aggdata{$key} }); 128 $stats{ $key } = $sum / scalar(@{ $aggdata{$key} }); 110 129 } 111 130 } -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm
r1457 r1462 634 634 ) 635 635 : sprintf( 636 q{select name, value from %s join %s on %s.ikey = %s.okey whereattr = ?} . ($base->{wexported} ? '' : ' and "exported" = true'),636 q{select name, value from %s left join %s on %s.ikey = %s.okey and attr = ?} . ($base->{wexported} ? '' : ' and "exported" = true'), 637 637 $base->db->quote_identifier($class->_object_table), 638 638 $base->db->quote_identifier($class->_object_table .
Note: See TracChangeset
for help on using the changeset viewer.