Skip to content

Commit

Permalink
created mode 3
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharm committed Sep 20, 2019
1 parent 8758436 commit eec7c55
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 13 deletions.
121 changes: 108 additions & 13 deletions ascl_list1.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,48 @@
parser.add_argument("--matchid", type = str, default = None, help = "print json for exact match ID (mode 1 only)")
parser.add_argument("--matchname", type = str, default = None, help = "print json for matching NAME")
parser.add_argument("--matchdesc", type = str, default = None, help = "print json for matching DESCRIPTION")
parser.add_argument("--matchfield", type = str, default = None, help = "print the matching fields for both databases")

args = parser.parse_args()

mode = args.mode
match_name = args.matchname
match_desc = args.matchdesc
match_id = args.matchid



match_field = args.matchfield

# d1: dict_keys(['version', 'agency', 'measurementType', 'releases']) where d1['releases'] is a list of dict:
# ['repositoryURL','name','tags','contact','laborHours','date','organization','permissions','identifier','description']
# d2: a list of dict
# ['Update_Date','Public Code Repo','Description','License','NASA Center','External Link','Contributors','Labor_Hours','Software','Categories','Categories_NLP']

# code.json fields catalog.json fields

# 'repositoryURL' 'Public Code Repo',
# 'name' 'Software',
# 'tags' 'Categories','Categories_NLP'
# 'contact' 'Contributors',
# 'laborHours' 'Labor_Hours',
# 'date', 'Update_Date',
# 'organization' 'NASA Center',
# 'permissions' 'License',
# 'identifier' seems unique, but only appears for < half of codes
# 'description' 'Description',
#


#if mode is 1 and match id is supplied, this will print the json
#dumps of the matching identifier
#Otherwise, will print the identifier and name


if mode == 1:

f1 = open(args.codedir + '/' + args.code)
d1 = json.load(f1)

r = d1['releases']


#prints all the tags sequentially
if args.tags:
for i in range(len(r)):
ri = r[i]
Expand All @@ -73,23 +87,23 @@
print(t)

else:

#if match_name is provided, then print json dump of the name
if match_name != None:
for i in range(len(r)):
ri = r[i]
name = ri['name']
if name.find(match_name) >= 0:
jstr = json.dumps(ri,indent=4)
print(jstr)

#same for description
elif match_desc != None:
for i in range(len(r)):
ri = r[i]
desc = ri['description']
if desc.find(match_desc) >= 0:
jstr = json.dumps(ri,indent=4)
print(jstr)

#same for id
elif match_id != None:
for i in range(len(r)):
ri = r[i]
Expand All @@ -98,7 +112,7 @@
if match_id == iden:
jstr = json.dumps(ri,indent=4)
print(jstr)

#otherwise print out "<identifier> <name>"
else:
for i in range(len(r)):
ri = r[i]
Expand All @@ -109,15 +123,16 @@
elif mode == 2:
f2 = open(args.codedir + '/' + args.catalog, )
d2 = json.load(f2)

#prints out all the tags sequentially
if args.tags:
for i in range(len(d2)):
ri = d2[i]
cat = ri['Categories']

for c in cat:
print(c)


#prints out the repo in csv formatting
elif args.list:
output_str = "Ordinal,Status,Software,Description,Public Code Repo,External Link,Contributers"
print( output_str )
Expand All @@ -137,6 +152,7 @@
print(output_str.encode("utf8"))

else:
#if match name is provided, print out all the dumps for matching names
if match_name != None:
for i in range(len(d2)):
ri = d2[i]
Expand All @@ -145,7 +161,7 @@
if soft.find(match_name) >= 0:
jstr = json.dumps(ri,indent=4)
print(jstr)

#same for description
elif match_desc != None:
for i in range(len(d2)):
ri = d2[i]
Expand All @@ -154,11 +170,90 @@
if desc.find(match_desc) >= 0:
jstr = json.dumps(ri,indent=4)
print(jstr)

#prints out name of the code
else:
for i in range(len(d2)):
ri = d2[i]
print("%s" % (ri['Software']))

elif mode == 3:
#MUST supply matchfield and matchname
#match_name is an exact match with both databases


#comparison mode
# code.json fields catalog.json fields Our field

# 'repositoryURL' 'Public Code Repo', repo
# 'name' 'Software', name
# 'tags' 'Categories','Categories_NLP' tags -both
# 'contact' 'Contributors', who -both
# 'laborHours' 'Labor_Hours', labor
# 'date', 'Update_Date', date -code.json
# 'organization' 'NASA Center', org
# 'permissions' 'License', lic -both
# 'identifier' --------------- id
# 'description' 'Description', desc
#

fields = {
"repo": ["repositoryURL", "Public Code Repo"],
"name": ["name", "Software"],
"tags": ["tags", "Categories"],
"who": ["contact", "Contributors"],
"labor":["laborHours", "Labor_Hours"],
"date": ["date", "Update_Date"],
"org": ["organization", "NASA Center"],
"lic": ["permissions", "License"],
"id":["identifier", ""],
"desc": ["description", "Description"],
}

if match_field and match_name:

f1 = open(args.codedir + '/' + args.code)
d1 = json.load(f1)

f2 = open(args.codedir + '/' + args.catalog, )
d2 = json.load(f2)

r = d1["releases"]
code_ans = "name not in code"
catalog_ans = "name not in catalog"

#iterates through code.json data structure and finds the first exact
#matching name. Sets the result equal to the appropriate field of the
#returned object
for i in range(len(r)):
ri = r[i]
if match_name == ri["name"]:


code_ans = str(ri[fields[match_field][0]])

#DOES NOT DISPLAY PROPERLY IF THE match_field IS tags, date, who, lic
#BREAKS IF match_field is id

'''
if match_field == "tags":
code_ans = ""
for tag in ri["tags"]:
code_ans += tag
'''

break
for j in range(len(d2)):
d2j = d2[j]
if match_name == d2j["Software"]:
catalog_ans = str(d2j[fields[match_field][1]])
break

print("code.json:\t" + code_ans + "\n" + "catalog.json:\t" + catalog_ans)

else:
print("missing matchfield and/or exact matchname")



else:
sys.exit(1)
Empty file removed try.csv
Empty file.

0 comments on commit eec7c55

Please sign in to comment.