Code Duplication    Length = 16-21 lines in 3 locations

chezbetty/models/transaction.py 3 locations

@@ 214-234 (lines=21) @@
211
        return utility.timeseries_balance_total_daily(rows)
212
213
214
    @classmethod
215
    def get_transactions_over_time_for_user(cls, user):
216
        return DBSession.query(cls.amount,
217
                               cls.type,
218
                               cls.to_account_virt_id,
219
                               cls.fr_account_virt_id,
220
                               event.Event.timestamp)\
221
                        .join(event.Event)\
222
                        .filter(event.Event.deleted==False)\
223
                        .filter(or_(
224
                                  cls.type=='purchase',
225
                                  cls.type=='cashdeposit',
226
                                  cls.type=='ccdeposit',
227
                                  cls.type=='btcdeposit',
228
                                  cls.type=='adjustment'
229
                                ))\
230
                        .filter(or_(
231
                            cls.to_account_virt_id == user.id,
232
                            cls.fr_account_virt_id == user.id,
233
                            ))\
234
                        .order_by(event.Event.timestamp)\
235
                        .all()
236
237
@@ 285-300 (lines=16) @@
282
account.Account.transactions = __transactions
283
284
# This is in a stupid place due to circular input problems
285
@limitable_all
286
def __get_events(self):
287
    return object_session(self).query(event.Event)\
288
            .join(Transaction)\
289
            .filter(or_(
290
                      or_(
291
                        Transaction.to_account_virt_id == self.id,
292
                        Transaction.fr_account_virt_id == self.id,
293
                        Transaction.to_account_cash_id == self.id,
294
                        Transaction.fr_account_cash_id == self.id),
295
                      and_(
296
                        or_(event.Event.type == "purchase",
297
                            event.Event.type == "deposit"),
298
                        event.Event.user_id == self.id)))\
299
            .filter(event.Event.deleted==False)\
300
            .order_by(desc(event.Event.timestamp))
301
302
@property
303
def __events(self):
@@ 193-211 (lines=19) @@
190
    # Returns an array of tuples where the first item is a millisecond timestamp,
191
    # the next is the total amount of debt, and the next is the total amount
192
    # of stored money for users.
193
    @classmethod
194
    def get_balance_total_daily(cls):
195
        rows = DBSession.query(cls.amount,
196
                               cls.type,
197
                               cls.to_account_virt_id,
198
                               cls.fr_account_virt_id,
199
                               event.Event.timestamp)\
200
                        .join(event.Event)\
201
                        .filter(event.Event.deleted==False)\
202
                        .filter(or_(
203
                                  cls.type=='purchase',
204
                                  cls.type=='cashdeposit',
205
                                  cls.type=='ccdeposit',
206
                                  cls.type=='btcdeposit',
207
                                  cls.type=='adjustment'
208
                                ))\
209
                        .order_by(event.Event.timestamp)\
210
                        .all()
211
        return utility.timeseries_balance_total_daily(rows)
212
213
214
    @classmethod