def topScores(channel, stat='exp', reverse=False):
columns = ['name', 'exp', 'killed_ducks', 'shoots_fired']
if stat not in columns:
columns.append(stat)
table = getChannelPlayers(channel, columns=columns)
players_list = []
for player in table:
if checks.is_player_check(player):
players_list.append(player)
# print(str(player["name"]) + " | " + str(player["exp"]) + "|" + str(player["killed_ducks"]))
try:
# Retourne l'ensemble des joueurs dans une liste par stat
# FIXME : le truc de l'infini est un moyen dégueulasse de ne pas avoir "None" devant 0 pour best_time
# éventuellement on pourrait ne pas mettre les gens avec None dans le top (à faire dans exp.py)
return sorted(players_list, key=lambda k: (k.get(stat, None) or (math.inf if stat == 'best_time' else 0)), reverse=not reverse)
except:
return []
python类inf()的实例源码
def __str__(self):
"""String representation of IntegerSet obj."""
interval_strs = []
for start, end in self.intervals:
if start > -math.inf:
start_str = "%d" % start
else:
start_str = "-inf"
if end < math.inf:
end_str = "%d" % end
else:
end_str = "inf"
if start_str != end_str:
interval_strs.append("[" + start_str + ", " + end_str + "]")
else:
interval_strs.append("{" + start_str + "}")
return ", ".join(interval_strs)
def typical_height(csize: SizeClass, metric: bool=False) -> (float, float):
"""
Returns the minimum/maximum height range for a creature of the given size.
Values are given in feet by default.
"""
size_to_height = {
SizeClass.Fine: (0.0, 0.5),
SizeClass.Diminutive: (0.5, 1),
SizeClass.Tiny: (1, 2),
SizeClass.Small: (2, 4),
SizeClass.Medium: (4, 8),
SizeClass.Large: (8, 16),
SizeClass.Huge: (16, 32),
SizeClass.Gargantuan: (32, 64),
SizeClass.Colossal: (64, inf),
}
height = size_to_height[csize]
return height * 0.3048 if metric else height
def typical_weight(csize: SizeClass, metric: bool=False) -> (float, float):
"""
Returns the minimum/maximum weight range for a creature of the given size.
Values are given in pounds by default.
"""
size_to_weight = {
SizeClass.Fine: (0.0, 0.125),
SizeClass.Diminutive: (0.125, 1),
SizeClass.Tiny: (1, 8),
SizeClass.Small: (8, 60),
SizeClass.Medium: (60, 500),
SizeClass.Large: (500, 4000),
SizeClass.Huge: (4000, 32000),
SizeClass.Gargantuan: (32000, 250000),
SizeClass.Colossal: (250000, inf),
}
weight = size_to_weight[csize]
return weight * 0.45359237 if metric else weight
def isGameComplete(self) -> bool:
if self.strikes == 3 or self.score >= self.maxScore:
return True
if self.turnCount > (self.endTurn or math.inf):
return True
return False
def __init__(self, s: float = 0, u: float = 0, o: float = 0):
"""Used list start analysis abstract domain representation.
:param s: initial end of S-elements in list: should be a float in ``[0,1,2,..., inf]``
:param u: initial end of U-elements in list: should be a float in ``[0,1,2,..., inf]``
:param o: initial end of O-elements in list: should be a float in ``[0,1,2,..., inf]``
"""
super().__init__()
self._suo = OrderedDict([
(S, s),
(U, u),
(O, o)
])
def is_top(self) -> bool:
return all(upper == inf for upper in self.suo.values())
def test_combine(self):
# we assume that following test lists are 6 element long (implicit, not necessary to specify)
a = UsedListStartLattice(6, 4, 0) # UUUUSS
b = UsedListStartLattice(0, 2, 6) # UUOOOO
ab = a.combine(b)
self.assertEqual(list(ab.suo.values()), [0, 2, 6]) # UUOOOO
a = UsedListStartLattice(6, 4, 0) # UUUUSS
b = UsedListStartLattice(6, 2, 0) # UUSSSS
ab = a.combine(b)
self.assertEqual(list(ab.suo.values()), [6, 4, 0]) # UUUUSS
a = UsedListStartLattice(4, 2, 0) # UUSSNN
b = UsedListStartLattice(0, 2, 5) # UUOOON
ab = a.combine(b)
self.assertEqual(list(ab.suo.values()), [0, 2, 5]) # UUOOON
a = UsedListStartLattice(0, 5, 0) # UUUUUN
b = UsedListStartLattice(0, 2, 5) # UUOOON
ab = a.combine(b)
self.assertEqual(list(ab.suo.values()), [0, 2, 5]) # UUOOON
# we assume that following test lists are infinite long
a = UsedListStartLattice(inf, 2, 0) # UUSSSS...
b = UsedListStartLattice(0, inf, 0) # UUUUUU...
ab = a.combine(b)
self.assertEqual(list(ab.suo.values()), [0, inf, 0]) # UUUUUU...
a = UsedListStartLattice(0, inf, 0) # UUUUUU...
b = UsedListStartLattice(0, 0, inf) # OOOOOO...
ab = a.combine(b)
self.assertEqual(list(ab.suo.values()), [0, 0, inf]) # OOOOOO...
def nan2inf(f):
return inf if isnan(f) else f
def __init__(self, size):
assert size % 2 == 0, "The size of a CDBM has to be even!"
self._size = size
self._m = []
for i in range(size):
row = [inf] * min((i + 2) // 2 * 2, size)
self._m.append(row)
def is_top(self) -> bool:
return self.lower == -inf and self.upper == inf
def _widening(self, other: 'IntervalLattice') -> 'IntervalLattice':
"""``[a, b] ? [c, d] = [(c < a? -oo : a), (b < d? +oo : b)]``."""
lower = self.lower
upper = self.upper
if other.lower < self.lower:
lower = -inf
if self.upper < other.upper:
upper = inf
return self.replace(IntervalLattice(lower, upper))
# arithmetic operations
def __repr__(self):
if self.is_bottom():
return "?"
elif self.is_top():
return "?"
else:
res = []
# represent unary constraints first
for var in self.variables:
lower = - self[PLUS, var, MINUS, var] // 2
upper = self[MINUS, var, PLUS, var] // 2
if lower < inf and upper < inf:
res.append(f"{lower}?{var.name}?{upper}")
elif lower < inf:
res.append(f"{lower}?{var.name}")
elif upper < inf:
res.append(f"{var.name}?{upper}")
# represent binary constraints second, do not repeat identical inequalities
for i, var1 in enumerate(self.variables):
for j, var2 in enumerate(self.variables):
if i > j:
c = self[MINUS, var1, PLUS, var2]
if c < inf:
res.append(f"{var1.name}+{var2.name}?{c}")
c = self[MINUS, var1, MINUS, var2]
if c < inf:
res.append(f"{var1.name}-{var2.name}?{c}")
c = self[PLUS, var1, PLUS, var2]
if c < inf:
res.append(f"-{var1.name}+{var2.name}?{c}")
c = self[PLUS, var1, MINUS, var2]
if c < inf:
res.append(f"-{var1.name}-{var2.name}?{c}")
return ", ".join(res)
def top(self):
for key in self.dbm.keys():
self.dbm[key] = inf
return self
def is_top(self) -> bool:
return all([isinf(b) for k, b in self.dbm.items() if k[0] != k[1]]) # check all inf, ignore diagonal for check
def forget(self, var: VariableIdentifier):
# close first to not lose implicit constraints about other variables
self.close()
# forget binary constraints
for index in self.binary_constraints_indices(sign1=None, var1=var):
self[index] = inf
# forget unary constraints
self[PLUS, var, MINUS, var] = inf
self[MINUS, var, PLUS, var] = inf
def _expected_result(self):
initial = re.compile('INITIAL:?\s*(?P<state>.*)')
state = re.compile('STATE:?\s*(?P<state>.*)')
loop = re.compile('LOOP:?\s*(?P<state>.*)')
final = re.compile('FINAL:?\s*(?P<state>.*)')
for token in tokenize.tokenize(io.BytesIO(self.source.encode('utf-8')).readline):
if token.type == tokenize.COMMENT:
comment = token.string.strip("# ")
initial_match = initial.match(comment)
state_match = state.match(comment)
loop_match = loop.match(comment)
final_match = final.match(comment)
if initial_match:
result = initial_match.group('state')
line = -inf # -inf for a precondition
yield line, result
if state_match:
result = state_match.group('state')
line = token.start[0]
yield line, result
if loop_match:
result = loop_match.group('state')
line = -token.start[0] # negative line number for a loop invariant
yield line, result
if final_match:
result = final_match.group('state')
line = inf # inf for a postcondition
yield line, result
def test_init(self):
self.assertFalse(IntervalLattice().is_bottom())
self.assertTrue(IntervalLattice().is_top())
self.assertFalse(IntervalLattice(0, 1).is_bottom())
self.assertFalse(IntervalLattice(0, 1).is_top())
self.assertEqual(IntervalLattice(upper=2), IntervalLattice(-inf, 2))
self.assertEqual(IntervalLattice(lower=3), IntervalLattice(3, inf))
self.assertTrue(IntervalLattice(1, 0).is_bottom())
self.assertFalse(IntervalLattice(1, 0).is_top())
def make_qq_unstratified(variants, include_qq):
neglog10_pvals = sorted((v.neglog10_pval for v in variants), reverse=True)
rv = {}
if include_qq:
rv['qq'] = compute_qq(neglog10_pvals)
rv['count'] = len(neglog10_pvals)
rv['gc_lambda'] = {}
for perc in ['0.5', '0.1', '0.01', '0.001']:
gc = gc_value_from_list(neglog10_pvals, float(perc))
if math.isnan(gc) or abs(gc) == math.inf:
print('WARNING: got gc_value {!r}'.format(gc))
else:
rv['gc_lambda'][perc] = round_sig(gc, 5)
return rv
def round_sig(x, digits):
if x == 0:
return 0
elif abs(x) == math.inf or math.isnan(x):
raise ValueError("Cannot round infinity or NaN")
else:
log = math.log10(abs(x))
digits_above_zero = int(math.floor(log))
return round(x, digits - 1 - digits_above_zero)