use of com.gitblit.models.Metric in project gitblit by gitblit.
the class MetricUtils method getAuthorMetrics.
/**
* Returns a list of author metrics for the specified repository.
*
* @param repository
* @param objectId
* if null or empty, HEAD is assumed.
* @param byEmailAddress
* group metrics by author email address otherwise by author name
* @return list of metrics
*/
public static List<Metric> getAuthorMetrics(Repository repository, String objectId, boolean byEmailAddress) {
final Map<String, Metric> metricMap = new HashMap<String, Metric>();
if (JGitUtils.hasCommits(repository)) {
try {
RevWalk walk = new RevWalk(repository);
// resolve branch
ObjectId branchObject;
if (StringUtils.isEmpty(objectId)) {
branchObject = JGitUtils.getDefaultBranch(repository);
} else {
branchObject = repository.resolve(objectId);
}
RevCommit lastCommit = walk.parseCommit(branchObject);
walk.markStart(lastCommit);
Iterable<RevCommit> revlog = walk;
for (RevCommit rev : revlog) {
String p;
if (byEmailAddress) {
p = rev.getAuthorIdent().getEmailAddress().toLowerCase();
if (StringUtils.isEmpty(p)) {
p = rev.getAuthorIdent().getName().toLowerCase();
}
} else {
p = rev.getAuthorIdent().getName().toLowerCase();
if (StringUtils.isEmpty(p)) {
p = rev.getAuthorIdent().getEmailAddress().toLowerCase();
}
}
p = p.replace('\n', ' ').replace('\r', ' ').trim();
if (!metricMap.containsKey(p)) {
metricMap.put(p, new Metric(p));
}
Metric m = metricMap.get(p);
m.count++;
}
} catch (Throwable t) {
error(t, repository, "{0} failed to mine log history for author metrics of {1}", objectId);
}
}
List<String> keys = new ArrayList<String>(metricMap.keySet());
Collections.sort(keys);
List<Metric> metrics = new ArrayList<Metric>();
for (String key : keys) {
metrics.add(metricMap.get(key));
}
return metrics;
}
use of com.gitblit.models.Metric in project gitblit by gitblit.
the class MetricsPage method createPieChart.
private void createPieChart(Charts charts, String id, List<Metric> metrics) {
if ((metrics != null) && (metrics.size() > 0)) {
Chart chart = charts.createPieChart(id, "", "day", getString("gb.commits"));
for (Metric metric : metrics) {
chart.addValue(metric.name, (int) metric.count);
}
charts.addChart(chart);
}
}
use of com.gitblit.models.Metric 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));
}
}
use of com.gitblit.models.Metric 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;
}
use of com.gitblit.models.Metric 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;
}
Aggregations