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

[Code review] Code style and module requirements. #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
145 changes: 86 additions & 59 deletions NeuroCI.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,83 @@
import requests
import yaml
import json
import datetime
import sys
import os
#from github import Github
from ast import literal_eval
import time
import datetime

from cbrainAPI import *
from cacheOps import *
import yaml

from cacheOps import (
download_cache,
populate_cache_filenames,
update_statuses,
pipeline_manager,
populate_results,
)
from cbrainAPI import cbrain_login, cbrain_logout, cbrain_get_all_tasks

##################################################################################

def main(cbrain_token, CCI_token, experiment_definition, cbrain_ids, latest_artifacts_url):

for dataset in experiment_definition['Datasets']:

download_cache(dataset + '.json', CCI_token, latest_artifacts_url) #Downloads newest cache to json file
print('Downloaded newest cache for: ' + dataset + '.json')

task_list = cbrain_get_all_tasks(cbrain_token) #Gets the complete list of tasks for the user on CBRAIN
print('Fetched the list of tasks for the CBRAIN user')

start = time.time()
update_statuses(dataset + '.json', task_list) #Updates the contents of a cache to reflect CBRAIN task statuses
end = time.time()
print('Updated statuses in cache for: ' + dataset + '.json in' + str(datetime.timedelta(seconds=(end - start))))

for pipeline in experiment_definition['Pipelines']:

start = time.time()
populate_cache_filenames(dataset + '.json', cbrain_token, experiment_definition['Datasets'][dataset]['Blocklist'], pipeline, cbrain_ids['Data_Provider_IDs'][dataset], experiment_definition) #Populates a cache with any new files found
end = time.time()
print('Populated cache filenames for: ' + dataset + '.json' + ', ' + pipeline + " in" + str(datetime.timedelta(seconds=(end - start))))

pipeline_manager(cbrain_token, experiment_definition, cbrain_ids, pipeline, dataset)
print('Posted tasks for: ' + dataset + '.json' + ', ' + pipeline)

populate_results(dataset + '.json', cbrain_token)
print('Populated results for ' + dataset + '.json')
#extract_results()
#analysis(expdef[script])

#start = time.time()
#update_statuses(dataset + '.json', cbrain_token)
#end = time.time()
#print('Updated statuses in cache for: ' + dataset + '.json in' + str(datetime.timedelta(seconds=(end - start))))

def main(
cbrain_token, CCI_token, experiment_definition, cbrain_ids, latest_artifacts_url
):

for dataset in experiment_definition["Datasets"]:

download_cache(
dataset + ".json", CCI_token, latest_artifacts_url
) # Downloads newest cache to json file
print("Downloaded newest cache for: " + dataset + ".json")

task_list = cbrain_get_all_tasks(
cbrain_token
) # Gets the complete list of tasks for the user on CBRAIN
print("Fetched the list of tasks for the CBRAIN user")

start = time.time()
update_statuses(
dataset + ".json", task_list
) # Updates the contents of a cache to reflect CBRAIN task statuses
end = time.time()
print(
"Updated statuses in cache for: "
+ dataset
+ ".json in"
+ str(datetime.timedelta(seconds=(end - start)))
)

for pipeline in experiment_definition["Pipelines"]:

start = time.time()
populate_cache_filenames(
dataset + ".json",
cbrain_token,
experiment_definition["Datasets"][dataset]["Blocklist"],
pipeline,
cbrain_ids["Data_Provider_IDs"][dataset],
experiment_definition,
) # Populates a cache with any new files found
end = time.time()
print(
"Populated cache filenames for: "
+ dataset
+ ".json"
+ ", "
+ pipeline
+ " in"
+ str(datetime.timedelta(seconds=(end - start)))
)

pipeline_manager(
cbrain_token, experiment_definition, cbrain_ids, pipeline, dataset
)
print("Posted tasks for: " + dataset + ".json" + ", " + pipeline)

populate_results(dataset + ".json", cbrain_token)
print("Populated results for " + dataset + ".json")


##################################################################################

#Obtain login credentials from args, stored in CI environment variables.
# Obtain login credentials from args, stored in CI environment variables.

cbrain_user = sys.argv[1]
cbrain_password = sys.argv[2]
Expand All @@ -60,22 +87,24 @@ def main(cbrain_token, CCI_token, experiment_definition, cbrain_ids, latest_arti

##################################################################################

#Main code execution section
# Main code execution section

with open('Experiment_Definition.yaml') as file: #Load experiment definition
try:
experiment_definition = yaml.safe_load(file)
except yaml.YAMLError as exception: #yaml file not valid
print('The Experiment Definition file is not valid')
print(exception)
with open("Experiment_Definition.yaml") as file: # Load experiment definition
try:
experiment_definition = yaml.safe_load(file)
except yaml.YAMLError as exception: # yaml file not valid
print("The Experiment Definition file is not valid")
print(exception)


with open('./Config_Files/CBRAIN_IDs.yaml') as file: #Load mappings for all CBRAIN DP_IDs and toolconfig IDs
try:
cbrain_ids = yaml.safe_load(file)
except yaml.YAMLError as exception: #yaml file not valid
print('The configuration file is not valid')
print(exception)
with open(
"./Config_Files/CBRAIN_IDs.yaml"
) as file: # Load mappings for all CBRAIN DP_IDs and toolconfig IDs
try:
cbrain_ids = yaml.safe_load(file)
except yaml.YAMLError as exception: # yaml file not valid
print("The configuration file is not valid")
print(exception)

print("Using artifacts from : " + latest_artifacts_url)

Expand All @@ -85,5 +114,3 @@ def main(cbrain_token, CCI_token, experiment_definition, cbrain_ids, latest_arti

cbrain_logout(cbrain_token)
##################################################################################


Loading