From a89f818dd768a146bd5801253192ea0f888b6449 Mon Sep 17 00:00:00 2001 From: Khalil Sarwari Date: Fri, 8 Sep 2017 22:44:55 -0700 Subject: [PATCH 1/4] no changes --- manage.py | 1 - oh_queue/views.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/manage.py b/manage.py index 78c9890..937c478 100755 --- a/manage.py +++ b/manage.py @@ -42,7 +42,6 @@ def seed(): student = User(name=real_name, email=email) db.session.add(student) db.session.commit() - delta = datetime.timedelta(minutes=random.randrange(0, 30)) ticket = Ticket( user=student, diff --git a/oh_queue/views.py b/oh_queue/views.py index 5c3635e..2d416e6 100644 --- a/oh_queue/views.py +++ b/oh_queue/views.py @@ -131,6 +131,7 @@ def disconnect(): @socketio.on('refresh') def refresh(ticket_ids): + """ Cuts out tickets that have elapsed time beyond cuttoff in minutes""" tickets = Ticket.query.filter(Ticket.id.in_(ticket_ids)).all() return { 'tickets': [ticket_json(ticket) for ticket in tickets], From 54e265f70622472a194c47c9833c10aa69501802 Mon Sep 17 00:00:00 2001 From: Khalil Sarwari Date: Fri, 8 Sep 2017 22:54:01 -0700 Subject: [PATCH 2/4] attempt to autodelete and autoresolve --- oh_queue/models.py | 4 ++-- oh_queue/views.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/oh_queue/models.py b/oh_queue/models.py index c0735e8..5208092 100644 --- a/oh_queue/models.py +++ b/oh_queue/models.py @@ -42,7 +42,7 @@ def short_name(self): return first_name.rsplit('@')[0] return first_name -TicketStatus = enum.Enum('TicketStatus', 'pending assigned resolved deleted') +TicketStatus = enum.Enum('TicketStatus', 'pending assigned resolved deleted autoresolved autodeleted') class Ticket(db.Model): """Represents an ticket in the queue. A student submits a ticket and receives @@ -87,7 +87,7 @@ def by_status(cls, status=None): TicketEventType = enum.Enum( 'TicketEventType', - 'create assign unassign resolve delete describe', + 'create assign unassign resolve delete describe autoresolve autodelete', ) class TicketEvent(db.Model): diff --git a/oh_queue/views.py b/oh_queue/views.py index 2d416e6..f80fd54 100644 --- a/oh_queue/views.py +++ b/oh_queue/views.py @@ -132,6 +132,20 @@ def disconnect(): @socketio.on('refresh') def refresh(ticket_ids): """ Cuts out tickets that have elapsed time beyond cuttoff in minutes""" + pending_cutoff = 180 + assigned_cutoff = 30 + + pending_cutoff_time = datetime.datetime.now() - datetime.timedelta(minutes = pending_cutoff) + assigned_cutoff_time = datetime.datetime.now() - datetime.timedelta(minutes = assigned_cutoff) + + exp_pending_tickets = Ticket.query.filter(Ticket.created < pending_cutoff_time, Ticket.status == TicketStatus.pending).all() + exp_pending_ticket_ids = [tick.id for tick in exp_pending_tickets] + autodelete(exp_pending_ticket_ids) + + exp_assigned_tickets = Ticket.query.filter(Ticket.updated < assigned_cutoff_time, Ticket.status == TicketStatus.assigned).all() + exp_assigned_ticket_ids = [tick.id for tick in exp_assigned_tickets] + autoresolve(exp_pending_ticket_ids) + tickets = Ticket.query.filter(Ticket.id.in_(ticket_ids)).all() return { 'tickets': [ticket_json(ticket) for ticket in tickets], @@ -205,6 +219,14 @@ def delete(ticket_ids): emit_event(ticket, TicketEventType.delete) db.session.commit() +@socketio.on('autodelete') +def autodelete(ticket_ids): + tickets = get_tickets(ticket_ids) + for ticket in tickets: + ticket.status = TicketStatus.autodeleted + emit_event(ticket, TicketEventType.autodelete) + db.session.commit() + @socketio.on('resolve') @logged_in def resolve(ticket_ids): @@ -217,6 +239,15 @@ def resolve(ticket_ids): db.session.commit() return get_next_ticket() +@socketio.on('resolve') +def autoresolve(ticket_ids): + tickets = get_tickets(ticket_ids) + for ticket in tickets: + ticket.status = TicketStatus.autoresolved + emit_event(ticket, TicketEventType.autoresolve) + db.session.commit() + #return get_next_ticket() + @socketio.on('assign') @is_staff def assign(ticket_ids): From 2eacb95b79db7aa5781f3f3523c662ad9e0a5a61 Mon Sep 17 00:00:00 2001 From: Khalil Sarwari Date: Sat, 9 Sep 2017 01:17:57 -0700 Subject: [PATCH 3/4] successful deletion and resolution from queue, visual --- manage.py | 32 +++++++++++++++++++++++--------- oh_queue/views.py | 27 ++++++++++++++++++++------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/manage.py b/manage.py index 937c478..8f15f19 100755 --- a/manage.py +++ b/manage.py @@ -43,15 +43,29 @@ def seed(): db.session.add(student) db.session.commit() delta = datetime.timedelta(minutes=random.randrange(0, 30)) - ticket = Ticket( - user=student, - status=TicketStatus.pending, - created=datetime.datetime.utcnow() - delta, - assignment=random.choice(['Hog', 'Scheme']), - description=random.choice(['', 'SyntaxError on Line 5']), - question=random.randrange(1, 6), - location=random.choice(['109 Morgan', '247 Cory']), - ) + if i % 2 == 0: + ticket = Ticket( + user=student, + status=TicketStatus.pending, + created=datetime.datetime.utcnow() - delta, + assignment=random.choice(['Hog', 'Scheme']), + description=random.choice(['', 'SyntaxError on Line 5']), + question=random.randrange(1, 6), + location=random.choice(['109 Morgan', '247 Cory']), + ) + else: + ticket = Ticket( + user=student, + status=TicketStatus.assigned, + created=datetime.datetime.utcnow() - delta, + updated= datetime.datetime.utcnow(), + assignment=random.choice(['Hog', 'Scheme']), + description=random.choice(['', 'SyntaxError on Line 5']), + question=random.randrange(1, 6), + location=random.choice(['109 Morgan', '247 Cory']), + helper_id = 61 + ) + db.session.add(ticket) db.session.commit() diff --git a/oh_queue/views.py b/oh_queue/views.py index f80fd54..6d100e6 100644 --- a/oh_queue/views.py +++ b/oh_queue/views.py @@ -41,11 +41,24 @@ def ticket_json(ticket): } def emit_event(ticket, event_type): - ticket_event = TicketEvent( + if event_type == TicketEventType.autodelete: + ticket_event = TicketEvent( event_type=event_type, ticket=ticket, - user=current_user, + user_id=0 # assuming ids start @ 1, 0 signifies admin/autodelete ) + elif event_type == TicketEventType.autoresolve: + ticket_event = TicketEvent( + event_type=event_type, + ticket=ticket, + user_id=ticket.helper_id + ) + else: + ticket_event = TicketEvent( + event_type=event_type, + ticket=ticket, + user=current_user, + ) db.session.add(ticket_event) db.session.commit() socketio.emit('event', { @@ -134,17 +147,17 @@ def refresh(ticket_ids): """ Cuts out tickets that have elapsed time beyond cuttoff in minutes""" pending_cutoff = 180 assigned_cutoff = 30 - - pending_cutoff_time = datetime.datetime.now() - datetime.timedelta(minutes = pending_cutoff) - assigned_cutoff_time = datetime.datetime.now() - datetime.timedelta(minutes = assigned_cutoff) - + + pending_cutoff_time = datetime.datetime.utcnow() - datetime.timedelta(minutes = pending_cutoff) + assigned_cutoff_time = datetime.datetime.utcnow() - datetime.timedelta(minutes = assigned_cutoff) + exp_pending_tickets = Ticket.query.filter(Ticket.created < pending_cutoff_time, Ticket.status == TicketStatus.pending).all() exp_pending_ticket_ids = [tick.id for tick in exp_pending_tickets] autodelete(exp_pending_ticket_ids) exp_assigned_tickets = Ticket.query.filter(Ticket.updated < assigned_cutoff_time, Ticket.status == TicketStatus.assigned).all() exp_assigned_ticket_ids = [tick.id for tick in exp_assigned_tickets] - autoresolve(exp_pending_ticket_ids) + autoresolve(exp_assigned_ticket_ids) tickets = Ticket.query.filter(Ticket.id.in_(ticket_ids)).all() return { From 39e73ceb736ec788e65302d2bcf1ab9873f6f752 Mon Sep 17 00:00:00 2001 From: Khalil Sarwari Date: Sun, 8 Oct 2017 13:26:57 -0700 Subject: [PATCH 4/4] focus on autoresolve, minimized interference with current ticket setup --- manage.py | 35 +++++++++++------------------------ oh_queue/models.py | 4 ++-- oh_queue/views.py | 38 +++++--------------------------------- 3 files changed, 18 insertions(+), 59 deletions(-) diff --git a/manage.py b/manage.py index 8f15f19..f0e3037 100755 --- a/manage.py +++ b/manage.py @@ -29,6 +29,7 @@ def wrapper(*args, **kwargs): @not_in_production def seed(): print('Seeding...') + delta = datetime.timedelta(minutes=random.randrange(0, 30)) for i in range(20): real_name = names.get_full_name() first_name, last_name = real_name.lower().split(' ') @@ -42,30 +43,16 @@ def seed(): student = User(name=real_name, email=email) db.session.add(student) db.session.commit() - delta = datetime.timedelta(minutes=random.randrange(0, 30)) - if i % 2 == 0: - ticket = Ticket( - user=student, - status=TicketStatus.pending, - created=datetime.datetime.utcnow() - delta, - assignment=random.choice(['Hog', 'Scheme']), - description=random.choice(['', 'SyntaxError on Line 5']), - question=random.randrange(1, 6), - location=random.choice(['109 Morgan', '247 Cory']), - ) - else: - ticket = Ticket( - user=student, - status=TicketStatus.assigned, - created=datetime.datetime.utcnow() - delta, - updated= datetime.datetime.utcnow(), - assignment=random.choice(['Hog', 'Scheme']), - description=random.choice(['', 'SyntaxError on Line 5']), - question=random.randrange(1, 6), - location=random.choice(['109 Morgan', '247 Cory']), - helper_id = 61 - ) - + + ticket = Ticket( + user=student, + status=TicketStatus.pending, + created=datetime.datetime.utcnow() - delta, + assignment=random.choice(['Hog', 'Scheme']), + description=random.choice(['', 'SyntaxError on Line 5']), + question=random.randrange(1, 6), + location=random.choice(['109 Morgan', '247 Cory']), + ) db.session.add(ticket) db.session.commit() diff --git a/oh_queue/models.py b/oh_queue/models.py index 5208092..9973255 100644 --- a/oh_queue/models.py +++ b/oh_queue/models.py @@ -42,7 +42,7 @@ def short_name(self): return first_name.rsplit('@')[0] return first_name -TicketStatus = enum.Enum('TicketStatus', 'pending assigned resolved deleted autoresolved autodeleted') +TicketStatus = enum.Enum('TicketStatus', 'pending assigned resolved deleted') class Ticket(db.Model): """Represents an ticket in the queue. A student submits a ticket and receives @@ -87,7 +87,7 @@ def by_status(cls, status=None): TicketEventType = enum.Enum( 'TicketEventType', - 'create assign unassign resolve delete describe autoresolve autodelete', + 'create assign unassign resolve delete describe autoresolve', ) class TicketEvent(db.Model): diff --git a/oh_queue/views.py b/oh_queue/views.py index 6d100e6..4144e7e 100644 --- a/oh_queue/views.py +++ b/oh_queue/views.py @@ -41,24 +41,12 @@ def ticket_json(ticket): } def emit_event(ticket, event_type): - if event_type == TicketEventType.autodelete: - ticket_event = TicketEvent( + ticket_event = TicketEvent( event_type=event_type, ticket=ticket, - user_id=0 # assuming ids start @ 1, 0 signifies admin/autodelete - ) - elif event_type == TicketEventType.autoresolve: - ticket_event = TicketEvent( - event_type=event_type, - ticket=ticket, - user_id=ticket.helper_id + user=ticket.helper if event_type == TicketEventType.autoresolve else current_user, + ) - else: - ticket_event = TicketEvent( - event_type=event_type, - ticket=ticket, - user=current_user, - ) db.session.add(ticket_event) db.session.commit() socketio.emit('event', { @@ -144,16 +132,10 @@ def disconnect(): @socketio.on('refresh') def refresh(ticket_ids): - """ Cuts out tickets that have elapsed time beyond cuttoff in minutes""" - pending_cutoff = 180 + """ Cuts out tickets that have elapsed time beyond cuttoff in minutes, and refreshes""" assigned_cutoff = 30 - - pending_cutoff_time = datetime.datetime.utcnow() - datetime.timedelta(minutes = pending_cutoff) assigned_cutoff_time = datetime.datetime.utcnow() - datetime.timedelta(minutes = assigned_cutoff) - exp_pending_tickets = Ticket.query.filter(Ticket.created < pending_cutoff_time, Ticket.status == TicketStatus.pending).all() - exp_pending_ticket_ids = [tick.id for tick in exp_pending_tickets] - autodelete(exp_pending_ticket_ids) exp_assigned_tickets = Ticket.query.filter(Ticket.updated < assigned_cutoff_time, Ticket.status == TicketStatus.assigned).all() exp_assigned_ticket_ids = [tick.id for tick in exp_assigned_tickets] @@ -232,14 +214,6 @@ def delete(ticket_ids): emit_event(ticket, TicketEventType.delete) db.session.commit() -@socketio.on('autodelete') -def autodelete(ticket_ids): - tickets = get_tickets(ticket_ids) - for ticket in tickets: - ticket.status = TicketStatus.autodeleted - emit_event(ticket, TicketEventType.autodelete) - db.session.commit() - @socketio.on('resolve') @logged_in def resolve(ticket_ids): @@ -252,14 +226,12 @@ def resolve(ticket_ids): db.session.commit() return get_next_ticket() -@socketio.on('resolve') def autoresolve(ticket_ids): tickets = get_tickets(ticket_ids) for ticket in tickets: - ticket.status = TicketStatus.autoresolved + ticket.status = TicketStatus.resolved emit_event(ticket, TicketEventType.autoresolve) db.session.commit() - #return get_next_ticket() @socketio.on('assign') @is_staff