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
9 """Base class for analyzers that write data to files and store time-lines
10
11 Combines the capabilities of TimeLineLineAnalyzer and FileLineAnalyzer"""
12
13 - def __init__(self,
14 doTimelines=False,
15 doFiles=False,
16 titles=[],
17 accumulation=None,
18 singleFile=False,
19 progressTemplate=None,
20 startTime=None,
21 endTime=None):
22 """
23 @param titles: The titles of the data elements
24 @param progressTemplate: Progress output to be reported
25 """
26 LogLineAnalyzer.__init__(self)
27
28 self.doTimelines=doTimelines
29 self.doFiles=doFiles
30 self.singleFile=singleFile
31
32 self.files=None
33 self.titles=titles
34
35 self.setTitles(titles)
36
37 accu="first"
38 if accumulation!=None:
39 accu=accumulation
40 if self.doTimelines:
41 self.lines=TimeLineCollection(accumulation=accu)
42 else:
43 self.lines=None
44
45 self.startTime=startTime
46 self.endTime=endTime
47
48 self.master=None
49
50 self.didProgress=False
51 self.progressTemplate=progressTemplate
52
58
60 """Assign another line-analyzer that will do the actual data gathering"""
61 self.master=master
62 if self.lines and self.master.lines:
63 self.master.lines.addSlave(self.lines)
64
66 """
67 Sets the titles anew
68 @param titles: the new titles
69 """
70 if self.doFiles:
71 self.titles=titles
72 if self.files!=None:
73 self.files.setTitles(titles)
74
76 """Creates the OutFileCollection-object"""
77 if self.doFiles:
78 self.files=OutFileCollection(oDir,
79 titles=self.titles,
80 singleFile=self.singleFile)
81 else:
82 self.files=None
83
94
96 """@param name: Name of the timeline to return
97 @return: the timeline as two list: the times and the values"""
98 if self.doTimelines:
99 return self.lines.getTimes(),self.lines.getValues(name)
100 else:
101 return [],[]
102
104 """General analysis method. Derived classes should instead override callbacks"""
105
106 m=self.exp.match(line)
107 if m!=None:
108 self.startAnalysis(m)
109
110 if self.doTimelines:
111 try:
112 time=float(self.getTime())
113 if (self.startTime==None or time>=self.startTime) and (self.endTime==None or time<=self.endTime):
114 self.addToTimelines(m)
115 except ValueError:
116 pass
117 if self.doFiles:
118 self.addToFiles(m)
119
120 self.endAnalysis(m)
121
122 if not self.didProgress and self.progressTemplate:
123 myProgress=self.progressTemplate
124 for i,g in enumerate(m.groups()):
125 myProgress=myProgress.replace("$%d" % i,g)
126 self.writeProgress(myProgress)
127
128 self.didProgress=False
129
131 """Method at the start of a successfull match"""
132 pass
133
135 """Method at the end of a successfull match"""
136 pass
137
139 """Method that adds matched data to timelines
140
141 @param match: data matched by a regular expression"""
142
143 pass
144
146 """Method that adds matched data to files
147
148 @param match: data matched by a regular expression"""
149
150 pass
151
158