mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
Tools: filter empty columns out of size_compare result
This commit is contained in:
parent
2ff314a478
commit
6589290053
@ -13,6 +13,35 @@ class FilterSizeCompareBranchesCSV(object):
|
||||
def pretty_print_data(self, data):
|
||||
print(tabulate.tabulate(data))
|
||||
|
||||
def prune_empty_columns(self, data):
|
||||
if len(data) == 0:
|
||||
return data
|
||||
|
||||
# populate an array indicating whether here are any non-empty
|
||||
# values in each column:
|
||||
line_length = len(data[0])
|
||||
column_has_content = [False] * line_length
|
||||
for line in data[1:]: # ASSUMPTION we have a header row!
|
||||
for i in range(line_length):
|
||||
if line[i] != "":
|
||||
column_has_content[i] = True
|
||||
|
||||
# if all columns are full then we don't need to any more:
|
||||
all_empty = False
|
||||
if not any(column_has_content):
|
||||
return data
|
||||
|
||||
new_data = []
|
||||
for line in data:
|
||||
new_line = []
|
||||
for i in range(line_length):
|
||||
if not column_has_content[i]:
|
||||
continue
|
||||
new_line.append(line[i])
|
||||
new_data.append(new_line)
|
||||
|
||||
return new_data
|
||||
|
||||
def run(self):
|
||||
csvt = csv.reader(open(self.filename,'r'))
|
||||
data = list(csvt)
|
||||
@ -29,6 +58,8 @@ class FilterSizeCompareBranchesCSV(object):
|
||||
new_data.append(line)
|
||||
data = new_data
|
||||
|
||||
data = self.prune_empty_columns(data)
|
||||
|
||||
self.pretty_print_data(data)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user