Spaces:
Runtime error
Runtime error
import json | |
import os | |
from datetime import date, timedelta | |
def list_files(startpath): | |
for root, dirs, files in os.walk(startpath): | |
level = root.replace(startpath, "").count(os.sep) | |
indent = " " * 4 * (level) | |
print("{}{}/".format(indent, os.path.basename(root))) | |
subindent = " " * 4 * (level + 1) | |
for f in files: | |
print("{}{}".format(subindent, f)) | |
def load_configs(configs_file_path): | |
"""Load a configuration file containing keys and secrets and return them as a dictionary. | |
Args: | |
config_file_path (str): The path to the configuration file to load. | |
Returns: | |
dict: A dictionary containing the keys and secrets loaded from | |
""" | |
with open(configs_file_path) as f: | |
configs = json.load(f) | |
return configs | |
def wilson_score_interval(obs, conf_level=0.95): | |
import math | |
from scipy import stats | |
""" | |
Calculates the Wilson score interval for a given list of observations. | |
Args: | |
obs (list): A list of observations (0s and 1s). | |
conf_level (float): The desired confidence level (default: 0.95). | |
Returns: | |
tuple: A tuple with the lower and upper bounds of the confidence interval. | |
""" | |
n = len(obs) | |
if n == 0: | |
return None | |
z = stats.norm.ppf(1 - (1 - conf_level) / 2) | |
phat = sum(obs) / n | |
term = z * math.sqrt(phat * (1 - phat) / n + z * z / (4 * n * n)) | |
lower_bound = (phat + z * z / (2 * n) - term) / (1 + z * z / n) | |
upper_bound = (phat + z * z / (2 * n) + term) / (1 + z * z / n) | |
return round(lower_bound, 2), round(upper_bound, 2) | |
def get_yesterday_date(): | |
today = date.today() | |
yesterday = today - timedelta(days=1) | |
return yesterday | |
def load_data_from_file(filename): | |
""" | |
Loads data from a file in JSON format if the file exists. | |
Args: | |
filename (str): The name of the file to load. | |
Returns: | |
The loaded data, or None if the file doesn't exist. | |
""" | |
if os.path.isfile(filename): | |
with open(filename, "r") as f: | |
data = json.load(f) | |
return data | |
else: | |
return None | |