1 |
733
|
aaronmk
|
# Map spreadsheet manipulation
|
2 |
|
|
|
3 |
1501
|
aaronmk
|
import strings
|
4 |
1504
|
aaronmk
|
import util
|
5 |
1501
|
aaronmk
|
|
6 |
|
|
def col_label(col_name): return col_name.partition(':')[0]
|
7 |
|
|
|
8 |
|
|
def combinable(*headers):
|
9 |
|
|
return strings.overlaps(*[col_label(header[0]) for header in headers])
|
10 |
|
|
|
11 |
1504
|
aaronmk
|
def is_nonexplicit_empty_mapping(row):
|
12 |
|
|
return reduce(util.and_, (v == '' for v in row[1:]))
|
13 |
|
|
|
14 |
736
|
aaronmk
|
def merge_values(*vals):
|
15 |
|
|
new = []
|
16 |
|
|
for val in vals:
|
17 |
|
|
if val != '' and val not in new: new.append(val)
|
18 |
|
|
return '; '.join(new)
|
19 |
|
|
|
20 |
733
|
aaronmk
|
def merge_rows(*rows):
|
21 |
|
|
'''e.g. ['a','b'] + ['','y','z'] = ['a','b; y','z']'''
|
22 |
|
|
def get(row, i):
|
23 |
|
|
try: return row[i]
|
24 |
|
|
except IndexError: return ''
|
25 |
736
|
aaronmk
|
return [merge_values(*[get(row, i) for row in rows])
|
26 |
|
|
for i in xrange(max(map(len, rows)))]
|
27 |
735
|
aaronmk
|
|
28 |
|
|
def merge_mappings(in_, out):
|
29 |
|
|
'''e.g. ['in','join','in_comments'] + ['join','out','out_comments'] =
|
30 |
|
|
['in','out','in_comments; out_comments']'''
|
31 |
|
|
new = [in_[0], out[1]] # mapping
|
32 |
|
|
new[2:] = merge_rows(in_[2:], out[2:]) # comments
|
33 |
|
|
return new
|