Skip to content

Commit

Permalink
Merge branch 'feature/daily_loaner_stats_report' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsher committed Dec 7, 2023
2 parents 07849a2 + 47d988c commit 2e4e978
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 27 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ You must also have a file called config.yml in the same folder as the devicekios
eoy_return_addresses: EOY email addresses
# Show daily loaner:true will add buttons on the start screen for daily device and charger borrowing
show_daily_loaner: true
# Show the button to print a report of daily loaner usage by student
show_loaner_report: true
# Email address that daily borrow/return notifications will be sent to
daily_email_list: daily borrowed device email address
email_daily_report: false
Expand Down
71 changes: 70 additions & 1 deletion src/devicekiosk.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class UI(QObject):
# Instead of calling like a regular function, we call them as:
# self.[signal].emit(argument)
showDailyLoanersSignal = Signal(None)
showLoanersReportSignal = Signal(None)
showUserSignal = Signal(None)
showEmailScreenSignal = Signal(None)
startOverSignal = Signal(None)
Expand All @@ -66,7 +67,7 @@ class UI(QObject):
showEOYReturnSignal = Signal(None)
showEOYStartSignal = Signal(None)
showDailyLoanerDeviceScreenSignal = Signal(None)
showDailyLoanerChargerScreenSignal = Signal(None)
showDailyLoanerChargerScreenSignal = Signal(None)
showFinishDailyBorrowSignal = Signal(None)
showFinishDailyReturnSignal = Signal(None)
showOutstandingLoansSignal = Signal(str)
Expand Down Expand Up @@ -139,6 +140,12 @@ def showHideDailyLoaners(self):
self.showDailyLoanersSignal.emit()
else:
print("keeping daily loaners hidden")

if (self.config["show_loaner_report"] == True):
print("showing loaner report")
self.showLoanersReportSignal.emit()
else:
print("keeping loaner report hidden")

# Receive data from User.qml and direct set the correct next screen based on the service mode
@Slot(list)
Expand Down Expand Up @@ -539,6 +546,68 @@ def checkForOustandingLoans(self):
sqliteConnection.close()
print('SQLite Connection closed')

@Slot()
def generateBorrowReport(self):
currentSchoolYear = self.thisSchoolYear()
reportAsOf = "8/1/" + currentSchoolYear
# print("Generating borrow report since " + currentSchoolYear + "-08-01")
body = "Borrowed Report since " + reportAsOf + "\n"
body += "--- Devices ---\n"
body += self.generateBorrowReportFromSQL(currentSchoolYear, "Laptop")
body += "\n--- Chargers ---\n"
body += self.generateBorrowReportFromSQL(currentSchoolYear, "Charger")
print(body)
self.printBorrowReport(body)

def generateBorrowReportFromSQL(self, currentSchoolYear, deviceType):
try:
# Connect to DB and create a cursor
path = os.path.dirname(os.path.abspath(__file__))
db = os.path.join(path,'daily.db')
sqliteConnection = sqlite3.connect(db)
cursor = sqliteConnection.cursor()

# Write a query and execute it with cursor
query = """SELECT Last_Name, First_Name, COUNT(*) AS count FROM DAILY WHERE Device = ? AND
date_borrowed BETWEEN ? AND 'now'
GROUP BY Last_Name, First_Name
ORDER BY count DESC, Last_Name ASC;"""
args = (deviceType, currentSchoolYear + "-08-01")

report = ""

# Fetch and output result
result = cursor.execute(query, args).fetchall()
for row in result:
report += row[0] + ", " + row[1] + ": " + str(row[2]) + "\n"

# Close the cursor
cursor.close()

return report

# Handle errors
except sqlite3.Error as error:
print('Error occurred - ', error)

# Close DB Connection irrespective of success
# or failure
finally:
if sqliteConnection:
sqliteConnection.close()
print('SQLite Connection closed')

def printBorrowReport(self, report):
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)
lpr.communicate(bytes(report, 'utf-8'))

def thisSchoolYear(self):
today = datetime.date.today()
if today.month < 8:
return str(today.year - 1)
else:
return str(today.year)

