2 Copyright (c) 2016, Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Marek Felix, Meissner Pascal, Trautmann Jeremias, Wittenbeck Valerij 6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 12 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 """ Generate state analysis in path 27 Folder has to contain log.csv file 31 log_path = os.path.join(path,
'log.csv')
33 if not os.path.isfile(log_path):
34 print(path +
" does not contain log.csv")
39 with open(log_path,
'r') as fin: 40 lines = fin.readlines() 46 lines[0] =
"timestamp state outcome\n" 48 with open(log_path,
'w')
as fout:
52 df = pd.read_csv(log_path, sep=
' ')
56 df[
'delta'] = (df[
'timestamp']-df[
'timestamp'].shift()).fillna(0)
59 new_df = pd.DataFrame({
'count': df.groupby(
'state')[
'delta'].count()})
62 new_df[
'sum'] = df.groupby(
'state')[
'delta'].sum()
65 new_df[
'mean'] = df.groupby(
'state')[
'delta'].mean()
67 new_df.to_csv(os.path.join(path, filename))
71 new_df = pd.read_csv(os.path.join(path, filename))
75 new_df.to_csv(os.path.join(path, filename), index=
False)
76 print "experiment_mean for: " + str(path) +
'\n' + str(new_df)
79 runtime = df[
'timestamp'][df.last_valid_index()] - \
80 df[
'timestamp'][df.first_valid_index()]
82 print "Runtime: " + str(runtime) +
'\n' 83 ret = {
'runtime': runtime,
'dataframe': new_df}
89 for file
in os.listdir(path):
90 if fnmatch.fnmatch(file,
'state_machine*.log'):
91 if log_path
is not None:
92 print(
"Multiple logs for state_machine found. This will be ignored: " + str(file))
94 log_path = os.path.join(path, file)
97 print(str(path) +
" does not contain state_machine*.log")
102 with open(log_path,
'r') as fin: 103 lines = fin.readlines() 110 searchForInit =
False 111 searchForNext =
False 124 if "Initial robot state" in line:
126 elif searchForInit
and "x: " in line:
127 oldX = float(line.replace(
"x: ",
""))
128 elif searchForInit
and "y: " in line:
129 oldY = float(line.replace(
"y: ",
""))
130 searchForInit =
False 134 elif "This is the actual robot pose after navigation: position:" in line:
136 elif searchForNext
and " x: " in line:
137 currentX = float(line.replace(
" x: ",
""))
138 elif searchForNext
and " y: " in line:
139 currentY = float(line.replace(
" y: ",
""))
141 my_sum +=
getDistance(oldX, oldY, currentX, currentY)
145 searchForNext =
False 153 df.loc[len(df)] = [
"MovedDistance (in m)", count, my_sum, mean]
157 return math.sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
161 """ Generates analysis in all subfolders with log.csv file """ 167 for root, dirs, files
in os.walk(path, topdown=
False):
168 abspathOfCurrentDir = os.path.abspath(root)
169 if os.path.isfile(os.path.join(root,
"log.csv")):
174 runtime_index[abspathOfCurrentDir] = [root]
175 runtime_data[abspathOfCurrentDir] = [ret[
'runtime']]
176 df_concat[abspathOfCurrentDir] = [ret[
'dataframe']]
184 return [os.path.abspath(os.path.join(a_dir, name))
for name
in os.listdir(a_dir)
185 if os.path.isdir(os.path.join(a_dir, name))]
188 all_runtime_index = []
189 all_runtime_data = []
193 for subDirPath
in subDirPaths:
194 if subDirPath
in runtime_index:
195 all_runtime_index.extend(runtime_index[subDirPath])
196 all_runtime_data.extend(runtime_data[subDirPath])
197 all_df_concat.extend(df_concat[subDirPath])
199 print "No csv in subDir: " + str(subDirPath)
200 if len(all_runtime_index) == 0:
201 print "There are no csv in the subdirs for the following dir: " + str(currentDir)
204 abspathOfCurrentDir = os.path.abspath(currentDir)
205 runtime_index[abspathOfCurrentDir] = all_runtime_index
206 runtime_data[abspathOfCurrentDir] = all_runtime_data
207 df_concat[abspathOfCurrentDir] = all_df_concat
209 createConcatCsv(runtime_index[abspathOfCurrentDir], runtime_data[abspathOfCurrentDir], df_concat[abspathOfCurrentDir], currentDir)
212 df_concat = pd.DataFrame()
213 for df
in df_concates:
214 df_concat = pd.concat((df_concat, df))
216 experiment_mean = pd.DataFrame()
217 experiment_mean[
'count'] = df_concat.groupby(
'state')[
'count'].mean()
218 experiment_mean[
'sum'] = df_concat.groupby(
'state')[
'sum'].mean()
219 experiment_mean[
'mean'] = df_concat.groupby(
'state')[
'mean'].mean()
221 filePrefix = os.path.basename(path)
222 print "experiment_mean for: " + str(path) +
'\n' + str(experiment_mean)
223 experiment_mean.to_csv(os.path.join(path, filePrefix +
'_mean.csv'))
225 pd.Series(runtime_datas, index=runtime_indexes).to_csv(os.path.join(path, filePrefix +
'_runtimes.csv'))
226 print "Runtime (mean): " + str(reduce(
lambda x, y: x + y, runtime_datas) / len(runtime_datas)) +
'\n' 229 if __name__ ==
'__main__':
230 print "This tool will generate analysis information from the log file(s). You can enter the path to the log file in the next step." 231 print "You can create a hierarchy of log_folders. For each level there will be a runtimes.csv and experiment_mean.csv generated." 232 path = str(raw_input(
"Enter path: "))
def appendDataAndCreateCsvForCurrentDepth(currentDir, subDirPaths, runtime_index, runtime_data, df_concat)
def generate_analysis(path, filename)
def getDistance(x1, y1, x2, y2)
def analyze_subfolders(path)
def generate_moved_distance(path, df)
def createConcatCsv(runtime_indexes, runtime_datas, df_concates, path)
def get_immediate_subdirectories(a_dir)