Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix: Hierarchical Fed Stats, prepare data: replace os.rename() function #2921

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ def parse_args(prog_name: str):

def prepare_data():
# Set variables
NUM_UNIVERSITIES = 7
num_universities = 7

DATASET_PATH = "/tmp/nvflare/data/hierarchical_stats/"
if not os.path.exists(DATASET_PATH):
os.makedirs(DATASET_PATH)
dataset_path = "/tmp/nvflare/data/hierarchical_stats/"
if not os.path.exists(dataset_path):
os.makedirs(dataset_path)

print(f"Preparing data at data directory `{DATASET_PATH}`...\n")
print(f"Preparing data at data directory `{dataset_path}`...\n")

# Generate the entries for 7 different universities and copy it to each client data directory
for n in range(1, NUM_UNIVERSITIES + 1):
output_file = f"university-{n}.csv"
for n in range(1, num_universities + 1):
client_path = os.path.join(dataset_path, f"university-{n}")
if not os.path.exists(client_path):
os.makedirs(client_path)
file_name = f"university-{n}.csv"
output_file = os.path.join(client_path, file_name)

with open(output_file, "w", newline="") as csvfile:
csvwriter = csv.writer(csvfile)
# Create and write the header to the CSV file
Expand All @@ -57,13 +62,8 @@ def prepare_data():
fail = 1
percentage = round(random.uniform(20.00, 49.99), 2)
csvwriter.writerow([pass_, fail, percentage])

client_path = os.path.join(DATASET_PATH, f"university-{n}")
if not os.path.exists(client_path):
os.makedirs(client_path)
os.rename(output_file, os.path.join(client_path, output_file))
print(
f"CSV file `{output_file}` is generated with {num_entries} entries for client `university-{n}` at {client_path}."
f"CSV file `{file_name}` is generated with {num_entries} entries for client `university-{n}` at {client_path}."
)

print("\nDone preparing data.")
Expand Down
Loading