Revision 1786
Added by Aaron Marcuse-Kubitza over 12 years ago
subtract | ||
---|---|---|
1 | 1 |
#!/usr/bin/env python |
2 | 2 |
# Subtracts map spreadsheet A1->C from A0->B to produce A->B. |
3 |
# A0 entries that are empty and have no comment documenting why they are empty |
|
4 |
# are subtracted as well if there is a matching entry in A1. |
|
3 |
# Other A0 entries are subtracted as well: |
|
4 |
# - Empty entries without a comment documenting why they are empty, if there is |
|
5 |
# a matching entry in A1. |
|
6 |
# - Entries whose input and output maps to the same non-empty value in A1 |
|
5 | 7 |
|
6 | 8 |
import csv |
7 | 9 |
import os.path |
... | ... | |
31 | 33 |
# Get map 1 |
32 | 34 |
input_cols = set() |
33 | 35 |
compare_cols = set() |
36 |
map_ = dict() |
|
34 | 37 |
stream = open(map_1_path, 'rb') |
35 | 38 |
reader = csv.reader(stream) |
36 | 39 |
headers[1] = reader.next() |
... | ... | |
38 | 41 |
if row[0] != '': |
39 | 42 |
input_cols.add(row[0]) |
40 | 43 |
compare_cols.add(compare_on(row)) |
44 |
if row[1] != '': map_[row[0]] = row[1] |
|
41 | 45 |
stream.close() |
42 | 46 |
|
43 | 47 |
# Open map 0 |
... | ... | |
54 | 58 |
writer = csv.writer(sys.stdout) |
55 | 59 |
writer.writerow(headers[0]) |
56 | 60 |
for row in reader: |
57 |
if not combinable or not ((maps.is_nonexplicit_empty_mapping(row) |
|
58 |
and row[0] in input_cols) or compare_on(row) in compare_cols): |
|
61 |
if not combinable or not ( |
|
62 |
(maps.is_nonexplicit_empty_mapping(row) and row[0] in input_cols) |
|
63 |
or compare_on(row) in compare_cols |
|
64 |
or util.have_same_value(map_, row[0], row[1]) # map to same place |
|
65 |
): |
|
59 | 66 |
# not combinable or not in map 1 |
60 | 67 |
writer.writerow(row) |
61 | 68 |
|
Also available in: Unified diff
subtract: Also remove mappings whose input and output maps to the same non-empty value in map_1