Commits

Sebastian Sdorra committed 3d22c2f

added statistic for top modified files

  • Participants
  • Parent commits 1e0205a

Comments (0)

Files changed (7)

File src/main/java/sonia/scm/statistic/StatisticCollector.java

 import sonia.scm.statistic.dto.CommitsPerAuthor;
 import sonia.scm.statistic.dto.CommitsPerHour;
 import sonia.scm.statistic.dto.CommitsPerMonth;
+import sonia.scm.statistic.dto.TopModifiedFiles;
 
 /**
  *
   public static CommitsPerAuthor collectCommitsPerAuthor(StatisticData data,
     int limit)
   {
-    Multiset<String> ordered =
-      Multisets.copyHighestCountFirst(data.getCommitsPerAuthor());
     Multiset<String> authors = HashMultiset.create();
+    int others = collectTopEntries(data.getCommitsPerAuthor(), authors, limit,
+                   true);
 
-    int i = 0;
-    int others = 0;
-
-    for (Entry<String> e : ordered.entrySet())
+    if (others > 0)
     {
-      if (i < limit)
-      {
-        authors.add(e.getElement(), e.getCount());
-        i++;
-      }
-      else
-      {
-        others += e.getCount();
-      }
+      authors.add("others", others);
     }
 
-    authors.add("others", others);
-
     return new CommitsPerAuthor(authors);
   }
 
 
     return new CommitsPerMonth(commitsPerMonth);
   }
+
+  /**
+   * Method description
+   *
+   *
+   * @param data
+   * @param limit
+   *
+   * @return
+   */
+  public static TopModifiedFiles collectTopModifiedFiles(StatisticData data,
+    int limit)
+  {
+    Multiset<String> files = HashMultiset.create();
+
+    collectTopEntries(data.getModifiedFiles(), files, limit, false);
+
+    return new TopModifiedFiles(files);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param source
+   * @param target
+   * @param limit
+   * @param countOthers
+   * @param <T>
+   *
+   * @return
+   */
+  private static <T> int collectTopEntries(Multiset<T> source,
+    Multiset<T> target, int limit, boolean countOthers)
+  {
+    Multiset<T> ordered = Multisets.copyHighestCountFirst(source);
+
+    int i = 0;
+    int others = 0;
+
+    for (Entry<T> e : ordered.entrySet())
+    {
+      if (i < limit)
+      {
+        target.add(e.getElement(), e.getCount());
+        i++;
+      }
+      else if (countOthers)
+      {
+        others += e.getCount();
+      }
+      else
+      {
+        break;
+      }
+    }
+
+    return others;
+  }
 }

File src/main/java/sonia/scm/statistic/StatisticData.java

     commitsPerAuthor = HashMultiset.create();
     commitsPerDay = HashMultiset.create();
     commitsPerHour = HashMultiset.create();
+    modifiedFiles = HashMultiset.create();
   }
 
   //~--- methods --------------------------------------------------------------
     commitsPerDay.add(Day.of(cal));
     commitsPerHour.add(cal.get(Calendar.HOUR_OF_DAY));
 
+    for (String file : c.getModifications().getModified())
+    {
+      modifiedFiles.add(file);
+    }
+
     return this;
   }
 
     return commitsPerHour;
   }
 
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  public Multiset<String> getModifiedFiles()
+  {
+    return modifiedFiles;
+  }
+
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */
   @XmlElement(name = "commits-per-hour")
   @XmlJavaTypeAdapter(XmlMultisetIntegerAdapter.class)
   private Multiset<Integer> commitsPerHour;
+
+  /** Field description */
+  @XmlElement(name = "modified-files")
+  @XmlJavaTypeAdapter(XmlMultisetStringAdapter.class)
+  private Multiset<String> modifiedFiles;
 }

