diff --git a/.ruby-version b/.ruby-version index b1b25a5..bc4abe8 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.2.2 +2.3.8 diff --git a/Gemfile b/Gemfile index 998fb63..9997fca 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,7 @@ gem "omniauth-google-oauth2" gem 'omniauth-oauth2', '~> 1.3.1' gem 'rspec-rails', '~> 3.6.1', group: [:test, :development] +gem 'rb-readline' group :test do gem 'factory_bot_rails' diff --git a/Gemfile.lock b/Gemfile.lock index 714eefb..8dec7d4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -285,6 +285,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) + rb-readline (0.5.5) rdoc (4.3.0) ref (2.0.0) representable (3.0.4) @@ -431,6 +432,7 @@ DEPENDENCIES rack_session_access rails (~> 4.2.10) rails_12factor + rb-readline responders (~> 2.0) rest-client rspec-rails (~> 3.6.1) diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index de893a2..c7e096d 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -1,4 +1,5 @@ class ActivitiesController < ApplicationController + layout false before_action :set_activity, only: [:show, :destroy] # GET /activities @@ -12,6 +13,10 @@ def index def show end + def meetings + @meetings = Activity.infer_meetings + end + # POST /activities.json def create @activity = Activity.new(activity_params) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 92d097f..f57ae67 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,7 +36,7 @@ def rescue_steps(message) def record_activity activity_param = { activity_type: "#{params[:controller]}\##{params[:action]}", - user_id: current_user.nil? ? nil : current_user[:id], + username: current_user.nil? ? nil : current_user['username'] } if params[:action].eql? 'project' diff --git a/app/helpers/activities_helper.rb b/app/helpers/activities_helper.rb index 4e9784c..1466b35 100644 --- a/app/helpers/activities_helper.rb +++ b/app/helpers/activities_helper.rb @@ -1,2 +1,22 @@ module ActivitiesHelper + def meeting_start(meetings) + meetings.first.created_at + end + + def meeting_length(meetings) + ((meetings.last.created_at - meetings.first.created_at) / 60.0).round(2) + end + + def num_stories_updated(meetings) + meetings.select { |act| act.activity_type.eql? 'dashboard#update' } + .map(&:story_id).uniq.length + end + + def num_votes(meetings) + meetings.select { |act| act.activity_type.eql? 'dashboard#vote' }.length + end + + def num_participants(meetings) + meetings.map(&:username).uniq.length + end end diff --git a/app/models/activity.rb b/app/models/activity.rb index 6fb8a9e..a3303a8 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -1,4 +1,20 @@ class Activity < ActiveRecord::Base - belongs_to :user belongs_to :vote, required: false + + def self.infer_meetings + prev_time = Activity.first.created_at + meetings = [] + current_meeting = [] + Activity.all.each do |activity| + if (activity.created_at - prev_time) > 60 * 60 + meetings.push(current_meeting.clone) + current_meeting = [activity] + else + current_meeting.push(activity) + end + prev_time = activity.created_at + end + meetings.push(current_meeting.clone) + meetings + end end diff --git a/app/views/activities/index.html.erb b/app/views/activities/index.html.erb new file mode 100644 index 0000000..8babf62 --- /dev/null +++ b/app/views/activities/index.html.erb @@ -0,0 +1,24 @@ + + + + + + + + + + + + + <%- @activities.each do |activity| %> + + + + + + + + + <% end %> + +
Project IDStory IDUserActivity TypeActivity DataTimestamp
<%= activity.project_id %><%= activity.story_id %><%= activity.username %><%= activity.activity_type %><%= activity.activity_data %><%= activity.created_at %>
diff --git a/app/views/activities/meetings.html.erb b/app/views/activities/meetings.html.erb new file mode 100644 index 0000000..4dee37f --- /dev/null +++ b/app/views/activities/meetings.html.erb @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + <%- @meetings.each_with_index do |meeting, ind| %> + + + + + + + + + + <% end %> + + +
Meeting NumberStarted AtLength of the meetingParticipantsStory updatedVotesSee more
+ Meeting <%= ind %> + + <%= meeting_start(meeting) %> + + <%= meeting_length(meeting) %> minutes + + <%= num_participants(meeting) %> participants + + <%= num_stories_updated(meeting) %> stories updated + + <%= num_votes(meeting) %> votes + + +
+ +<%- @meetings.each_with_index do |meeting, ind| %> + + +<% end %> + diff --git a/config/routes.rb b/config/routes.rb index 36624e0..dfcb226 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,5 +28,9 @@ get 'discussion/:story_id', action: :discussion, as: :discussion end - resources :activities, only: [:index, :show, :create, :destroy] + resources :activities, only: [:index] do + collection do + get 'meetings' + end + end end \ No newline at end of file diff --git a/db/development b/db/development deleted file mode 100644 index f251d36..0000000 Binary files a/db/development and /dev/null differ diff --git a/db/migrate/20190409034843_add_username_to_activity.rb b/db/migrate/20190409034843_add_username_to_activity.rb new file mode 100644 index 0000000..dabf844 --- /dev/null +++ b/db/migrate/20190409034843_add_username_to_activity.rb @@ -0,0 +1,5 @@ +class AddUsernameToActivity < ActiveRecord::Migration + def change + add_column :activities, :username, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index bb9b581..b28c1fe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180801063748) do +ActiveRecord::Schema.define(version: 20190409034843) do create_table "activities", force: :cascade do |t| t.integer "user_id" @@ -22,6 +22,7 @@ t.text "activity_data" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "username" end add_index "activities", ["user_id"], name: "index_activities_on_user_id" diff --git a/db/test b/db/test deleted file mode 100644 index 37fd136..0000000 Binary files a/db/test and /dev/null differ diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb index 9e6f082..856f785 100644 --- a/spec/controllers/dashboard_controller_spec.rb +++ b/spec/controllers/dashboard_controller_spec.rb @@ -20,7 +20,7 @@ def valid_session it 'should create an activity' do Activity.expects(:create) - .with({user_id: user.id, activity_type: 'dashboard#index'}) + .with({username: user.username, activity_type: 'dashboard#index'}) get :index, {}, valid_session end end @@ -42,7 +42,7 @@ def valid_session it 'should create an acvitiy' do Activity.expects(:create) .with({ - user_id: user.id, + username: user.username, activity_type: 'dashboard#project', project_id: params[:id] }) @@ -79,7 +79,7 @@ def valid_session it 'should create an activity' do Activity.expects(:create) .with({ - user_id: user.id, + username: user.username, activity_type: 'dashboard#vote', story_id: '123', activity_data: { @@ -120,7 +120,7 @@ def valid_session it 'should create an activity' do Activity.expects(:create) .with({ - user_id: user.id, + username: user.username, activity_type: 'dashboard#reset', story_id: '123', activity_data: {story_id: '123', user: decoded_user(params['user'])}.to_json @@ -149,7 +149,7 @@ def valid_session it 'should create an activity' do Activity.expects(:create) .with({ - user_id: user.id, + username: user.username, activity_type: 'dashboard#detail', story_id: '123', activity_data: { @@ -181,7 +181,7 @@ def valid_session it 'should create an activity' do Activity.expects(:create) .with({ - user_id: user.id, + username: user.username, activity_type: 'dashboard#reveal', story_id: '123', activity_data: {story_id: '123'}.to_json @@ -230,7 +230,7 @@ def valid_session it 'should create an activity' do Activity.expects(:create) .with({ - user_id: user.id, + username: user.username, activity_type: 'dashboard#update', story_id: '1', activity_data: fake_return.to_json @@ -259,7 +259,7 @@ def valid_session it 'should create an activity' do Activity.expects(:create) .with({ - user_id: user.id, + username: user.username, activity_type: 'dashboard#select', story_id: '123', activity_data: {story_id: '123', username: 'username'}.to_json diff --git a/spec/factories.rb b/spec/factories.rb index a70c9d6..c88d6db 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -13,4 +13,7 @@ vote { Forgery::Basic.number(at_least: 1, at_most: 5) } end + factory :activity do + end + end \ No newline at end of file diff --git a/spec/models/activity_spec.rb b/spec/models/activity_spec.rb index 24e659a..4641ed7 100644 --- a/spec/models/activity_spec.rb +++ b/spec/models/activity_spec.rb @@ -1,4 +1,25 @@ -require 'rails_helper' +require 'spec_helper' RSpec.describe Activity, type: :model do + + describe 'self.infer_meetings' do + before :each do + t = Time.now + FactoryBot.create(:activity, created_at: t) + FactoryBot.create(:activity, created_at: t+1.minute) + FactoryBot.create(:activity, created_at: t+1.hour+2.minute) + FactoryBot.create(:activity, created_at: t+1.day) + FactoryBot.create(:activity, created_at: t+1.day+1.minute) + end + it 'groups activities together' do + expect(Activity.infer_meetings.length).to eql(3) + end + + it 'divides activities correctly' do + meetings = Activity.infer_meetings + expect(meetings[0].length).to eql(2) + expect(meetings[1].length).to eql(1) + expect(meetings[2].length).to eql(2) + end + end end diff --git a/spec/routing/activities_routing_spec.rb b/spec/routing/activities_routing_spec.rb index 3bdea6e..50611e0 100644 --- a/spec/routing/activities_routing_spec.rb +++ b/spec/routing/activities_routing_spec.rb @@ -7,16 +7,8 @@ expect(:get => "/activities").to route_to("activities#index") end - it "routes to #show" do - expect(:get => "/activities/1").to route_to("activities#show", :id => "1") - end - - it "routes to #create" do - expect(:post => "/activities").to route_to("activities#create") - end - - it "routes to #destroy" do - expect(:delete => "/activities/1").to route_to("activities#destroy", :id => "1") + it "routes to #meetings" do + expect(get: '/activities/meetings').to route_to('activities#meetings') end end