Skip to content

Commit

Permalink
email show up without errors
Browse files Browse the repository at this point in the history
  • Loading branch information
azliu0 committed Apr 16, 2024
1 parent 367562f commit 618d883
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
42 changes: 23 additions & 19 deletions server/controllers/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ def get_response():
response = db.session.execute(
select(Response).where(Response.email_id == data["id"])
).scalar()

if not response:
return {"message": "Response not found"}, 400
return response.map()
Expand Down Expand Up @@ -524,23 +525,26 @@ def get_threads():
Get a list of all threads.
"""
thread_list = db.session.execute(select(Thread)).all()
print("thread list", thread_list)
# thread_list = db.session.execute(
# select(Thread).order_by(Thread.resolved, Thread.last_email.desc())
# ).all()
# email_list = [
# {
# "id": thread.id,
# "resolved": thread.resolved,
# "emailList": [
# thread_email.map()
# for thread_email in db.session.execute(
# select(Email).where(Email.thread_id == thread.id)
# ).all()
# ],
# }
# for thread in thread_list
# ]
email_list = []
thread_list = (
db.session.execute(
select(Thread).order_by(Thread.resolved, Thread.last_email.desc())
)
.scalars()
.all()
)
email_list = [
{
"id": thread.id,
"resolved": thread.resolved,
"emailList": [
thread_email.map()
for thread_email in db.session.execute(
select(Email).where(Email.thread_id == thread.id)
)
.scalars()
.all()
],
}
for thread in thread_list
]
return email_list
17 changes: 15 additions & 2 deletions server/models/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,25 @@ class Response(db.Model):
)

def map(self):
"""Map the response to a dictionary."""
"""Map the response to a dictionary.
Groups documents and document_confidences into a list of lists clustered by
question.
"""
doc_confs = []
docs = []
cur_idx = 0
for num_docs in self.docs_per_question:
doc_confs.append(self.document_confidences[cur_idx : cur_idx + num_docs])
docs.append(self.documents[cur_idx : cur_idx + num_docs])
cur_idx += num_docs
docs = [[doc.map() for doc in doc_list] for doc_list in docs]
return {
"id": self.id,
"content": self.response,
"questions": self.questions,
"document_confidences": self.document_confidences,
"documents": docs,
"document_confidences": doc_confs,
"confidence": self.confidence,
"emailId": self.email_id,
}
Empty file added server_tests/test_admin.py
Empty file.

0 comments on commit 618d883

Please sign in to comment.