File src/main/java/sonia/scm/statistic/dto/TopModifiedFiles.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of SCM-Manager;
+ * nor the names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.statistic.dto;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import com.google.common.collect.Multiset;
+
+import sonia.scm.statistic.xml.XmlMultisetStringAdapter;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "top-modified-files")
+public class TopModifiedFiles
+{
+
+  /**
+   * Constructs ...
+   *
+   */
+  public TopModifiedFiles() {}
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param topModifiedFiles
+   */
+  public TopModifiedFiles(Multiset<String> topModifiedFiles)
+  {
+    this.topModifiedFiles = topModifiedFiles;
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  public Multiset<String> getTopModifiedFiles()
+  {
+    return topModifiedFiles;
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  @XmlElement(name = "file")
+  @XmlJavaTypeAdapter(XmlMultisetStringAdapter.class)
+  private Multiset<String> topModifiedFiles;
+}

File src/main/java/sonia/scm/statistic/resources/StatisticSubResource.java

 import sonia.scm.statistic.dto.CommitsPerAuthor;
 import sonia.scm.statistic.dto.CommitsPerHour;
 import sonia.scm.statistic.dto.CommitsPerMonth;
+import sonia.scm.statistic.dto.TopModifiedFiles;
 
 //~--- JDK imports ------------------------------------------------------------
 
     return data;
   }
 
+  /**
+   * Method description
+   *
+   *
+   * @param limit
+   *
+   * @return
+   */
+  @GET
+  @Path("top-modified-files")
+  @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+  public TopModifiedFiles getTopModifiedFiles(@QueryParam("limit")
+  @DefaultValue("10") int limit)
+  {
+    return StatisticCollector.collectTopModifiedFiles(data, limit);
+  }
+
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */

File src/main/resources/META-INF/scm/plugin.xml

     <script>/sonia/scm/statistic/sonia.statistic.commitsperauthor.js</script>
     <script>/sonia/scm/statistic/sonia.statistic.commitspermonth.js</script>
     <script>/sonia/scm/statistic/sonia.statistic.commitsperhour.js</script>
+    <script>/sonia/scm/statistic/sonia.statistic.topmodifiedfiles.js</script>
   </resources>
 
 </plugin>

File src/main/resources/sonia/scm/statistic/sonia.statistic.js

         text: 'Commits per Hour',
         handler: this.openCommitsPerHour,
         scope: this
+      },{
+        xtype: 'link',
+        style: 'font-weight: bold',
+        text: 'Top modified Files',
+        handler: this.openTopModifiedFiles,
+        scope: this
       }]
     }
     
       repository: this.item,
       closable: true
     });
+  },
+  
+  openTopModifiedFiles: function(){
+    main.addTab({
+      id: 'topModifiedFiles;' + this.item.id,
+      xtype: 'statisticTopModifiedFilesPanel',
+      repository: this.item,
+      closable: true
+    });
   }
   
 });

File src/main/resources/sonia/scm/statistic/sonia.statistic.topmodifiedfiles.js

+/* *
+ * Copyright (c) 2010, Sebastian Sdorra
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. Neither the name of SCM-Manager; nor the names of its
+ *    contributors may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * http://bitbucket.org/sdorra/scm-manager
+ * 
+ */
+
+Ext.ns('Sonia.statistic');
+
+Sonia.statistic.TopModifiedFiles = Ext.extend(Ext.Panel, {
+  
+  repository: null,
+  
+  initComponent: function(){    
+    var store = new Sonia.rest.JsonStore({
+      proxy: new Ext.data.HttpProxy({
+        url: restUrl + 'plugins/statistic/' + this.repository.id + '/top-modified-files.json',
+        disableCaching: false
+      }),
+      fields: ['count', 'value'],
+      root: 'file'
+    });
+    
+    var config = {
+      title: 'Top modified Files',
+      items: [{
+        store: store,
+        xtype: 'piechart',
+        dataField: 'count',
+        categoryField: 'value',
+        extraStyle: {
+          legend: {
+            display: 'bottom',
+            padding: 5,
+            font: {
+              family: 'Tahoma',
+              size: 13
+            }
+          }
+        }
+      }]
+    }
+    
+    Ext.apply(this, Ext.apply(this.initialConfig, config));
+    Sonia.statistic.TopModifiedFiles.superclass.initComponent.apply(this, arguments);
+  }
+  
+});
+
+// register xtype
+Ext.reg("statisticTopModifiedFilesPanel", Sonia.statistic.TopModifiedFiles);