Skip to content

Commit

Permalink
Merge pull request #588 from ChicagoWorldcon/development
Browse files Browse the repository at this point in the history
2.0.0-rc1
  • Loading branch information
Gailbear authored Aug 11, 2022
2 parents a107219 + d8ef6ac commit 60bdc10
Show file tree
Hide file tree
Showing 37 changed files with 809 additions and 114 deletions.
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ def render_jsonapi_internal_server_error(exception)
# NOTE: if we have a central log put it in here
super(exception)
end

def set_timezone(&block)
timezone = ConfigService.value('convention_timezone')
Time.use_zone(timezone, &block)
end
end
11 changes: 11 additions & 0 deletions app/controllers/publication_dates_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class PublicationDatesController < ResourceController
SERIALIZER_CLASS = 'PublicationDateSerializer'.freeze
POLICY_CLASS = 'PublicationDatePolicy'.freeze
POLICY_SCOPE_CLASS = 'PublicationDatePolicy::Scope'.freeze
DEFAULT_SORTBY = 'timestamp'
DEFAULT_ORDER = 'desc'.freeze

def paginate
false
end
end
10 changes: 9 additions & 1 deletion app/controllers/publications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ class PublicationsController < ApplicationController
around_action :set_timezone

def schedule
sessions = SessionService.live_sessions
# use published if any otherwise use live
sessions = if PublishedSession.count > 0
SessionService.published_sessions
else
SessionService.live_sessions
end

