Beispiel #1
0
 def aggregate(cs):
     for f in cs[2]:
         ext = lower(f.extension)
         if ext in LANGUAGES_EXTENSIONS_MAP.keys() and not f.is_binary:
             if ext in code_stats:
                 code_stats[ext] += 1
             else:
                 code_stats[ext] = 1
Beispiel #2
0
 def aggregate(cs):
     for f in cs[2]:
         ext = lower(f.extension)
         if ext in LANGUAGES_EXTENSIONS_MAP.keys() and not f.is_binary:
             if ext in code_stats:
                 code_stats[ext] += 1
             else:
                 code_stats[ext] = 1
Beispiel #3
0
    def index(self, repo_name):
        p = safe_int(request.GET.get('page'), 1)
        size = safe_int(request.GET.get('size'), 10)
        try:
            collection = c.db_repo_scm_instance.get_changesets(reverse=True)
        except EmptyRepositoryError as e:
            h.flash(e, category='warning')
            collection = []
        c.cs_pagination = Page(collection, page=p, items_per_page=size)
        page_revisions = [x.raw_id for x in list(c.cs_pagination)]
        c.cs_comments = c.db_repo.get_comments(page_revisions)
        c.cs_statuses = c.db_repo.statuses(page_revisions)

        c.ssh_repo_url = None
        if request.authuser.is_default_user:
            username = None
        else:
            username = request.authuser.username
            if c.ssh_enabled:
                c.ssh_repo_url = c.db_repo.clone_url(
                    clone_uri_tmpl=c.clone_ssh_tmpl)

        c.clone_repo_url = c.db_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl,
                                               with_id=False,
                                               username=username)
        c.clone_repo_url_id = c.db_repo.clone_url(
            clone_uri_tmpl=c.clone_uri_tmpl, with_id=True, username=username)

        if c.db_repo.enable_statistics:
            c.show_stats = True
        else:
            c.show_stats = False

        stats = Statistics.query() \
            .filter(Statistics.repository == c.db_repo) \
            .scalar()

        c.stats_percentage = 0

        if stats and stats.languages:
            lang_stats_d = ext_json.loads(stats.languages)
            lang_stats = [(x, {
                "count": y,
                "desc": LANGUAGES_EXTENSIONS_MAP.get(x, '?')
            }) for x, y in lang_stats_d.items()]
            lang_stats.sort(key=lambda k: (-k[1]['count'], k[0]))
            c.trending_languages = lang_stats[:10]
        else:
            c.trending_languages = []

        c.enable_downloads = c.db_repo.enable_downloads
        c.readme_data, c.readme_file = \
            self.__get_readme_data(c.db_repo)
        return render('summary/summary.html')
Beispiel #4
0
    def statistics(self, repo_name):
        if c.db_repo.enable_statistics:
            c.show_stats = True
            c.no_data_msg = _('No data ready yet')
        else:
            c.show_stats = False
            c.no_data_msg = _('Statistics are disabled for this repository')

        td = date.today() + timedelta(days=1)
        td_1m = td - timedelta(days=calendar.mdays[td.month])
        td_1y = td - timedelta(days=365)

        ts_min_m = mktime(td_1m.timetuple())
        ts_min_y = mktime(td_1y.timetuple())
        ts_max_y = mktime(td.timetuple())
        c.ts_min = ts_min_m
        c.ts_max = ts_max_y

        stats = self.sa.query(Statistics) \
            .filter(Statistics.repository == c.db_repo) \
            .scalar()
        c.stats_percentage = 0
        if stats and stats.languages:
            c.no_data = False is c.db_repo.enable_statistics
            lang_stats_d = json.loads(stats.languages)
            c.commit_data = stats.commit_activity
            c.overview_data = stats.commit_activity_combined

            lang_stats = ((x, {"count": y,
                               "desc": LANGUAGES_EXTENSIONS_MAP.get(x)})
                          for x, y in lang_stats_d.items())

            c.trending_languages = json.dumps(
                sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10]
            )
            last_rev = stats.stat_on_revision + 1
            c.repo_last_rev = c.db_repo_scm_instance.count() \
                if c.db_repo_scm_instance.revisions else 0
            if last_rev == 0 or c.repo_last_rev == 0:
                pass
            else:
                c.stats_percentage = '%.2f' % ((float((last_rev)) /
                                                c.repo_last_rev) * 100)
        else:
            c.commit_data = json.dumps({})
            c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10]])
            c.trending_languages = json.dumps({})
            c.no_data = True

        recurse_limit = 500  # don't recurse more than 500 times when parsing
        run_task(get_commits_stats, c.db_repo.repo_name, ts_min_y,
                 ts_max_y, recurse_limit)
        return render('summary/statistics.html')
