Changeset 1428
- Timestamp:
- 10/29/15 15:00:00 (9 years ago)
- Location:
- trunk/LATMOS-Accounts
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Stat.pm
r1427 r1428 100 100 } 101 101 102 return %stats;102 return \%stats; 103 103 } 104 104 … … 132 132 } 133 133 134 my %stats = $self->compute();134 my $stats = $self->compute(); 135 135 136 136 my $sthr = $self->db->prepare( … … 146 146 } 147 147 ); 148 foreach (keys % stats) {149 $sthv->execute($id, $_, $stats {$_});148 foreach (keys %$stats) { 149 $sthv->execute($id, $_, $stats->{$_}); 150 150 } 151 151 $self->_set_c_fields('lastStatId' => $id) or do { … … 157 157 } 158 158 159 =head2 getStat($id) 160 161 Return the statistics value for this stat entry. 162 163 If not given, C<$id> will be the last entry found 164 165 =cut 166 167 sub getStat { 168 my ($self, $id) = @_; 169 170 ($id) ||= $self->_attributes('lastStatId'); 171 172 if (!$id) { 173 $self->base->log(LA_ERR, "No Stat Id given for stat name %s", $self->id); 174 return; 175 } 176 177 my $sthentry = $self->db->prepare('SELECT * from statsentry where okey = ? and id = ?'); 178 $sthentry->execute($self->Iid, $id); 179 if (!(my $res = $sthentry->fetchrow_hashref)) { 180 $self->base->log(LA_ERR, "No stat entry %d found for stat %s", $id, $self->id); 181 return; 182 } 183 184 my $sthvalues = $self->db->prepare("SELECT * FROM statvalues where sid = ?"); 185 $sthvalues->execute($id); 186 187 my $stats = {}; 188 while (my $res = $sthvalues->fetchrow_hashref) { 189 $stats->{$res->{value}} = $res->{count}; 190 } 191 192 $stats 193 } 194 195 sub getAllStat { 196 my ($self) = @_; 197 198 my $sth = $self->db->prepare(q{ 199 SELECT count, value, to_char(tstamp, 'YYYY-MM-DD') as d from statsentry join 200 statvalues 201 on statsentry.id = statvalues.sid 202 where statsentry.okey = ? 203 order by statsentry.tstamp, value 204 }); 205 $sth->execute($self->Iid); 206 207 my $stats = {}; 208 while(my $res = $sth->fetchrow_hashref) { 209 $stats->{$res->{d}}{$res->{value}} = $res->{count}; 210 } 211 212 return $stats; 213 } 159 214 160 215 1;
Note: See TracChangeset
for help on using the changeset viewer.