Module statgen
[hide private]
[frames] | no frames]

Source Code for Module statgen

  1  #!/usr/bin/env python 
  2   
  3   
  4  import os 
  5  import re 
  6  import timeseries 
  7  import corestats 
  8   
  9   
 10   
11 -class LogParser:
12
13 - def __init__(self, input_type, query):
14 self.commandline_opts = '-i:' + input_type + ' -o:CSV ' + '"' + query + '"' 15 self.log_parser = 'LogParser.exe' # make sure its on your Path or else put the full Path here 16 self.data_set = [] 17 self.headers = '' 18 self.footers = '' 19 20 # load the object with data from Log Parser query results 21 self.query()
22 23
24 - def mslogparser_wrapper(self):
25 # wrapper for the Log Parser CLI 26 # execute the command as a subprocess and return file objects (child_stdin, child_stdout_and_stderr) 27 cmd = os.popen4(self.log_parser + ' ' + self.commandline_opts) 28 # read contents of the file object (child_stdout_and_stderr) until EOF 29 cmd_output = cmd[1].read() 30 # close the handles 31 for fd in cmd: fd.close() 32 return cmd_output
33 34
35 - def query(self):
36 # we call the Log Parser wrapper to execute the query. 37 # rows returned from the query are split into csv's and stored in a list 38 data_set = self.mslogparser_wrapper().splitlines() 39 # store the output column headings 40 self.headers = data_set[:1] 41 # store the output footers (statistics) 42 self.footers = data_set[-6:-1][2:] 43 # trim the header and footers from the list so all we have left are rows of csv data 44 # store the list in the object's data_set instance var 45 self.data_set = data_set[2:-7]
46 47
48 - def print_dataset(self):
49 # print the data_set (newline delimited) 50 for row in self.data_set: 51 print row
52 53
54 - def dataset(self):
55 return data_set
56 57
58 - def dataset_row(self, line_number):
59 # get a single line from our data_set (zero indexed) 60 return self.data_set[line_number]
61 62
63 - def dataset_column(self, column_number):
64 # get a single column from our data_set (zero indexed) 65 data_column = [re.split(',', row)[column_number] for row in self.data_set] 66 return data_column
67 68
69 - def sum(self, column_number):
70 col = self.dataset_column(column_number) 71 stats = corestats.Stats(col) 72 return stats.sum()
73 74
75 - def count(self, column_number):
76 col = self.dataset_column(column_number) 77 stats = corestats.Stats(col) 78 return stats.count()
79 80
81 - def min(self, column_number):
82 col = self.dataset_column(column_number) 83 stats = corestats.Stats(col) 84 return stats.min()
85 86
87 - def max(self, column_number):
88 col = self.dataset_column(column_number) 89 stats = corestats.Stats(col) 90 return stats.max()
91 92
93 - def avg(self, column_number):
94 col = self.dataset_column(column_number) 95 stats = corestats.Stats(col) 96 return stats.avg()
97 98
99 - def median(self, column_number):
100 col = self.dataset_column(column_number) 101 stats = corestats.Stats(col) 102 return stats.median()
103 104
105 - def stdev(self, column_number):
106 col = self.dataset_column(column_number) 107 stats = corestats.Stats(col) 108 return stats.stdev()
109 110
111 - def percentile(self, percentile, column_number):
112 col = self.dataset_column(column_number) 113 stats = corestats.Stats(col) 114 return stats.percentile(percentile)
115 116
117 - def timeseries(self, interval):
118 return timeseries.TimeSeries(interval, self.data_set)
119