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
54 """Assign another line-analyzer that will do the actual data gathering"""
55 self.master=master
56 if self.lines and self.master.lines:
57 self.master.lines.addSlave(self.lines)
58
60 """
61 Sets the titles anew
62 @param titles: the new titles
63 """
64 if self.doFiles:
65 self.titles=titles
66 if self.files!=None:
67 self.files.setTitles(titles)
68
70 """Creates the OutFileCollection-object"""
71 if self.doFiles:
72 self.files=OutFileCollection(oDir,
73 titles=self.titles,
74 singleFile=self.singleFile)
75 else:
76 self.files=None
77
88
90 """@param name: Name of the timeline to return
91 @return: the timeline as two list: the times and the values"""
92 if self.doTimelines:
93 return self.lines.getTimes(),self.lines.getValues(name)
94 else:
95 return [],[]
96
98 """General analysis method. Derived classes should instead override callbacks"""
99
100 m=self.exp.match(line)
101 if m!=None:
102 self.startAnalysis(m)
103
104 if self.doTimelines:
105 try:
106 time=float(self.getTime())
107 if (self.startTime==None or time>=self.startTime) and (self.endTime==None or time<=self.endTime):
108 self.addToTimelines(m)
109 except ValueError:
110 pass
111 if self.doFiles:
112 self.addToFiles(m)
113
114 self.endAnalysis(m)
115
116 if not self.didProgress and self.progressTemplate:
117 myProgress=self.progressTemplate
118 for i,g in enumerate(m.groups()):
119 myProgress=myProgress.replace("$%d" % i,g)
120 self.writeProgress(myProgress)
121
122 self.didProgress=False
123
125 """Method at the start of a successfull match"""
126 pass
127
129 """Method at the end of a successfull match"""
130 pass
131
133 """Method that adds matched data to timelines
134
135 @param match: data matched by a regular expression"""
136
137 pass
138
140 """Method that adds matched data to files
141
142 @param match: data matched by a regular expression"""
143
144 pass
145
152