Coverage Report - net.sf.statcvs.reports.DevelopersOfTheMonthTable
 
Classes in this File Line Coverage Branch Coverage Complexity
DevelopersOfTheMonthTable
0%
0/67
0%
0/32
2.75
 
 1  
 package net.sf.statcvs.reports;
 2  
 
 3  
 import java.util.Calendar;
 4  
 import java.util.Collection;
 5  
 import java.util.Date;
 6  
 import java.util.GregorianCalendar;
 7  
 import java.util.Iterator;
 8  
 
 9  
 import net.sf.statcvs.model.Author;
 10  
 import net.sf.statcvs.model.Repository;
 11  
 import net.sf.statcvs.model.Revision;
 12  
 import net.sf.statcvs.output.ConfigurationOptions;
 13  
 import net.sf.statcvs.output.ReportConfig;
 14  
 import net.sf.statcvs.pages.CommitLogPageMaker;
 15  
 import net.sf.statcvs.pages.TwitterHelp;
 16  
 import net.sf.statcvs.reportmodel.AuthorColumn;
 17  
 import net.sf.statcvs.reportmodel.IntegerColumn;
 18  
 import net.sf.statcvs.reportmodel.LinkColumn;
 19  
 import net.sf.statcvs.reportmodel.SimpleTextColumn;
 20  
 import net.sf.statcvs.reportmodel.Table;
 21  
 import net.sf.statcvs.util.IntegerMap;
 22  
 
 23  
 /**
 24  
  * Table report which creates a table containing the names of all developers,
 25  
  * their LOC contributions and number of changes.
 26  
  * 
 27  
  * @author Anja Jentzsch (anja@anjeve.de)
 28  
  * @version $Id: DevelopersTableReport.java,v 1.1 2006/12/08 16:19:25 cyganiak
 29  
  *          Exp $
 30  
  */
 31  
 public class DevelopersOfTheMonthTable implements TableReport {
 32  0
     private final ReportConfig config;
 33  
     private final Repository repository;
 34  
     private Table table;
 35  
 
 36  0
     private final static String[] MONTH_NAME = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
 37  
             "December" };
 38  
 
 39  
     /**
 40  
      * Creates a table report containing all authors, their number of changes
 41  
      * and LOC contributions.
 42  0
      * 
 43  0
      * @param content
 44  0
      *            the version control source data
 45  
      */
 46  0
     public DevelopersOfTheMonthTable(final ReportConfig config) {
 47  0
         this.repository = config.getRepository();
 48  0
         this.config = config;
 49  0
     }
 50  0
 
 51  
     public void calculate() {
 52  0
         final LinkColumn months = new LinkColumn("Month");
 53  0
         final AuthorColumn developers = new AuthorColumn();
 54  0
         final IntegerColumn loc = new IntegerColumn("Lines");
 55  0
         final SimpleTextColumn twitter = new SimpleTextColumn("Tweet This");
 56  0
         loc.setShowPercentages(false);
 57  
 
 58  0
         this.table = new Table("Repository Tags");
 59  0
         this.table.setKeysInFirstColumn(true);
 60  0
         this.table.addColumn(months);
 61  0
         this.table.addColumn(developers);
 62  0
         this.table.addColumn(loc);
 63  0
         if (ConfigurationOptions.isEnableTwitterButton()) {
 64  0
             this.table.addColumn(twitter);
 65  0
         }
 66  0
         final Date start = this.repository.getFirstDate();
 67  0
         final Date end = this.repository.getLastDate();
 68  0
         final Calendar calendar = new GregorianCalendar();
 69  0
         calendar.setTime(end);
 70  0
         final Calendar startCal = new GregorianCalendar();
 71  0
         startCal.setTime(start);
 72  0
         while (true) {
 73  0
             final int year = calendar.get(Calendar.YEAR);
 74  0
             final int month = calendar.get(Calendar.MONTH);
 75  0
             final String month_year = MONTH_NAME[month] + " " + year;
 76  0
             final IntegerMap developerMap = getMostActiveUserOfMonth(month, year);
 77  0
             if (developerMap.size() > 0) {
 78  0
                 months.addValue(CommitLogPageMaker.getURL(calendar.getTime()), month_year);
 79  0
                 final Iterator it = developerMap.iteratorSortedByValueReverse();
 80  0
                 final Author developer = (Author) it.next();
 81  0
                 developers.addValue(developer);
 82  0
                 loc.addValue(developerMap.get(developer));
 83  0
                 twitter.addValue(TwitterHelp.buildDeveloperOfMonthLink(developer, developerMap.get(developer), repository, month_year, config));
 84  
             }
 85  0
 
 86  0
             if (calendar.get(Calendar.YEAR) == startCal.get(Calendar.YEAR) && calendar.get(Calendar.MONTH) == startCal.get(Calendar.MONTH)) {
 87  0
                 break;
 88  0
             }
 89  0
             calendar.add(Calendar.MONTH, -1);
 90  0
         }
 91  0
     }
 92  0
 
 93  0
     private IntegerMap getMostActiveUserOfMonth(final int month, final int year) {
 94  0
         final Collection revisions = this.repository.getRevisions();
 95  0
         final Calendar calendar = new GregorianCalendar();
 96  0
         final IntegerMap developerMap = new IntegerMap();
 97  0
         final Iterator it = revisions.iterator();
 98  0
         while (it.hasNext()) {
 99  0
             final Revision revision = (Revision) it.next();
 100  0
             calendar.setTime(revision.getDate());
 101  0
             if (calendar.get(Calendar.YEAR) != year || calendar.get(Calendar.MONTH) != month || revision.getAuthor() == null) {
 102  0
                 continue;
 103  
             }
 104  0
             if (developerMap.contains(revision.getAuthor())) {
 105  0
                 final int loc = developerMap.get(revision.getAuthor());
 106  0
                 developerMap.put(revision.getAuthor(), revision.getNewLines() + loc);
 107  0
             } else {
 108  0
                 developerMap.put(revision.getAuthor(), revision.getNewLines());
 109  
             }
 110  0
         }
 111  0
         return developerMap;
 112  
     }
 113  
 
 114  
     public Table getTable() {
 115  0
         return this.table;
 116  
     }
 117  
 }