Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_replace():
d = None
assert utils.replace(d, "a", float) is None
# empty dict
d = {}
assert not utils.replace(d, "a", float)
# normal case
d = {"a": "1"}
utils.replace(d, "a", float)
assert d["a"] == 1.0
roundNumber
tournamentId
soc
staker
status
txHash
value
}
}
}
"""
data = self.raw_query(query, authorization=True)['data']
stakes = data['user']['stakeTxs']
# convert strings to python objects
for s in stakes:
utils.replace(s, "insertedAt", utils.parse_datetime_string)
utils.replace(s, "soc", utils.parse_float_string)
utils.replace(s, "confidence", utils.parse_float_string)
utils.replace(s, "value", utils.parse_float_string)
return stakes
name
public_id
scopes
}
v2Stake {
status
txHash
}
}
}
"""
data = self.raw_query(query, authorization=True)['data']['user']
# convert strings to python objects
utils.replace(data, "insertedAt", utils.parse_datetime_string)
utils.replace(data, "availableUsd", utils.parse_float_string)
utils.replace(data, "availableNmr", utils.parse_float_string)
return data
}
'''
arguments = {'number': round_num, 'tournament': tournament}
result = self.raw_query(query, arguments)['data']['rounds'][0]
if result is None:
return None
stakes = result['leaderboard']
# filter those with actual stakes
stakes = [item for item in stakes if item["stake"] is not None]
# convert strings to python objects
for s in stakes:
utils.replace(s["stake"], "insertedAt",
utils.parse_datetime_string)
utils.replace(s["stake"], "confidence", utils.parse_float_string)
utils.replace(s["stake"], "soc", utils.parse_float_string)
utils.replace(s["stake"], "value", utils.parse_float_string)
return stakes
'''
arguments = {'tournament': tournament, 'username': username}
data = self.raw_query(query, arguments)['data']['userActivities']
# filter rounds with no activity
data = [item for item in data
if item['submission']['date'] is not None]
for item in data:
# remove stakes with all values set to None
if item['stake']['date'] is None:
del item['stake']
# parse
else:
utils.replace(item['stake'], "date",
utils.parse_datetime_string)
for col in ['confidence', 'value', 'nmrEarned', 'usdEarned']:
utils.replace(item['stake'], col, utils.parse_float_string)
# parse
for item in data:
utils.replace(item['submission'], "date",
utils.parse_datetime_string)
return data
'''
arguments = {'number': round_num, 'tournament': tournament}
result = self.raw_query(query, arguments)['data']['rounds']
if len(result) == 0:
msg = "no entries for round number {} & tournament ".format(
round_num, tournament)
self.logger.warning(msg)
raise ValueError
leaderboard = result[0]['leaderboard']
# parse to correct data types
for item in leaderboard:
for p in ["paymentGeneral", "paymentStaking"]:
utils.replace(item[p], "nmrAmount", utils.parse_float_string)
utils.replace(item[p], "usdAmount", utils.parse_float_string)
utils.replace(item['stakeResolution'], "paid",
utils.parse_float_string)
utils.replace(item['return'], "nmrAmount",
utils.parse_float_string)
return leaderboard
query($roundNumber: Int!) {
v2RoundDetails(roundNumber: $roundNumber) {
userPerformances {
date
correlation
username
}
}
}
"""
arguments = {'roundNumber': round_num}
data = self.raw_query(query, arguments)['data']['v2RoundDetails']
performances = data['userPerformances']
# convert strings to python objects
for perf in performances:
utils.replace(perf, "date", utils.parse_datetime_string)
return performances