Beispiel #5
0
    def statistics(self, repo_name):
        if c.db_repo.enable_statistics:
            c.show_stats = True
            c.no_data_msg = _('No data ready yet')
        else:
            c.show_stats = False
            c.no_data_msg = _('Statistics are disabled for this repository')

        td = date.today() + timedelta(days=1)
        td_1m = td - timedelta(days=calendar.mdays[td.month])
        td_1y = td - timedelta(days=365)

        ts_min_m = mktime(td_1m.timetuple())
        ts_min_y = mktime(td_1y.timetuple())
        ts_max_y = mktime(td.timetuple())
        c.ts_min = ts_min_m
        c.ts_max = ts_max_y

        stats = Statistics.query() \
            .filter(Statistics.repository == c.db_repo) \
            .scalar()
        c.stats_percentage = 0
        if stats and stats.languages:
            c.no_data = False is c.db_repo.enable_statistics
            lang_stats_d = json.loads(stats.languages)
            c.commit_data = json.loads(stats.commit_activity)
            c.overview_data = json.loads(stats.commit_activity_combined)

            lang_stats = ((x, {"count": y,
                               "desc": LANGUAGES_EXTENSIONS_MAP.get(x)})
                          for x, y in lang_stats_d.items())

            c.trending_languages = (
                sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10]
            )
            last_rev = stats.stat_on_revision + 1
            c.repo_last_rev = c.db_repo_scm_instance.count() \
                if c.db_repo_scm_instance.revisions else 0
            if last_rev == 0 or c.repo_last_rev == 0:
                pass
            else:
                c.stats_percentage = '%.2f' % ((float((last_rev)) /
                                                c.repo_last_rev) * 100)
        else:
            c.commit_data = {}
            c.overview_data = ([[ts_min_y, 0], [ts_max_y, 10]])
            c.trending_languages = {}
            c.no_data = True

        recurse_limit = 500  # don't recurse more than 500 times when parsing
        get_commits_stats(c.db_repo.repo_name, ts_min_y, ts_max_y, recurse_limit)
        return render('summary/statistics.html')
Beispiel #6
0
    def index(self, repo_name):
        _load_changelog_summary()

        username = ''
        if self.authuser.username != User.DEFAULT_USER:
            username = safe_str(self.authuser.username)

        _def_clone_uri = _def_clone_uri_by_id = c.clone_uri_tmpl
        if '{repo}' in _def_clone_uri:
            _def_clone_uri_by_id = _def_clone_uri.replace(
                '{repo}', '_{repoid}')
        elif '{repoid}' in _def_clone_uri:
            _def_clone_uri_by_id = _def_clone_uri.replace(
                '_{repoid}', '{repo}')

        c.clone_repo_url = c.db_repo.clone_url(user=username,
                                               uri_tmpl=_def_clone_uri)
        c.clone_repo_url_id = c.db_repo.clone_url(
            user=username, uri_tmpl=_def_clone_uri_by_id)

        if c.db_repo.enable_statistics:
            c.show_stats = True
        else:
            c.show_stats = False

        stats = self.sa.query(Statistics)\
            .filter(Statistics.repository == c.db_repo)\
            .scalar()

        c.stats_percentage = 0

        if stats and stats.languages:
            c.no_data = False is c.db_repo.enable_statistics
            lang_stats_d = json.loads(stats.languages)

            lang_stats = ((x, {
                "count": y,
                "desc": LANGUAGES_EXTENSIONS_MAP.get(x)
            }) for x, y in lang_stats_d.items())

            c.trending_languages = json.dumps(
                sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10])
        else:
            c.no_data = True
            c.trending_languages = json.dumps([])

        c.enable_downloads = c.db_repo.enable_downloads
        c.readme_data, c.readme_file = \
            self.__get_readme_data(c.db_repo)
        return render('summary/summary.html')
Beispiel #7
0
    def index(self, repo_name):
        _load_changelog_summary()

        if request.authuser.is_default_user:
            username = ''
        else:
            username = safe_str(request.authuser.username)

        _def_clone_uri = _def_clone_uri_by_id = c.clone_uri_tmpl
        if '{repo}' in _def_clone_uri:
            _def_clone_uri_by_id = _def_clone_uri.replace('{repo}', '_{repoid}')
        elif '{repoid}' in _def_clone_uri:
            _def_clone_uri_by_id = _def_clone_uri.replace('_{repoid}', '{repo}')

        c.clone_repo_url = c.db_repo.clone_url(user=username,
                                                uri_tmpl=_def_clone_uri)
        c.clone_repo_url_id = c.db_repo.clone_url(user=username,
                                                uri_tmpl=_def_clone_uri_by_id)

        if c.db_repo.enable_statistics:
            c.show_stats = True
        else:
            c.show_stats = False

        stats = Statistics.query() \
            .filter(Statistics.repository == c.db_repo) \
            .scalar()

        c.stats_percentage = 0

        if stats and stats.languages:
            c.no_data = False is c.db_repo.enable_statistics
            lang_stats_d = json.loads(stats.languages)

            lang_stats = ((x, {"count": y,
                               "desc": LANGUAGES_EXTENSIONS_MAP.get(x)})
                          for x, y in lang_stats_d.items())

            c.trending_languages = (
                sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10]
            )
        else:
            c.no_data = True
            c.trending_languages = []

        c.enable_downloads = c.db_repo.enable_downloads
        c.readme_data, c.readme_file = \
            self.__get_readme_data(c.db_repo)
        return render('summary/summary.html')