Passed
Push — master ( d9ae97...694e2f )
by Dean
09:21 queued 06:02
created

ActionHistory.has_scrobbled()   A

Complexity

Conditions 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.2963

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 1
cts 3
cp 0.3333
rs 9.4285
cc 1
crap 1.2963
1 1
from plugin.models.core import db
2 1
from plugin.models.account import Account
3 1
from plugin.models.session import Session
4
5 1
from playhouse.apsw_ext import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like playhouse.apsw_ext should generally be avoided.
Loading history...
6
7
8 1
class ActionHistory(Model):
9 1
    class Meta:
10 1
        database = db
11 1
        db_table = 'action.history'
12
13 1
    account = ForeignKeyField(Account, 'action_history')
14 1
    session = ForeignKeyField(Session, 'action_history', null=True)
15
16 1
    rating_key = IntegerField(null=True)
17
18 1
    event = CharField()
19 1
    performed = CharField(null=True)
20
21 1
    queued_at = DateTimeField()
22 1
    sent_at = DateTimeField()
23
24 1
    @classmethod
25
    def has_scrobbled(cls, account, rating_key, after):
26
        # Find matching "scrobble" events
27
        results = ActionHistory.select().where(
28
            ActionHistory.account == account,
29
            ActionHistory.rating_key == rating_key,
30
31
            ActionHistory.performed == 'scrobble',
32
33
            ActionHistory.sent_at > after
34
        )
35
36
        # Check for at least one result
37
        return results.count() > 0
38