Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'Sentiment': 'N/A',
'Sentiment Label': 'N/A',
'Arousal': 'N/A',
'Dominance': 'N/A',
'# Words Found': 0,
'Found Words': 'N/A',
'All Words': all_words
})
i += 1
else: # output sentiment info for this sentence
# get values
if mode == 'median':
sentiment = statistics.median(v_list)
arousal = statistics.median(a_list)
dominance = statistics.median(d_list)
else:
sentiment = statistics.mean(v_list)
arousal = statistics.mean(a_list)
dominance = statistics.mean(d_list)
# set sentiment label
label = 'neutral'
if sentiment > 6:
label = 'positive'
elif sentiment < 4:
label = 'negative'
writer.writerow({'Sentence ID': i,
'Sentence': s,
'Sentiment': sentiment,
'Sentiment Label': label,
def _produce_projection(self, data, agreement):
response = {
"agreement": 0,
"points": [entry["value"] for entry in data],
"median": 0,
"average": 0,
"timestamp": median([entry["timestamp"] for entry in data]),
"disagree": []
}
med = response["median"] = median(response["points"])
def evaluate_value(_v):
return bool(med - med*self._d < _v < med + med*self._d)
perc = 100 / len(data)
agreed = []
for entry in data:
if evaluate_value(entry["value"]):
response["agreement"] += perc
agreed.append(entry["value"])
else:
response["disagree"].append(entry["hostname"])
response["agree"] = (response["agreement"] >= agreement)
try:
node_info = plugin.rpc.listnodes(node_id)['nodes'][0]
except IndexError:
return "Node id not found"
node_channels = [c for c in plugin.rpc.listchannels()['channels'] if c['source'] == node_id]
active_channels = [c for c in node_channels if c['active'] is True]
capacity = [c['satoshis'] for c in active_channels]
fee_rate = [c['fee_per_millionth'] for c in active_channels]
base_fee = [c['base_fee_millisatoshi'] for c in active_channels]
num_active_channels = len(active_channels)
num_closed_channels = len(node_channels) - num_active_channels
if num_active_channels > 0:
capacity_sats = sum(capacity)
capacity_med = median(capacity)
capacity_avg = capacity_sats / num_active_channels
fee_rate_med = median(fee_rate)
base_fee_med = median(base_fee)
else:
capacity_sats = 0
capacity_med = 0
capacity_avg = 0
fee_rate_med = 0
fee_rate_avg = 0
base_fee_med = 0
base_fee_avg = 0
data = {
'node': node_id,
'alias': node_info['alias'],
'color': node_info['color'],
print(f"Speed (median): {statistics.median(times)}ms")
# Strip output from new line
result = cmd_run.out.strip()
print(f"Result: {result}")
# Calculate accuracy
if not self.debug:
accuracy = self.diff_letters(f"{math.pi:.{len(result)-2}f}", result)
print(f"Accuracy: {accuracy:.2%}")
else:
accuracy = 0.0000
print() # new line
self.results["median"] = statistics.median(times)
self.results["best"] = min(times)
self.results["worst"] = max(times)
self.results["accuracy"] = f"{accuracy*100:.4}"
return self.results
def remove_outliers(values):
"""
Return the list of values without any outliers.
:param values: Iterable series of numbers.
:return: `values` without outliers defined by being outside 1.5 times the IQR.
"""
values = list(values)
values.sort()
count = len(values)
q1 = median(values[:count//2])
q3 = median(values[count//2+1:])
iqr = q3 - q1
min_v = q1 - 1.5 * iqr
max_v = q3 + 1.5 * iqr
return list(filter(lambda v: min_v <= v <= max_v, values))
def add_stats(all_before, all_after, entity_names, colors):
avg_before = statistics.mean(all_before)
avg_after = statistics.mean(all_after)
all_before.append(avg_before)
all_after.append(avg_after)
entity_names.append("(AVG)")
colors.append("b")
median_before = statistics.median(all_before)
median_after = statistics.median(all_after)
all_before.append(median_before)
all_after.append(median_after)
entity_names.append("(MEDIAN)")
colors.append("y")
stdev_before = statistics.pstdev(all_before,avg_before)
stdev_after = statistics.pstdev(all_after,avg_after)
all_before.append(stdev_before)
all_after.append(stdev_after)
entity_names.append("(STDEV)")
colors.append("c")
values.append(-float(incident_type["value"]))
# let's see if this is over under type
elif LookupBettingMarketGroup.is_ou_type(type):
log.debug(
"Dealing with over/under value: {}".format(
incident_type["value"]
)
)
# store value
values.append(float(incident_type["value"]))
if values:
log.debug("Obtaining median ({}) for values: {}".format(type, str(values)))
return statistics.median(values)
else:
log.warning("No values could be processed for type {}!".format(type))
assert (n_steps is None) != (n_episodes is None)
if isinstance(env, chainerrl.env.VectorEnv):
scores = batch_run_evaluation_episodes(
env, agent, n_steps, n_episodes,
max_episode_len=max_episode_len,
logger=logger)
else:
scores = run_evaluation_episodes(
env, agent, n_steps, n_episodes,
max_episode_len=max_episode_len,
logger=logger)
stats = dict(
episodes=len(scores),
mean=statistics.mean(scores),
median=statistics.median(scores),
stdev=statistics.stdev(scores) if len(scores) >= 2 else 0.0,
max=np.max(scores),
min=np.min(scores))
return stats
def format_stats(series, d, f=0):
mean = statistics.mean(series)
med = statistics.median(series)
std = statistics.stdev(series)
return f"x {mean:{d}.{f}f} μ {med:{d}.{f}f} σ² {std:{d}.{f}f}"
up_to_date += 1
try:
updated_date = datetime.datetime.strptime(i["updated_date"], "%a, %d %b %Y %H:%M:%S GMT")
if i["last_change_date"] and updated_date + datetime.timedelta(seconds=70) < now:
updated_periods.append(
datetime.datetime.strptime(i["last_change_date"], "%a, %d %b %Y %H:%M:%S GMT"))
except TypeError:
pass
updated_periods.sort()
timedeltas = [updated_periods[i - 1] - updated_periods[i] for i in range(1, len(updated_periods))]
if timedeltas:
average_timedelta = sum(timedeltas, datetime.timedelta(0)) / len(timedeltas)
average_timedelta = datetime.timedelta(microseconds=average_timedelta.microseconds) - average_timedelta
median_timedelta = statistics.median(timedeltas)
median_timedelta = datetime.timedelta(microseconds=median_timedelta.microseconds) - median_timedelta
eta = median_timedelta.seconds * datetime.timedelta(seconds=(len(ignition) - up_to_date))
eta = (eta + now).strftime("%H:%M") if eta else ""
else:
average_timedelta = "-"
median_timedelta = "-"
eta = "-"
req = requests.get("%s/lifecycle/rolling" % self.enj_uri)
req.close()
rolling = json.loads(req.content.decode())
rolling_nb = 0
for j in rolling:
if j["enable"] is True:
rolling_nb += 1