@@ -32,11 +32,13 @@ function read_files(target_path) {
3232 //.filter(item => !item.isDirectory())
3333 . filter ( name => path . extname ( name ) === target_ext ) ;
3434 if ( local_debug ) console . log ( '_names:' , _names ) ;
35+
3536 let _content = fs . readdirSync ( target_path )
3637 //.filter(item => !item.isDirectory())
3738 . filter ( name => path . extname ( name ) === target_ext )
3839 . map ( name => require ( path . join ( target_path , name ) ) ) ;
3940 if ( local_debug ) console . log ( '_content:' , _content ) ;
41+
4042 for ( let i = 0 ; i < _names . length ; i ++ ) {
4143 const id = _names [ i ] . split ( '.' ) [ 0 ] ;
4244 _out [ id ] = _content [ i ] ;
@@ -50,11 +52,15 @@ function data_lint(data) {
5052 let reason = '' ;
5153 if ( ( typeof project_data . name !== 'string' ) || ( project_data . name . length == 0 ) ) reason += 'name; ' ;
5254 if ( typeof project_data . relations !== 'object' ) reason += 'relations; ' ; // 'array'
55+
5356 if ( typeof project_data . note !== 'string' ) reason += 'note; ' ; // || (relation.name.length == 0)
5457 if ( typeof project_data . meta !== 'object' ) reason += 'meta; ' ;
58+
5559 if ( typeof project_data . meta . migrated_commit !== 'string' ) reason += 'meta.migrated_commit; ' ; // || (relation.meta.migrated_commit == 0)
60+
5661 if ( ( typeof project_data . meta . added_by !== 'string' ) || ( project_data . meta . added_by == 0 ) ) reason += 'meta.added_by; ' ;
5762 if ( typeof project_data . meta . add_date !== 'string' ) reason += 'meta.add_date; ' ; // || (relation.meta.add_date == 0)
63+
5864 for ( let i = 0 ; i < project_data . relations . length ; i ++ ) {
5965 const relation = project_data . relations [ i ] ;
6066 if ( ( typeof relation . name !== 'string' ) || ( relation . name . length == 0 ) ) reason += 'relation.name; ' ;
@@ -77,14 +83,21 @@ function get_score(data) {
7783 'relations_count' : { }
7884 } ;
7985 for ( const project_data of Object . values ( data ) ) {
86+ if ( ! project_data . meta . added_by ) console . log ( 'No "Added by" field:' , project_data ) ;
87+ if ( ! project_data . name ) console . log ( 'No "Added by" field:' , project_data ) ;
88+
8089 if ( ! score . adders [ project_data . meta . added_by ] ) score . adders [ project_data . meta . added_by ] = 0 ;
8190 if ( ! score . relations_count [ project_data . name ] ) score . relations_count [ project_data . name ] = 0 ;
91+
8292 score . adders [ project_data . meta . added_by ] += 1 ;
8393 score . relations_count [ project_data . name ] += 1 ;
94+
8495 for ( let ii = 0 ; ii < project_data . relations . length ; ii ++ ) {
8596 const relation = project_data . relations [ ii ] ;
97+
8698 if ( ! score . adders [ relation . meta . added_by ] ) score . adders [ relation . meta . added_by ] = 0 ;
8799 score . adders [ relation . meta . added_by ] += 1 ;
100+
88101 if ( ! score . relations_count [ relation . name ] ) score . relations_count [ relation . name ] = 0 ;
89102 score . relations_count [ relation . name ] += 1 ;
90103 }
@@ -104,19 +117,26 @@ function require_project(project_id) {
104117}
105118
106119// http://stackoverflow.com/a/25500462/8175291
107- function dict_sort ( dict ) {
120+ function dict_sort ( dict , keys_pos_inverted = true ) {
108121 // Create items array
109- var items = Object . keys ( dict ) . map ( ( key ) => {
122+ var items = Object . keys ( dict ) . sort ( ) . map ( ( key ) => {
110123 return [ key , dict [ key ] ] ;
111124 } ) ;
112125
113126 // Sort the array based on the second element
114127 items . sort ( ( first , second ) => {
115128 return second [ 1 ] - first [ 1 ] ;
116129 } ) ;
117- var items2 = [ ]
118- for ( let i = 0 ; i < items . length ; i ++ ) {
119- items2 . push ( [ items [ i ] [ 1 ] , items [ i ] [ 0 ] ] ) ;
130+ var items2 = [ ] ;
131+ if ( keys_pos_inverted ) {
132+ for ( let i = 0 ; i < items . length ; i ++ ) {
133+ items2 . push ( [ items [ i ] [ 1 ] , items [ i ] [ 0 ] ] ) ;
134+ }
135+ items2 . sort ( ( first , second ) => {
136+ return second [ 1 ] - first [ 1 ] ;
137+ } ) ;
138+ } else {
139+ items2 = items ;
120140 }
121141
122142
@@ -143,23 +163,23 @@ async function main() {
143163 //console.log('jsonData:', jsonData);
144164
145165 const _out = read_files ( target_path ) ;
146- console . log ( '_out :' , _out ) ;
166+ console . log ( 'read_files (1) :' , _out ) ;
147167
148168 const score = get_score ( _out ) ;
149- console . log ( 'get_score 1 :' , score ) ;
169+ console . log ( 'get_score (1) :' , score ) ;
150170
151171
152172 const _out2 = read_files ( target_path + 'outsourcing\\' ) ;
153173 const score2 = get_score ( _out2 ) ;
154174 let score2_sorted = { 'adders' : dict_sort ( score2 . adders ) , 'relations_count' : dict_sort ( score2 . relations_count ) } ;
155- console . log ( 'get_score 2 sort:' , score2_sorted ) ;
175+ console . log ( 'get_score (2) sort:' , score2_sorted ) ;
156176
157177
158178 const unaccepted = data_lint ( _out ) ;
159- console . log ( 'unaccepted 1 :' , unaccepted ) ;
179+ console . log ( 'unaccepted (read_files 1) :' , unaccepted ) ;
160180
161181 const unaccepted2 = data_lint ( _out2 ) ;
162- console . log ( 'unaccepted 2 :' , unaccepted2 ) ;
182+ console . log ( 'unaccepted (read_files 2) :' , unaccepted2 ) ;
163183
164184}
165185
0 commit comments