From 1fa5e85b2d208636a6237ef8930f200767165baa Mon Sep 17 00:00:00 2001 From: James Moger Date: Tue, 7 Jun 2011 20:55:19 -0400 Subject: Improved metrics page and added metrics links to branches panel. --- docs/00_index.mkd | 1 - src/com/gitblit/models/RefModel.java | 5 +++ src/com/gitblit/utils/MetricUtils.java | 21 ++++----- src/com/gitblit/wicket/GitBlitWebApp.properties | 6 ++- src/com/gitblit/wicket/pages/MetricsPage.html | 26 ++++++++--- src/com/gitblit/wicket/pages/MetricsPage.java | 55 ++++++++++-------------- src/com/gitblit/wicket/pages/RepositoryPage.html | 2 +- src/com/gitblit/wicket/pages/RepositoryPage.java | 3 -- src/com/gitblit/wicket/pages/SummaryPage.html | 2 +- src/com/gitblit/wicket/pages/SummaryPage.java | 12 +++--- src/com/gitblit/wicket/panels/BranchesPanel.html | 20 +++++++-- src/com/gitblit/wicket/panels/BranchesPanel.java | 33 +++++++++++--- src/com/gitblit/wicket/panels/RefsPanel.java | 8 ++-- src/com/gitblit/wicket/panels/TagsPanel.java | 9 ++++ src/com/gitblit/wicket/resources/gitblit.css | 23 +++++++--- tests/com/gitblit/tests/MetricUtilsTest.java | 6 +-- 16 files changed, 148 insertions(+), 84 deletions(-) diff --git a/docs/00_index.mkd b/docs/00_index.mkd index 8c8f9322..d1331636 100644 --- a/docs/00_index.mkd +++ b/docs/00_index.mkd @@ -56,7 +56,6 @@ sources @ [Github][gitbltsrc] ### Todo List - Code documentation - Unit testing -- Branch selector on Metrics - Blame - Clone remote repository diff --git a/src/com/gitblit/models/RefModel.java b/src/com/gitblit/models/RefModel.java index 39bf19c9..0b65c092 100644 --- a/src/com/gitblit/models/RefModel.java +++ b/src/com/gitblit/models/RefModel.java @@ -127,4 +127,9 @@ public class RefModel implements Serializable, Comparable { public int compareTo(RefModel o) { return getDate().compareTo(o.getDate()); } + + @Override + public String toString() { + return displayName; + } } \ No newline at end of file diff --git a/src/com/gitblit/utils/MetricUtils.java b/src/com/gitblit/utils/MetricUtils.java index d8286e29..492b0243 100644 --- a/src/com/gitblit/utils/MetricUtils.java +++ b/src/com/gitblit/utils/MetricUtils.java @@ -39,10 +39,12 @@ public class MetricUtils { private static final Logger LOGGER = LoggerFactory.getLogger(MetricUtils.class); - public static List getDateMetrics(Repository r, boolean includeTotal, String format) { + public static List getDateMetrics(Repository r, String objectId, boolean includeTotal, String format) { Metric total = new Metric("TOTAL"); final Map metricMap = new HashMap(); - + if (StringUtils.isEmpty(objectId)) { + objectId = Constants.HEAD; + } if (JGitUtils.hasCommits(r)) { final List tags = JGitUtils.getTags(r, true, -1); final Map tagMap = new HashMap(); @@ -51,7 +53,7 @@ public class MetricUtils { } try { RevWalk walk = new RevWalk(r); - ObjectId object = r.resolve(Constants.HEAD); + ObjectId object = r.resolve(objectId); RevCommit lastCommit = walk.parseCommit(object); walk.markStart(lastCommit); @@ -62,12 +64,9 @@ public class MetricUtils { int diffDays = (lastCommit.getCommitTime() - firstCommit.getCommitTime()) / (60 * 60 * 24); total.duration = diffDays; - if (diffDays <= 90) { + if (diffDays <= 365) { // Days df = new SimpleDateFormat("yyyy-MM-dd"); - } else if (diffDays > 90 && diffDays < 365) { - // Weeks - df = new SimpleDateFormat("yyyy-MM (w)"); } else { // Months df = new SimpleDateFormat("yyyy-MM"); @@ -108,13 +107,15 @@ public class MetricUtils { return metrics; } - public static List getAuthorMetrics(Repository r, boolean byEmail) { + public static List getAuthorMetrics(Repository r, String objectId, boolean byEmail) { final Map metricMap = new HashMap(); - + if (StringUtils.isEmpty(objectId)) { + objectId = Constants.HEAD; + } if (JGitUtils.hasCommits(r)) { try { RevWalk walk = new RevWalk(r); - ObjectId object = r.resolve(Constants.HEAD); + ObjectId object = r.resolve(objectId); RevCommit lastCommit = walk.parseCommit(object); walk.markStart(lastCommit); diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index f64f1e56..d6102dbf 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -55,6 +55,7 @@ gb.modification = modification gb.deletion = deletion gb.rename = rename gb.metrics = metrics +gb.stats = stats gb.markdown = markdown gb.changedFiles = changed files gb.filesAdded = {0} files added @@ -94,4 +95,7 @@ gb.showReadme = show readme gb.showReadmeDescription = show a \"readme\" markdown file on the summary page gb.nameDescription = use '/' to group repositories. e.g. libraries/mycoollib.git gb.ownerDescription = the owner may edit repository settings -gb.blob = blob \ No newline at end of file +gb.blob = blob +gb.commitActivityTrend = commit activity trend +gb.commitActivityDOW = commit activity by day of week +gb.commitActivityAuthors = primary authors by commit activity \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/MetricsPage.html b/src/com/gitblit/wicket/pages/MetricsPage.html index d6f23e01..734b9fad 100644 --- a/src/com/gitblit/wicket/pages/MetricsPage.html +++ b/src/com/gitblit/wicket/pages/MetricsPage.html @@ -6,18 +6,30 @@ -

