|
@@ 223-236 (lines=14) @@
|
| 220 |
|
.filter(event.Event.deleted==False) |
| 221 |
|
return r |
| 222 |
|
|
| 223 |
|
@classmethod |
| 224 |
|
def count(cls, *, trans_type=None, start=None, end=None): |
| 225 |
|
r = DBSession.query(func.count(cls.id).label('c'))\ |
| 226 |
|
.join(event.Event)\ |
| 227 |
|
.filter(event.Event.deleted==False) |
| 228 |
|
|
| 229 |
|
if trans_type: |
| 230 |
|
r = r.filter(cls.type==trans_type) |
| 231 |
|
if start: |
| 232 |
|
r = r.filter(event.Event.timestamp>=start) |
| 233 |
|
if end: |
| 234 |
|
r = r.filter(event.Event.timestamp<end) |
| 235 |
|
|
| 236 |
|
return r.one().c |
| 237 |
|
|
| 238 |
|
@classmethod |
| 239 |
|
def distinct(cls, *, distinct_on=None, start=None, end=None): |
|
@@ 280-292 (lines=13) @@
|
| 277 |
|
return r.one().d or Decimal(0.0) |
| 278 |
|
|
| 279 |
|
# Get the total amount of fees people have paid for being in debt |
| 280 |
|
@classmethod |
| 281 |
|
def fees(cls, start=None, end=None): |
| 282 |
|
r = DBSession.query(func.sum((cls.amount / (1-cls.discount)) - cls.amount).label('f'))\ |
| 283 |
|
.join(event.Event)\ |
| 284 |
|
.filter(cls.discount < 0)\ |
| 285 |
|
.filter(event.Event.deleted==False) |
| 286 |
|
|
| 287 |
|
if start: |
| 288 |
|
r = r.filter(event.Event.timestamp>=start) |
| 289 |
|
if end: |
| 290 |
|
r = r.filter(event.Event.timestamp<end) |
| 291 |
|
|
| 292 |
|
return r.one().f or Decimal(0.0) |
| 293 |
|
|
| 294 |
|
# Returns an array of tuples where the first item is a millisecond timestamp, |
| 295 |
|
# the next is the total amount of debt, and the next is the total amount |
|
@@ 265-277 (lines=13) @@
|
| 262 |
|
|
| 263 |
|
# Get the total amount of discounts people have received for keeping |
| 264 |
|
# money in their account |
| 265 |
|
@classmethod |
| 266 |
|
def discounts(cls, start=None, end=None): |
| 267 |
|
r = DBSession.query(func.sum((cls.amount / (1-cls.discount)) - cls.amount).label('d'))\ |
| 268 |
|
.join(event.Event)\ |
| 269 |
|
.filter(cls.discount > 0)\ |
| 270 |
|
.filter(event.Event.deleted==False) |
| 271 |
|
|
| 272 |
|
if start: |
| 273 |
|
r = r.filter(event.Event.timestamp>=start) |
| 274 |
|
if end: |
| 275 |
|
r = r.filter(event.Event.timestamp<end) |
| 276 |
|
|
| 277 |
|
return r.one().d or Decimal(0.0) |
| 278 |
|
|
| 279 |
|
# Get the total amount of fees people have paid for being in debt |
| 280 |
|
@classmethod |
|
@@ 238-253 (lines=16) @@
|
| 235 |
|
|
| 236 |
|
return r.one().c |
| 237 |
|
|
| 238 |
|
@classmethod |
| 239 |
|
def distinct(cls, *, distinct_on=None, start=None, end=None): |
| 240 |
|
r = DBSession.query(cls).join(event.Event)\ |
| 241 |
|
.filter(event.Event.deleted==False) |
| 242 |
|
|
| 243 |
|
if start: |
| 244 |
|
r = r.filter(event.Event.timestamp>=start) |
| 245 |
|
if end: |
| 246 |
|
r = r.filter(event.Event.timestamp<end) |
| 247 |
|
|
| 248 |
|
if distinct_on is None: |
| 249 |
|
raise NotImplementedError("required argument distinct_on missing") |
| 250 |
|
|
| 251 |
|
r = r.distinct(distinct_on) |
| 252 |
|
|
| 253 |
|
return r.count() |
| 254 |
|
|
| 255 |
|
@classmethod |
| 256 |
|
@datefilter_one_or_zero(label='a') |