Changeset 2293
- Timestamp:
- 06/08/05 21:58:00 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/dumper.py
r2289 r2293 125 125 return entries 126 126 else : 127 sys.stderr.write("WARNING : --sum command line option is not implemented yet !\n")128 127 headers = entries[0] 129 128 nbheaders = len(headers) 130 129 fieldnumber = {} 130 fieldname = {} 131 131 for i in range(nbheaders) : 132 fieldnumber[headers[i]] = i 132 name = headers[i] 133 fieldnumber[name] = i 134 fieldname[i] = name 135 133 136 if datatype == "payments" : 137 totalize = [ ("amount", float) ] 138 ignored = [ "date" ] 139 key = "username" 140 141 fnkey = fieldnumber[key] 134 142 newentries = [ headers ] 135 fnusername = fieldnumber["username"]136 fnamount = fieldnumber["amount"]137 fndate = fieldnumber["date"]138 143 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] 144 sortedentries.sort(lambda x, y, fnum=fnkey : cmp(x[fnum], y[fnum])) 145 totals = {} 146 for (k, t) in totalize : 147 totals[k] = { "convert" : t, "value" : 0.0 } 148 prevkey = sortedentries[0][fnkey] 142 149 for entry in sortedentries : 143 if entry[fn username] != prevusername:150 if entry[fnkey] != prevkey : 144 151 summary = [None] * nbheaders 145 summary[fnusername] = prevusername 146 summary[fnamount] = amount 147 summary[fndate] = "*" 152 summary[fnkey] = prevkey 153 for ignore in ignored : 154 summary[fieldnumber[ignore]] = '*' 155 for k in totals.keys() : 156 summary[fieldnumber[k]] = totals[k]["convert"](totals[k]["value"]) 148 157 newentries.append(summary) 149 amount = entry[fnamount] 158 for k in totals.keys() : 159 totals[k]["value"] = totals[k]["convert"](entry[fieldnumber[k]]) 150 160 else : 151 amount += entry[fnamount] 152 prevusername = entry[fnusername] 161 for k in totals.keys() : 162 totals[k]["value"] += totals[k]["convert"](entry[fieldnumber[k]]) 163 prevkey = entry[fnkey] 153 164 summary = [None] * nbheaders 154 summary[fnusername] = prevusername 155 summary[fnamount] = amount 156 summary[fndate] = "*" 165 summary[fnkey] = prevkey 166 for ignore in ignored : 167 summary[fieldnumber[ignore]] = '*' 168 for k in totals.keys() : 169 summary[fieldnumber[k]] = totals[k]["convert"](totals[k]["value"]) 157 170 newentries.append(summary) 158 171 elif datatype == "history" :