Skip to content
This repository has been archived by the owner on Dec 19, 2021. It is now read-only.

Initial refactoring of the dashboard logic #393

Merged
merged 12 commits into from
Oct 25, 2021
Prev Previous commit
Next Next commit
Use scope and rename method
  • Loading branch information
NickSchimek committed Oct 24, 2021
commit c536a8855a250b100b0aa137f7d89c5765ad3224
6 changes: 2 additions & 4 deletions models/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ def json():
"stat": TicketModel.new().count(),
},
"unseen24Hrs": {
"stat": TicketModel.find_count_by_update_status(TicketModel.NEW, 1440),
"stat": TicketModel.new().updated_within(days=1).count(),
},
},
"inProgress": {
"allInProgress": {
"stat": TicketModel.in_progress().count(),
},
"inProgress1Week": {
"stat": TicketModel.find_count_by_update_status(
TicketModel.IN_PROGRESS, 10080
),
"stat": TicketModel.in_progress().updated_within(days=7).count(),
},
},
},
Expand Down
12 changes: 0 additions & 12 deletions models/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,3 @@ def json(self):
"created_at": Time.format_date(self.created_at),
"updated_at": Time.format_date(self.updated_at),
}

# Get tickets updated with the given time and with the given status
@classmethod
def find_count_by_update_status(cls, status, minutes):
# calculated in minutes: 1 day = 1440, 1 week = 10080
dateTime = datetime.utcnow() - timedelta(minutes=minutes)
return (
db.session.query(TicketModel)
.filter(TicketModel.updated_at >= dateTime)
.filter(TicketModel.status == status)
.count()
)
6 changes: 6 additions & 0 deletions nobiru/nobiru_query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from nobiru.nobiru import Nobiru
from flask_sqlalchemy import BaseQuery
from sqlalchemy import column

from utils.time import TimeStamp


class NobiruQuery(BaseQuery):
def json(self):
return Nobiru.json(self)

def updated_within(self, days=None):
return self.filter(column("updated_at") >= TimeStamp.days_ago(days))