def emit_appointment_event(appointment, event_type): # TODO: log to db socketio.emit("appointment_event", { "type": event_type, "appointment": appointments_json(appointment), }, room=get_course())
def emit_state(attrs, broadcast=False): state = {} if 'tickets' in attrs: tickets = Ticket.query.filter( Ticket.status.in_([TicketStatus.pending, TicketStatus.assigned])).all() state['tickets'] = [ticket_json(ticket) for ticket in tickets] if 'assignments' in attrs: assignments = Assignment.query.all() state['assignments'] = [ assignment_json(assignment) for assignment in assignments ] if 'locations' in attrs: locations = Location.query.all() state['locations'] = [ location_json(location) for location in locations ] if 'config' in attrs: state['config'] = config_json() if not broadcast and 'current_user' in attrs: state['current_user'] = student_json(current_user) if broadcast: socketio.emit('state', state) else: emit('state', state)
def emit_state(attrs, broadcast=False, callback=None): assert not (callback and broadcast), "Cannot have a callback when broadcasting!" state = {} if 'tickets' in attrs: tickets = Ticket.query.filter( Ticket.status.in_(active_statuses), Ticket.course == get_course(), ).all() state['tickets'] = [ticket_json(ticket) for ticket in tickets] pendingTickets = Ticket.query.filter( Ticket.status.in_([TicketStatus.pending])).all() activeStaffList = list(user_presence[get_course()]['staff']) for ticket in tickets: if ticket not in pendingTickets: ticketHelper = (ticket.helper.email, ticket.helper.name) if ticketHelper in activeStaffList: activeStaffList.remove(ticketHelper) state['waitTimes'], state['stddev'] = avgWaitTimeList( "./oh_queue/query_result_ticket_event.csv", len(pendingTickets) + 1, len(activeStaffList)) if 'assignments' in attrs: assignments = Assignment.query.filter_by(course=get_course()).all() state['assignments'] = [ assignment_json(assignment) for assignment in assignments ] if 'locations' in attrs: locations = Location.query.filter(Location.course == get_course(), Location.name != "Online").all() state['locations'] = [ location_json(location) for location in locations ] state["locations"].append(location_json(get_online_location())) if 'config' in attrs: state['config'] = config_json() if 'appointments' in attrs: appointments = Appointment.query.filter( Appointment.status != AppointmentStatus.resolved, Appointment.course == get_course(), ).order_by(Appointment.id).all() state['appointments'] = [ appointments_json(appointment) for appointment in appointments ] if not broadcast and 'current_user' in attrs: state['current_user'] = student_json(current_user) if broadcast: socketio.emit('state', state, room=get_course()) elif callback: emit('state', state, callback=copy_current_request_context(callback)) else: emit('state', state)
def emit_presence(data): out = {k: len(v) for k,v in data.items()} active_staff = {(t.helper.email, t.helper.name) for t in Ticket.query.filter( Ticket.status.in_(active_statuses), Ticket.helper != None, Ticket.course == get_course(), ).all()} out["staff"] = len(data["staff"] | active_staff) out["staff_list"] = list(data["staff"] | active_staff) socketio.emit('presence', out, room=get_course())
def emit_event(ticket, event_type): ticket_event = TicketEvent( event_type=event_type, ticket=ticket, user=current_user, ) db.session.add(ticket_event) db.session.commit() socketio.emit('event', { 'type': event_type.name, 'ticket': ticket_json(ticket), })
def emit_state(attrs, broadcast=False, callback=None): assert not (callback and broadcast), "Cannot have a callback when broadcasting!" state = {} if 'tickets' in attrs: tickets = Ticket.query.filter( Ticket.status.in_(active_statuses), Ticket.course == get_course(), ).all() state['tickets'] = [ticket_json(ticket) for ticket in tickets] if 'assignments' in attrs: assignments = Assignment.query.filter_by(course=get_course()).all() state['assignments'] = [ assignment_json(assignment) for assignment in assignments ] if 'locations' in attrs: locations = Location.query.filter(Location.course == get_course(), Location.name != "Online").all() state['locations'] = [ location_json(location) for location in locations ] state["locations"].append(location_json(get_online_location())) if 'config' in attrs: state['config'] = config_json() if 'appointments' in attrs: appointments = Appointment.query.filter( Appointment.status != AppointmentStatus.resolved, Appointment.course == get_course(), ).order_by(Appointment.id).all() state['appointments'] = [ appointments_json(appointment) for appointment in appointments ] if not broadcast and 'current_user' in attrs: state['current_user'] = student_json(current_user) if broadcast: socketio.emit('state', state, room=get_course()) elif callback: emit('state', state, callback=copy_current_request_context(callback)) else: emit('state', state)
def emit_presence(data): socketio.emit('presence', {k: len(v) for k, v in data.items()})
def emit_message(message): socketio.emit('chat_message', message, room=get_course())
def emit_group_event(group, event_type): socketio.emit("group_event", { "type": event_type, "group": group_json(group), }, room=get_course())