Search in sources :

Example 1 with Charts

use of com.gitblit.wicket.charting.Charts in project gitblit by gitblit.

the class OverviewPage method insertActivityGraph.

private void insertActivityGraph(List<Metric> metrics) {
    if ((metrics != null) && (metrics.size() > 0) && app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
        Charts charts = new Flotr2Charts();
        // daily line chart
        Chart chart = charts.createLineChart("chartDaily", "", "unit", getString("gb.commits"));
        for (Metric metric : metrics) {
            chart.addValue(metric.name, metric.count);
        }
        chart.setWidth(375);
        chart.setHeight(150);
        charts.addChart(chart);
        add(new HeaderContributor(charts));
    }
}
Also used : Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) HeaderContributor(org.apache.wicket.behavior.HeaderContributor) Charts(com.gitblit.wicket.charting.Charts) Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) Metric(com.gitblit.models.Metric) Chart(com.gitblit.wicket.charting.Chart)

Example 2 with Charts

use of com.gitblit.wicket.charting.Charts in project gitblit by gitblit.

the class ActivityPage method createCharts.

/**
	 * Creates the daily activity line chart, the active repositories pie chart,
	 * and the active authors pie chart
	 *
	 * @param recentActivity
	 * @return
	 */
private Charts createCharts(List<Activity> recentActivity) {
    // activity metrics
    Map<String, Metric> repositoryMetrics = new HashMap<String, Metric>();
    Map<String, Metric> authorMetrics = new HashMap<String, Metric>();
    // aggregate repository and author metrics
    for (Activity activity : recentActivity) {
        // aggregate author metrics
        for (Map.Entry<String, Metric> entry : activity.getAuthorMetrics().entrySet()) {
            String author = entry.getKey();
            if (!authorMetrics.containsKey(author)) {
                authorMetrics.put(author, new Metric(author));
            }
            authorMetrics.get(author).count += entry.getValue().count;
        }
        // aggregate repository metrics
        for (Map.Entry<String, Metric> entry : activity.getRepositoryMetrics().entrySet()) {
            String repository = StringUtils.stripDotGit(entry.getKey());
            if (!repositoryMetrics.containsKey(repository)) {
                repositoryMetrics.put(repository, new Metric(repository));
            }
            repositoryMetrics.get(repository).count += entry.getValue().count;
        }
    }
    // build charts
    Charts charts = new Flotr2Charts();
    // sort in reverse-chronological order and then reverse that
    Collections.sort(recentActivity);
    Collections.reverse(recentActivity);
    // daily line chart
    Chart chart = charts.createLineChart("chartDaily", getString("gb.dailyActivity"), "day", getString("gb.commits"));
    SimpleDateFormat df = new SimpleDateFormat("MMM dd");
    df.setTimeZone(getTimeZone());
    for (Activity metric : recentActivity) {
        chart.addValue(metric.startDate, metric.getCommitCount());
    }
    charts.addChart(chart);
    // active repositories pie chart
    chart = charts.createPieChart("chartRepositories", getString("gb.activeRepositories"), getString("gb.repository"), getString("gb.commits"));
    for (Metric metric : repositoryMetrics.values()) {
        chart.addValue(metric.name, metric.count);
    }
    chart.setShowLegend(false);
    String url = urlFor(SummaryPage.class, null).toString() + "?r=";
    chart.setClickUrl(url);
    charts.addChart(chart);
    // active authors pie chart
    chart = charts.createPieChart("chartAuthors", getString("gb.activeAuthors"), getString("gb.author"), getString("gb.commits"));
    for (Metric metric : authorMetrics.values()) {
        chart.addValue(metric.name, metric.count);
    }
    chart.setShowLegend(false);
    charts.addChart(chart);
    return charts;
}
Also used : Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) HashMap(java.util.HashMap) Activity(com.gitblit.models.Activity) Charts(com.gitblit.wicket.charting.Charts) Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) Metric(com.gitblit.models.Metric) HashMap(java.util.HashMap) Map(java.util.Map) SimpleDateFormat(java.text.SimpleDateFormat) Chart(com.gitblit.wicket.charting.Chart)

Example 3 with Charts

use of com.gitblit.wicket.charting.Charts in project gitblit by gitblit.

the class SummaryPage method createCharts.

private Charts createCharts(List<Metric> metrics) {
    Charts charts = new Flotr2Charts();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String displayFormat = "MMM dd";
    if (metrics.size() > 0 && metrics.get(0).name.length() == 7) {
        df = new SimpleDateFormat("yyyy-MM");
        displayFormat = "yyyy MMM";
    }
    df.setTimeZone(getTimeZone());
    // build google charts
    Chart chart = charts.createLineChart("commitsChart", getString("gb.activity"), "day", getString("gb.commits"));
    chart.setDateFormat(displayFormat);
    for (Metric metric : metrics) {
        Date date;
        try {
            date = df.parse(metric.name);
        } catch (ParseException e) {
            logger.error("Unable to parse date: " + metric.name);
            return charts;
        }
        chart.addValue(date, (int) metric.count);
        if (metric.tag > 0) {
            chart.addHighlight(date, (int) metric.count);
        }
    }
    charts.addChart(chart);
    return charts;
}
Also used : Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) Charts(com.gitblit.wicket.charting.Charts) Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) Metric(com.gitblit.models.Metric) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Chart(com.gitblit.wicket.charting.Chart) Date(java.util.Date)

