Commit 9c2d41ac by Bui Minh Duc

fixed bug and implement User page

parent 265e25cb
...@@ -3,7 +3,11 @@ class IssuesController < ApplicationController ...@@ -3,7 +3,11 @@ class IssuesController < ApplicationController
def index def index
# need some params: repo, label, filter(include from date, label) # need some params: repo, label, filter(include from date, label)
@from_date = params[:date].empty? ? "" : Date.parse(params[:date]) # @from_date = params[:date].empty? ? "" : Date.parse(params[:date])
@from_date = ""
if !params[:date].nil? && !params[:date].empty?
@from_date = Date.parse(params[:date])
end
@filter_labels = params[:filter] @filter_labels = params[:filter]
@type_of_issue = params[:type] @type_of_issue = params[:type]
...@@ -19,7 +23,7 @@ class IssuesController < ApplicationController ...@@ -19,7 +23,7 @@ class IssuesController < ApplicationController
@repo_name = params[:repo] @repo_name = params[:repo]
issues_query = Issue.joins(:repository).joins(:labels).where( issues_query = Issue.joins(:repository).joins(:labels).where(
"repositories.name = ? AND labels.name = ? AND issues.is_pull IN (?) AND issues.created_at >= ?", "repositories.name = ? AND labels.name = ? AND issues.is_pull IN (?) AND issues.created_at >= ?",
params[:repo], params[:label], type_of_issue_query, @from_date) params[:repo], params[:label], type_of_issue_query, @from_date).order("issues.id DESC")
if @filter_labels.nil? if @filter_labels.nil?
@issues = issues_query @issues = issues_query
......
class MainController < ApplicationController class MainController < ApplicationController
def index def index
# byebug
@from_date = session[:filter_date] @from_date = session[:filter_date]
@label_filter_params = session[:filter_label] @label_filter_params = session[:filter_label]
if @label_filter_params.nil? || @label_filter_params.empty? if @label_filter_params.nil? || @label_filter_params.empty?
@label_filter_params = [] @label_filter_params = []
...@@ -81,6 +81,7 @@ class MainController < ApplicationController ...@@ -81,6 +81,7 @@ class MainController < ApplicationController
end end
def update_params_selected def update_params_selected
# byebug
session[:filter_label] = params[:selected] session[:filter_label] = params[:selected]
session[:filter_date] = params[:date] session[:filter_date] = params[:date]
session[:type_of_issue] = params[:issue_type] session[:type_of_issue] = params[:issue_type]
......
...@@ -4,7 +4,9 @@ class PullsController < ApplicationController ...@@ -4,7 +4,9 @@ class PullsController < ApplicationController
@id = params[:id] @id = params[:id]
@pull = Issue.find_by(id: @id) @pull = Issue.find_by(id: @id)
@issue = @pull.issue @issue = @pull.issue
@repo = @issue.repository if !@issue.nil?
@repo = @issue.repository
end
@comments = @pull.comments.where(comment_type: 0) @comments = @pull.comments.where(comment_type: 0)
@rv_comments = @pull.review_comments @rv_comments = @pull.review_comments
......
...@@ -24,6 +24,8 @@ class RepositoriesController < ApplicationController ...@@ -24,6 +24,8 @@ class RepositoriesController < ApplicationController
else else
@issues = @repo.issues.where(is_pull: false) @issues = @repo.issues.where(is_pull: false)
end end
@issues = @issues.order("id DESC")
@issues = @issues.includes(:labels, :pull_requests)
end end
......
class UserController < ApplicationController
def index
@users = User.all
end
end
class UsersController < ApplicationController
def index
@users = User.where(team_ventura: true)#.includes(own_issues: [:review_comments, :comments]).where(issues: {is_pull: true, comments: { comment_type: 1 }}, )
@score = Hash.new
@users.each do |user|
user_score = Hash.new
user_score[:before] = {0 => 0, 1 => 0, 2 => 0, 3 => 0}
user_score[:after] = {0 => 0, 1 => 0, 2 => 0, 3 => 0}
pulls = user.own_issues.includes(:review_comments, :comments).where(is_pull: true, comments: { comment_type: 1 })
pulls.each do |pull|
rv_comments = pull.review_comments
rv_comments.each do |rv_comment|
user_score[:before][rv_comment.score.to_i] += 1
end
comments = pull.comments.where(comment_type: 1)
comments.each do |comment|
user_score[:after][comment.score.to_i] += 1
end
end
@score[user.login.to_sym] = user_score
end
end
def show
@user = User.find_by(id: params[:id])
@pulls = Issue.where(user_id: @user.id, is_pull: true).includes(:review_comments, :comments).where(comments: { comment_type: 1 })
@score_before = {0 => 0, 1 => 0, 2 => 0, 3 => 0}
@score_after = {0 => 0, 1 => 0, 2 => 0, 3 => 0}
@pulls.each do |pull|
rv_comments = pull.review_comments
rv_comments.each do |rv_comment|
@score_before[rv_comment.score.to_i] += 1
end
comments = pull.comments.where(comment_type: 1)
comments.each do |comment|
@score_after[comment.score.to_i] += 1
end
end
# @pulls = Issue.where(user_id: @user.id, is_pull: true)
end
end
module UsersHelper
def before_release_point(score)
before_point(score)
end
def after_release_point(score)
after_point(score)
end
def arg_point(score)
x = (estimated_point + before_point(score) + after_point(score)) / 3
x.round(2)
end
def total_comment(score)
score.map{ |k, v| v }.sum
end
def total_minus_point_before(score)
x = score[1] * 0.1 + score[2] * 0.25 + score[3] * 0.5
x.round(2)
end
def total_point_before(score)
x = 1.0 - (score[1] * 0.1 + score[2] * 0.25 + score[3] * 0.5) / total_comment(score)
x.round(2)
end
def total_minus_point_after(score)
x = score[1] * 0.2 + score[2] * 0.5 + score[3] * 1.0
x.round(2)
end
def total_point_after(score)
x = 1.0 - (score[1] * 0.2 + score[2] * 0.5 + score[3] * 1.0) / total_comment(score)
x.round(2)
end
private
def estimated_point
1.0
end
def before_point(score)
score_before = score[:before]
x1 = score_before[0] * 0 + score_before[1] * 0.1 + score_before[2] * 0.25 + score_before[3] * 0.5
x2 = score_before[0] + score_before[1] + score_before[2] + score_before[3]
x3 = 1.0 - x1 / x2
if x2 != 0
x3.round(2)
else
1.0
end
end
def after_point(score)
score_after = score[:after]
x1 = score_after[0] * 0 + score_after[1] * 0.2 + score_after[2] * 0.5 + score_after[3] * 1.0
x2 = score_after[0] + score_after[1] + score_after[2] + score_after[3]
x3 = 1.0 - x1 / x2
if x2 != 0
x3.round(2)
else
1.0
end
end
end
class User < ApplicationRecord class User < ApplicationRecord
has_and_belongs_to_many :issues has_and_belongs_to_many :issues
has_many :own_issues, class_name: "Issue", foreign_key: "user_id"
end end
...@@ -44,7 +44,9 @@ ...@@ -44,7 +44,9 @@
</div> </div>
<div id="collapse1" class="panel-collapse collapse"> <div id="collapse1" class="panel-collapse collapse">
<div class="panel-body"> <div class="panel-body">
<%= $markdown.render(@issue.body).html_safe %> <% unless @issue.body.nil? %>
<%= $markdown.render(@issue.body).html_safe %>
<% end %>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</div> </div>
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><%= link_to "User", user_path %></li> <li><%= link_to "User", users_path %></li>
<li><%= link_to "Repository", repositories_path %></li> <li><%= link_to "Repository", repositories_path %></li>
<li><%= link_to "Settings", settings_path %></li> <li><%= link_to "Settings", settings_path %></li>
</ul> </ul>
......
...@@ -147,9 +147,10 @@ ...@@ -147,9 +147,10 @@
url: "<%= update_params_selected_path %>", url: "<%= update_params_selected_path %>",
data: { selected: selected_labels, date: from_date, issue_type: issue_type }, data: { selected: selected_labels, date: from_date, issue_type: issue_type },
success: function(res) { success: function(res) {
// location.reload(); location.reload();
} }
}); });
return false;
}); });
$(document).on('ready', function(event) { $(document).on('ready', function(event) {
......
<div class="container"> <div class="container">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li><%= link_to @repo.name, @repo %></li> <% if !@issue.nil? %>
<li><%= link_to @issue.title, @issue %></li> <li><%= link_to @repo.name, @repo %></li>
<li><%= link_to @issue.title, @issue %></li>
<% end %>
<li><%= @pull.title %></li> <li><%= @pull.title %></li>
</ol> </ol>
<div class="row"> <div class="row">
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<td><%= repo.description %></td> <td><%= repo.description %></td>
<td> <td>
<%= form_for :repo, url: { action: "update", id: repo.id }, method: :patch, html: { class: "form-inline" } do |f| %> <%= form_for :repo, url: { action: "update", id: repo.id }, method: :patch, html: { class: "form-inline" } do |f| %>
<%= f.submit "Update" %> <%= f.submit "Update", class: "btn btn-default btn-xs" %>
<i class="fa fa-refresh fa-spin" style="font-size:18px; visibility: hidden;"></i> <i class="fa fa-refresh fa-spin" style="font-size:18px; visibility: hidden;"></i>
<% end %> <% end %>
</td> </td>
......
...@@ -38,7 +38,12 @@ ...@@ -38,7 +38,12 @@
<tbody> <tbody>
<% @issues.each do |issue| %> <% @issues.each do |issue| %>
<tr> <tr>
<td><b><%= link_to issue.title, issue %></b></td> <td>
<b><%= link_to issue.title, issue %></b>
<% issue.labels.each do |label| %>
<span class="label label-default" style="background-color: #<%= label.color %>; color: #<%= get_text_color(label.color) %>;"><%= label.name %></span>
<% end %>
</td>
<td><%= issue.created_at %></td> <td><%= issue.created_at %></td>
</tr> </tr>
<% issue.pull_requests.each do |pull| %> <% issue.pull_requests.each do |pull| %>
...@@ -51,4 +56,7 @@ ...@@ -51,4 +56,7 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<div style="height: 100px;">
</div>
</div> </div>
<div class="container"> <div class="container">
<div id="toolbar">
<form class="form-inline">
<div class="form-group">
<label for="from">From</label>
<div class='input-group date' id='from_date'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<label for="to">To</label>
<div class='input-group date' id='to_date'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<div class="input-group">
<input type="submit" name="Filter" class="btn btn-default">
</div>
</div>
</form>
</div>
<div> <div>
<table data-toolbar="#toolbar" <table data-toolbar="#toolbar"
data-toggle="table" data-toggle="table"
...@@ -15,23 +39,38 @@ ...@@ -15,23 +39,38 @@
<thead> <thead>
<tr> <tr>
<th class="col-md-4">User name</th> <th class="col-md-4">User name</th>
<th class="col-md-2">Score 1 (80%)</th> <th class="col-md-2">Estimated Time (A)</th>
<th class="col-md-2">Score 2 (10%)</th> <th class="col-md-2">Before Release (B)</th>
<th class="col-md-2">Score 3 (10%)</th> <th class="col-md-2">After Release (C)</th>
<th class="col-md-2">Arg Score</th> <th class="col-md-2">Arg Point (A + B + C) / 3</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% @users.each do |user| %> <% @users.each do |user| %>
<tr> <tr>
<td><%= link_to user.login, user.html_url %></td> <td><%= link_to user.login, user_path(user) %></td>
<td>10</td> <td>1.0</td>
<td>10</td> <td><%= before_release_point @score[user.login.to_sym] %></td>
<td>10</td> <td><%= after_release_point @score[user.login.to_sym] %></td>
<td>10</td> <td><%= arg_point @score[user.login.to_sym] %></td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
<script type="text/javascript">
$(document).on('ready', function(event) {
// location.reload();
$('#from_date').datetimepicker({
format: "DD/MM/YYYY",
showClear: true
});
$('#to_date').datetimepicker({
format: "DD/MM/YYYY",
showClear: true
});
});
</script>
<div class="container">
<ol class="breadcrumb">
<li><%= @user.login %></li>
</ol>
<div class="panel panel-default">
<div class="panel-heading">
<h4>Before Release</h4>
</div>
<table class="table table-bordered">
<tbody>
<tr>
<td class="col-md-3">None</td>
<td class="col-md-3"><%= @score_before[0] %></td>
<td class="col-md-3"><%= "x 0" %></td>
<td class="col-md-3"><%= @score_before[0] * 0 %></td>
</tr>
<tr>
<td class="col-md-3">Small</td>
<td class="col-md-3"><%= @score_before[1] %></td>
<td class="col-md-3"><%= "x 0.1" %></td>
<td class="col-md-3"><%= @score_before[1] * 0.1 %></td>
</tr>
<tr>
<td class="col-md-3">Medium</td>
<td class="col-md-3"><%= @score_before[2] %></td>
<td class="col-md-3"><%= "x 0.25" %></td>
<td class="col-md-3"><%= @score_before[2] * 0.25 %></td>
</tr>
<tr>
<td class="col-md-3">Large</td>
<td class="col-md-3"><%= @score_before[3] %></td>
<td class="col-md-3"><%= "x 0.5" %></td>
<td class="col-md-3"><%= @score_before[3] * 0.5 %></td>
</tr>
<tr style="font-weight: bold">
<td class="col-md-3 text-right">Total Comment (A)</td>
<td class="col-md-3"><%= total_comment @score_before %></td>
<td class="col-md-3 text-right">Total Minus Point (B)</td>
<td class="col-md-3"><%= total_minus_point_before @score_before %></td>
</tr>
<tr style="font-weight: bold">
<td class="col-md-3"></td>
<td class="col-md-3"></td>
<td class="col-md-3 text-right">Total Point 1 - (B) / (A)</td>
<td class="col-md-3"><%= total_point_before @score_before %></td>
</tr>
</tbody>
</table>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4>After Release</h4>
</div>
<table class="table table-bordered">
<tbody>
<tr>
<td class="col-md-3">None</td>
<td class="col-md-3"><%= @score_after[0] %></td>
<td class="col-md-3"><%= "x 0" %></td>
<td class="col-md-3"><%= @score_after[0] * 0 %></td>
</tr>
<tr>
<td class="col-md-3">Small</td>
<td class="col-md-3"><%= @score_after[1] %></td>
<td class="col-md-3"><%= "x 0.2" %></td>
<td class="col-md-3"><%= @score_after[1] * 0.2 %></td>
</tr>
<tr>
<td class="col-md-3">Medium</td>
<td class="col-md-3"><%= @score_after[2] %></td>
<td class="col-md-3"><%= "x 0.5" %></td>
<td class="col-md-3"><%= @score_after[2] * 0.5 %></td>
</tr>
<tr style="font-weight: bold">
<td class="col-md-3 text-right">Total Comment (A)</td>
<td class="col-md-3"><%= total_comment @score_after %></td>
<td class="col-md-3 text-right">Total Minus Point (B)</td>
<td class="col-md-3"><%= total_minus_point_after @score_after %></td>
</tr>
<tr style="font-weight: bold">
<td class="col-md-3"></td>
<td class="col-md-3"></td>
<td class="col-md-3 text-right">Total Point 1 - (B) / (A)</td>
<td class="col-md-3"><%= total_point_after @score_after %></td>
</tr>
</tbody>
</table>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>List of pulls</th>
</tr>
</thead>
<tbody>
<% @pulls.each do |pull| %>
<tr>
<td><%= link_to pull.title, pull_path(pull) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
...@@ -5,7 +5,7 @@ Rails.application.routes.draw do ...@@ -5,7 +5,7 @@ Rails.application.routes.draw do
post "/update_params_selected", to: "main#update_params_selected" post "/update_params_selected", to: "main#update_params_selected"
post "/load_repo_selected", to: "main#load_repo_selected" post "/load_repo_selected", to: "main#load_repo_selected"
get "/user", to: "user#index" resources :users
resources :issues resources :issues
resources :pulls do resources :pulls do
resources :comments resources :comments
......
class AddTeamVenturaToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :team_ventura, :boolean
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170110090046) do ActiveRecord::Schema.define(version: 20170116025901) do
create_table "comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| create_table "comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
t.string "html_url" t.string "html_url"
...@@ -109,6 +109,12 @@ ActiveRecord::Schema.define(version: 20170110090046) do ...@@ -109,6 +109,12 @@ ActiveRecord::Schema.define(version: 20170110090046) do
t.index ["user_id"], name: "index_review_comments_on_user_id", using: :btree t.index ["user_id"], name: "index_review_comments_on_user_id", using: :btree
end end
create_table "teams", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "timelines", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| create_table "timelines", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
t.integer "duration" t.integer "duration"
t.integer "issue_id" t.integer "issue_id"
...@@ -124,8 +130,11 @@ ActiveRecord::Schema.define(version: 20170110090046) do ...@@ -124,8 +130,11 @@ ActiveRecord::Schema.define(version: 20170110090046) do
t.string "login" t.string "login"
t.string "url" t.string "url"
t.string "html_url" t.string "html_url"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "team_id"
t.boolean "team_ventura"
t.index ["team_id"], name: "index_users_on_team_id", using: :btree
end end
add_foreign_key "comments", "issues" add_foreign_key "comments", "issues"
...@@ -136,4 +145,5 @@ ActiveRecord::Schema.define(version: 20170110090046) do ...@@ -136,4 +145,5 @@ ActiveRecord::Schema.define(version: 20170110090046) do
add_foreign_key "review_comments", "issues" add_foreign_key "review_comments", "issues"
add_foreign_key "review_comments", "users" add_foreign_key "review_comments", "users"
add_foreign_key "timelines", "issues" add_foreign_key "timelines", "issues"
add_foreign_key "users", "teams"
end end
...@@ -86,6 +86,31 @@ class GithubLoader ...@@ -86,6 +86,31 @@ class GithubLoader
db_user.save db_user.save
end end
end end
insert_teams(client)
end
def insert_teams(client)
$logger.info "Insert users"
teams = client.organization_teams($org)
teams.each do |team|
if team.slug == "ventura-developers"
members = client.team_members(team.id)
last_page = 1
unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
# byebug
for i in (1..last_page)
members = client.team_members(team.id, {page: i})
members.each do |member|
db_member = User.find_by(id: member.id)
db_member.team_ventura = true
db_member.save
end
end
end
end
end end
def insert_issues(client, db_repos) def insert_issues(client, db_repos)
...@@ -154,8 +179,12 @@ class GithubLoader ...@@ -154,8 +179,12 @@ class GithubLoader
new_timeline(db_issue.id, new_label.name) new_timeline(db_issue.id, new_label.name)
elsif !old_label.nil? and new_label.nil? elsif !old_label.nil? and new_label.nil?
timeline = Timeline.where(issue_id: db_issue.id, label: old_label.name).last timeline = Timeline.where(issue_id: db_issue.id, label: old_label.name).last
timeline.end_time = Time.now begin
timeline.save timeline.end_time = Time.now
timeline.save
rescue
# ignore this case for first time insert
end
end end
else # both old_label and new label is not nil else # both old_label and new label is not nil
if new_label.name != old_label.name if new_label.name != old_label.name
...@@ -278,7 +307,7 @@ class GithubLoader ...@@ -278,7 +307,7 @@ class GithubLoader
unless issue_number.nil? unless issue_number.nil?
issue = issues.where(repository_id: pull.repository_id).find_by(number: issue_number.to_s[1..-1]) issue = issues.where(repository_id: pull.repository_id).find_by(number: issue_number.to_s[1..-1])
pull.issue = issue pull.issue = issue
puts pull.save # puts pull.save
end end
end end
end end
......
...@@ -38,19 +38,9 @@ namespace :github do ...@@ -38,19 +38,9 @@ namespace :github do
task insert_repo_only: :environment do task insert_repo_only: :environment do
loader = GithubLoader.new loader = GithubLoader.new
$logger.info "Begin task insert repository" $logger.info "Begin task insert repository"
list_db_repo = loader.insert_repos($client) loader.insert_repos($client)
# list_db_user = loader.insert_users($client) loader.insert_users($client)
list_db_label = loader.insert_labels($client, list_db_repo) # loader.insert_labels($client)
ActiveRecord::Base.transaction do
list_db_repo.each do |db_repo|
db_repo.save
end
list_db_label.each do |db_label|
db_label.save
end
end
$logger.info "Finished task insert repository" $logger.info "Finished task insert repository"
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment