gitstats-rb 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +674 -0
  4. data/README.md +74 -0
  5. data/bin/gitstats +200 -0
  6. data/gitstats-rb.gemspec +24 -0
  7. data/lib/gitstats.rb +18 -0
  8. data/lib/gitstats/author.rb +37 -0
  9. data/lib/gitstats/git.rb +165 -0
  10. data/lib/gitstats/renderer.rb +30 -0
  11. data/lib/gitstats/renderer/gnuplot.rb +150 -0
  12. data/lib/gitstats/renderer/haml.rb +72 -0
  13. data/lib/gitstats/renderer/sass.rb +33 -0
  14. data/lib/gitstats/statgen.rb +119 -0
  15. data/lib/gitstats/stats.rb +12 -0
  16. data/lib/gitstats/stats/commit.rb +63 -0
  17. data/lib/gitstats/stats/commit/author.rb +17 -0
  18. data/lib/gitstats/stats/commit/time.rb +109 -0
  19. data/lib/gitstats/stats/file.rb +15 -0
  20. data/lib/gitstats/stats/file/filetype.rb +14 -0
  21. data/lib/gitstats/yearmonth.rb +39 -0
  22. data/template/gnuplot/activity.haml +3 -0
  23. data/template/gnuplot/asc.gif +0 -0
  24. data/template/gnuplot/authors.haml +2 -0
  25. data/template/gnuplot/bg.gif +0 -0
  26. data/template/gnuplot/commits_per_hour.plot +14 -0
  27. data/template/gnuplot/commits_per_month.plot +15 -0
  28. data/template/gnuplot/commits_per_wday.plot +15 -0
  29. data/template/gnuplot/commits_per_year.plot +11 -0
  30. data/template/gnuplot/commits_per_yearmonth.plot +11 -0
  31. data/template/gnuplot/desc.gif +0 -0
  32. data/template/gnuplot/filechanges_by_yearmonth.plot +17 -0
  33. data/template/gnuplot/files.haml +2 -0
  34. data/template/gnuplot/files_by_yearmonth.plot +11 -0
  35. data/template/gnuplot/helpers/block.rb +26 -0
  36. data/template/gnuplot/helpers/config.rb +12 -0
  37. data/template/gnuplot/helpers/names.rb +79 -0
  38. data/template/gnuplot/helpers/utils.rb +16 -0
  39. data/template/gnuplot/index.haml +2 -0
  40. data/template/gnuplot/jqplot.canvasAxisLabelRenderer.min.js +57 -0
  41. data/template/gnuplot/jqplot.canvasAxisTickRenderer.min.js +57 -0
  42. data/template/gnuplot/jqplot.canvasTextRenderer.min.js +57 -0
  43. data/template/gnuplot/jqplot.cursor.min.js +57 -0
  44. data/template/gnuplot/jqplot.dateAxisRenderer.min.js +57 -0
  45. data/template/gnuplot/jquery.jqplot.min.css +1 -0
  46. data/template/gnuplot/jquery.jqplot.min.js +57 -0
  47. data/template/gnuplot/jquery.js +4 -0
  48. data/template/gnuplot/jquery.tablesorter.js +4 -0
  49. data/template/gnuplot/lastweeks.plot +14 -0
  50. data/template/gnuplot/layouts/default.haml +117 -0
  51. data/template/gnuplot/linechanges_by_yearmonth.plot +17 -0
  52. data/template/gnuplot/lines.haml +2 -0
  53. data/template/gnuplot/lines_by_yearmonth.plot +11 -0
  54. data/template/gnuplot/partials/authors.haml +30 -0
  55. data/template/gnuplot/partials/blockheader.haml +2 -0
  56. data/template/gnuplot/partials/blocktoc.haml +7 -0
  57. data/template/gnuplot/partials/commitchart.haml +60 -0
  58. data/template/gnuplot/partials/commits_per_month.haml +27 -0
  59. data/template/gnuplot/partials/commits_per_year.haml +27 -0
  60. data/template/gnuplot/partials/commits_per_yearmonth.haml +27 -0
  61. data/template/gnuplot/partials/day_of_week.haml +28 -0
  62. data/template/gnuplot/partials/filechanges_by_yearmonth.haml +3 -0
  63. data/template/gnuplot/partials/files_by_yearmonth.haml +3 -0
  64. data/template/gnuplot/partials/fileschart.haml +86 -0
  65. data/template/gnuplot/partials/filetypes.haml +23 -0
  66. data/template/gnuplot/partials/general.haml +34 -0
  67. data/template/gnuplot/partials/hour_of_day.haml +28 -0
  68. data/template/gnuplot/partials/hour_of_week.haml +24 -0
  69. data/template/gnuplot/partials/lastweeks.haml +24 -0
  70. data/template/gnuplot/partials/linechanges_by_yearmonth.haml +3 -0
  71. data/template/gnuplot/partials/lines_by_yearmonth.haml +3 -0
  72. data/template/gnuplot/partials/lineschart.haml +86 -0
  73. data/template/gnuplot/partials/repos.haml +13 -0
  74. data/template/gnuplot/partials/top_authors_of_year.haml +30 -0
  75. data/template/gnuplot/partials/top_authors_of_yearmonth.haml +30 -0
  76. data/template/gnuplot/style.scss +132 -0
  77. data/template/highcharts/activity.haml +5 -0
  78. data/template/highcharts/authors.haml +3 -0
  79. data/template/highcharts/bootstrap-theme.min.css +10 -0
  80. data/template/highcharts/bootstrap.min.css +10 -0
  81. data/template/highcharts/bootstrap.min.js +11 -0
  82. data/template/highcharts/exporting.js +23 -0
  83. data/template/highcharts/glyphicons-halflings-regular.eot +0 -0
  84. data/template/highcharts/glyphicons-halflings-regular.svg +229 -0
  85. data/template/highcharts/glyphicons-halflings-regular.ttf +0 -0
  86. data/template/highcharts/glyphicons-halflings-regular.woff +0 -0
  87. data/template/highcharts/heatmap.js +23 -0
  88. data/template/highcharts/helpers/block.rb +27 -0
  89. data/template/highcharts/helpers/names.rb +62 -0
  90. data/template/highcharts/helpers/params.rb +35 -0
  91. data/template/highcharts/highcharts.js +308 -0
  92. data/template/highcharts/index.haml +2 -0
  93. data/template/highcharts/jquery-1.11.1.min.js +4 -0
  94. data/template/highcharts/jquery.dataTables.min.css +1 -0
  95. data/template/highcharts/jquery.dataTables.min.js +164 -0
  96. data/template/highcharts/layouts/default.haml +54 -0
  97. data/template/highcharts/partials/activity_per_day.haml +65 -0
  98. data/template/highcharts/partials/activity_per_hour.haml +42 -0
  99. data/template/highcharts/partials/activity_per_month.haml +47 -0
  100. data/template/highcharts/partials/activity_per_week_last_year.haml +47 -0
  101. data/template/highcharts/partials/activity_per_weekday.haml +44 -0
  102. data/template/highcharts/partials/activity_per_weekday_and_hour.haml +20 -0
  103. data/template/highcharts/partials/blocktoc.haml +4 -0
  104. data/template/highcharts/partials/commits_per_author.haml +64 -0
  105. data/template/highcharts/partials/commits_per_author_detailed.haml +92 -0
  106. data/template/highcharts/partials/general.haml +33 -0
  107. data/template/highcharts/partials/globalstats.haml +41 -0
  108. data/template/highcharts/partials/repos.haml +12 -0
  109. data/template/highcharts/set_highcharts.js +323 -0
  110. data/template/highcharts/style.scss +148 -0
  111. metadata +227 -0
