ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/ClientStatAnalysis.py
Revision: 610
Committed: Wed Sep 21 15:07:05 2016 UTC (9 years, 6 months ago) by nino.borges
Content type: text/x-python
File size: 3037 byte(s)
Log Message:
Created a program that will take a PTS report and cull out parts to then put into a spreadsheet. in the future it will make the spreadsheet.

File Contents

# User Rev Content
1 nino.borges 610 """
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     outputFileNamePredictive = r"C:\Test\ClientAnalysisPrediction.dat"
18     outputFileNameYearTotal = r"C:\Test\ClientAnalysisYearTotal.dat"
19     rawReportContents = open(clientRawReportFile,'r').readlines()
20     rawReportContents = rawReportContents[1:]
21    
22     reportCategoryList = ['Service Revenue - Other', 'Hosting', 'Forensics', 'Paper', 'Attorney Review', 'ESI']
23     reportCategoryListSelected = ['Hosting','Forensics', 'ESI']
24    
25     reportCategoryColumnNumb = 12
26     reportDateColumnNumb = 11
27     reportRevenueColumnNumb = 7
28    
29     esiReportMatrix = {}
30     esiReportYearTotalMatrix = {}
31     esiReportPredictionMatrix = {}
32    
33     for line in rawReportContents:
34     line = line.split(",")
35     reportCategory = line[reportCategoryColumnNumb]
36     reportDate = line[reportDateColumnNumb]
37     reportRevenue = line[reportRevenueColumnNumb]
38     if reportCategory in reportCategoryListSelected:
39     if reportDate in esiReportMatrix.keys():
40     esiReportMatrix[reportDate] = esiReportMatrix[reportDate] + float(reportRevenue)
41     else:
42     esiReportMatrix[reportDate] = float(reportRevenue)
43    
44     outputFile = open(outputFileNameAnalysis,'w')
45     reportDateList = esiReportMatrix.keys()
46     reportDateList.sort()
47     for i in reportDateList:
48     outputFile.write("%s|%s\n"%(i,esiReportMatrix[i]))
49     outputFile.close()
50    
51    
52     for n in reportDateList:
53     year = n.split("-")[0]
54     if year in esiReportYearTotalMatrix.keys():
55     esiReportYearTotalMatrix[year] = esiReportYearTotalMatrix[year] + float(esiReportMatrix[n])
56     else:
57     esiReportYearTotalMatrix[year] = float(esiReportMatrix[n])
58    
59     outputFile = open(outputFileNameYearTotal,'w')
60     yearTotalList = esiReportYearTotalMatrix.keys()
61     yearTotalList.sort()
62     for yr in yearTotalList:
63     outputFile.write("%s|%s\n"%(yr,esiReportYearTotalMatrix[yr]))
64     outputFile.close()
65    
66     for x in reportDateList:
67     month = x.split("-")[1]
68     if month in esiReportPredictionMatrix.keys():
69     esiReportPredictionMatrix[month].append(float(esiReportMatrix[x]))
70     else:
71     esiReportPredictionMatrix[month] = [float(esiReportMatrix[x])]
72     outputFile = open(outputFileNamePredictive,'w')
73     monthPredictionList = esiReportPredictionMatrix.keys()
74     monthPredictionList.sort()
75     for m in monthPredictionList:
76     sumTotal = 0
77     for tot in esiReportPredictionMatrix[m]:
78     sumTotal = sumTotal + tot
79     averageTotal = sumTotal/len(esiReportPredictionMatrix[m])
80     outputFile.write("%s|%s\n"%(m,averageTotal))
81     outputFile.close()