# Email the daily loaner report
def emailDailyReport(self, body):
msg = EmailMessage()
Expand Down
40 changes: 20 additions & 20 deletions src/images/schoollogo.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@%%%%@@@@@%%%%%%%%@@@@@%%%%%@@@@@@
@@@@@@%+::::::::::::::::::::::::-%@@@@@@
@@@@@@@= :=+++= -+++=- :%@@@@@@
@@@@@@@= .+@@@@@#..... +@@@@@*. :%@@@@@@
@@@@@@%+.-%@%%**+:======+#@@@%=.-%@@@@@@
@@@@@@@%%@#*#%#%%%%@#*#%#+-#@@%%%%@@@@@@
@@@@@@@@@%+#@@%+=+@@@@@#+%#:#@@@@@@@@@@@
@@@@@@@%+#%%***++%@@@@@@%*-.:@@@@@@@@@@@
@@@@@@@%=*=-.. .:=#@@@@@@%= .#@@@@@@@@@@
@@@@@@@@#+%%#..::+%@@@@@@%: .%@@@@@@@@@@
@@@@@@@@@@@@=-*==%@@@@%%%-. +@@@@@@@@@@@
@@@@@@@@@@@#==+*.+%*=@+.: .*@@@@@@@@@@@@
@@@@@@@@@@@@@@*=:.. .:..-*@@@@@@@@@@@@@@
@@@@@@@@@@@@%%%%=.:::..-#%%%@@@@@@@@@@@@
@@@@@@@@@@@@%-.. ...... ...*@@@@@@@@@@@@
@@@@@@@@@@@@%##############%@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡏⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠩⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⣠⣤⣶⣶⣶⣦⠀⠀⠀⠀⠀⠀⢰⣶⣶⣶⣤⣄⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⣼⣿⣿⣿⣿⣿⣿⠀⠀⣀⣀⠀⠀⢸⣿⣿⣿⣿⣿⣧⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣇⢀⢰⣿⣿⣿⡿⠿⠟⣋⠉⡤⠤⠤⣤⣌⡉⠛⢿⣿⣿⣿⣿⣇⢀⢐⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢋⣴⣿⣷⣿⣿⣿⣿⣿⣷⣤⣽⢿⣷⣄⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢓⣿⣿⣿⣛⠋⠩⢌⣿⣿⣿⣿⣿⣗⣙⣿⣷⡀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⢋⣾⣿⣿⣯⣛⡻⠓⠶⣿⣿⣿⣿⣿⣿⣿⣿⣮⠉⠁⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡘⣏⣉⠁⠀⠀⠀⠀⠉⠪⣹⣿⣿⣿⣿⣿⣿⡿⢇⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣷⣌⣿⣿⣦⠀⠀⡠⠀⣚⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⣰⢋⡄⠚⢿⣿⣿⣿⣿⣿⢿⡿⠉⠀⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣤⡄⠻⡟⠀⠞⣿⠟⠹⣿⠟⠀⠁⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⡀⠀⠀⠀⠀⠁⠀⠀⣀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠏⠀⠀⠒⠒⠂⠈⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
28 changes: 22 additions & 6 deletions src/qml/Start.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Item {
btnDailyChargerReturn.visible = true;
btnDailyReport.visible = true;
}
function onShowLoanersReportSignal(){
btnLoanerReport.visible = true;
}
}

function showHideDailyLoaners() {
Expand Down Expand Up @@ -136,22 +139,35 @@ Item {
ui.start(2)
}
}
Button {
RowLayout {
// Will be handy when PySide6 supports uniformCellSizes
// uniformCellSizes: true
Button {
id: btnDailyReport
text: "Daily Report"
text: "Print Daily Report"
visible: false
font.pointSize: 50
Layout.fillWidth: true
Layout.fillHeight: true
onClicked: {
// ui.toEmail()
// contentFrame.push(Qt.createComponent("Email.qml"))
ui.dailyReport()
}
}
Button {
id: btnLoanerReport
text: "Print Total\nBorrows by Student"
visible: false
font.pointSize: 50
Layout.fillWidth: true
Layout.fillHeight: true
onClicked: {
ui.generateBorrowReport()
}
}
}

}
// Setting focus any other way doesn't seem to work.
// Kind of kludge, but works
// Show/hide daily loaner buttons based on config
Timer {
interval: 100
running: true
Expand Down

0 comments on commit 2e4e978

Please sign in to comment.