send_data XmlFormatter.new(sessions).render('schedule', sessions)
.gsub(/&#39;/, '&#8217;')
.gsub(/&lt;em&gt;/, '<em>')
.gsub(/&lt;\/em&gt;/, '</em>')
.gsub(/\<\?xml version="1\.0"\?\>\n/, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!-- Formatted for the special requirements of importing to Adobe InDesign. -->')
.gsub(/\<schedule\>\n /, '<schedule>')
.gsub(/\<session\>\n /, '<session>')
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/reports/conflict_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,4 @@ def people_outside_availability
filename: "PeopleOutsideAvailability#{Time.now.strftime('%m-%d-%Y')}.xlsx",
disposition: 'attachment'
end

def set_timezone(&block)
timezone = ConfigService.value('convention_timezone')
Time.use_zone(timezone, &block)
end
end
46 changes: 41 additions & 5 deletions app/controllers/reports/people_reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
class Reports::PeopleReportsController < ApplicationController
around_action :set_timezone

def moderators
authorize Person, policy_class: ReportPolicy

people = SessionService.live_moderators

workbook = FastExcel.open(constant_memory: true)
worksheet = workbook.add_worksheet("Moderators and Sessions")

worksheet.append_row(
[
'Published Name',
'Primary Email',
'Attendance Type',
'Participant Status',
'Session Name',
'Session Format',
'Session Environment'
]
)

people.each do |person|
person.sessions.moderating.each do |session|
worksheet.append_row(
[
person.published_name,
person.primary_email&.email,
person.attendance_type,
person.con_state,
session.title,
session.format&.name,
session.environment
]
)
end
end

send_data workbook.read_string,
filename: "ParticipantsModeratingSessions-#{Time.now.strftime('%m-%d-%Y')}.xlsx",
disposition: 'attachment'
end

def record_stream_permissions
authorize Person, policy_class: ReportPolicy

Expand Down Expand Up @@ -59,9 +100,4 @@ def record_stream_permissions
filename: "PeopleRecordStream-#{Time.now.strftime('%m-%d-%Y')}.xlsx",
disposition: 'attachment'
end

def set_timezone(&block)
timezone = ConfigService.value('convention_timezone')
Time.use_zone(timezone, &block)
end
end
52 changes: 52 additions & 0 deletions app/controllers/reports/program_ops_reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class Reports::ProgramOpsReportsController < ApplicationController
around_action :set_timezone

def back_of_badge
authorize SessionAssignment, policy_class: Reports::ProgramOpsReportPolicy

assignments = PublishedSessionAssignment
.includes(:person, :session_assignment_role_type, :published_session)
.order("people.published_name, published_sessions.start_time asc")


workbook = FastExcel.open #(constant_memory: true)
worksheet = workbook.add_worksheet("Back of Badge")
date_time_style = workbook.number_format("d mmm yyyy h:mm")

worksheet.append_row([]) # For the header

group_assignments = assignments.group_by {|a| a.person}
max_sessions = 0
group_assignments.each do |person, grouped|
row = [
person.published_name
]
styles = [nil]

grouped.each do |assignment|
row.concat [
assignment.session.title,
assignment.session.start_time ? FastExcel.date_num(assignment.session.start_time, assignment.session.start_time.in_time_zone.utc_offset) : nil,
assignment.session.duration,
assignment.session.room&.name,
]
styles.concat [
nil, date_time_style, nil, nil
]
end
max_sessions = grouped.size if grouped.size > max_sessions

worksheet.append_row(row, styles)
end

header = ['Published Name']
(0..max_sessions).each do |n|
header.concat ["Title #{n+1}", "Start Time #{n+1}", "Duration #{n+1}", "Room #{n+1}"]
end
worksheet.write_row(0, header)

send_data workbook.read_string,
filename: "BackOfBadge-#{Time.now.strftime('%m-%d-%Y')}.xlsx",
disposition: 'attachment'
end
end
207 changes: 207 additions & 0 deletions app/controllers/reports/schedule_reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
class Reports::ScheduleReportsController < ApplicationController
around_action :set_timezone

def schedule_diff
authorize Person, policy_class: Reports::ScheduleReportPolicy

# TODO: base the from and to on the publish ids and this will be ok as a get
pd_from = PublicationDate.find params[:from] if params[:from]

from = pd_from.timestamp if pd_from
from ||= PublicationDate.order('created_at desc').first&.timestamp
from ||= Time.now - 2.year # TODO: for testing

pd_to = PublicationDate.find params[:to] if params[:to]
to = pd_to.timestamp if pd_to

# changes = ChangeService.published_changes(from: from, to: to)
changes = if to
ChangeService.published_changes(from: from, to: to)
else
ChangeService.session_changes(from: from)
end

to ||= Time.now
workbook = FastExcel.open(constant_memory: true)
date_time_style = workbook.number_format("d mmm yyyy h:mm")

session_time_changed = workbook.add_worksheet("Session Time Changed")
session_room_changed = workbook.add_worksheet("Session Room Changed")
session_title_changed = workbook.add_worksheet("Session Title Changed")
session_description_changed = workbook.add_worksheet("Session Description Changed")
session_added = workbook.add_worksheet("Sessions Add")
session_removed = workbook.add_worksheet("Sessions Removed")

participants_fully_dropped = workbook.add_worksheet("Participants Dropped")
participants_add_drop = workbook.add_worksheet("Participants Add Drop")

tab_headers(session_time_changed, session_room_changed, session_title_changed, session_description_changed, session_added, session_removed, participants_add_drop, participants_fully_dropped)

# Rails.logger.debug "******** CHANGES: #{changes[:sessions]}"

changes[:sessions].values.sort{|a,b| (a[:object] ? a[:object].title : '') <=> (b[:object] ? b[:object].title : '')}.each do |change|
# Rails.logger.debug "******** CHANGE: #{change}"
next unless change[:object]

if change[:changes]['room_id'] || change[:changes]['start_time']
if change[:changes]['room_id'] && change[:changes]['start_time'] &&
((!change[:changes]['room_id'][0] && change[:changes]['room_id'][1]) ||
(!change[:changes]['start_time'][0] && change[:changes]['start_time'][1]))
session_added_row(session_added, change, date_time_style)
else
if (change[:changes]['room_id'] && !change[:changes]['room_id'][1]) || (change[:changes]['start_time'] && !change[:changes]['start_time'][1])|| change[:event] == 'destroy'
session_removed_row(session_removed, change)
else
if change[:changes]['room_id']
session_room_change_row(session_room_changed, change)
end
if change[:changes]['start_time']
session_time_change_row(session_time_changed, change, date_time_style)
end
end
end
end

if change[:changes]['title']
session_title_change_row(session_title_changed, change)
end
if change[:changes]['description']
session_description_change_row(session_description_changed, change)
end
end

moderator = SessionAssignmentRoleType.find_by(name: 'Moderator')
participant = SessionAssignmentRoleType.find_by(name: 'Participant')
roles = [moderator.id, participant.id]
# Rails.logger.debug "******** ROLES #{roles}"

# TODO: sort .... ??? how
fully_dropped = []
changes[:assignments].each do |id, change|
next unless change[:object]

# Participants add/drop
if change[:changes]['session_assignment_role_type_id']
session = change[:object].session if change[:object].session
session ||= Session.find change[:object].session_id
if (roles.include?(change[:changes]['session_assignment_role_type_id'][1]))
participants_add_drop.append_row(
[
session.title,
'',
change[:object].person.published_name
]
)
elsif (roles.include?(change[:changes]['session_assignment_role_type_id'][0]))
participants_add_drop.append_row(
[
session.title,
change[:object].person.published_name,
]
)
if change[:object].person.sessions.scheduled.count == 0
fully_dropped.append [change[:object].person.published_name]
end
end
end
end

fully_dropped.uniq.each do |name|
participants_fully_dropped.append_row(name)
end

send_data workbook.read_string,
filename: "ScheduleDiff-#{from.strftime('%m-%d-%Y_%H_%M')}_to_#{to.strftime('%m-%d-%Y_%H_%M')}.xlsx",
disposition: 'attachment'
end

def tab_headers(session_time_changed, session_room_changed, session_title_changed, session_description_changed, session_added, session_removed, participants_add_drop, participants_fully_dropped)
session_time_changed.append_row(['Session Title','Original Start Time', 'New Start Time'])
session_room_changed.append_row(['Session Title','Original Room', 'New Room'])
session_title_changed.append_row(['Original Session Title', 'New Session Title'])
session_description_changed.append_row(['Session Title','Original Description', 'New Description'])
session_added.append_row(['Session Title', 'Session Description', 'Format', 'Areas', 'Start Time', 'Room', 'Moderators', 'Participants'])
session_removed.append_row(['Session Title'])

participants_add_drop.append_row(['Session Title', 'Participant Dropped', 'Participant Added'])
participants_fully_dropped.append_row(['Participant Dropped'])
end

def session_description_change_row(sheet, change)
sheet.append_row(
[
change[:object].title,
change[:changes]['description'][0],
change[:changes]['description'][1]
]
)
end

def session_title_change_row(sheet, change)
sheet.append_row(
[
change[:changes]['title'][0],
change[:changes]['title'][1]
]
)
end

def session_room_change_row(sheet, change)
orig_room = Room.find change[:changes]['room_id'][0] if change[:changes]['room_id'][0]
new_room = Room.find change[:changes]['room_id'][1] if change[:changes]['room_id'][1]
sheet.append_row(
[
change[:object].title,
orig_room&.name,
new_room&.name
]
)
end

def session_removed_row(sheet, change)
# TODO: if it is a destroy ....
sheet.append_row(
[
change[:object].title
]
)
end

def session_time_change_row(sheet, change, date_time_style)
orig_time = Time.parse(change[:changes]['start_time'][0]) if change[:changes]['start_time'][0]
new_time = Time.parse(change[:changes]['start_time'][1]) if change[:changes]['start_time'][1]
# Rails.logger.debug "********* #{change[:changes]['start_time'][1]} => #{new_time.class} #{new_time.strftime("%H")}"
sheet.append_row(
[
change[:object].title,
orig_time ? FastExcel.date_num(orig_time, orig_time.in_time_zone.utc_offset) : nil,
new_time ? FastExcel.date_num(new_time, new_time.in_time_zone.utc_offset) : nil
],
[
nil, date_time_style, date_time_style
]
)
end

# Generate a row for sessions added
def session_added_row(sheet, change, date_time_style)
moderator = SessionAssignmentRoleType.find_by(name: 'Moderator')
participant = SessionAssignmentRoleType.find_by(name: 'Participant')

sheet.append_row(
[
change[:object].title,
change[:object].description,
change[:object].format&.name,
change[:object].areas.collect(&:name).join("; "),
FastExcel.date_num(change[:object].start_time, change[:object].start_time.in_time_zone.utc_offset),
change[:object].room&.name,
change[:object].participant_assignments.where("session_assignment_role_type_id = ?", moderator).collect{|a| a.person.published_name}.join("; "),
change[:object].participant_assignments.where("session_assignment_role_type_id = ?", participant).collect{|a| a.person.published_name}.join("; ")
],
[
nil, nil, nil, nil, date_time_style, nil, nil, nil
]
)
end
end
Loading

0 comments on commit 60bdc10

Please sign in to comment.