diff --git a/db/up/find_sessions_2020.sql b/db/up/find_sessions_2020.sql index 2166d31aa..2f41c4005 100644 --- a/db/up/find_sessions_2020.sql +++ b/db/up/find_sessions_2020.sql @@ -156,3 +156,6 @@ CREATE INDEX msuh_id_idx ON music_sessions_user_history USING btree (id); CREATE INDEX quick_mixes_user_id_idx ON quick_mixes USING btree (user_id); CREATE INDEX recorded_videos_user_id_idx ON recorded_videos USING btree (user_id); CREATE INDEX music_sessions_user_id_idx ON music_sessions USING btree (user_id); + +ALTER TABLE users ADD COLUMN used_current_month INT; +ALTER TABLE users ADD COLUMN used_month_play_time INT; \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/music_session_user_history.rb b/ruby/lib/jam_ruby/models/music_session_user_history.rb index cee965424..7e35f39d5 100644 --- a/ruby/lib/jam_ruby/models/music_session_user_history.rb +++ b/ruby/lib/jam_ruby/models/music_session_user_history.rb @@ -80,14 +80,37 @@ module JamRuby hist = self .where(:user_id => user_id) .where(:music_session_id => session_id) + .order('created_at DESC') .limit(1) .first hist.end_history if hist end def end_history - self.session_removed_at = Time.now if self.session_removed_at.nil? - self.update_attributes(:session_removed_at => self.session_removed_at, :max_concurrent_connections => determine_max_concurrent) + if self.session_removed_at.nil? + self.session_removed_at = Time.now + self.max_concurrent_connections = determine_max_concurrent + self.update_attributes(:session_removed_at => self.session_removed_at, :max_concurrent_connections => self.max_concurrent_connections) + self.update_remaining_play_time + end + end + + # update the users monthly play time + def update_remaining_play_time + now = Time.now + current_month = (now.year * 100 + now.month) + remaining_time_so_far = self.user.used_month_play_time.to_i + + if current_month != self.user.used_current_month + # reset because it's a new month + remaining_time_so_far = 0 + end + + if self.max_concurrent_connections > 1 + remaining_time_so_far = remaining_time_so_far + duration_minutes * 60 + end + + self.user.update_attributes(:used_current_month => current_month, :used_month_play_time => remaining_time_so_far) end # figures out what the peak amount of other clients the user saw while playing at any given time. diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index ce812a198..dd72cd714 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -72,7 +72,7 @@ module JamRuby after_save :update_teacher_pct - attr_accessible :first_name, :last_name, :email, :city, :password, :password_confirmation, :state, :country, :birth_date, :subscribe_email, :terms_of_service, :original_fpfile, :cropped_fpfile, :cropped_large_fpfile, :cropped_s3_path, :cropped_large_s3_path, :photo_url, :large_photo_url, :crop_selection + attr_accessible :first_name, :last_name, :email, :city, :password, :password_confirmation, :state, :country, :birth_date, :subscribe_email, :terms_of_service, :original_fpfile, :cropped_fpfile, :cropped_large_fpfile, :cropped_s3_path, :cropped_large_s3_path, :photo_url, :large_photo_url, :crop_selection, :used_current_month, :used_month_play_time # updating_password corresponds to a lost_password attr_accessor :test_drive_packaging, :validate_instruments, :updating_password, :updating_email, :updated_email, :update_email_confirmation_url, :administratively_created, :current_password, :setting_password, :confirm_current_password, :updating_avatar, :updating_progression_field, :mods_json, :expecting_gift_card, :purchase_required @@ -2875,7 +2875,13 @@ module JamRuby if play_time_per_month.nil? rules[:remaining_month_play_time] = nil else - rules[:remaining_month_play_time] = (play_time_per_month * 3600) - MusicSessionUserHistory.where(user_id: self.id).where("date_trunc('month', created_at) = date_trunc('month', NOW())").where('session_removed_at IS NOT NULL').sum("extract('epoch' from (session_removed_at - created_at))") + now = Time.now + if used_current_month != (now.year * 100 + now.month) + # if this is a new month, then they get full play time + rules[:remaining_month_play_time] = (play_time_per_month * 3600) + else + rules[:remaining_month_play_time] = (play_time_per_month * 3600) - self.used_month_play_time.to_i + end end end diff --git a/ruby/lib/jam_ruby/resque/scheduled/stats_maker.rb b/ruby/lib/jam_ruby/resque/scheduled/stats_maker.rb index 78a40aa6c..7149ae755 100644 --- a/ruby/lib/jam_ruby/resque/scheduled/stats_maker.rb +++ b/ruby/lib/jam_ruby/resque/scheduled/stats_maker.rb @@ -27,11 +27,11 @@ module JamRuby def run log.debug("starting...") - Stats.write('connection', Connection.stats) - Stats.write('users', User.stats) - Stats.write('sessions', ActiveMusicSession.stats) - Stats.write('jam_track_rights', JamTrackRight.stats) - Stats.write('jam_track_mixdown_packages', JamTrackMixdownPackage.stats) + #Stats.write('connection', Connection.stats) + #Stats.write('users', User.stats) + #Stats.write('sessions', ActiveMusicSession.stats) + #Stats.write('jam_track_rights', JamTrackRight.stats) + #Stats.write('jam_track_mixdown_packages', JamTrackMixdownPackage.stats) end end diff --git a/web/app/assets/javascripts/support/react-components/SupportPage.js.jsx b/web/app/assets/javascripts/support/react-components/SupportPage.js.jsx index 5633b229e..b3e9f81d1 100644 --- a/web/app/assets/javascripts/support/react-components/SupportPage.js.jsx +++ b/web/app/assets/javascripts/support/react-components/SupportPage.js.jsx @@ -15,7 +15,7 @@ window.SupportPage = React.createClass({ } // You just need to add '&disable[fieldName]=true' or '&disable[custom_field][fieldName]=true' depending on whether the field is default or custom. - + var src = `https://jamkazam.freshdesk.com/widgets/feedback_widget/new?&helpdesk_ticket[requester]=${encodeURIComponent(gon.email)}&disable[requester]=true&helpdesk_ticket[custom_field][cf_plan_1596882]=${encodeURIComponent(display)}&disable[custom_field][cf_plan_1596882]=true&widgetType=embedded&formTitle=JamKazam+Support&submitTitle=Send+Feedback&submitThanks=Thank+you+for+your+message.+We+will+use+our+best+efforts+to+reply+within+24+hours.` // helpdesk_ticket_cf_plan_1596882 diff --git a/web/config/scheduler.yml b/web/config/scheduler.yml index c98fab231..a3c6fa432 100644 --- a/web/config/scheduler.yml +++ b/web/config/scheduler.yml @@ -91,7 +91,7 @@ RecordingsCleaner: description: "Cleans up recordings that no one wants after 7 days" StatsMaker: - cron: "* * * * *" +# cron: "* * * * *" class: "JamRuby::StatsMaker" description: "Generates interesting stats from the database"