66from .upload_summary import upload_summary
77
88output = {}
9+ def safe_dic (dic , key ):
10+ try :
11+ return dic [key ]
12+ except :
13+ return None
914def __json_serial (obj ):
1015 """JSON serializer for objects not serializable by default json code
1116 Returns
@@ -21,17 +26,22 @@ def reset_dict():
2126 output ['has_documentation' ] = 0
2227 output ['identifiers' ] = {'num_doi' : 0 , 'num_pid' : 0 , 'num_without_identifier' : 0 }
2328 output ['readme' ] = {'Level 0' : 0 , 'Level 1' : 0 , 'Level 2' : 0 , 'Level 3' : 0 }
29+ output ['num_no_readme' ] = 0
30+ output ['num_with_readme' ] = 0
31+ output ['num_with_description' ] = 0
32+ output ['num_with_acknowledgement' ] = 0
33+ output ['num_with_installation' ] = 0
34+ output ['num_with_requirement' ] = 0
2435 output ['licenses' ] = {'APACHE' : 0 , 'MIT' : 0 , 'GPL' : 0 , 'OTHER' : 0 , 'MISSING' : 0 }
2536 output ['has_citation' ] = 0
2637 output ['CFF_file' ] = 0
2738 output ['no_citation' ] = 0
2839 output ['released' ] = {'<2 MONTHS' : 0 , 'LONGER' : 0 }
2940 output ['_soca_version' ] = soca_ver
3041 output ['_somef_version' ] = somef_ver
31- output ['_org_name' ] = ""
32- #TODO look into portal date/time
3342 output ['_timestamp' ] = __json_serial (datetime .now ())
3443 output ['num_repos' ] = 0
44+ output ['language_count' ] = {}
3545
3646
3747
@@ -100,10 +110,8 @@ def readme_score(json_obj):
100110 score += 1
101111 if json_obj ['acknowledgement' ]:
102112 score += 1
103- #TODO
104113 if json_obj ['requirement' ]:
105114 score += 1
106- #TODO
107115 if json_obj ['description' ] is not None :
108116 score += 1
109117
@@ -114,6 +122,27 @@ def readme_score(json_obj):
114122 if score <= 2 :
115123 return "Level 1"
116124
125+ def __readme_analysis (json_obj ):
126+ """Function that checks if readme exists and counts the number of practices
127+ Good practices taken into consideration: installation, acknowledgement, requirement, description
128+ Returns
129+ ---------
130+ Nothing
131+ """
132+ if not json_obj ['readmeUrl' ]:
133+ output ['num_no_readme' ] += 1
134+ else :
135+ output ['num_with_readme' ] += 1
136+ if json_obj ['installation' ]:
137+ output ['num_with_installation' ] += 1
138+ if json_obj ['acknowledgement' ]:
139+ output ['num_with_acknowledgment' ] += 1
140+ if json_obj ['requirement' ]:
141+ output ['num_with_requirement' ] += 1
142+ if json_obj ['description' ]:
143+ output ['num_with_description' ] += 1
144+
145+
117146def __findCitation (json_obj ):
118147 """Function that counts the number of repositories per citation
119148 Returns
@@ -127,6 +156,21 @@ def __findCitation(json_obj):
127156 else :
128157 output ['no_citation' ] += 1
129158
159+ def __languages (json_obj ):
160+ try :
161+ for language in json_obj ['languages' ]:
162+ if language in output ['language_count' ]:
163+ output ['language_count' ][language ] += 1
164+ else :
165+ output ['language_count' ][language ] = 1
166+ except :
167+ if 'ERROR' in output ['language_count' ]:
168+ output ['language_count' ]['ERROR' ].append (json_obj ['id' ])
169+ else :
170+ output ['language_count' ]['ERROR' ] = []
171+ output ['language_count' ]['ERROR' ].append (json_obj ['id' ])
172+
173+
130174
131175#function that opens array of jsons given the organisation
132176def __open_Json (directory ):
@@ -160,13 +204,14 @@ def create_summary(directory_org_data,outFile, want2Upload):
160204 # finds identifiers
161205 __findId (item )
162206 # gives readme evaluation
163- output [ 'readme' ][ readme_score (item )] = output [ 'readme' ][ readme_score ( item )] + 1
207+ __readme_analysis (item )
164208 # release time
165209 output ['released' ][__last_update (item )] = output ['released' ][__last_update (item )] + 1
166210 # adds org_name
167211 output ['_org_name' ] = item ['owner' ]
168212 output ['num_repos' ] += 1
169-
213+ #licenses
214+ __languages (item )
170215
171216 # saves dictionary to json file
172217 with open (outFile + "/" + item ['owner' ] + "_summary.json" , 'w+' ) as out_file :
0 commit comments