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 """Returns string to match. To be overriden for multi-line expressions"""
126 return line
127
129 """General analysis method. Derived classes should instead override callbacks"""
130
131 m=self.exp.match(self.stringToMatch(line))
132 if m!=None:
133 self.startAnalysis(m)
134
135 if self.doTimelines:
136 try:
137 time=float(self.getTime())
138 if (self.startTime==None or time>=self.startTime) and (self.endTime==None or time<=self.endTime):
139 self.addToTimelines(m)
140 except ValueError:
141 e = sys.exc_info()[1]
142 warning("Problem doing timelines",e)
143
144 if self.doFiles:
145 self.addToFiles(m)
146
147 self.endAnalysis(m)
148
149 if not self.didProgress and self.progressTemplate:
150 myProgress=self.progressTemplate
151 for i,g in enumerate(m.groups()):
152 myProgress=myProgress.replace("$%d" % i,g)
153 self.writeProgress(myProgress)
154
155 self.didProgress=False
156
158 """Method at the start of a successfull match"""
159 pass
160
162 """Method at the end of a successfull match"""
163 pass
164
166 """Method that adds matched data to timelines
167
168 @param match: data matched by a regular expression"""
169
170 pass
171
173 """Method that adds matched data to files
174
175 @param match: data matched by a regular expression"""
176
177 pass
178
185
186
187