reorderCsvs.py
Go to the documentation of this file.
1 '''
2 Copyright (c) 2016, Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Marek Felix, Meissner Pascal, Trautmann Jeremias, Wittenbeck Valerij
3 
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 
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.
11 
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.
13 
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.
15 '''
16 
17 import os
18 import os.path
19 
20 order = ["Zustand", "state", "ObjectSearchInit", "DirectSearchInit", "SearchInit", "SceneRecognition", "PosePrediction", "CropBoxGeneration", "NBVSetPointCloud", "GetGoalCameraPose", "NextBestView", "GenerateRandomPose", "MoveBase", "FakeMoveBase", "MovePTU", "PTUPoseCorrection", "FrustumViz", "VisualizeWaypoints", "ObjectDetection", "NextBestViewUpdate", "CropboxStateRecording", "GridInitStateRecording", "CheckSearchFinished", "Total", "MovedDistance"]
21 
22 toRemove = ["ObjectSearchInit", "DirectSearchInit", "SearchInit", "FrustumViz", "VisualizeWaypoints", "CheckSearchFinished", "Total"]
23 
24 def isNumber(s):
25  try:
26  float(s)
27  return True
28  except ValueError:
29  return False
30 
31 def roundAllValues(content):
32  content = [x.strip() for x in content]
33  newContent = []
34 
35  for line in content:
36  countEach = 0
37  isFirst = True
38  newLine = str()
39  for each in line.split(','):
40  if isFirst:
41  isFirst = False
42  else:
43  newLine += ","
44  if isNumber(each):
45  newLine += "{0:.2f}".format(float(each))
46  if line.startswith("MovedDistance") and countEach >= 2:
47  newLine += " m"
48  else:
49  newLine += each
50  countEach += 1
51  newLine += "\n"
52  newContent.append(newLine)
53  return newContent
54 
55 def isToRemove(line):
56  for removeLine in toRemove:
57  if line.startswith(removeLine):
58  return True
59  return False
60 
61 def calculateTotal(content):
62  totalSum = 0.0
63 
64  for line in content:
65  if line.startswith("Zustand") or line.startswith("state") or line.startswith("MovedDistance") or line.startswith("Total"):
66  continue
67 
68  eachs = line.split(',')
69  totalSum += float(eachs[2])
70 
71  return "Total,-," + "{0:.2f}".format(totalSum / 60.0) + " min,-\n"
72 
73 def reorderFile(file):
74  with open(file, 'r') as f:
75  content = f.readlines()
76 
77  content = roundAllValues(content)
78  content = [line for line in content if not isToRemove(line)]
79  content.append(calculateTotal(content))
80 
81  reorderedContent = []
82  for newOrder in order:
83  for line in content:
84  if line.startswith(newOrder):
85  reorderedContent.append(line)
86  break
87 
88  for line in content:
89  isFound = False
90  for reordereLine in reorderedContent:
91  if line == reordereLine:
92  isFound = True
93  break
94  if isFound == False:
95  print ("Unknown, will be append to end: %s" % line)
96  reorderedContent.append(line)
97 
98  with open(file, 'w') as f:
99  for line in reorderedContent:
100  f.write("%s" % line)
101 
102 def reorderCsvs(path):
103  for root, dirs, files in os.walk(path):
104  for name in files:
105  if ".csv" in name and "mean" in name:
106  reorderFile(os.path.join(root, name))
107 
108 if __name__ == '__main__':
109  print "This tool will reorder the states of the generated logs by analysis.py, according to the order in the script. Furthermore, some states will be deleted, a state for total will be added and all values will be rounded to two digits."
110  print "Enter the path to the top log folder"
111  path = str(raw_input("Enter path: "))
112  reorderCsvs(path)
113 
def isNumber(s)
Definition: reorderCsvs.py:24
def reorderCsvs(path)
Definition: reorderCsvs.py:102
def roundAllValues(content)
Definition: reorderCsvs.py:31
def isToRemove(line)
Definition: reorderCsvs.py:55
def reorderFile(file)
Definition: reorderCsvs.py:73
def calculateTotal(content)
Definition: reorderCsvs.py:61


asr_state_machine
Author(s): Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Marek Felix, Meißner Pascal, Trautmann Jeremias, Wittenbeck Valerij
autogenerated on Mon Feb 28 2022 21:53:50