Commit Activity

+
+ +
+ + +
+
+ + +

+ + + +

-

Commit Activity by Day of Week

+ +

-

Commit Activity by Time of Day

-
- -

Most Prolific Authors

+ +

- +
\ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/MetricsPage.java b/src/com/gitblit/wicket/pages/MetricsPage.java index c6231e9d..9dd10d1b 100644 --- a/src/com/gitblit/wicket/pages/MetricsPage.java +++ b/src/com/gitblit/wicket/pages/MetricsPage.java @@ -17,16 +17,16 @@ package com.gitblit.wicket.pages; import java.awt.Color; import java.awt.Dimension; -import java.text.ParseException; +import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; -import java.util.Date; import java.util.List; import org.apache.wicket.PageParameters; +import org.apache.wicket.markup.html.basic.Label; import org.eclipse.jgit.lib.Repository; import org.wicketstuff.googlecharts.Chart; import org.wicketstuff.googlecharts.ChartAxis; @@ -40,17 +40,28 @@ import org.wicketstuff.googlecharts.ShapeMarker; import com.gitblit.models.Metric; import com.gitblit.utils.MetricUtils; +import com.gitblit.utils.TimeUtils; import com.gitblit.wicket.WicketUtils; public class MetricsPage extends RepositoryPage { public MetricsPage(PageParameters params) { - super(params); + super(params); Repository r = getRepository(); - insertLinePlot("commitsChart", MetricUtils.getDateMetrics(r, false, null)); - insertBarPlot("dayOfWeekChart", getDayOfWeekMetrics(r)); - insertLinePlot("timeOfDayChart", getTimeOfDayMetrics(r)); - insertPieChart("authorsChart", getAuthorMetrics(r)); + add(new Label("branchTitle", objectId)); + Metric metricsTotal = null; + List metrics = MetricUtils.getDateMetrics(r, objectId, true, null); + metricsTotal = metrics.remove(0); + if (metricsTotal == null) { + add(new Label("branchStats", "")); + } else { + add(new Label("branchStats", MessageFormat.format( + "{0} commits and {1} tags in {2}", metricsTotal.count, metricsTotal.tag, + TimeUtils.duration(metricsTotal.duration)))); + } + insertLinePlot("commitsChart", metrics); + insertBarPlot("dayOfWeekChart", getDayOfWeekMetrics(r, objectId)); + insertPieChart("authorsChart", getAuthorMetrics(r, objectId)); } private void insertLinePlot(String wicketId, List metrics) { @@ -118,8 +129,8 @@ public class MetricsPage extends RepositoryPage { } } - private List getDayOfWeekMetrics(Repository repository) { - List list = MetricUtils.getDateMetrics(repository, false, "E"); + private List getDayOfWeekMetrics(Repository repository, String objectId) { + List list = MetricUtils.getDateMetrics(repository, objectId, false, "E"); SimpleDateFormat sdf = new SimpleDateFormat("E"); Calendar cal = Calendar.getInstance(); @@ -143,35 +154,15 @@ public class MetricsPage extends RepositoryPage { return sorted; } - private List getTimeOfDayMetrics(Repository repository) { - SimpleDateFormat ndf = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - List list = MetricUtils.getDateMetrics(repository, false, "yyyy-MM-dd HH:mm"); - Calendar cal = Calendar.getInstance(); - - for (Metric metric : list) { - try { - Date date = sdf.parse(metric.name); - cal.setTime(date); - double y = cal.get(Calendar.HOUR_OF_DAY) + (cal.get(Calendar.MINUTE) / 60d); - metric.duration = (int) (date.getTime() / 60000L); - metric.count = y; - metric.name = ndf.format(date); - } catch (ParseException p) { - } - } - return list; - } - - private List getAuthorMetrics(Repository repository) { - List authors = MetricUtils.getAuthorMetrics(repository, true); + private List getAuthorMetrics(Repository repository, String objectId) { + List authors = MetricUtils.getAuthorMetrics(repository, objectId, true); Collections.sort(authors, new Comparator() { @Override public int compare(Metric o1, Metric o2) { if (o1.count > o2.count) { return -1; } else if (o1.count < o2.count) { - return 1; + return 1; } return 0; } diff --git a/src/com/gitblit/wicket/pages/RepositoryPage.html b/src/com/gitblit/wicket/pages/RepositoryPage.html index ffb484f1..0e0ce476 100644 --- a/src/com/gitblit/wicket/pages/RepositoryPage.html +++ b/src/com/gitblit/wicket/pages/RepositoryPage.html @@ -18,7 +18,7 @@ diff --git a/src/com/gitblit/wicket/pages/RepositoryPage.java b/src/com/gitblit/wicket/pages/RepositoryPage.java index eceda998..3ceb9f5f 100644 --- a/src/com/gitblit/wicket/pages/RepositoryPage.java +++ b/src/com/gitblit/wicket/pages/RepositoryPage.java @@ -76,7 +76,6 @@ public abstract class RepositoryPage extends BasePage { put("branches", "gb.branches"); put("tags", "gb.tags"); put("tree", "gb.tree"); - put("metrics", "gb.metrics"); put("tickets", "gb.tickets"); put("edit", "gb.edit"); } @@ -105,8 +104,6 @@ public abstract class RepositoryPage extends BasePage { WicketUtils.newRepositoryParameter(repositoryName))); add(new BookmarkablePageLink("tree", TreePage.class, WicketUtils.newRepositoryParameter(repositoryName))); - add(new BookmarkablePageLink("metrics", MetricsPage.class, - WicketUtils.newRepositoryParameter(repositoryName))); // per-repository extra page links List extraPageLinks = new ArrayList(); diff --git a/src/com/gitblit/wicket/pages/SummaryPage.html b/src/com/gitblit/wicket/pages/SummaryPage.html index 7d5629b6..7784a471 100644 --- a/src/com/gitblit/wicket/pages/SummaryPage.html +++ b/src/com/gitblit/wicket/pages/SummaryPage.html @@ -25,7 +25,7 @@ [description][repository description] [owner][repository owner] [last change][repository last change] - [metrics][repository metrics] + [stats][branch stats] [metrics] [URL][repository clone url] diff --git a/src/com/gitblit/wicket/pages/SummaryPage.java b/src/com/gitblit/wicket/pages/SummaryPage.java index fd21ed64..03b1b1c7 100644 --- a/src/com/gitblit/wicket/pages/SummaryPage.java +++ b/src/com/gitblit/wicket/pages/SummaryPage.java @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; import org.apache.wicket.protocol.http.WebRequest; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; @@ -77,7 +78,7 @@ public class SummaryPage extends RepositoryPage { List metrics = null; Metric metricsTotal = null; if (GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) { - metrics = MetricUtils.getDateMetrics(r, true, null); + metrics = MetricUtils.getDateMetrics(r, null, true, null); metricsTotal = metrics.remove(0); } @@ -88,12 +89,13 @@ public class SummaryPage extends RepositoryPage { add(WicketUtils.createTimestampLabel("repositoryLastChange", JGitUtils.getLastChange(r), getTimeZone())); if (metricsTotal == null) { - add(new Label("repositoryMetrics", "")); + add(new Label("branchStats", "")); } else { - add(new Label("repositoryMetrics", MessageFormat.format( + add(new Label("branchStats", MessageFormat.format( "{0} commits and {1} tags in {2}", metricsTotal.count, metricsTotal.tag, TimeUtils.duration(metricsTotal.duration)))); } + add(new BookmarkablePageLink("metrics", MetricsPage.class, WicketUtils.newRepositoryParameter(repositoryName))); List repositoryUrls = new ArrayList(); @@ -141,8 +143,8 @@ public class SummaryPage extends RepositoryPage { .setEscapeModelStrings(false)); add(new LogPanel("commitsPanel", repositoryName, null, r, numberCommits, 0)); - add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs)); - add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs)); + add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty()); + add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs).hideIfEmpty()); if (getRepositoryModel().showReadme) { String htmlText = null; diff --git a/src/com/gitblit/wicket/panels/BranchesPanel.html b/src/com/gitblit/wicket/panels/BranchesPanel.html index 497003a5..91c34d2d 100644 --- a/src/com/gitblit/wicket/panels/BranchesPanel.html +++ b/src/com/gitblit/wicket/panels/BranchesPanel.html @@ -17,16 +17,28 @@ [branch name] [branch type] - - | - +
[all branches]
- + + + + + | | + + + + + + + | + + + \ No newline at end of file diff --git a/src/com/gitblit/wicket/panels/BranchesPanel.java b/src/com/gitblit/wicket/panels/BranchesPanel.java index 82f8a045..b11c03ab 100644 --- a/src/com/gitblit/wicket/panels/BranchesPanel.java +++ b/src/com/gitblit/wicket/panels/BranchesPanel.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.BookmarkablePageLink; +import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.markup.repeater.data.DataView; import org.apache.wicket.markup.repeater.data.ListDataProvider; @@ -35,6 +36,7 @@ import com.gitblit.utils.StringUtils; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.pages.BranchesPage; import com.gitblit.wicket.pages.LogPage; +import com.gitblit.wicket.pages.MetricsPage; import com.gitblit.wicket.pages.SummaryPage; import com.gitblit.wicket.pages.TreePage; @@ -42,6 +44,8 @@ public class BranchesPanel extends BasePanel { private static final long serialVersionUID = 1L; + private final boolean hasBranches; + public BranchesPanel(String wicketId, final RepositoryModel model, Repository r, final int maxCount) { super(wicketId); @@ -89,11 +93,23 @@ public class BranchesPanel extends BasePanel { item.add(new Label("branchType", remote ? getString("gb.remote") : getString("gb.local")).setVisible(maxCount <= 0)); - item.add(new BookmarkablePageLink("log", LogPage.class, WicketUtils - .newObjectParameter(model.name, entry.getName()))); - item.add(new BookmarkablePageLink("tree", TreePage.class, WicketUtils - .newObjectParameter(model.name, entry.getName()))); - + if (maxCount <= 0) { + Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this); + fragment.add(new BookmarkablePageLink("log", LogPage.class, WicketUtils + .newObjectParameter(model.name, entry.getName()))); + fragment.add(new BookmarkablePageLink("tree", TreePage.class, WicketUtils + .newObjectParameter(model.name, entry.getName()))); + fragment.add(new BookmarkablePageLink("metrics", MetricsPage.class, + WicketUtils.newObjectParameter(model.name, entry.getName()))); + item.add(fragment); + } else { + Fragment fragment = new Fragment("branchLinks", "branchPanelLinks", this); + fragment.add(new BookmarkablePageLink("log", LogPage.class, WicketUtils + .newObjectParameter(model.name, entry.getName()))); + fragment.add(new BookmarkablePageLink("tree", TreePage.class, WicketUtils + .newObjectParameter(model.name, entry.getName()))); + item.add(fragment); + } WicketUtils.setAlternatingBackground(item, counter); counter++; } @@ -105,5 +121,12 @@ public class BranchesPanel extends BasePanel { add(new LinkPanel("allBranches", "link", new StringResourceModel("gb.allBranches", this, null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name))); } + // We always have 1 branch + hasBranches = branches.size() > 1; + } + + public BranchesPanel hideIfEmpty() { + setVisible(hasBranches); + return this; } } diff --git a/src/com/gitblit/wicket/panels/RefsPanel.java b/src/com/gitblit/wicket/panels/RefsPanel.java index 8cf137b1..f25b53b2 100644 --- a/src/com/gitblit/wicket/panels/RefsPanel.java +++ b/src/com/gitblit/wicket/panels/RefsPanel.java @@ -70,19 +70,19 @@ public class RefsPanel extends Panel { Class linkClass = CommitPage.class; String cssClass = ""; if (name.startsWith(Constants.R_HEADS)) { - // local head + // local branch linkClass = LogPage.class; name = name.substring(Constants.R_HEADS.length()); - cssClass = "headRef"; + cssClass = "localBranch"; } else if (name.equals(Constants.HEAD)) { // local head linkClass = LogPage.class; cssClass = "headRef"; } else if (name.startsWith(Constants.R_REMOTES)) { - // remote head + // remote branch linkClass = LogPage.class; name = name.substring(Constants.R_REMOTES.length()); - cssClass = "remoteRef"; + cssClass = "remoteBranch"; } else if (name.startsWith(Constants.R_TAGS)) { // tag if (entry.isAnnotatedTag()) { diff --git a/src/com/gitblit/wicket/panels/TagsPanel.java b/src/com/gitblit/wicket/panels/TagsPanel.java index f6dd762b..4504c511 100644 --- a/src/com/gitblit/wicket/panels/TagsPanel.java +++ b/src/com/gitblit/wicket/panels/TagsPanel.java @@ -44,6 +44,8 @@ import com.gitblit.wicket.pages.TreePage; public class TagsPanel extends BasePanel { private static final long serialVersionUID = 1L; + + private final boolean hasTags; public TagsPanel(String wicketId, final String repositoryName, Repository r, final int maxCount) { super(wicketId); @@ -162,5 +164,12 @@ public class TagsPanel extends BasePanel { add(new LinkPanel("allTags", "link", new StringResourceModel("gb.allTags", this, null), TagsPage.class, WicketUtils.newRepositoryParameter(repositoryName))); } + + hasTags = tags.size() > 0; + } + + public TagsPanel hideIfEmpty() { + setVisible(hasTags); + return this; } } diff --git a/src/com/gitblit/wicket/resources/gitblit.css b/src/com/gitblit/wicket/resources/gitblit.css index 5dd0f160..a0ab10ab 100644 --- a/src/com/gitblit/wicket/resources/gitblit.css +++ b/src/com/gitblit/wicket/resources/gitblit.css @@ -708,7 +708,11 @@ td.treeLinks { width: 13em; } -span .tagRef, span .headRef, span .remoteRef, span .otherRef { +span.metricsTitle { + font-size: 2em; +} + +span .tagRef, span .headRef, span .localBranch, span .remoteBranch, span .otherRef { padding: 0px 3px; margin-right:2px; font-family: sans-serif; @@ -718,26 +722,26 @@ span .tagRef, span .headRef, span .remoteRef, span .otherRef { color: black; } -span .tagRef a span, span .headRef a span, span .remoteRef a span, span .otherRef a span { +span .tagRef a span, span .headRef a span, span .localBranch a span, span .remoteBranch a span, span .otherRef a span { font-size: 9px; } -span .tagRef a, span .headRef a, span .remoteRef a, span .otherRef a { +span .tagRef a, span .headRef a, span .localBranch a, span .remoteBranch a, span .otherRef a { text-decoration: none; color: black !important; } -span .tagRef a:hover, span .headRef a:hover, span .remoteRef a:hover, span .otherRef a:hover { +span .tagRef a:hover, span .headRef a:hover, span .localBranch a:hover, span .remoteBranch a:hover, span .otherRef a:hover { color: black !important; text-decoration: underline; } span .otherRef { - background-color: #ffaaff; - border-color: #ff00ee; + background-color: #80ccdd; + border-color: #80aaaa; } -span .remoteRef { +span .remoteBranch { background-color: #cAc2f5; border-color: #6c6cbf; } @@ -748,6 +752,11 @@ span .tagRef { } span .headRef { + background-color: #ffaaff; + border-color: #ff00ee; +} + +span .localBranch { background-color: #ccffcc; border-color: #00cc33; } diff --git a/tests/com/gitblit/tests/MetricUtilsTest.java b/tests/com/gitblit/tests/MetricUtilsTest.java index 07cd6060..db994b80 100644 --- a/tests/com/gitblit/tests/MetricUtilsTest.java +++ b/tests/com/gitblit/tests/MetricUtilsTest.java @@ -28,15 +28,15 @@ public class MetricUtilsTest extends TestCase { public void testMetrics() throws Exception { Repository repository = GitBlitSuite.getHelloworldRepository(); - List metrics = MetricUtils.getDateMetrics(repository, true, null); + List metrics = MetricUtils.getDateMetrics(repository, null, true, null); repository.close(); assertTrue("No date metrics found!", metrics.size() > 0); } public void testAuthorMetrics() throws Exception { Repository repository = GitBlitSuite.getHelloworldRepository(); - List byEmail = MetricUtils.getAuthorMetrics(repository, true); - List byName = MetricUtils.getAuthorMetrics(repository, false); + List byEmail = MetricUtils.getAuthorMetrics(repository, null, true); + List byName = MetricUtils.getAuthorMetrics(repository, null, false); repository.close(); assertTrue("No author metrics found!", byEmail.size() == 9); assertTrue("No author metrics found!", byName.size() == 8); -- cgit v1.2.3