22import math
33import functools
44
5+
56def calculate_score (repo ):
67 # initial score is 50 to give active repos with low GitHub KPIs (forks, watchers, stars) a better starting point
78 iScore = float (50 )
89
910 # weighting: forks and watches count most, then stars, add some little score for open issues, too
1011 iScore += repo ["forks_count" ] * 5
11- iScore += ' subscribers_count' in repo or 0
12+ iScore += " subscribers_count" in repo or 0
1213 iScore += repo ["stargazers_count" ] / 3
1314 iScore += repo ["open_issues_count" ] / 5
1415
1516 # updated in last 3 months: adds a bonus multiplier between 0..1 to overall score (1 = updated today, 0 = updated more than 100 days ago)
16- iDaysSinceLastUpdate = (datetime .datetime .now ().timestamp () - datetime .datetime .strptime (repo ['updated_at' ], '%Y-%m-%dT%H:%M:%SZ' ).timestamp ()) / 86400
17+ iDaysSinceLastUpdate = (
18+ datetime .datetime .now ().timestamp ()
19+ - datetime .datetime .strptime (
20+ repo ["updated_at" ], "%Y-%m-%dT%H:%M:%SZ"
21+ ).timestamp ()
22+ ) / 86400
1723 iScore = iScore * ((1 + (100 - min (iDaysSinceLastUpdate , 100 ))) / 100 )
1824
1925 # evaluate participation stats for the previous 3 months
20- if repo ['_InnerSourceMetadata' ]: repo ['_InnerSourceMetadata' ] or {}
26+ if repo ["_InnerSourceMetadata" ]:
27+ repo ["_InnerSourceMetadata" ] or {}
2128
22- if ' participation' in repo [' _InnerSourceMetadata' ]:
29+ if " participation" in repo [" _InnerSourceMetadata" ]:
2330 # average commits: adds a bonus multiplier between 0..1 to overall score (1 = >10 commits per week, 0 = less than 3 commits per week)
24- sliced = repo ['_InnerSourceMetadata' ]['participation' ][len (repo ['_InnerSourceMetadata' ]['participation' ]) - 13 :]
31+ sliced = repo ["_InnerSourceMetadata" ]["participation" ][
32+ len (repo ["_InnerSourceMetadata" ]["participation" ]) - 13 :
33+ ]
2534
26- iAverageCommitsPerWeek = functools .reduce (lambda a , b : a + b , sliced ) / 13
35+ iAverageCommitsPerWeek = functools .reduce (lambda a , b : a + b , sliced ) / 13
2736
2837 iScore = iScore * ((1 + (min (max (iAverageCommitsPerWeek - 3 , 0 ), 7 ))) / 7 )
2938
3039 # boost calculation:
3140 # all repositories updated in the previous year will receive a boost of maximum 1000 declining by days since last update
32- iBoost = ( 1000 - min (iDaysSinceLastUpdate , 365 ) * 2.74 )
41+ iBoost = 1000 - min (iDaysSinceLastUpdate , 365 ) * 2.74
3342 # gradually scale down boost according to repository creation date to mix with "real" engagement stats
34- iDaysSinceCreation = (datetime .datetime .now ().timestamp () - datetime .datetime .strptime (repo ['created_at' ], '%Y-%m-%dT%H:%M:%SZ' ).timestamp ()) / 86400
43+ iDaysSinceCreation = (
44+ datetime .datetime .now ().timestamp ()
45+ - datetime .datetime .strptime (
46+ repo ["created_at" ], "%Y-%m-%dT%H:%M:%SZ"
47+ ).timestamp ()
48+ ) / 86400
3549 iBoost *= (365 - min (iDaysSinceCreation , 365 )) / 365
3650 # add boost to score
3751 iScore += iBoost
3852 # give projects with a meaningful description a static boost of 50
39- if len (repo ["description" ]) > 30 and repo ["_InnerSourceMetadata" ] or ("motivation" in repo ["_InnerSourceMetadata" ] and repo ["_InnerSourceMetadata" ]["motivation" ].length > 30 ):
53+ if (
54+ len (repo ["description" ]) > 30
55+ and repo ["_InnerSourceMetadata" ]
56+ or (
57+ "motivation" in repo ["_InnerSourceMetadata" ]
58+ and repo ["_InnerSourceMetadata" ]["motivation" ].length > 30
59+ )
60+ ):
4061 iScore += 50
4162 # give projects with contribution guidelines (CONTRIBUTING.md) file a static boost of 100
4263 if repo ["_InnerSourceMetadata" ] and "guidelines" in repo ["_InnerSourceMetadata" ]:
@@ -46,8 +67,8 @@ def calculate_score(repo):
4667 iScore = 3000 + math .log (iScore ) * 100
4768 # final score is a rounded value starting from 0 (subtract the initial value)
4869 iScore = round (iScore - 50 )
49-
70+
5071 # add score to metadata on the fly
51- repo [' _InnerSourceMetadata' ][ ' score' ] = iScore
72+ repo [" _InnerSourceMetadata" ][ " score" ] = iScore
5273
5374 return iScore
0 commit comments