mirror of
https://github.com/mbirth/tcl_ota_check.git
synced 2024-11-12 23:36:46 +00:00
Added actual weighted choice. Numpy for now, Python 3.6 has it in
random.choices().
This commit is contained in:
parent
0aa04ae42f
commit
a3b1b90874
@ -5,6 +5,7 @@
|
|||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import numpy
|
||||||
import platform
|
import platform
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
@ -89,7 +90,13 @@ class FotaCheck:
|
|||||||
return "{}{}".format(str(millis), tail)
|
return "{}{}".format(str(millis), tail)
|
||||||
|
|
||||||
def get_master_server(self):
|
def get_master_server(self):
|
||||||
return random.choice(self.master_servers)
|
weight_sum = 0
|
||||||
|
for i in self.master_servers_weights:
|
||||||
|
weight_sum += i
|
||||||
|
numpy_weights = []
|
||||||
|
for i in self.master_servers_weights:
|
||||||
|
numpy_weights.append(i/weight_sum)
|
||||||
|
return numpy.random.choice(self.master_servers, p=numpy_weights)
|
||||||
|
|
||||||
def master_server_downvote(self):
|
def master_server_downvote(self):
|
||||||
idx = self.master_servers.index(self.g2master)
|
idx = self.master_servers.index(self.g2master)
|
||||||
|
Loading…
Reference in New Issue
Block a user