Skip to content

Commit 13a4e04

Browse files
committed
Add longest current streak
1 parent 66d3eb7 commit 13a4e04

File tree

5 files changed

+72
-49
lines changed

5 files changed

+72
-49
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
class StatsController < ApplicationController
22

33
def index
4-
@stats = Stat.order(commits: :desc)
5-
@streaks = Stat.order(streaks: :desc)
4+
@stats = Stat.order(commits: :desc)
5+
@streaks = Stat.order(streaks: :desc)
6+
@current_streaks = Stat.order(current_streaks: :desc)
67
@updated_at = Stat.first.when_created
78
end
89

910
private
1011

1112
def commit_params
12-
params.require(:record).permit(:name, :commits, :streaks)
13+
params.require(:record).permit(:name, :commits, :streaks, :current_streaks)
1314
end
1415
end

app/views/stats/index.html.erb

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,51 +59,62 @@
5959
<!-- Page Content -->
6060
<div class="container">
6161
<div class="row">
62-
<div class="col-lg-12 text-center">
62+
<div class="col-md-12 text-center">
6363
<h1>1507 Git Commit Race</h1>
6464
<p class="lead">Compete with the best - who will have the most commits when Turing is over?</p>
6565
<p> Results as of: <%= @updated_at %>
6666
</div>
6767
</div>
6868
</div>
6969
</div>
70+
<br>
7071

7172
<div class="container">
72-
73-
74-
<div class="col-md-6">
75-
<h3 id="leaderboard">Commits Leaderboard</h3>
76-
<table class="table">
73+
<div class="col-md-8">
74+
<h3 id="leaderboard">Commits Leaderboard</h3>
75+
<table class="table">
76+
<tr>
77+
<td>Name</td>
78+
<td>Commits Since <%= Time.now.month %>/<%= Time.now.day %>/<%= Time.now.year - 1 %></td>
79+
</tr>
80+
<% @stats.each do |stat| %>
7781
<tr>
78-
<td>Name</td>
79-
<td>Commits</td>
82+
<td><%= stat.name %></td>
83+
<td><%= stat.commits %></td>
8084
</tr>
81-
<% @stats.each do |stat| %>
82-
<tr>
83-
<td><%= stat.name %></td>
84-
<td><%= stat.commits %></td>
85-
</tr>
86-
<% end %>
87-
<table>
88-
</div>
89-
90-
<div class="col-md-6">
91-
<h3 id="leaderboard">Longest Streak Leaderboard</h3>
92-
<table class="table">
85+
<% end %>
86+
<table>
87+
</div>
88+
<div class="col-md-8">
89+
<h3 id="leaderboard">Longest Current Streak Leaderboard</h3>
90+
<table class="table">
91+
<tr>
92+
<td>Name</td>
93+
<td>Longest Current Streak</td>
94+
</tr>
95+
<% @current_streaks.each do |stat| %>
9396
<tr>
94-
<td>Name</td>
95-
<td>Longest One Period Streak of Coding</td>
97+
<td><%= stat.name %></td>
98+
<td><%= stat.current_streaks %> days</td>
9699
</tr>
97-
<% @streaks.each do |stat| %>
98-
<tr>
99-
<td><%= stat.name %></td>
100-
<td><%= stat.streaks %></td>
101-
</tr>
102-
<% end %>
103-
<table>
104-
</div>
105-
106-
100+
<% end %>
101+
<table>
102+
</div>
103+
<div class="col-md-8">
104+
<h3 id="leaderboard">Longest Streak Leaderboard</h3>
105+
<table class="table">
106+
<tr>
107+
<td>Name</td>
108+
<td>Longest Streak</td>
109+
</tr>
110+
<% @streaks.each do |stat| %>
111+
<tr>
112+
<td><%= stat.name %></td>
113+
<td><%= stat.streaks %> days</td>
114+
</tr>
115+
<% end %>
116+
<table>
117+
</div>
107118
</div>
108119

109120
</body>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddCurrentStreaksToStat < ActiveRecord::Migration
2+
def change
3+
add_column :stats, :current_streaks, :integer
4+
end
5+
end

db/schema.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20151007231721) do
14+
ActiveRecord::Schema.define(version: 20151007235942) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
1818

1919
create_table "stats", force: :cascade do |t|
2020
t.string "name"
2121
t.integer "commits"
22-
t.datetime "created_at", null: false
23-
t.datetime "updated_at", null: false
22+
t.datetime "created_at", null: false
23+
t.datetime "updated_at", null: false
2424
t.integer "streaks"
25+
t.integer "current_streaks"
2526
end
2627

2728
end

lib/tasks/update_commits.rake

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,32 @@ task :update_commits => :environment do
2828
end
2929
puts "Mapped Streaks"
3030

31+
#Current Streak
32+
@current_streaks = @urls.map do |url|
33+
Nokogiri::HTML(open(url)).css(".contrib-column").css(".table-column").css(".contrib-number")[2].text.strip.gsub("days","").rstrip
34+
end
35+
puts "Mapped Current Streaks"
36+
3137
join = @names.zip(@commits)
3238
final = join.zip(@streaks)
3339

3440
final = final.map do |stat|
3541
stat.flatten
3642
end
3743

38-
final.each do |stat|
39-
stat.flatten
40-
Stat.create(name: stat[0], commits: stat[1], streaks: stat[2])
41-
puts "creating #{stat[0]} with #{stat[1]}commits and a streak of #{stat[2]} days"
42-
end
43-
44-
45-
46-
47-
48-
44+
real_final = final.zip(@current_streaks)
4945

5046

47+
real_final = real_final.map do |stat|
48+
stat.flatten
49+
end
5150

51+
real_final.each do |stat|
52+
stat.flatten
53+
Stat.create(name: stat[0], commits: stat[1], streaks: stat[2], current_streaks: stat[3])
54+
puts "creating #{stat[0]} with #{stat[1]}commits and a l
55+
ongest streak of #{stat[2]} days and a current streak of #{stat[3]} days"
56+
end
5257

5358
puts "All done Mr. Doucette"
5459
end

0 commit comments

Comments
 (0)