Test Failed
Push — beta ( 918fe2...7d3e07 )
by Dean
03:03
created

SessionHandler.has_finished()   A

Complexity

Conditions 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 11
ccs 4
cts 5
cp 0.8
rs 9.4285
c 1
b 0
f 0
cc 3
crap 3.072
1 1
class Handler(object):
2 1
    __event__ = None
3
4 1
    __src__ = []
5 1
    __dst__ = []
6
7 1
    @classmethod
8
    def is_valid_source(cls, state):
9 1
        return state in cls.__src__
10
11 1
    @classmethod
12
    def is_valid_destination(cls, state):
13
        return state in cls.__dst__
14
15 1
    @classmethod
16
    def process(cls, obj, payload):
17
        pass
18
19
20 1
class SessionHandler(Handler):
21 1
    @staticmethod
22
    def has_finished(session, payload):
23 1
        if not session or not session.duration:
24
            return False
25
26
        # Calculate session progress
27 1
        # TODO update to support multi-part sessions
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
28
        progress = float(payload.get('view_offset')) / session.duration
29
30 1
        # Session is finished when `progress` reaches at least 100%
31
        return progress >= 1.0
32 1
33
    @staticmethod
34 1
    def has_media_changed(session, payload):
35
        if not session or not session.rating_key:
36
            return False
37 1
38
        if session.rating_key != payload.get('rating_key'):
39
            return True
40
41
        if session.part != payload.get('part', 1):
42
            return True
43
44
        return False
45