129 | | return entries |
| 128 | headers = entries[0] |
| 129 | nbheaders = len(headers) |
| 130 | fieldnumber = {} |
| 131 | for i in range(nbheaders) : |
| 132 | fieldnumber[headers[i]] = i |
| 133 | if datatype == "payments" : |
| 134 | newentries = [ headers ] |
| 135 | fnusername = fieldnumber["username"] |
| 136 | fnamount = fieldnumber["amount"] |
| 137 | fndate = fieldnumber["date"] |
| 138 | sortedentries = entries[1:] |
| 139 | sortedentries.sort(lambda x, y, fnum=fnusername : cmp(x[fnum], y[fnum])) |
| 140 | amount = 0.0 |
| 141 | prevusername = sortedentries[0][fnusername] |
| 142 | for entry in sortedentries : |
| 143 | if entry[fnusername] != prevusername : |
| 144 | summary = [None] * nbheaders |
| 145 | summary[fnusername] = prevusername |
| 146 | summary[fnamount] = amount |
| 147 | summary[fndate] = "*" |
| 148 | newentries.append(summary) |
| 149 | amount = entry[fnamount] |
| 150 | else : |
| 151 | amount += entry[fnamount] |
| 152 | prevusername = entry[fnusername] |
| 153 | summary = [None] * nbheaders |
| 154 | summary[fnusername] = prevusername |
| 155 | summary[fnamount] = amount |
| 156 | summary[fndate] = "*" |
| 157 | newentries.append(summary) |
| 158 | elif datatype == "history" : |
| 159 | newentries = entries # Fake this for now |
| 160 | else : |
| 161 | raise PyKotaToolError, _("Summarizing is not implemented for the [%s] data type, sorry.") % datatype |
| 162 | return newentries |