Example 4 with Charts

use of com.gitblit.wicket.charting.Charts in project gitblit by gitblit.

the class DashboardPage method addCharts.

/**
	 * Creates the daily activity line chart, the active repositories pie chart,
	 * and the active authors pie chart
	 *
	 * @param recentChanges
	 * @param authorExclusions
	 * @param daysBack
	 */
protected void addCharts(Fragment frag, List<DailyLogEntry> recentChanges, Set<String> authorExclusions, int daysBack) {
    // activity metrics
    Map<String, Metric> repositoryMetrics = new HashMap<String, Metric>();
    Map<String, Metric> authorMetrics = new HashMap<String, Metric>();
    // aggregate repository and author metrics
    int totalCommits = 0;
    for (RefLogEntry change : recentChanges) {
        // aggregate repository metrics
        String repository = StringUtils.stripDotGit(change.repository);
        if (!repositoryMetrics.containsKey(repository)) {
            repositoryMetrics.put(repository, new Metric(repository));
        }
        repositoryMetrics.get(repository).count += 1;
        for (RepositoryCommit commit : change.getCommits()) {
            totalCommits++;
            String author = StringUtils.removeNewlines(commit.getAuthorIdent().getName());
            String authorName = author.toLowerCase();
            String authorEmail = StringUtils.removeNewlines(commit.getAuthorIdent().getEmailAddress()).toLowerCase();
            if (!authorExclusions.contains(authorName) && !authorExclusions.contains(authorEmail)) {
                if (!authorMetrics.containsKey(author)) {
                    authorMetrics.put(author, new Metric(author));
                }
                authorMetrics.get(author).count += 1;
            }
        }
    }
    String headerPattern;
    if (daysBack == 1) {
        // today
        if (totalCommits == 0) {
            headerPattern = getString("gb.todaysActivityNone");
        } else {
            headerPattern = getString("gb.todaysActivityStats");
        }
    } else {
        // multiple days
        if (totalCommits == 0) {
            headerPattern = getString("gb.recentActivityNone");
        } else {
            headerPattern = getString("gb.recentActivityStats");
        }
    }
    frag.add(new Label("feedheader", MessageFormat.format(headerPattern, daysBack, totalCommits, authorMetrics.size())));
    if (app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
        // build google charts
        Charts charts = new Flotr2Charts();
        // active repositories pie chart
        Chart chart = charts.createPieChart("chartRepositories", getString("gb.activeRepositories"), getString("gb.repository"), getString("gb.commits"));
        for (Metric metric : repositoryMetrics.values()) {
            chart.addValue(metric.name, metric.count);
        }
        chart.setShowLegend(false);
        String url = urlFor(SummaryPage.class, null).toString() + "?r=";
        chart.setClickUrl(url);
        charts.addChart(chart);
        // active authors pie chart
        chart = charts.createPieChart("chartAuthors", getString("gb.activeAuthors"), getString("gb.author"), getString("gb.commits"));
        for (Metric metric : authorMetrics.values()) {
            chart.addValue(metric.name, metric.count);
        }
        chart.setShowLegend(false);
        charts.addChart(chart);
        add(new HeaderContributor(charts));
        frag.add(new Fragment("charts", "chartsFragment", this));
    } else {
        frag.add(new Label("charts").setVisible(false));
    }
}
Also used : Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) HashMap(java.util.HashMap) Label(org.apache.wicket.markup.html.basic.Label) Charts(com.gitblit.wicket.charting.Charts) Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) RepositoryCommit(com.gitblit.models.RepositoryCommit) Fragment(org.apache.wicket.markup.html.panel.Fragment) RefLogEntry(com.gitblit.models.RefLogEntry) HeaderContributor(org.apache.wicket.behavior.HeaderContributor) Metric(com.gitblit.models.Metric) Chart(com.gitblit.wicket.charting.Chart)

Aggregations

Metric (com.gitblit.models.Metric)4 Chart (com.gitblit.wicket.charting.Chart)4 Charts (com.gitblit.wicket.charting.Charts)4 Flotr2Charts (com.gitblit.wicket.charting.Flotr2Charts)4 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 HeaderContributor (org.apache.wicket.behavior.HeaderContributor)2 Activity (com.gitblit.models.Activity)1 RefLogEntry (com.gitblit.models.RefLogEntry)1 RepositoryCommit (com.gitblit.models.RepositoryCommit)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Map (java.util.Map)1 Label (org.apache.wicket.markup.html.basic.Label)1 Fragment (org.apache.wicket.markup.html.panel.Fragment)1