def get_repo_commit_stats (gh, reponame): """Get statistics for the logged-in user's commits in the named repository. The `reponame` should look something like "pkgw/bibtools". Returns a Holder. """ from inifile import Holder repo = gh.get_repo (reponame) res = Holder (commits=0, lines=0) latest = None for c in repo.get_commits (author=gh.get_user ()): res.commits += 1 # I want to count the total lines committed, but this requires # fetching the full commit information for each commit, which is slow # and blows up my GitHup API rate limit. TODO: figure out alternative # metric? ### XXX res.lines += c.stats.total if latest is None: latest = c.commit.committer.date else: latest = max (latest, c.commit.committer.date) res.latest_date = latest return res
def setup_processing (render, datadir): context = Holder () context.render = render context.items = list (load (datadir)) context.pubs = [i for i in context.items if i.section == 'pub'] context.pubgroups = partition_pubs (context.pubs) context.props = [i for i in context.items if i.section == 'prop'] context.time_allocs = compute_time_allocations (context.props) context.cur_formatter = None context.my_abbrev_name = None commands = {} commands['CITESTATS'] = cmd_cite_stats commands['FORMAT'] = cmd_format commands['MYABBREVNAME'] = cmd_my_abbrev_name commands['PUBLIST'] = cmd_pub_list commands['TALLOCLIST'] = cmd_talloc_list commands['RMISCLIST'] = cmd_rev_misc_list commands['RMISCLIST_IF'] = cmd_rev_misc_list_if commands['RMISCLIST_IF_NOT'] = cmd_rev_misc_list_if_not commands['TODAY.'] = cmd_today return context, commands
def get_repo_impact_stats (gh, reponame): """Get statistics that try to get at the impact/popularity of a particular repository. The `reponame` should look something like "pkgw/bibtools". Returns a Holder. """ from inifile import Holder from time import sleep repo = gh.get_repo (reponame) res = Holder () res.description = repo.description # OK this isn't impact but it's handy # It can take GitHub a little while to compute the 'stats' items, in which # case the relevant binding functions will return None. We make these # requests first, then make other ones; the hope is that by the time we # come back and retry, the stats will have been computed. def retry (func, first_try): if first_try is not None: return first_try for i in xrange (5): result = func () if result is not None: return result sleep (1) raise Exception ('function %r took too long' % func) contrib = repo.get_stats_contributors () res.commits = github_list_size (repo.get_commits ()) # this counts commits on main branch res.forks = github_list_size (repo.get_forks ()) res.stars = github_list_size (repo.get_stargazers ()) res.contributors = github_list_size (retry (repo.get_stats_contributors, contrib)) return res
def partition_pubs (pubs): groups = Holder () groups.all = [] groups.refereed = [] groups.refpreprint = [] groups.non_refereed = [] groups.all_formal = [] groups.all_non_refereed = [] groups.informal = [] for pub in pubs: refereed = (pub.refereed == 'y') refpreprint = (pub.get ('refpreprint', 'n') == 'y') formal = (pub.get ('informal', 'n') == 'n') # we assume refereed implies formal. groups.all.append (pub) if formal: groups.all_formal.append (pub) if refereed: groups.refereed.append (pub) elif refpreprint: groups.refpreprint.append (pub) else: groups.all_non_refereed.append (pub) if formal: groups.non_refereed.append (pub) else: groups.informal.append (pub) groups.all_rev = groups.all[::-1] groups.refereed_rev = groups.refereed[::-1] groups.refpreprint_rev = groups.refpreprint[::-1] groups.non_refereed_rev = groups.non_refereed[::-1] groups.informal_rev = groups.informal[::-1] return groups
def compute_cite_stats (pubs): """Compute an h-index and other stats from the known publications.""" from time import gmtime stats = Holder () stats.refpubs = 0 stats.refcites = 0 stats.reffirstauth = 0 cites = [] dates = [] for pub in pubs: if pub.refereed == 'y': stats.refpubs += 1 if int (pub.mypos) == 1: stats.reffirstauth += 1 citeinfo = parse_ads_cites (pub) if citeinfo is None: continue if citeinfo.cites < 1: continue cites.append (citeinfo.cites) dates.append (citeinfo.lastupdate) if pub.refereed == 'y': stats.refcites += citeinfo.cites if not len (cites): stats.meddate = 0 stats.hindex = 0 else: ranked = sorted (cites, reverse=True) index = 0 while index < len (ranked) and ranked[index] >= index + 1: index += 1 dates = sorted (dates) stats.meddate = dates[len (dates) // 2] stats.hindex = index stats.year, stats.month, stats.day = gmtime (stats.meddate)[:3] stats.monthstr = months[stats.month - 1] stats.italich = MupItalics ('h') stats.adslink = MupLink ('http://labs.adsabs.harvard.edu/adsabs', 'ADS') return stats
def setup_processing(render, datadir): context = Holder() context.render = render context.items = list(load(datadir)) context.pubs = [i for i in context.items if i.section == "pub"] context.pubgroups = partition_pubs(context.pubs) context.props = [i for i in context.items if i.section == "prop"] context.time_allocs = compute_time_allocations(context.props) context.repos = process_repositories(context.items) context.cite_stats = compute_cite_stats(context.pubgroups.all_formal) context.repo_stats = compute_repo_stats(context.repos) context.talk_stats = summarize_talks([i for i in context.items if i.section == "talk"]) context.engagement_stats = summarize_engagement([i for i in context.items if i.section == "engagement"]) context.cur_formatter = None context.my_abbrev_name = None commands = {} commands["BEGIN_SUBST"] = cmd_begin_subst commands["FORMAT"] = cmd_format commands["MYABBREVNAME"] = cmd_my_abbrev_name commands["PUBLIST"] = cmd_pub_list commands["TALLOCLIST"] = cmd_talloc_list commands["RMISCLIST"] = cmd_rev_misc_list commands["RMISCLIST_IF"] = cmd_rev_misc_list_if commands["RMISCLIST_IF_NOT"] = cmd_rev_misc_list_if_not commands["RREPOLIST"] = cmd_rev_repo_list commands["TODAY."] = cmd_today return context, commands
def partition_pubs(pubs): groups = Holder() groups.all = [] groups.refereed = [] groups.refpreprint = [] groups.non_refereed = [] groups.all_formal = [] groups.all_non_refereed = [] groups.informal = [] for pub in pubs: refereed = pub.refereed == "y" refpreprint = pub.get("refpreprint", "n") == "y" formal = pub.get("informal", "n") == "n" # we assume refereed implies formal. groups.all.append(pub) if formal: groups.all_formal.append(pub) if refereed: groups.refereed.append(pub) elif refpreprint: groups.refpreprint.append(pub) else: groups.all_non_refereed.append(pub) if formal: groups.non_refereed.append(pub) else: groups.informal.append(pub) groups.all_rev = groups.all[::-1] groups.refereed_rev = groups.refereed[::-1] groups.refpreprint_rev = groups.refpreprint[::-1] groups.non_refereed_rev = groups.non_refereed[::-1] groups.informal_rev = groups.informal[::-1] return groups