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 private final ReportConfig config; 33 private final Repository repository; 34 private Table table; 35 36 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 * 43 * @param content 44 * the version control source data 45 */ 46 public DevelopersOfTheMonthTable(final ReportConfig config) { 47 this.repository = config.getRepository(); 48 this.config = config; 49 } 50 51 public void calculate() { 52 final LinkColumn months = new LinkColumn("Month"); 53 final AuthorColumn developers = new AuthorColumn(); 54 final IntegerColumn loc = new IntegerColumn("Lines"); 55 final SimpleTextColumn twitter = new SimpleTextColumn("Tweet This"); 56 loc.setShowPercentages(false); 57 58 this.table = new Table("Repository Tags"); 59 this.table.setKeysInFirstColumn(true); 60 this.table.addColumn(months); 61 this.table.addColumn(developers); 62 this.table.addColumn(loc); 63 if (ConfigurationOptions.isEnableTwitterButton()) { 64 this.table.addColumn(twitter); 65 } 66 final Date start = this.repository.getFirstDate(); 67 final Date end = this.repository.getLastDate(); 68 final Calendar calendar = new GregorianCalendar(); 69 calendar.setTime(end); 70 final Calendar startCal = new GregorianCalendar(); 71 startCal.setTime(start); 72 while (true) { 73 final int year = calendar.get(Calendar.YEAR); 74 final int month = calendar.get(Calendar.MONTH); 75 final String month_year = MONTH_NAME[month] + " " + year; 76 final IntegerMap developerMap = getMostActiveUserOfMonth(month, year); 77 if (developerMap.size() > 0) { 78 months.addValue(CommitLogPageMaker.getURL(calendar.getTime()), month_year); 79 final Iterator it = developerMap.iteratorSortedByValueReverse(); 80 final Author developer = (Author) it.next(); 81 developers.addValue(developer); 82 loc.addValue(developerMap.get(developer)); 83 twitter.addValue(TwitterHelp.buildDeveloperOfMonthLink(developer, developerMap.get(developer), repository, month_year, config)); 84 } 85 86 if (calendar.get(Calendar.YEAR) == startCal.get(Calendar.YEAR) && calendar.get(Calendar.MONTH) == startCal.get(Calendar.MONTH)) { 87 break; 88 } 89 calendar.add(Calendar.MONTH, -1); 90 } 91 } 92 93 private IntegerMap getMostActiveUserOfMonth(final int month, final int year) { 94 final Collection revisions = this.repository.getRevisions(); 95 final Calendar calendar = new GregorianCalendar(); 96 final IntegerMap developerMap = new IntegerMap(); 97 final Iterator it = revisions.iterator(); 98 while (it.hasNext()) { 99 final Revision revision = (Revision) it.next(); 100 calendar.setTime(revision.getDate()); 101 if (calendar.get(Calendar.YEAR) != year || calendar.get(Calendar.MONTH) != month || revision.getAuthor() == null) { 102 continue; 103 } 104 if (developerMap.contains(revision.getAuthor())) { 105 final int loc = developerMap.get(revision.getAuthor()); 106 developerMap.put(revision.getAuthor(), revision.getNewLines() + loc); 107 } else { 108 developerMap.put(revision.getAuthor(), revision.getNewLines()); 109 } 110 } 111 return developerMap; 112 } 113 114 public Table getTable() { 115 return this.table; 116 } 117 }