ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/ClientStatAnalysis.py
Revision: 640
Committed: Wed Mar 28 20:23:01 2018 UTC (8 years ago) by nino.borges
Content type: text/x-python
File size: 3148 byte(s)
Log Message:
minor changes in use

File Contents

# Content
1 """
2
3 ClientStatAnalysis.py
4
5 A simple program that will take in a client report and analyze it, creating a report with
6 projections.
7
8 Created by
9 Emanuel Borges
10 2016.09.20
11
12 """
13
14 if __name__ == '__main__':
15 clientRawReportFile = r"C:\Test\ClientRawData.csv"
16 outputFileNameAnalysis = r"C:\Test\ClientAnalysis.dat"
17 outputFileNameStackedAnalysis = r"C:\Test\ClientStackedAnalysis.dat"
18 outputFileNamePredictive = r"C:\Test\ClientAnalysisPrediction.dat"
19 outputFileNameYearTotal = r"C:\Test\ClientAnalysisYearTotal.dat"
20 rawReportContents = open(clientRawReportFile,'r').readlines()
21 rawReportContents = rawReportContents[1:]
22
23 reportCategoryList = ['Service Revenue - Other', 'Hosting', 'Forensics', 'Paper', 'Attorney Review', 'ESI']
24 reportCategoryListSelected = ['Hosting','Forensics', 'ESI']
25
26 reportCategoryColumnNumb = 12
27 reportDateColumnNumb = 11
28 reportRevenueColumnNumb = 7
29 reportProjectNameColumnNumb = 3
30
31 esiReportMatrix = {}
32 esiReportYearTotalMatrix = {}
33 esiReportPredictionMatrix = {}
34
35 for line in rawReportContents:
36 line = line.split(",")
37 reportCategory = line[reportCategoryColumnNumb]
38 reportDate = line[reportDateColumnNumb]
39 reportRevenue = line[reportRevenueColumnNumb]
40 if reportCategory in reportCategoryListSelected:
41 if reportDate in esiReportMatrix.keys():
42 esiReportMatrix[reportDate] = esiReportMatrix[reportDate] + float(reportRevenue)
43 else:
44 esiReportMatrix[reportDate] = float(reportRevenue)
45
46 outputFile = open(outputFileNameAnalysis,'w')
47 reportDateList = esiReportMatrix.keys()
48 reportDateList.sort()
49 for i in reportDateList:
50 outputFile.write("%s|%s\n"%(i,esiReportMatrix[i]))
51 outputFile.close()
52
53
54 for n in reportDateList:
55 year = n.split("-")[0]
56 if year in esiReportYearTotalMatrix.keys():
57 esiReportYearTotalMatrix[year] = esiReportYearTotalMatrix[year] + float(esiReportMatrix[n])
58 else:
59 esiReportYearTotalMatrix[year] = float(esiReportMatrix[n])
60
61 outputFile = open(outputFileNameYearTotal,'w')
62 yearTotalList = esiReportYearTotalMatrix.keys()
63 yearTotalList.sort()
64 for yr in yearTotalList:
65 outputFile.write("%s|%s\n"%(yr,esiReportYearTotalMatrix[yr]))
66 outputFile.close()
67
68 for x in reportDateList:
69 month = x.split("-")[1]
70 if month in esiReportPredictionMatrix.keys():
71 esiReportPredictionMatrix[month].append(float(esiReportMatrix[x]))
72 else:
73 esiReportPredictionMatrix[month] = [float(esiReportMatrix[x])]
74 outputFile = open(outputFileNamePredictive,'w')
75 monthPredictionList = esiReportPredictionMatrix.keys()
76 monthPredictionList.sort()
77 for m in monthPredictionList:
78 sumTotal = 0
79 for tot in esiReportPredictionMatrix[m]:
80 sumTotal = sumTotal + tot
81 averageTotal = sumTotal/len(esiReportPredictionMatrix[m])
82 outputFile.write("%s|%s\n"%(m,averageTotal))
83 outputFile.close()