-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfreader.py
522 lines (465 loc) · 16.4 KB
/
pdfreader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
import os
from datetime import *
import shutil
from tika import parser
from collections import OrderedDict
import matplotlib.pyplot as plt
import numpy as np
import xlsxwriter
from tkinter import *
import statistics
#| |/ / | |
#| ' / __ _ _ __ ___ _ _ ___| |__ _ _
#| < / _` | '_ ` _ \| | | / __| '_ \| | | |
#| . \ (_| | | | | | | |_| \__ \ | | | |_| |
#|_|\_\__,_|_| |_| |_|\__,_|___/_| |_|\__, |
# __/ |
# |___/
dates= {}
week = 0
filenumber = 0
backslash = "\\"
sundaypay = {}
sundayhours = {}
saturdaypay = {}
saturdayhours = {}
weekpay = {}
weekhours = {}
holidaypay = {}
holidayhours = {}
def finddate():
global dates, filething, folder
#path to folder
folder = os.listdir(fr"{os.path.dirname(__file__)}\files\\")
for file in folder:
#add the file name onto the path
filething = fr'{os.path.dirname(__file__)}\files\\{file}'
#get raw data from file
raw = parser.from_file(filething)
alldata = raw['content']
#split the pdf
alldata = alldata.split()
#get the 25th line which has the date
rightline = alldata[25]
#add the line and file name to array e.g. 04/04/2022: C:file.py
if rightline == "Date:":
dates[alldata[26]] = filething
else:
dates[rightline] = filething
def orderpdf():
global dates, ordereddate, folder, filenumber, backslash
#makes a folder
try:
os.mkdir('organisedpdfs')
except:
shutil.rmtree('organisedpdfs')
os.mkdir('organisedpdfs')
#sorts list of dates
for item in dates.items():
print(item)
ordereddate = OrderedDict(sorted(dates.items(), key = lambda x:datetime.strptime(x[0], '%d/%m/%Y')))
#for item in dictionary
for key, value in ordereddate.items():
#add 1 to file number so files can be ordered by numbers
filenumber = int(filenumber)
filenumber = filenumber + 1
filenumber = str(filenumber)
zeroLeading = filenumber.zfill(4)
#gets the orignal value
valueold = value
#replaces where the files in past where from and changes it to new directory
valuenew = value.replace("files", "organisedpdfs")
#reverses the new value
reversednew = valuenew[::-1]
#finds the index of the last backslash
char = reversednew.index(backslash)
#gets the filename after the .pdf
removing = reversednew[4:char]
#reversed the reversed to get it back to normal
removing = removing[::-1]
#replaces the filename with a number so it can used earlier in the future
valuenew = valuenew.replace(removing, str(zeroLeading))
#copys file into new location
shutil.copyfile(valueold, valuenew)
print("files are now ordered and in place")
totalpay = {}
totalhours = {}
def getinfo():
#gets current file path adds 'organised pdfs' onto it
locationorganised = os.listdir(fr"{os.path.dirname(__file__)}\organisedpdfs\\")
global sundaypay, week, saturdaypay, saturdayhours, weekpay, weekhours, holidayhours, holidaypay, totalpay, totalhours
for file in sorted(locationorganised):
#gets current file path then adds organised pdfs and the file name onti it
toopenfile = fr'{os.path.dirname(__file__)}\organisedpdfs\{file}'
#get rawdata from file
raworganised = parser.from_file(toopenfile)
allData = raworganised['content']
#split the pdf
allData = allData.split()\
#adds to week
week = week + 1
saturdayhours[week] = 0
saturdaypay[week] = 0
sundayhours[week] = 0
sundaypay[week] = 0
weekpay[week] = 0
weekhours[week] = 0
holidayhours[week] = 0
holidaypay[week] = 0
totalhours[week] = 0
totalpay[week] = 0
#for line in file
for i in allData:
#gets index
i2 = allData.index(i)
if i == "Sunday":
#adds 4 to index which is the location of pay
sundayPayindex = i2 + 4
if allData[sundayPayindex] == "Wages":
sundaypay[week] = 0
totalpay[week] + 0
break
sundaypay[week] = allData[sundayPayindex]
bruh = allData[sundayPayindex].replace("$", "")
totalpay[week] = totalpay[week] + float(round(float(bruh), 2))
sundayHourindex = i2 + 2
sundayhours[week] = float(allData[sundayHourindex])
totalhours[week] = totalhours[week] + float(allData[sundayHourindex])
elif i == "Saturday":
#adds 4 to index which is the location of pay
saturdayPayindex = i2 + 4
if allData[saturdayPayindex] == "Wages":
saturdaypay[week] = 0
totalpay[week] + 0
break
saturdaypay[week] = allData[saturdayPayindex]
bruh = allData[saturdayPayindex].replace("$", "")
totalpay[week] = totalpay[week] + float(round(float(bruh), 2))
saturdayHourindex = i2 + 2
saturdayhours[week] = float(allData[saturdayHourindex])
totalhours[week] = totalhours[week] + float(allData[saturdayHourindex])
elif i == "W/day":
#adds 4 to index which is the location of pay
weekPayindex = i2 + 4
if allData[weekPayindex] == "Wages":
weekpay[week] = 0
totalpay[week] + 0
break
weekpay[week] = allData[weekPayindex]
bruh = allData[weekPayindex].replace("$", "")
totalpay[week] = totalpay[week] + float(round(float(bruh), 2))
weekPayindex = i2 +2
weekhours[week] = float(allData[weekPayindex])
totalhours[week] = totalhours[week] + float(allData[weekPayindex])
elif i == "P/Holiday":
#adds 4 to index which is the location of pay
holidayPayindex = i2 + 4
if allData[holidayPayindex] == "Wages":
holidaypay[week] = 0
totalpay[week] + 0
break
holidaypay[week] = allData[holidayPayindex]
bruh = allData[holidayPayindex].replace("$", "")
totalpay[week] = totalpay[week] + float(round(float(bruh), 2))
holidayPayindex = i2 + 2
holidayhours[week] = float(allData[holidayPayindex])
totalhours[week] = totalhours[week] + float(allData[holidayPayindex])
def removedollar():
for key, value in sundaypay.items():
value = str(value)
if "$" in value:
value = value.replace("$", "")
value = float(value)
sundaypay[key] = round(value)
else:
pass
for key, value in saturdaypay.items():
value = str(value)
if "$" in value:
value = value.replace("$", "")
value = float(value)
saturdaypay[key] = round(value)
else:
pass
for key, value in weekpay.items():
value = str(value)
if "$" in value:
value = value.replace("$", "")
value = float(value)
weekpay[key] = round(value)
else:
pass
for key, value in holidaypay.items():
value = str(value)
if "$" in value:
value = value.replace("$", "")
value = float(value)
holidaypay[key] = round(value)
else:
pass
for key, value in totalpay.items():
value = float(value)
totalpay[key] = round(value)
for key, value in totalhours.items():
value = float(value)
totalhours[key] = round(value)
for key, value in weekhours.items():
value = float(value)
weekhours[key] = round(value)
for key, value in sundayhours.items():
value = float(value)
sundayhours[key] = round(value)
for key, value in saturdayhours.items():
value = float(value)
saturdayhours[key] = round(value)
def graphing():
plt.figure(1)
plt.bar(*zip(*sundaypay.items()), label="Pay")
plt.bar(*zip(*sundayhours.items()), label='Hours')
plt.xlabel('Week Number')
plt.ylabel('Pay(In AUD)')
plt.title('Sunday Pay')
plt.grid(color='#95a5a6', linestyle='-', linewidth=1, axis='y', alpha=0.5)
x = np.arange(1, week+1, 1)
plt.xticks(x)
plt.legend()
plt.figure(2)
plt.bar(*zip(*weekpay.items()), label="Pay")
plt.bar(*zip(*weekhours.items()), label='Hours')
plt.xlabel('Week Number')
plt.ylabel('Pay(In AUD)')
plt.title('Weekday Pay')
plt.grid(color='#95a5a6', linestyle='-', linewidth=1, axis='y', alpha=0.5)
x = np.arange(1, week+1, 1)
plt.xticks(x)
plt.legend()
plt.figure(3)
plt.bar(*zip(*saturdaypay.items()), label="Pay")
plt.bar(*zip(*saturdayhours.items()), label='Hours')
plt.xlabel('Week Number')
plt.ylabel('Pay(In AUD)')
plt.title('Saturday Pay')
plt.grid(color='#95a5a6', linestyle='-', linewidth=1, axis='y', alpha=0.5)
x = np.arange(1, week+1, 1)
plt.xticks(x)
plt.legend()
plt.figure(4)
plt.bar(*zip(*holidaypay.items()), label="Pay")
plt.bar(*zip(*holidayhours.items()), label='Hours')
plt.xlabel('Week Number')
plt.ylabel('Pay(In AUD)')
plt.title('Holiday Pay')
plt.grid(color='#95a5a6', linestyle='-', linewidth=1, axis='y', alpha=0.5)
x = np.arange(1, week+1, 1)
plt.xticks(x)
plt.legend()
plt.figure(5)
plt.bar(*zip(*totalpay.items()), label="Pay")
plt.bar(*zip(*totalhours.items()), label='Hours')
plt.xlabel('Week Number')
plt.ylabel('Pay(In AUD)')
plt.title('All time Pay')
plt.grid(color='#95a5a6', linestyle='-', linewidth=1, axis='y', alpha=0.5)
x = np.arange(1, week+1, 1)
plt.xticks(x)
plt.legend()
plt.show()
def createdoc():
try:
workbook = xlsxwriter.Workbook('HoursAndPay.xlsx')
except:
workbook = xlsxwriter.Workbook('HoursAndPay.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
currency_format = workbook.add_format({'num_format': '$#,##0'})
row = 0
column = 0
worksheet.write(row, column,"Week Number", bold)
row +=1
for key, value in weekpay.items():
worksheet.write(row, column, key)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Weekday Pay", bold)
row +=1
for key, value in weekpay.items():
worksheet.write(row, column, value, currency_format)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Saturday Pay", bold)
row +=1
for key, value in saturdaypay.items():
worksheet.write(row, column, value, currency_format)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Sunday Pay", bold)
row +=1
for key, value in sundaypay.items():
worksheet.write(row, column, value, currency_format)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Holiday Pay", bold)
row +=1
for key, value in holidaypay.items():
worksheet.write(row, column, value, currency_format)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Total Pay", bold)
row +=1
for key, value in totalpay.items():
worksheet.write(row, column, value, currency_format)
row += 1
column +=2
row = 0
worksheet.write(row, column,"WeekDay Hours", bold)
row +=1
for key, value in weekhours.items():
row += 1
column +=1
row = 0
worksheet.write(row, column,"Saturday Hours", bold)
row +=1
for key, value in saturdayhours.items():
worksheet.write(row, column, value)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Sunday Hours", bold)
row +=1
for key, value in sundayhours.items():
worksheet.write(row, column, value)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Holiday Hours", bold)
row +=1
for key, value in holidayhours.items():
worksheet.write(row, column, value)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Total Hours", bold)
row +=1
for key, value in totalhours.items():
worksheet.write(row, column, value)
row += 1
column += 2
row = 0
worksheet.write(row, column,"Week Number", bold)
row +=1
for key, value in weekpay.items():
worksheet.write(row, column, key)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Total Hours", bold)
row +=1
for key, value in totalhours.items():
worksheet.write(row, column, value)
row += 1
column +=1
row = 0
worksheet.write(row, column,"Total Pay", bold)
row +=1
for key, value in totalpay.items():
worksheet.write(row, column, value)
row += 1
column +=1
row = 0
workbook.close()
def averages():
global indexcounthour, totalpaynumber, totalhournumber
pay = []
totalpaynumber = 0
indexcount =0
weekcount = []
for key, value in totalpay.items():
indexcount = indexcount + 1
pay.append(value)
weekcount.append(key)
totalpaynumber = totalpaynumber + value
mean = round(totalpaynumber / indexcount)
median = round(statistics.median(pay))
mode = statistics.mode(pay)
range1 = max(pay) - min(pay)
hours = []
totalhournumber = 0
indexcounthour =0
weekcounthour = []
for key, value in totalhours.items():
indexcounthour = indexcounthour + 1
hours.append(value)
weekcounthour.append(key)
totalhournumber = totalhournumber + value
meanhour = round(totalhournumber / indexcounthour)
medianhour = round(statistics.median(hours))
modehour = statistics.mode(hours)
rangehour = max(hours) - min(hours)
averagesforpay = f"""
Pay averages per week
Mean: ${mean}
Mode: ${mode}
Median: ${median}
Range: ${range1}
Hour averages per week
Mean: {meanhour}
Mode: {modehour}
Median: {medianhour}
Range: {rangehour}
"""
root = Tk()
root.geometry("500x500")
root.title("Averages")
l = Label(root, text = averagesforpay, anchor="center")
l.config(font =("Arial", 24))
l.place(x=230, y=250, anchor="center")
root.mainloop()
Totalpayandhours = f"""
Total Pay: {totalpaynumber}
Total Hours: {totalhournumber}
"""
root = Tk()
root.geometry("500x500")
root.title("Averages")
l = Label(root, text = Totalpayandhours, anchor="center")
l.config(font =("Arial", 24))
l.place(x=230, y=250, anchor="center")
root.mainloop()
def timewasted():
#convert weeks into hours
#total hours / hours of all weeks = percentage of weeks spent at work
#
global indexcounthour, totalhours
if indexcounthour >= 52:
for i in range(totalhours[-52], totalhours[0]):
for key, value in totalhours:
totalhoursrecent += totalhours(value)
else:
weeknumber = list(totalhours)[-1]
finddate()
orderpdf()
getinfo()
removedollar()
createdoc()
averages()
graphing()
timewasted()
print(f"sundaypay: {sundaypay}")
print(f"saturdaypay: {saturdaypay}")
print(f"sundayhour: {sundayhours}")
print(f"saturday hour: {saturdayhours}")
print(f"weekday hour: {weekhours}")
print(f"weekday pay: {weekpay}")
print(f"holiday pay: {holidaypay}")
print(f"holiday hours: {holidayhours}")
print(f"total pay: {totalpay}")
print(f"total hours: {totalhours}")
print("totalhours:")
print(totalhournumber)
print("totalpay:")
print(totalpaynumber)