Class: BigbluebuttonRecording
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BigbluebuttonRecording
- Includes:
- ActiveModel::ForbiddenAttributesProtection
- Defined in:
- app/models/bigbluebutton_recording.rb
Class Method Summary collapse
-
.overall_average_length ⇒ Object
Returns the overall (i.e. for all recordings) average length of recordings in seconds Uses the length of the default playback format.
-
.overall_average_size ⇒ Object
Returns the overall (i.e. for all recordings) average size of recordings in bytes Uses the length of the default playback format.
-
.sync(server, recordings, full_sync = false) ⇒ Object
Syncs the recordings in the db with the array of recordings in ‘recordings’, as received from BigBlueButtonApi#get_recordings.
Instance Method Summary collapse
Class Method Details
.overall_average_length ⇒ Object
Returns the overall (i.e. for all recordings) average length of recordings in seconds Uses the length of the default playback format
37 38 39 40 41 |
# File 'app/models/bigbluebutton_recording.rb', line 37 def self.overall_average_length avg = BigbluebuttonPlaybackFormat.joins(:playback_type) .where("bigbluebutton_playback_types.default = ?", true).average(:length) avg.nil? ? 0 : (avg.truncate(2) * 60) end |
.overall_average_size ⇒ Object
Returns the overall (i.e. for all recordings) average size of recordings in bytes Uses the length of the default playback format
45 46 47 48 |
# File 'app/models/bigbluebutton_recording.rb', line 45 def self.overall_average_size avg = BigbluebuttonRecording.average(:size) avg.nil? ? 0 : avg end |
.sync(server, recordings, full_sync = false) ⇒ Object
Syncs the recordings in the db with the array of recordings in ‘recordings’, as received from BigBlueButtonApi#get_recordings. Will add new recordings that are not in the db yet and update the ones that already are (matching by ‘recordid’). Will NOT delete recordings from the db if they are not in the array but instead mark them as unavailable. ‘server’ is the BigbluebuttonServer object from which the recordings were fetched.
TODO: catch exceptions on creating/updating recordings
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/bigbluebutton_recording.rb', line 59 def self.sync(server, recordings, full_sync=false) recordings.each do |rec| rec_obj = BigbluebuttonRecording.find_by_recordid(rec[:recordID]) rec_data = adapt_recording_hash(rec) BigbluebuttonRecording.transaction do if rec_obj logger.info "Sync recordings: updating recording #{rec_obj.inspect}" logger.debug "Sync recordings: recording data #{rec_data.inspect}" self.update_recording(server, rec_obj, rec_data) else logger.info "Sync recordings: creating recording" logger.debug "Sync recordings: recording data #{rec_data.inspect}" self.create_recording(server, rec_data) end end end # set as unavailable the recordings that are not in 'recordings', but # only in a full synchronization process, which means that the recordings # in `recordings` are *all* available in `server`, not a subset. if full_sync recordIDs = recordings.map{ |rec| rec[:recordID] } if recordIDs.length <= 0 # empty response BigbluebuttonRecording. where(available: true, server: server). update_all(available: false) else BigbluebuttonRecording. where(available: true, server: server). where.not(recordid: recordIDs). update_all(available: false) end end end |
Instance Method Details
#default_playback_format ⇒ Object
30 31 32 33 |
# File 'app/models/bigbluebutton_recording.rb', line 30 def default_playback_format playback_formats.joins(:playback_type) .where("bigbluebutton_playback_types.default = ?", true).first end |
#to_param ⇒ Object
26 27 28 |
# File 'app/models/bigbluebutton_recording.rb', line 26 def to_param self.recordid end |