1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-09 22:06:47 +00:00

Added actual weighted choice. Numpy for now, Python 3.6 has it in

random.choices().
This commit is contained in:
Markus Birth 2017-10-06 02:49:23 +02:00
parent 0aa04ae42f
commit a3b1b90874
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A

View File

@ -5,6 +5,7 @@
import base64
import binascii
import hashlib
import numpy
import platform
import random
import time
@ -89,7 +90,13 @@ class FotaCheck:
return "{}{}".format(str(millis), tail)
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):
idx = self.master_servers.index(self.g2master)