@@ -0,0 +1,17 @@
1
+ class AuthorsCommitStats < CommitStats
2
+ include StatsHash
3
+
4
+ def initialize
5
+ super
6
+ @hash = Hash.new
7
+ end
8
+
9
+ def update(commit)
10
+ super(commit)
11
+
12
+ author = commit[:author]
13
+ @hash[author] ||= CommitStats.new
14
+ @hash[author].update(commit)
15
+ end
16
+ end
17
+
@@ -0,0 +1,109 @@
1
+ class YearCommitStats
2
+ include StatsHash
3
+
4
+ def initialize
5
+ @hash = Hash.new
6
+ end
7
+
8
+ def update(commit)
9
+ year = commit[:time].year
10
+ @hash[year] ||= AuthorsCommitStats.new
11
+ @hash[year].update(commit)
12
+ end
13
+ end
14
+
15
+ class MonthCommitStats
16
+ include StatsHash
17
+
18
+ def initialize
19
+ @hash = Hash.new
20
+ end
21
+
22
+ def update(commit)
23
+ month = commit[:time].month
24
+ @hash[month] ||= AuthorsCommitStats.new
25
+ @hash[month].update(commit)
26
+ end
27
+ end
28
+
29
+ class YearMonthCommitStats
30
+ include StatsHash
31
+
32
+ def initialize
33
+ @hash = Hash.new
34
+ end
35
+
36
+ def update(commit)
37
+ yearmonth = YearMonth.new(commit[:time])
38
+ @hash[yearmonth] ||= AuthorsCommitStats.new
39
+ @hash[yearmonth].update(commit)
40
+ end
41
+ end
42
+
43
+ class DateCommitStats
44
+ include StatsHash
45
+
46
+ def initialize
47
+ @hash = Hash.new
48
+ end
49
+
50
+ def update(commit)
51
+ t = commit[:time]
52
+ date = Date.civil(t.year, t.month, t.day)
53
+ @hash[date] ||= AuthorsCommitStats.new
54
+ @hash[date].update(commit)
55
+ end
56
+ end
57
+
58
+ class HourCommitStats < CommitStats
59
+ include StatsHash
60
+
61
+ def initialize
62
+ super
63
+ @hash = Hash.new
64
+ end
65
+
66
+ def update(commit)
67
+ super(commit)
68
+
69
+ hour = commit[:time].hour
70
+ @hash[hour] ||= CommitStats.new
71
+ @hash[hour].update(commit)
72
+ end
73
+ end
74
+
75
+ class DayOfWeekCommitStats
76
+ include StatsHash
77
+
78
+ def initialize
79
+ @hash = Hash.new
80
+ end
81
+
82
+ def update(commit)
83
+ day = commit[:time].wday
84
+ @hash[day] ||= HourCommitStats.new
85
+ @hash[day].update(commit)
86
+ end
87
+ end
88
+
89
+ class LastWeeksCommitStats
90
+ include StatsHash
91
+
92
+ def initialize
93
+ today = Time.now.to_date
94
+ nextCwStart = Date.commercial(today.cwyear,today.cweek)+7
95
+ @hash = Hash.new
96
+ @base = nextCwStart.to_time
97
+ end
98
+
99
+ def update(commit)
100
+ return if commit[:time] > @base
101
+
102
+ diff = ((@base - commit[:time]) / 604800).to_i
103
+ return if diff >= 52
104
+
105
+ @hash[diff] ||= CommitStats.new
106
+ @hash[diff].update(commit)
107
+ end
108
+ end
109
+
@@ -0,0 +1,15 @@
1
+ class FileStats
2
+ attr_reader :count
3
+ attr_reader :size
4
+
5
+ def initialize
6
+ @count = 0
7
+ @size = 0
8
+ end
9
+
10
+ def update(file)
11
+ @count += 1
12
+ @size += file[:size]
13
+ end
14
+ end
15
+
@@ -0,0 +1,14 @@
1
+ class FileTypeFileStats
2
+ include StatsHash
3
+
4
+ def initialize
5
+ @hash = Hash.new
6
+ end
7
+
8
+ def update(file)
9
+ type = File.extname(file[:name])
10
+ @hash[type] ||= FileStats.new
11
+ @hash[type].update(file)
12
+ end
13
+ end
14
+
@@ -0,0 +1,39 @@
1
+ class YearMonth
2
+ include Comparable
3
+
4
+ attr_reader :year
5
+ attr_reader :month
6
+
7
+ def initialize(a, b = nil)
8
+ if a.is_a? Time
9
+ @year = a.year
10
+ @month = a.month
11
+ elsif b.nil?
12
+ @year = (a / 100).to_i
13
+ @month = a % 100
14
+ else
15
+ @year = a.to_i
16
+ @month = b.to_i
17
+ end
18
+ end
19
+
20
+ def <=>(b)
21
+ to_i <=> b.to_i
22
+ end
23
+
24
+ def to_i
25
+ @year * 12 + @month - 1
26
+ end
27
+
28
+ def to_s
29
+ '%04d-%02d' % [@year, @month]
30
+ end
31
+
32
+ def eql?(b)
33
+ to_i == b.to_i
34
+ end
35
+
36
+ def hash
37
+ to_i
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ - layout :default
2
+ = blocks :lastweeks, :hour_of_day, :day_of_week, :hour_of_week, :commitchart, :commits_per_year, :commits_per_month, :commits_per_yearmonth
3
+
Binary file
@@ -0,0 +1,2 @@
1
+ - layout :default
2
+ = blocks :authors, :top_authors_of_year, :top_authors_of_yearmonth
Binary file
@@ -0,0 +1,14 @@
1
+ defplot do |plotter|
2
+ plotter.plot.xrange '[-0.5:23.5]'
3
+ plotter.plot.xtics '1'
4
+ plotter.plot.ylabel 'Commits'
5
+
6
+ plotter.add_boxes(:setrange => false, :limitlabels => false) do |x, l, y|
7
+ for hour in 0..23
8
+ s = stats.hour_stats[hour]
9
+ x << hour
10
+ l << hour
11
+ y << (s.nil? ? 0 : s.commits)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ defplot do |plotter|
2
+ plotter.plot.xrange '[0.5:12.5]'
3
+ plotter.plot.xtics '1'
4
+ plotter.plot.ylabel 'Commits'
5
+ plotter.plot.yrange '[0:]'
6
+
7
+ plotter.add_boxes(:setrange => false, :limitlabels => false) do |x, l, y|
8
+ for month in 1..12
9
+ s = stats.month_stats[month]
10
+ x << month
11
+ l << monthname(month)
12
+ y << (s.nil? ? 0 : s.commits)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ defplot do |plotter|
2
+ plotter.plot.xrange '[0.5:7.5]'
3
+ plotter.plot.xtics '1'
4
+ plotter.plot.ylabel 'Commits'
5
+
6
+ plotter.add_boxes(:setrange => false, :limitlabels => false) do |x, l, y|
7
+ for i in 0..6
8
+ s = stats.wday_stats[i]
9
+ day = (i + 6) % 7
10
+ x << day + 1
11
+ l << weekday(day)
12
+ y << (s.nil? ? 0 : s.commits)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ defplot do |plotter|
2
+ plotter.plot.ylabel 'Commits'
3
+
4
+ plotter.add_boxes do |x, l, y|
5
+ stats.year_stats.each_sorted do |year, stats|
6
+ x << year
7
+ l << year
8
+ y << stats.commits
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ defplot do |plotter|
2
+ plotter.plot.ylabel 'Commits'
3
+
4
+ plotter.add_boxes do |x, l, y|
5
+ stats.yearmonth_stats.each_sorted do |yearmonth, stats|
6
+ x << yearmonth.to_i
7
+ l << yearmonth.to_s
8
+ y << stats.commits
9
+ end
10
+ end
11
+ end
Binary file
@@ -0,0 +1,17 @@
1
+ defplot do |plotter|
2
+ plotter.add_steps do |x, l, y|
3
+ stats.yearmonth_stats.each_sorted do |yearmonth, stats|
4
+ x << yearmonth.to_i
5
+ l << yearmonth.to_s
6
+ y << stats.files_added
7
+ end
8
+ end
9
+
10
+ plotter.add_steps do |x, l, y|
11
+ stats.yearmonth_stats.each_sorted do |yearmonth, stats|
12
+ x << yearmonth.to_i
13
+ l << yearmonth.to_s
14
+ y << stats.files_deleted
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ - layout :default
2
+ = blocks :fileschart, :files_by_yearmonth, :filechanges_by_yearmonth, :filetypes
@@ -0,0 +1,11 @@
1
+ defplot do |plotter|
2
+ plotter.add_steps do |x, l, y|
3
+ files = 0
4
+ stats.yearmonth_stats.each_sorted do |yearmonth, stats|
5
+ files += stats.files
6
+ x << yearmonth.to_i
7
+ l << yearmonth.to_s
8
+ y << files
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ module BlockHelper
2
+ def blocktoc(*args)
3
+ partial :blocktoc, { :blocks => args }
4
+ end
5
+
6
+ def block(name)
7
+ haml_concat(partial(:blockheader, { :name => name }))
8
+ haml_concat("<div id=\"block-#{name.to_s}\" class=\"blockcontainer\">")
9
+ yield
10
+ haml_concat('</div>')
11
+ end
12
+
13
+ def blocks(*args)
14
+ ret = blocktoc(*args)
15
+ args.each do |block|
16
+ if block_given?
17
+ ret += yield(partial(block))
18
+ else
19
+ ret += partial(block)
20
+ end
21
+ end
22
+ ret
23
+ end
24
+ end
25
+
26
+ self.extend BlockHelper
@@ -0,0 +1,12 @@
1
+ module ConfigHelper
2
+ def author_count
3
+ 100
4
+ end
5
+
6
+ def top_author_count
7
+ 20
8
+ end
9
+ end
10
+
11
+ self.extend ConfigHelper
12
+
@@ -0,0 +1,79 @@
1
+ module NamesHelper
2
+ def label(name)
3
+ @names ||= {
4
+ :repos => 'Repositories',
5
+ :general => 'Stats',
6
+ :hour_of_day => 'Hour of day',
7
+ :day_of_week => 'Day of week',
8
+ :hour_of_week => 'Hour of week',
9
+ :commits_per_month => 'Commits per month',
10
+ :commits_per_year => 'Commits per year',
11
+ :commits_per_yearmonth => 'Commits per year and month',
12
+ :authors => "Top #{author_count} authors",
13
+ :top_authors_of_year => "Top #{top_author_count} authors of year",
14
+ :top_authors_of_yearmonth => "Top #{top_author_count} authors of year and month",
15
+ :files_by_yearmonth => 'Files by year and month',
16
+ :filechanges_by_yearmonth => 'Filechanges by year and month',
17
+ :lines_by_yearmonth => 'Lines by year and month',
18
+ :linechanges_by_yearmonth => 'Linechanges by year and month',
19
+ :filetypes => 'Filetypes',
20
+ :lastweeks => 'Last years weeks',
21
+ :fileschart => 'Fileschart',
22
+ :lineschart => 'Lineschart',
23
+ :commitchart => 'Commitchart',
24
+ }
25
+
26
+ @names[name].nil? ? name.to_s : @names[name]
27
+ end
28
+
29
+ def weekday(wday)
30
+ case wday
31
+ when 0
32
+ 'Mon'
33
+ when 1
34
+ 'Tue'
35
+ when 2
36
+ 'Wed'
37
+ when 3
38
+ 'Thu'
39
+ when 4
40
+ 'Fri'
41
+ when 5
42
+ 'Sat'
43
+ when 6
44
+ 'Sun'
45
+ end
46
+ end
47
+
48
+ def monthname(month)
49
+ case month
50
+ when 1
51
+ 'Jan'
52
+ when 2
53
+ 'Feb'
54
+ when 3
55
+ 'Mar'
56
+ when 4
57
+ 'Apr'
58
+ when 5
59
+ 'May'
60
+ when 6
61
+ 'Jun'
62
+ when 7
63
+ 'Jul'
64
+ when 8
65
+ 'Aug'
66
+ when 9
67
+ 'Sep'
68
+ when 10
69
+ 'Oct'
70
+ when 11
71
+ 'Nov'
72
+ when 12
73
+ 'Dec'
74
+ end
75
+ end
76
+ end
77
+
78
+ self.extend NamesHelper
79
+