def add_location(self, vals, name): if len(vals) == 0: return vals have_address = False have_fill_in = False pattern = [0] fill_in = [] offset = 0 for idx, cell in enumerate(vals[0]): nn = normalize_name(cell) if nn == 'address': pattern = [idx] have_address = True if cell is not None and len(cell)>0 and cell[0] == '[': have_fill_in = True vals[0][idx] = cell[1:-1] fill_in.append([normalize_name(vals[0][idx]), idx]) if self.fill_columns is not None: if nn in self.fill_columns: have_fill_in = True fill_in.append([nn, idx]) if self.add_columns is not None: if name in self.add_columns: if cell in self.add_columns[name]: offset -= 1 fill_in.append([normalize_name(nn), idx]) have_fill_in = True if self.address_columns is not None: if name in self.address_columns: have_address = True pattern = self.address_columns[name] for idx, col in enumerate(pattern): try: pattern[idx] = vals[0].index(col) except ValueError: pass print("!!!", name, have_fill_in, have_address) if not(have_fill_in) or not(have_address): return vals from sheetsite.geocache import GeoCache cache = GeoCache(self.geocache_filename, geocoder=self.geocoder) cache.find_all(vals[1:], pattern, fill_in) return vals
def add_column_fills(self, fill_columns): if fill_columns is None: self.fill_columns = None return self.fill_columns = [normalize_name(n) for n in fill_columns]
def add_location(self, vals, name): if len(vals) == 0: return vals have_address = False have_fill_in = False pattern = [0] fill_in = [] group_index = None offset = 0 for idx, cell in enumerate(vals[0]): if name in self.rename_columns: renames = self.rename_columns[name] if cell in renames: cell = renames[cell] vals[0][idx] = cell if cell == self.group_key and self.group_key is not None: group_index = idx nn = normalize_name(cell) if nn == 'address': pattern = [idx] have_address = True if cell is not None and len(cell) > 0 and cell[0] == '[': have_fill_in = True vals[0][idx] = cell[1:-1] fill_in.append([normalize_name(vals[0][idx]), idx]) if self.fill_columns is not None: if nn in self.fill_columns: have_fill_in = True fill_in.append([nn, idx]) if self.add_columns is not None: if name in self.add_columns: if cell in self.add_columns[name]: offset -= 1 fill_in.append([normalize_name(nn), idx]) have_fill_in = True if self.address_columns is not None: if name in self.address_columns: have_address = True pattern = self.address_columns[name] for idx, col in enumerate(pattern): try: pattern[idx] = vals[0].index(col) except ValueError: pass if have_fill_in: dccid = None for at, (cname, cidx) in enumerate(fill_in): if cname == 'dccid' and self.ids is not None: dccid = at if name in self.ids: ref = self.ids[name] for idx, row in enumerate(vals): if idx == 0: continue key = ref.get(idx) row[cidx] = key if dccid is not None: del fill_in[dccid] if len(fill_in) == 0: have_fill_in = False if not (have_fill_in) or not (have_address): return vals from sheetsite.geocache import GeoCache cache = GeoCache(self.geocache_filename, geocoder=self.geocoder, group_key=group_index) cache.find_all(vals[1:], pattern, fill_in) return vals