Passed
Push — master ( 2f86f7...74d48b )
by Markus
01:48
created

tcllib.servervote.ServerVoteMixin.__init__()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
import numpy
4
5
class ServerVoteMixin:
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
6
    def __init__(self):
7
        self.g2master = None
8
        self.master_servers = [
9
            "g2master-us-east.tclclouds.com",
10
            "g2master-us-west.tclclouds.com",
11
            "g2master-eu-west.tclclouds.com",
12
            "g2master-ap-south.tclclouds.com",
13
            "g2master-ap-north.tclclouds.com",
14
            "g2master-sa-east.tclclouds.com",
15
        ]
16
        self.master_servers_weights = [3] * len(self.master_servers)
17
        self.check_time_sum = 3
18
        self.check_time_count = 1
19
20
    def get_master_server(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
21
        weight_sum = 0
22
        for i in self.master_servers_weights:
23
            weight_sum += i
24
        numpy_weights = []
25
        for i in self.master_servers_weights:
26
            numpy_weights.append(i/weight_sum)
27
        return numpy.random.choice(self.master_servers, p=numpy_weights)
28
29
    def master_server_downvote(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
30
        idx = self.master_servers.index(self.g2master)
31
        if self.master_servers_weights[idx] > 1:
32
            self.master_servers_weights[idx] -= 1
33
34
    def master_server_upvote(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
35
        idx = self.master_servers.index(self.g2master)
36
        if self.master_servers_weights[idx] < 10:
37
            self.master_servers_weights[idx] += 1
38
39
    def check_time_add(self, duration):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
40
        self.check_time_sum += duration
41
        self.check_time_count += 1
42
43
    def check_time_avg(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
44
        return (self.check_time_sum / self.check_time_count)
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after return.
Loading history...
45
46
    def master_server_vote_on_time(self, last_duration, avg_duration):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
47
        if last_duration < avg_duration - 0.5:
48
            self.master_server_upvote()
49
        elif last_duration > avg_duration + 0.5:
50
            self.master_server_downvote()
51