Passed
Push — develop ( 9e1b8b...5d0b21 )
by Dean
03:00
created

SessionHandler   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 78.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
dl 0
loc 25
ccs 11
cts 14
cp 0.7856
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A has_finished() 0 11 3
B has_media_changed() 0 12 5
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
        # 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 1
        progress = float(payload.get('view_offset')) / session.duration
29
30
        # Session is finished when `progress` reaches at least 100%
31 1
        return progress >= 1.0
32
33 1
    @staticmethod
34
    def has_media_changed(session, payload):
35 1
        if not session or not session.rating_key:
36
            return False
37
38 1
        if session.rating_key != payload.get('rating_key'):
39 1
            return True
40
41 1
        if session.part != payload.get('part', 1):
42
            return True
43
44
        return False
45