This commit is contained in:
Seth Call 2021-01-01 09:02:49 -06:00
parent 8b3cb159ae
commit a09e33a083
6 changed files with 43 additions and 11 deletions

View File

@ -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 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 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); 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;

View File

@ -80,14 +80,37 @@ module JamRuby
hist = self hist = self
.where(:user_id => user_id) .where(:user_id => user_id)
.where(:music_session_id => session_id) .where(:music_session_id => session_id)
.order('created_at DESC')
.limit(1) .limit(1)
.first .first
hist.end_history if hist hist.end_history if hist
end end
def end_history def end_history
self.session_removed_at = Time.now if self.session_removed_at.nil? if self.session_removed_at.nil?
self.update_attributes(:session_removed_at => self.session_removed_at, :max_concurrent_connections => determine_max_concurrent) 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 end
# figures out what the peak amount of other clients the user saw while playing at any given time. # figures out what the peak amount of other clients the user saw while playing at any given time.

View File

@ -72,7 +72,7 @@ module JamRuby
after_save :update_teacher_pct 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 # 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 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? if play_time_per_month.nil?
rules[:remaining_month_play_time] = nil rules[:remaining_month_play_time] = nil
else 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
end end

View File

@ -27,11 +27,11 @@ module JamRuby
def run def run
log.debug("starting...") log.debug("starting...")
Stats.write('connection', Connection.stats) #Stats.write('connection', Connection.stats)
Stats.write('users', User.stats) #Stats.write('users', User.stats)
Stats.write('sessions', ActiveMusicSession.stats) #Stats.write('sessions', ActiveMusicSession.stats)
Stats.write('jam_track_rights', JamTrackRight.stats) #Stats.write('jam_track_rights', JamTrackRight.stats)
Stats.write('jam_track_mixdown_packages', JamTrackMixdownPackage.stats) #Stats.write('jam_track_mixdown_packages', JamTrackMixdownPackage.stats)
end end
end end

View File

@ -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. // 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.` 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 // helpdesk_ticket_cf_plan_1596882

View File

@ -91,7 +91,7 @@ RecordingsCleaner:
description: "Cleans up recordings that no one wants after 7 days" description: "Cleans up recordings that no one wants after 7 days"
StatsMaker: StatsMaker:
cron: "* * * * *" # cron: "* * * * *"
class: "JamRuby::StatsMaker" class: "JamRuby::StatsMaker"
description: "Generates interesting stats from the database" description: "Generates interesting stats from the database"