use of com.gitblit.models.Activity in project gitblit by gitblit.
the class ActivityUtils method getRecentActivity.
/**
* Gets the recent activity from the repositories for the last daysBack days
* on the specified branch.
*
* @param settings
* the runtime settings
* @param repositoryManager
* the repository manager
* @param models
* the list of repositories to query
* @param daysBack
* the number of days back from Now to collect
* @param objectId
* the branch to retrieve. If this value is null or empty all
* branches are queried.
* @param timezone
* the timezone for aggregating commits
* @return
*/
public static List<Activity> getRecentActivity(IStoredSettings settings, IRepositoryManager repositoryManager, List<RepositoryModel> models, int daysBack, String objectId, TimeZone timezone) {
// Activity panel shows last daysBack of activity across all
// repositories.
Date thresholdDate = new Date(System.currentTimeMillis() - daysBack * TimeUtils.ONEDAY);
// Build a map of DailyActivity from the available repositories for the
// specified threshold date.
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
df.setTimeZone(timezone);
Calendar cal = Calendar.getInstance();
cal.setTimeZone(timezone);
// aggregate author exclusions
Set<String> authorExclusions = new TreeSet<String>();
authorExclusions.addAll(settings.getStrings(Keys.web.metricAuthorExclusions));
for (RepositoryModel model : models) {
if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {
authorExclusions.addAll(model.metricAuthorExclusions);
}
}
Map<String, Activity> activity = new HashMap<String, Activity>();
for (RepositoryModel model : models) {
if (!model.isShowActivity()) {
// skip this repository
continue;
}
if (model.hasCommits && model.lastChange.after(thresholdDate)) {
if (model.isCollectingGarbage) {
continue;
}
Repository repository = repositoryManager.getRepository(model.name);
List<String> branches = new ArrayList<String>();
if (StringUtils.isEmpty(objectId)) {
for (RefModel local : JGitUtils.getLocalBranches(repository, true, -1)) {
if (!local.getDate().after(thresholdDate)) {
// branch not recently updated
continue;
}
branches.add(local.getName());
}
} else {
branches.add(objectId);
}
for (String branch : branches) {
String shortName = branch;
if (shortName.startsWith(Constants.R_HEADS)) {
shortName = shortName.substring(Constants.R_HEADS.length());
}
List<RepositoryCommit> commits = CommitCache.instance().getCommits(model.name, repository, branch, thresholdDate);
if (model.maxActivityCommits > 0 && commits.size() > model.maxActivityCommits) {
// trim commits to maximum count
commits = commits.subList(0, model.maxActivityCommits);
}
for (RepositoryCommit commit : commits) {
Date date = commit.getCommitDate();
String dateStr = df.format(date);
if (!activity.containsKey(dateStr)) {
// Normalize the date to midnight
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Activity a = new Activity(cal.getTime());
a.excludeAuthors(authorExclusions);
activity.put(dateStr, a);
}
activity.get(dateStr).addCommit(commit);
}
}
// close the repository
repository.close();
}
}
List<Activity> recentActivity = new ArrayList<Activity>(activity.values());
return recentActivity;
}
use of com.gitblit.models.Activity 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;
}
Aggregations