1
2 """Line analyzer with output and the capability to store lines"""
3
4 from .LogLineAnalyzer import LogLineAnalyzer
5 from PyFoam.Basics.OutFileCollection import OutFileCollection
6 from PyFoam.Basics.TimeLineCollection import TimeLineCollection
7
8 from PyFoam.Error import warning
9 import sys
12 """Base class for analyzers that write data to files and store time-lines
13
14 Combines the capabilities of TimeLineLineAnalyzer and FileLineAnalyzer"""
15
16
17 __phase = ""
18
19 - def __init__(self,
20 doTimelines=False,
21 doFiles=False,
22 titles=[],
23 accumulation=None,
24 singleFile=False,
25 progressTemplate=None,
26 startTime=None,
27 endTime=None):
28 """
29 @param titles: The titles of the data elements
30 @param progressTemplate: Progress output to be reported
31 """
32 LogLineAnalyzer.__init__(self)
33
34 self.doTimelines=doTimelines
35 self.doFiles=doFiles
36 self.singleFile=singleFile
37
38 self.files=None
39 self.titles=titles
40
41 self.setTitles(titles)
42
43 accu="first"
44 if accumulation!=None:
45 accu=accumulation
46 if self.doTimelines:
47 self.lines=TimeLineCollection(accumulation=accu)
48 else:
49 self.lines=None
50
51 self.startTime=startTime
52 self.endTime=endTime
53
54 self.master=None
55
56 self.didProgress=False
57 self.progressTemplate=progressTemplate
58
59 @staticmethod
62
63 @staticmethod
69
75
77 """Assign another line-analyzer that will do the actual data gathering"""
78 self.master=master
79 if self.lines and self.master.lines:
80 self.master.lines.addSlave(self.lines)
81
83 """
84 Sets the titles anew
85 @param titles: the new titles
86 """
87 if self.doFiles:
88 self.titles=titles
89 if self.files!=None:
90 self.files.setTitles(titles)
91
93 """Creates the OutFileCollection-object"""
94 if self.doFiles:
95 self.files=OutFileCollection(oDir,
96 titles=self.titles,
97 singleFile=self.singleFile)
98 else:
99 self.files=None
100
115
117 """@param name: Name of the timeline to return
118 @return: the timeline as two list: the times and the values"""
119 if self.doTimelines:
120 return self.lines.getTimes(),self.lines.getValues(name)
121 else:
122 return [],[]
123
125 """General analysis method. Derived classes should instead override callbacks"""
126
127 m=self.exp.match(line)
128 if m!=None:
129 self.startAnalysis(m)
130
131 if self.doTimelines:
132 try:
133 time=float(self.getTime())
134 if (self.startTime==None or time>=self.startTime) and (self.endTime==None or time<=self.endTime):
135 self.addToTimelines(m)
136 except ValueError:
137 e = sys.exc_info()[1]
138 warning("Problem doing timelines",e)
139
140 if self.doFiles:
141 self.addToFiles(m)
142
143 self.endAnalysis(m)
144
145 if not self.didProgress and self.progressTemplate:
146 myProgress=self.progressTemplate
147 for i,g in enumerate(m.groups()):
148 myProgress=myProgress.replace("$%d" % i,g)
149 self.writeProgress(myProgress)
150
151 self.didProgress=False
152
154 """Method at the start of a successfull match"""
155 pass
156
158 """Method at the end of a successfull match"""
159 pass
160
162 """Method that adds matched data to timelines
163
164 @param match: data matched by a regular expression"""
165
166 pass
167
169 """Method that adds matched data to files
170
171 @param match: data matched by a regular expression"""
172
173 pass
174
181
182
183