def update_license_statistics(suites): # compute License stats license_stats_file = os.path.join(conf['cache_dir'], 'license_stats.data') dual_license_file = os.path.join(conf['cache_dir'], 'dual_license.data') license_stats = dict() license_d_stats = dict() hist_lic = dict((suite, HistoryCopyright(suite, timestamp=now)) for suite in suites) results = statistics.get_licenses(session) for suite in suites: temp = dict( (item[0], item[2]) for item in results if item[1] == suite) summary = statistics.licenses_summary(temp) for res in summary: license_stats[suite + "." + res.rstrip()] = summary[res] setattr(hist_lic[suite], 'license', res.replace('_', ' ')) setattr(hist_lic[suite], 'files', summary[res]) if not conf['dry_run'] and 'db' in conf['backends']: session.add(hist_lic[suite]) # no historical here, only save to file dual_query = statistics.licenses_summary_w_dual(temp) for res in dual_query: license_d_stats[suite + "." + res.rstrip()] = dual_query[res] # overall dual licenses overall_d_licenses = statistics.licenses_summary_w_dual( statistics.get_licenses(session, 'ALL')) for stat in overall_d_licenses: license_d_stats['overall.' + stat] = overall_d_licenses[stat] # save dual licenses to file if not conf['dry_run'] and 'fs' in conf['backends']: statistics.save_metadata_cache(license_d_stats, dual_license_file) session.flush() overall_licenses = statistics.licenses_summary( statistics.get_licenses(session, 'ALL')) for stat in overall_licenses: lic = HistoryCopyright('ALL', timestamp=now) setattr(lic, 'license', stat.replace('_', ' ')) setattr(lic, 'files', overall_licenses[stat]) license_stats['overall.' + stat] = overall_licenses[stat] if not conf['dry_run'] and 'db' in conf['backends']: session.add(lic) session.flush() if not conf['dry_run'] and 'fs' in conf['backends']: statistics.save_metadata_cache(license_stats, license_stats_file)
def update_license_statistics(suites): # compute License stats license_stats_file = os.path.join(conf['cache_dir'], 'license_stats.data') dual_license_file = os.path.join(conf['cache_dir'], 'dual_license.data') license_stats = dict() license_d_stats = dict() hist_lic = dict((suite, HistoryCopyright(suite, timestamp=now)) for suite in suites) results = statistics.get_licenses(session) for suite in suites: temp = dict((item[0], item[2]) for item in results if item[1] == suite) summary = statistics.licenses_summary(temp) for res in summary: license_stats[suite + "." + res.rstrip()] = summary[res] setattr(hist_lic[suite], 'license', res.replace('_', ' ')) setattr(hist_lic[suite], 'files', summary[res]) if not conf['dry_run'] and 'db' in conf['backends']: session.add(hist_lic[suite]) # no historical here, only save to file dual_query = statistics.licenses_summary_w_dual(temp) for res in dual_query: license_d_stats[suite + "." + res.rstrip()] = dual_query[res] # overall dual licenses overall_d_licenses = statistics.licenses_summary_w_dual( statistics.get_licenses(session, 'ALL')) for stat in overall_d_licenses: license_d_stats['overall.' + stat] = overall_d_licenses[stat] # save dual licenses to file if not conf['dry_run'] and 'fs' in conf['backends']: statistics.save_metadata_cache(license_d_stats, dual_license_file) session.flush() overall_licenses = statistics.licenses_summary( statistics.get_licenses(session, 'ALL')) for stat in overall_licenses: lic = HistoryCopyright('ALL', timestamp=now) setattr(lic, 'license', stat.replace('_', ' ')) setattr(lic, 'files', overall_licenses[stat]) license_stats['overall.' + stat] = overall_licenses[stat] if not conf['dry_run'] and 'db' in conf['backends']: session.add(lic) session.flush() if not conf['dry_run'] and 'fs' in conf['backends']: statistics.save_metadata_cache(license_stats, license_stats_file)
def update_license_statistics(suites): # compute License stats license_stats_file = conf["cache_dir"] / "license_stats.data" dual_license_file = conf["cache_dir"] / "dual_license.data" license_stats = dict() license_d_stats = dict() hist_lic = { suite: HistoryCopyright(suite, timestamp=now) for suite in suites } results = statistics.get_licenses(session) for suite in suites: temp = {item[0]: item[2] for item in results if item[1] == suite} summary = statistics.licenses_summary(temp) for res in summary: license_stats[suite + "." + res.rstrip()] = summary[res] setattr(hist_lic[suite], "license", res.replace("_", " ")) setattr(hist_lic[suite], "files", summary[res]) if not conf["dry_run"] and "db" in conf["backends"]: session.add(hist_lic[suite]) # no historical here, only save to file dual_query = statistics.licenses_summary_w_dual(temp) for res in dual_query: license_d_stats[suite + "." + res.rstrip()] = dual_query[res] # overall dual licenses overall_d_licenses = statistics.licenses_summary_w_dual( statistics.get_licenses(session, "ALL")) for stat in overall_d_licenses: license_d_stats["overall." + stat] = overall_d_licenses[stat] # save dual licenses to file if not conf["dry_run"] and "fs" in conf["backends"]: statistics.save_metadata_cache(license_d_stats, dual_license_file) session.flush() overall_licenses = statistics.licenses_summary( statistics.get_licenses(session, "ALL")) for stat in overall_licenses: lic = HistoryCopyright("ALL", timestamp=now) setattr(lic, "license", stat.replace("_", " ")) setattr(lic, "files", overall_licenses[stat]) license_stats["overall." + stat] = overall_licenses[stat] if not conf["dry_run"] and "db" in conf["backends"]: session.add(lic) session.flush() if not conf["dry_run"] and "fs" in conf["backends"]: statistics.save_metadata_cache(license_stats, license_stats_file)
def update_license_charts(): # License: historical histogramms for (period, granularity) in CHARTS: for suite in suites + ['ALL']: mseries = getattr(statistics, 'history_copyright_' + granularity)(session, interval=period, suite=suite) chart_file = os.path.join( conf['cache_dir'], 'stats', 'copyright_%s-license-%s.png' % (suite, period.replace(' ', '-'))) if not conf['dry_run']: charts.multiseries_plot(mseries, chart_file, cols=3) # License: overall pie chart overall_licenses = statistics.licenses_summary( statistics.get_licenses(session, 'ALL')) ratio = qry.get_ratio(session) chart_file = os.path.join(conf['cache_dir'], 'stats', 'copyright_overall-license_pie.png') if not conf['dry_run']: charts.pie_chart(overall_licenses, chart_file, ratio) # License: bar chart and per suite pie chart. all_suites = statistics.sticky_suites(session) \ + __target_suites(session, None) licenses_per_suite = [] results = statistics.get_licenses(session) for suite in all_suites: temp = dict( (item[0], item[2]) for item in results if item[1] == suite) licenses = statistics.licenses_summary(temp) ratio = qry.get_ratio(session, suite=suite) # draw license pie chart if not conf['dry_run']: chart_file = os.path.join( conf['cache_dir'], 'stats', 'copyright_%s' '-license_pie-current.png' % suite) charts.pie_chart(licenses, chart_file, ratio) licenses_per_suite.append(licenses) chart_file = os.path.join(conf['cache_dir'], 'stats', 'copyright_license_bar_plot.png') if not conf['dry_run']: charts.bar_chart(licenses_per_suite, all_suites, chart_file, top_langs, 'Number of files')
def update_license_charts(): # License: historical histogramms for (period, granularity) in CHARTS: for suite in suites + ['ALL']: mseries = getattr(statistics, 'history_copyright_' + granularity)( session, interval=period, suite=suite) chart_file = os.path.join(conf['cache_dir'], 'stats', 'copyright_%s-license-%s.png' % (suite, period.replace(' ', '-'))) if not conf['dry_run']: charts.multiseries_plot(mseries, chart_file, cols=3) # License: overall pie chart overall_licenses = statistics.licenses_summary( statistics.get_licenses(session, 'ALL')) ratio = qry.get_ratio(session) chart_file = os.path.join(conf['cache_dir'], 'stats', 'copyright_overall-license_pie.png') if not conf['dry_run']: charts.pie_chart(overall_licenses, chart_file, ratio) # License: bar chart and per suite pie chart. all_suites = statistics.sticky_suites(session) \ + __target_suites(session, None) licenses_per_suite = [] results = statistics.get_licenses(session) for suite in all_suites: temp = dict((item[0], item[2]) for item in results if item[1] == suite) licenses = statistics.licenses_summary(temp) ratio = qry.get_ratio(session, suite=suite) # draw license pie chart if not conf['dry_run']: chart_file = os.path.join(conf['cache_dir'], 'stats', 'copyright_%s' '-license_pie-current.png' % suite) charts.pie_chart(licenses, chart_file, ratio) licenses_per_suite.append(licenses) chart_file = os.path.join(conf['cache_dir'], 'stats', 'copyright_license_bar_plot.png') if not conf['dry_run']: charts.bar_chart(licenses_per_suite, all_suites, chart_file, top_langs, 'Number of files')
def update_license_charts(): # License: historical histogramms for (period, granularity) in CHARTS: for suite in suites + ["ALL"]: mseries = getattr(statistics, "history_copyright_" + granularity)(session, interval=period, suite=suite) filename = "copyright_%s-license-%s.png" % ( suite, period.replace(" ", "-"), ) chart_file = conf["cache_dir"] / "stats" / filename if not conf["dry_run"]: charts.multiseries_plot(mseries, chart_file, cols=3) # License: overall pie chart overall_licenses = statistics.licenses_summary( statistics.get_licenses(session, "ALL")) ratio = qry.get_ratio(session) chart_file = conf[ "cache_dir"] / "stats" / "copyright_overall-license_pie.png" if not conf["dry_run"]: charts.pie_chart(overall_licenses, chart_file, ratio) # License: bar chart and per suite pie chart. all_suites = statistics.sticky_suites(session) + __target_suites( session, None) licenses_per_suite = [] for suite in all_suites: licenses = statistics.licenses_summary( statistics.get_licenses(session, suite)) ratio = qry.get_ratio(session, suite=suite) # draw license pie chart if not conf["dry_run"]: filename = "copyright_%s-license_pie-current.png" % suite chart_file = conf["cache_dir"] / "stats" / filename charts.pie_chart(licenses, chart_file, ratio) licenses_per_suite.append(licenses) chart_file = conf[ "cache_dir"] / "stats" / "copyright_license_bar_plot.png" if not conf["dry_run"]: charts.bar_chart(licenses_per_suite, all_suites, chart_file, top_langs, "Number of files")
def test_license_summary(self): expected_stats = { 'BSD-3-clause': 1, 'GFDL-1.3+': 6, 'GPL-2': 31, 'GPL-2+': 105 } jessie_stats = statistics.licenses_summary(dict( statistics.get_licenses(self.session, 'jessie'))) self.assertDictContainsSubset(expected_stats, jessie_stats)
def test_license_summary(self): expected_stats = { 'BSD-3-clause': 1, 'GFDL-1.3+': 6, 'GPL-2': 31, 'GPL-2+': 105 } jessie_stats = statistics.licenses_summary( dict(statistics.get_licenses(self.session, 'jessie'))) self.assertDictContainsSubset(expected_stats, jessie_stats)
def test_license_summary(self): expected_stats = { "BSD-3-clause": 1, "GFDL-1.3+": 6, "GPL-2": 31, "GPL-2+": 105 } jessie_stats = statistics.licenses_summary( dict(statistics.get_licenses(self.session, "jessie"))) self.assertDictContainsSubset(expected_stats, jessie_stats)