Last active
August 29, 2015 13:55
-
-
Save dzhibas/8772697 to your computer and use it in GitHub Desktop.
zf2 module scoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'nikolajus' | |
import subprocess | |
import requests | |
import json | |
from urlparse import urlparse | |
from time import strptime, mktime | |
from datetime import datetime, timedelta | |
from math import log10 | |
""" | |
Kpn scores | |
It does by considering the following factors: | |
1 point for each followers on GitHub. This is an indicator of the bundle's popularity in the community. | |
5 points if your README is more than 300 characters long. Encourages maintainer to write a proper README. | |
5 points if you use Travis CI, since it means you have a running test suite. | |
5 more points if your Travis CI build status is actually ok ;) | |
5 points if you provide a Composer package. | |
5 points per person recommending the bundle on KnpBundles. | |
Small boost (the actual formula is (30 - days) / 5) for bundles with commits in the past 30 days. Active bundles get more points, but not much to avoid spoiling stable bundles. | |
For more details on the items above please refer to the remaining answers. | |
1*info[subscribers_count] | |
1*info[watchers_count] same as 1*info[stargazers_count] | |
forks | |
open_issues_count | |
size of repo | |
last push info[pushed_at] | |
if travis | |
https://raw2.github.com/EvanDotPro/EdpGithub/master/.travis.yml | |
if readme | |
https://raw2.github.com/EvanDotPro/EdpGithub/master/README.md | |
https://raw2.github.com/EvanDotPro/EdpGithub/master/README.markdown | |
https://raw2.github.com/EvanDotPro/EdpGithub/master/README.txt | |
https://raw2.github.com/EvanDotPro/EdpGithub/master/README | |
https://raw2.github.com/EvanDotPro/EdpGithub/master/README.rst | |
https://raw2.github.com/EvanDotPro/EdpGithub/master/README. | |
package exists if: | |
https://packagist.org/packages/rmzamora/media-bundle | |
is HTTP 200 OK | |
""" | |
modules = [ | |
"https://github.com/ZF-Commons/ZfcUser", | |
"https://github.com/ZF-Commons/ZfcUserDoctrineORM", | |
"https://github.com/doctrine/DoctrineModule", | |
"https://github.com/Bacon/BaconAssetLoader", | |
"https://github.com/albulescu/zf2-module-assets", | |
"https://github.com/widmogrod/zf2-assetic-module", | |
"https://github.com/EvanDotPro/EdpGithub", | |
"https://github.com/coogle/Logger", | |
"https://github.com/coogle/MultiDatabase", | |
"https://github.com/coogle/Twilio", | |
"https://github.com/coogle/CoogleLib", | |
"https://github.com/coogle/OAuth2", | |
"https://github.com/AndyDune/RznViewComponent", | |
"https://github.com/radnan/rdn-doctrine", | |
"https://github.com/vodiahco/DDataAcl", | |
"https://github.com/carnage/mailchimp", | |
"https://github.com/vodiahco/dhtml", | |
"https://github.com/RayaMedia/yimaTheme", | |
"https://github.com/bushbaby/BsbDoctrineReconnect", | |
"https://github.com/diemuzi/mp3", | |
"https://github.com/zf-fr/zfr-stripe-module", | |
"https://github.com/libracms/libra-assets-installer", | |
"https://github.com/middleout/third-party-connect", | |
"https://github.com/acelaya/ZF2-AcMailer", | |
"https://github.com/stefanorg/JHttps", | |
"https://github.com/ojhaujjwal/auth", | |
"https://github.com/pruno/ZF2-MongoDB-VirtualCollections", | |
"https://github.com/mtymek/MtMail", | |
"https://github.com/enlitepro/enlite-monolog", | |
"https://github.com/buggymanhq/buggyman-module", | |
"https://github.com/bushbaby/BsbLocalizedTemplatePathStack", | |
"https://github.com/openWorkers/osw-asset-helper", | |
"https://github.com/bushbaby/BsbTranslateControllerPlugin", | |
"https://github.com/codeliner/zf2-cqrs-module", | |
"https://github.com/martyshka/ShoppingCart", | |
"https://github.com/macnibblet/MCNElasticSearch", | |
"https://github.com/blanchonvincent/NamedArgumentsDispatching", | |
"https://github.com/zf-fr/zfr-cors", | |
"https://github.com/SCLInternet/SclContact", | |
"https://github.com/ipascual/MyZend_Minify", | |
"https://github.com/dwolke/DwApcInfo", | |
"https://github.com/vikey89/ZendCart", | |
"https://github.com/snapshotpl/ZfSnapGeoip", | |
"https://github.com/mxc-commons/MxcRouteGuard", | |
"https://github.com/ipascual/MyZend_Core", | |
"https://github.com/macnibblet/MCNEmail", | |
"https://github.com/macnibblet/MCNCommon", | |
"https://github.com/jhekasoft/HtmlShortcode", | |
"https://github.com/spiffyjr/spiffy-routes", | |
"https://github.com/SCLInternet/BmCalendar", | |
"https://github.com/xFran/TarSignup", | |
"https://github.com/ze-pequeno/pequeno-spotify-module", | |
] | |
def get_repo_info(uri): | |
link = "https://api.github.com/repos" + uri | |
print(link) | |
r = requests.get(link, auth=('****', '****')) | |
if r.status_code != 200: | |
return None | |
try: | |
return json.loads(r.text) | |
except KeyError: | |
return None | |
""" | |
returns 1 if it has travis config 0 if no | |
lets assume everyone has travis | |
""" | |
def has_travis(uri): | |
return 1 | |
""" | |
returns 1 if there is readme and 0 if no | |
lets assume everyone has readme | |
""" | |
def has_readme(uri): | |
return 1 | |
""" | |
returns 1 if there is composer package and 0 if not | |
lets assume everyone has package registered | |
""" | |
def has_composer_package(uri): | |
return 1 | |
repos_data = [] | |
forks = [] | |
subscribers = [] | |
watchers = [] | |
size = [] | |
last_commit_in = [] | |
issues = [] | |
idx = 0 | |
for url in modules: | |
idx += 1 | |
print("Fetch {0} out of {1}".format(idx, len(modules))) | |
uri = urlparse(url).path | |
info = get_repo_info(uri) | |
if info is None: | |
continue | |
last_push = datetime.strptime(info['pushed_at'], "%Y-%m-%dT%H:%M:%SZ") | |
delta = datetime.today() - last_push | |
forks.append(info['forks']) | |
subscribers.append(info['subscribers_count']) | |
watchers.append(info['watchers_count']) | |
size.append(info['size']) | |
last_commit_in.append(1. / (1+log10(1+delta.days))) | |
issues.append(info['open_issues_count']) | |
repos_data.append([uri, info['forks'], info['subscribers_count'], info['watchers_count'], info['size'], 1. / (1+log10(1+delta.days)), info['open_issues_count']]) | |
def score(repo): | |
# forks | |
f1 = (float(repo[1])-min(forks)) / (max(forks) - min(forks)) | |
# subscribers | |
f2 = (float(repo[2])-min(subscribers)) / (max(subscribers) - min(subscribers)) | |
# watchers | |
f3 = (float(repo[3])-min(watchers)) / (max(watchers) - min(watchers)) | |
# size | |
f4 = ((float(repo[4])-min(size)) / (max(size) - min(size))) | |
# last push | |
f5 = float(repo[5]) | |
# issues | |
f6 = ((float(repo[6])-min(issues)) / (max(issues) - min(issues))) | |
f7 = 1. * has_readme(repo[0]) | |
f8 = 1. * has_travis(repo[0]) | |
f9 = 1. * has_composer_package(repo[0]) | |
# sum = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 | |
s = f1 + f2 + f3 + f6 + .1 * f5 | |
print("{0} {1} {2} {3} {4} {5} {6}".format(repo[0], f1, f2, f3, f6, .1*f5, s)) | |
# rescale to 1-10 scale | |
rescale = (99./4.1)*(s-0+1) | |
return rescale | |
for_sort = {} | |
for repo in repos_data: | |
for_sort[repo[0]] = score(repo) | |
print(for_sort) | |
for i in sorted(for_sort.items(), key=lambda x:x[1], reverse=True): | |
print("{0}\t{1}".format(int(i[1]), i[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment