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

SessionHandler   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B has_media_changed() 0 12 5
A has_finished() 0 11 3
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