| 1 |
nino.borges |
561 |
"""
|
| 2 |
|
|
|
| 3 |
|
|
HPPR_ReportParser.py
|
| 4 |
|
|
|
| 5 |
|
|
This program will take a history export from the HPPR and parse and hten make a spreadsheet
|
| 6 |
|
|
with the results.
|
| 7 |
|
|
"""
|
| 8 |
|
|
|
| 9 |
nino.borges |
569 |
import os, shutil, time, ExcelLib
|
| 10 |
nino.borges |
561 |
|
| 11 |
|
|
class DB_View:
|
| 12 |
nino.borges |
564 |
def __init__(self,begno,viewDate):
|
| 13 |
|
|
self.begNo = begno
|
| 14 |
|
|
self.viewCount = 1
|
| 15 |
|
|
self.viewDateList = [viewDate,]
|
| 16 |
|
|
def AddToViewDateList(self,date):
|
| 17 |
|
|
"""Adds value to view date list"""
|
| 18 |
|
|
self.viewDateList.append(date)
|
| 19 |
|
|
def IncrementViewCount (self,n=1):
|
| 20 |
|
|
"""Increments the viewcount. default if to increment by 1"""
|
| 21 |
|
|
self.viewCount += n
|
| 22 |
nino.borges |
561 |
def ReturnInformation(self,info):
|
| 23 |
|
|
data = getattr(self,info)
|
| 24 |
|
|
return data
|
| 25 |
|
|
def SaveInformation(self,field,info):
|
| 26 |
|
|
data = setattr(self,field,info)
|
| 27 |
|
|
|
| 28 |
|
|
class DB_Print:
|
| 29 |
nino.borges |
564 |
def __init__(self,begno,printDate):
|
| 30 |
|
|
self.begNo = begno
|
| 31 |
|
|
self.printCount = 1
|
| 32 |
|
|
self.printDateList = [printDate,]
|
| 33 |
|
|
def AddToPrintDateList(self,date):
|
| 34 |
|
|
"""Adds value to print date list"""
|
| 35 |
|
|
self.printDateList.append(date)
|
| 36 |
|
|
def IncrementPrintCount (self,n=1):
|
| 37 |
|
|
"""Increments the viewcount. default if to increment by 1"""
|
| 38 |
|
|
self.printCount += n
|
| 39 |
nino.borges |
561 |
def ReturnInformation(self,info):
|
| 40 |
|
|
data = getattr(self,info)
|
| 41 |
|
|
return data
|
| 42 |
|
|
def SaveInformation(self,field,info):
|
| 43 |
|
|
data = setattr(self,field,info)
|
| 44 |
|
|
|
| 45 |
|
|
class DB_Query:
|
| 46 |
|
|
def __init__(self,begno):
|
| 47 |
|
|
self.BegNo = begno
|
| 48 |
|
|
def ReturnInformation(self,info):
|
| 49 |
|
|
data = getattr(self,info)
|
| 50 |
|
|
return data
|
| 51 |
|
|
def SaveInformation(self,field,info):
|
| 52 |
|
|
data = setattr(self,field,info)
|
| 53 |
|
|
|
| 54 |
nino.borges |
564 |
class Reporting:
|
| 55 |
nino.borges |
569 |
def __init__(self,caseName):
|
| 56 |
|
|
reportingFolder = r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Honeywell\HPPR\Reporting"
|
| 57 |
|
|
fileName = caseName+ time.strftime("_%Y%m%d") +"_HBPD_Report.xlsx"
|
| 58 |
|
|
shutil.copy2(r"HBPD_Report_skel.xlsx",os.path.join(reportingFolder,fileName))
|
| 59 |
|
|
|
| 60 |
|
|
self.spreadsheet = ExcelLib.ExcelConnection(os.path.join(reportingFolder,fileName))
|
| 61 |
|
|
self.caseName = caseName
|
| 62 |
|
|
|
| 63 |
nino.borges |
564 |
self.activityByDocFile = r"C:\McDermott-Discovery\Client\activityByDocument.txt"
|
| 64 |
nino.borges |
569 |
|
| 65 |
|
|
def CreateDocsOpenedReport(self,viewedMatrix):
|
| 66 |
|
|
"""Creates the documents opened report"""
|
| 67 |
|
|
myTab = "Docs Opened"
|
| 68 |
|
|
|
| 69 |
|
|
self.spreadsheet.setCell(myTab,4,1,self.spreadsheet.getCell(myTab,4,1).replace("{DATE}",time.strftime("%m-%d-%Y")))
|
| 70 |
|
|
self.spreadsheet.setCell(myTab,3,1,self.spreadsheet.getCell(myTab,3,1).replace("{Username / Case}",self.caseName))
|
| 71 |
|
|
|
| 72 |
|
|
docColumn = 2
|
| 73 |
|
|
dateColumn = 4
|
| 74 |
|
|
docNameColumn = 6
|
| 75 |
|
|
rowCount = 7
|
| 76 |
|
|
|
| 77 |
|
|
## Need to make a new matrix with sorted date as key
|
| 78 |
|
|
newMatrix = {}
|
| 79 |
|
|
for i in viewedMatrix.keys():
|
| 80 |
|
|
for dt in viewedMatrix[i].viewDateList:
|
| 81 |
|
|
if dt in newMatrix.keys():
|
| 82 |
|
|
newMatrix[dt].append(i)
|
| 83 |
|
|
else:
|
| 84 |
|
|
newMatrix[dt] = [i,]
|
| 85 |
|
|
dateList = newMatrix.keys()
|
| 86 |
|
|
dateList.sort()
|
| 87 |
|
|
|
| 88 |
|
|
for dt in dateList:
|
| 89 |
|
|
for document in newMatrix[dt]:
|
| 90 |
|
|
self.spreadsheet.setCell(myTab,rowCount,docColumn,document)
|
| 91 |
|
|
self.spreadsheet.setCell(myTab,rowCount,dateColumn,dt)
|
| 92 |
|
|
rowCount = rowCount +1
|
| 93 |
|
|
|
| 94 |
|
|
def CreateDocsPrintedReport(self,printedMatrix):
|
| 95 |
|
|
"""Creates the documents printed report"""
|
| 96 |
|
|
myTab = "Docs Printed"
|
| 97 |
|
|
|
| 98 |
|
|
self.spreadsheet.setCell(myTab,4,1,self.spreadsheet.getCell(myTab,4,1).replace("{DATE}",time.strftime("%m-%d-%Y")))
|
| 99 |
|
|
self.spreadsheet.setCell(myTab,3,1,self.spreadsheet.getCell(myTab,3,1).replace("{Username / Case}",self.caseName))
|
| 100 |
|
|
|
| 101 |
|
|
docColumn = 2
|
| 102 |
|
|
dateColumn = 4
|
| 103 |
|
|
docNameColumn = 6
|
| 104 |
|
|
rowCount = 7
|
| 105 |
|
|
|
| 106 |
|
|
## Need to make a new matrix with sorted date as key
|
| 107 |
|
|
newMatrix = {}
|
| 108 |
|
|
for i in printedMatrix.keys():
|
| 109 |
|
|
for dt in printedMatrix[i].printDateList:
|
| 110 |
|
|
if dt in newMatrix.keys():
|
| 111 |
|
|
newMatrix[dt].append(i)
|
| 112 |
|
|
else:
|
| 113 |
|
|
newMatrix[dt] = [i,]
|
| 114 |
|
|
dateList = newMatrix.keys()
|
| 115 |
|
|
dateList.sort()
|
| 116 |
|
|
|
| 117 |
|
|
for dt in dateList:
|
| 118 |
|
|
for document in newMatrix[dt]:
|
| 119 |
|
|
self.spreadsheet.setCell(myTab,rowCount,docColumn,document)
|
| 120 |
|
|
self.spreadsheet.setCell(myTab,rowCount,dateColumn,dt)
|
| 121 |
|
|
rowCount = rowCount +1
|
| 122 |
|
|
|
| 123 |
|
|
def CreateDocsViewCountReport(self,viewedMatrix):
|
| 124 |
|
|
"""Creates the documents View Count report. Right now this is just docs viewed but might need to merge with printed."""
|
| 125 |
|
|
myTab = "Docs by View Count"
|
| 126 |
|
|
|
| 127 |
|
|
self.spreadsheet.setCell(myTab,4,1,self.spreadsheet.getCell(myTab,4,1).replace("{DATE}",time.strftime("%m-%d-%Y")))
|
| 128 |
|
|
self.spreadsheet.setCell(myTab,3,1,self.spreadsheet.getCell(myTab,3,1).replace("{Username / Case}",self.caseName))
|
| 129 |
|
|
|
| 130 |
|
|
docColumn = 2
|
| 131 |
|
|
viewsColumn = 3
|
| 132 |
|
|
docNameColumn = 6
|
| 133 |
|
|
rowCount = 6
|
| 134 |
|
|
|
| 135 |
|
|
|
| 136 |
|
|
## Need to make a new matrix with sorted date as key
|
| 137 |
|
|
newMatrix = {}
|
| 138 |
|
|
for i in viewedMatrix.keys():
|
| 139 |
|
|
cnt=viewedMatrix[i].viewCount
|
| 140 |
|
|
if cnt in newMatrix.keys():
|
| 141 |
|
|
newMatrix[cnt].append(i)
|
| 142 |
|
|
else:
|
| 143 |
|
|
newMatrix[cnt] = [i,]
|
| 144 |
|
|
cntList = newMatrix.keys()
|
| 145 |
|
|
cntList.sort(reverse=True)
|
| 146 |
|
|
|
| 147 |
|
|
for ct in cntList:
|
| 148 |
|
|
for document in newMatrix[ct]:
|
| 149 |
|
|
self.spreadsheet.setCell(myTab,rowCount,docColumn,document)
|
| 150 |
|
|
self.spreadsheet.setCell(myTab,rowCount,viewsColumn,ct)
|
| 151 |
|
|
rowCount = rowCount +1
|
| 152 |
|
|
|
| 153 |
|
|
|
| 154 |
|
|
def CreateActivityByDocReport(self,viewedMatrix,printedMatrix):
|
| 155 |
nino.borges |
564 |
""" Creates the activity by document report"""
|
| 156 |
|
|
outputFile = open(self.activityByDocFile,'w')
|
| 157 |
|
|
viewedList = viewedMatrix.keys()
|
| 158 |
|
|
printedList = printedMatrix.keys()
|
| 159 |
|
|
combinedList = viewedList + list(set(printedList) - set(viewedList))
|
| 160 |
|
|
|
| 161 |
nino.borges |
569 |
def FinalizeReport(self):
|
| 162 |
|
|
"""Saves and closes the report. Without this, it wont save anything."""
|
| 163 |
|
|
self.spreadsheet.save()
|
| 164 |
|
|
self.spreadsheet.close()
|
| 165 |
|
|
|
| 166 |
|
|
|
| 167 |
nino.borges |
561 |
if __name__ == '__main__':
|
| 168 |
nino.borges |
569 |
excelReport = Reporting("CA_Johnson")
|
| 169 |
nino.borges |
564 |
documentsQueried = []
|
| 170 |
|
|
documentsPrintedMatrix = {}
|
| 171 |
|
|
documentPrinted = []
|
| 172 |
|
|
documentsViewedMatrix = {}
|
| 173 |
|
|
documentsViewed = []
|
| 174 |
nino.borges |
569 |
#reportFile = r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Honeywell\HPPR\Reporting\Don_report.dat"
|
| 175 |
|
|
reportFile = r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Honeywell\HPPR\Reporting\CA_Johnson_export.dat"
|
| 176 |
nino.borges |
564 |
|
| 177 |
nino.borges |
561 |
contents = open(reportFile).readlines()
|
| 178 |
nino.borges |
564 |
contents = contents[1:]
|
| 179 |
|
|
|
| 180 |
|
|
## First we pack the objs into the lists.
|
| 181 |
|
|
|
| 182 |
nino.borges |
561 |
for line in contents:
|
| 183 |
nino.borges |
564 |
line = line.replace("\n","")
|
| 184 |
nino.borges |
561 |
line = line.split("|")
|
| 185 |
nino.borges |
564 |
actionType = line[1]
|
| 186 |
|
|
if actionType == "View":
|
| 187 |
|
|
docID = line[0]
|
| 188 |
|
|
date = line[4]
|
| 189 |
|
|
if docID in documentsViewedMatrix.keys():
|
| 190 |
|
|
documentsViewedMatrix[docID].IncrementViewCount()
|
| 191 |
|
|
documentsViewedMatrix[docID].AddToViewDateList(date)
|
| 192 |
|
|
else:
|
| 193 |
|
|
docObj = DB_View(docID,date)
|
| 194 |
|
|
documentsViewedMatrix[docID] = docObj
|
| 195 |
|
|
elif actionType == "Document Query":
|
| 196 |
|
|
pass
|
| 197 |
|
|
elif actionType == "Print":
|
| 198 |
|
|
docID = line[0]
|
| 199 |
|
|
date = line[4]
|
| 200 |
|
|
if docID in documentsPrintedMatrix.keys():
|
| 201 |
|
|
documentsPrintedMatrix[docID].IncrementPrintCount()
|
| 202 |
|
|
documentsPrintedMatrix[docID].AddToPrintDateList(date)
|
| 203 |
|
|
else:
|
| 204 |
|
|
docObj = DB_Print(docID,date)
|
| 205 |
|
|
documentsPrintedMatrix[docID] = docObj
|
| 206 |
|
|
else:
|
| 207 |
|
|
print "ERROR: Unsupported action type - %s"% actionType
|
| 208 |
|
|
|
| 209 |
|
|
## Then we unpack into the report.
|
| 210 |
nino.borges |
569 |
printReport = open(r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Honeywell\HPPR\Reporting\printReport.txt",'w')
|
| 211 |
|
|
viewReport = open(r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Honeywell\HPPR\Reporting\viewReport.txt","w")
|
| 212 |
nino.borges |
564 |
for i in documentsPrintedMatrix.keys():
|
| 213 |
|
|
printReport.write("%s was printed %s times on the following dates:"% (i,documentsPrintedMatrix[i].printCount))
|
| 214 |
|
|
for x in documentsPrintedMatrix[i].printDateList:
|
| 215 |
|
|
printReport.write("%s,"%x)
|
| 216 |
|
|
printReport.write("\n")
|
| 217 |
|
|
for i in documentsViewedMatrix.keys():
|
| 218 |
|
|
viewReport.write("%s was Viewed %s times on the following dates:"% (i,documentsViewedMatrix[i].viewCount))
|
| 219 |
|
|
for x in documentsViewedMatrix[i].viewDateList:
|
| 220 |
|
|
viewReport.write("%s,"%x)
|
| 221 |
|
|
viewReport.write("\n")
|
| 222 |
|
|
printReport.close()
|
| 223 |
|
|
viewReport.close()
|
| 224 |
nino.borges |
569 |
|
| 225 |
|
|
## Excel Reporting
|
| 226 |
|
|
excelReport.CreateDocsOpenedReport(documentsViewedMatrix)
|
| 227 |
|
|
excelReport.CreateDocsPrintedReport(documentsPrintedMatrix)
|
| 228 |
|
|
excelReport.CreateDocsViewCountReport(documentsViewedMatrix)
|
| 229 |
|
|
excelReport.FinalizeReport()
|
| 230 |
nino.borges |
564 |
|
| 231 |
|
|
|