"""Function to help view project information."""importjsonimportpprint
[docs]defprint_info(project=None,show_code=False):""" Print formatted information about the provided Project. :param project: Project information as returned by :func:`~jii_multispeq.get.get` or :func:`~jii_multispeq.file.load`. :type project: dict :param show_code: Display the protocol's code in addition to the description. Defaults to False. :type show_code: bool :return: None :rtype: NoneType :raises ValueError: if no project data is provided or the project data has the wrong format :alias: :func:`~jii_multispeq.project.info.show` """# Required keyskeys={'name','id','project_url','tag_list','data_count','created_at','updated_at','locations','creator','description','directions_to_collaborators','filters','protocols','protocol_json'}# Display exeption if no dictionary is providedifprojectisNone:raiseValueError("Provided Project has no information")# Check if first level keys are availableifnotkeys<=project.keys():raiseValueError("Provided Project doesn't seem to have the correct format, missing key")# Project Titleprint("="*(11+len(project["name"])+len(str(project["id"]))))print(" %s (ID: %s)"%(project["name"],project["id"]))print("="*(11+len(project["name"])+len(str(project["id"]))))# Project URLprint("\nURL: %s\n"%(project["project_url"]))# Tagsiflen(project["tag_list"])>0:print("Tag(s): %s\n"%(", ".join(project["tag_list"])))# Basic Infoprint("Basic Info:\n-----------")print("Datasets: %s"%(project["data_count"]))print("Created: %s"%(project["created_at"]))print("Last Update: %s"%(project["updated_at"]))# Locationiflen(project["locations"])>0:print("Locations:")forlocationinproject["locations"]:print(" - %s (%s, %s)"%(location["address"],location["latitude"],location["longitude"]))# Project Creatorprint("\nProject Creator:\n----------------")print("Name: %s"%(project["creator"]['name']))ifproject["creator"]['institute']!='':print("Institute: %s"%(project["creator"]['institute']))print("URL: %s"%(project["creator"]['profile_url']))# Descriptionprint("\nProject Details:\n----------------")ifproject["description"]isNoneor(len(project["description"])<=80):print(project["description"])else:print(pprint.pformat(project["description"],width=80)[2:-2].replace("'\n '","\n"))# Directionsifproject["directions_to_collaborators"]isNoneor(len(project["directions_to_collaborators"])<=80):print("Directions: \n%s"%(project["directions_to_collaborators"]))else:print("Directions: \n%s"%(pprint.pformat(project["directions_to_collaborators"],width=80)[2:-2].replace("'\n '","\n")))# Meta Dataquestion_type=["Multiple Choice","Multiple Choice (with images)","Short Answer","Take picture"]iflen(project["filters"])>0:print("\nMeta Data:\n----------")forfilterinproject["filters"]:print(" * %s - %s%s"%(filter["label"],question_type[filter["value_type"]],(' (Deleted)'iffilter["is_deleted"]isTrueelse"")))print(" Unique Inputs: %s"%(len(filter["value"])))# Protocoliflen(project["protocols"])>0:print("\nProtocol(s):\n------------")forprotocolinproject["protocols"]:print(" * %s (ID: %s)\n%s"%(protocol["name"],protocol["id"],protocol["description"]if(protocol["description"]isNone)or(len(protocol["description"])<=80)elsepprint.pformat(protocol["description"],width=80)[2:-2].replace("'\n '","\n ")))# Protocol JSONifshow_code:print("\nProtocol Code:\n--------------")print(pprint.pprint(json.loads(project['protocol_json']),compact=True))