-
Notifications
You must be signed in to change notification settings - Fork 34
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
function for loading users #125
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ceacbc6
WIP load users
45855b6
Add functionality to support no data directory and lint
tab-cmd 0b18532
remove unused import
tab-cmd 04e6536
Add unittest examples with some direction
tab-cmd 074c897
Testing
AlisterD 25c0d6c
Ran Make Lint Command
AlisterD b1c9d86
change input into load_users, update tests
tab-cmd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import logging | ||
import pickle | ||
import json | ||
import os | ||
from pathlib import Path | ||
from shutil import copyfile | ||
from time import localtime, strftime | ||
from tkinter import Tk | ||
from tkinter.filedialog import askdirectory, askopenfilename | ||
|
||
from typing import List | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
|
@@ -227,3 +230,53 @@ def load_txt_data() -> str: | |
'File type unrecognized. Please use a supported text type') | ||
|
||
return filename | ||
|
||
|
||
def load_users(parameters: Parameters) -> List[str]: | ||
"""Load Users. | ||
|
||
Loads user directory names below experiments from the data path defined in parameters.json | ||
and returns them as a list. If the save data directory is not found, this method returns an | ||
empty list assuming no experiments have been run yet. | ||
""" | ||
# build a saved users list, pull out the data save location from parameters | ||
saved_users = [] | ||
# parameters.get('data_save_loc', False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused code. We should remove this |
||
data_save_loc = parameters['data_save_loc'] | ||
|
||
# check the directory is valid, if it is, set path as data save location | ||
if os.path.isdir(data_save_loc): | ||
path = data_save_loc | ||
|
||
# check the directory is valid after adding bcipy, if it is, set path as data save location | ||
elif os.path.isdir(f'bcipy/{data_save_loc}'): | ||
path = f'bcipy/{data_save_loc}' | ||
|
||
else: | ||
log.info(f'User save data location not found at [{data_save_loc}]! Returning empty user list.') | ||
return saved_users | ||
|
||
# grab all experiments in the directory and iterate over them to get the users | ||
experiments = fast_scandir(path, return_path=True) | ||
|
||
for experiment in experiments: | ||
users = fast_scandir(experiment, return_path=False) | ||
# If it is a new user, append it to the saved_user list | ||
for user in users: | ||
if user not in saved_users: | ||
saved_users.append(user) | ||
|
||
return saved_users | ||
|
||
|
||
def fast_scandir(directory_name: str, return_path: bool = True) -> List[str]: | ||
"""Fast Scan Directory. | ||
|
||
directory_name: name of the directory to be scanned | ||
return_path: whether or not to return the scanned directories as a relative path or name. | ||
False will return the directory name only. | ||
""" | ||
if return_path: | ||
return [f.path for f in os.scandir(directory_name) if f.is_dir()] | ||
|
||
return [f.name for f in os.scandir(directory_name) if f.is_dir()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing all of the parameters, let's extract the data path in advance and pass it to your method!