def _determine_units(sheet: xlrd.book.sheet) -> (str, str, int): indicator_unit = "?" flow_unit = "?" unit_col = -1 row, col, _ = _find_data_start(sheet) row -= 2 if row > 0: s = xls.cell_str(sheet, row, col) if s is not None and s != "": if "/" in s: parts = s.strip(" ()").split("/") indicator_unit = parts[0].strip() flow_unit = parts[1].strip() else: indicator_unit = s.strip() for row, col in xls.iter_cells(sheet): if row > 5: break s = xls.cell_str(sheet, row, col) if _eqstr(s, "Unit"): unit_col = col break if indicator_unit != "?": log.debug("determined indicator unit: %s", indicator_unit) elif _containstr(sheet.name, "land", "transformation"): log.debug("unknown indicator unit; assuming it is m2") indicator_unit = "m2" elif _containstr(sheet.name, "land", "occupation"): log.debug("unknown indicator unit; assuming it is m2*a") indicator_unit = "m2*a" elif _containstr(sheet.name, "water", "consumption"): log.debug("unknown indicator unit; assuming it is m3") indicator_unit = "m3" else: log.debug("unknown indicator unit") if _containstr(flow_unit, "kg"): flow_unit = "kg" if unit_col > -1: log.debug("take units from column %i", unit_col) elif flow_unit != "?": log.debug("determined flow unit: %s", flow_unit) elif _containstr(sheet.name, "land", "transformation"): log.debug("unknown flow unit; assume it is m2") flow_unit = "m2" elif _containstr(sheet.name, "land", "occupation"): log.debug("unknown flow unit; assuming it is m2*a") flow_unit = "m2*a" elif _containstr(sheet.name, "water", "consumption"): log.debug("unknown flow unit; assuming it is m3") flow_unit = "m3" else: log.debug("unknown flow unit; assuming it is 'kg'") flow_unit = "kg" return indicator_unit, flow_unit, unit_col
def _find_cas_column(sheet: xlrd.book.sheet) -> int: ccol = -1 for row, col in xls.iter_cells(sheet): s = xls.cell_str(sheet, row, col) if _eqstr(s, "cas"): ccol = col log.debug("identified column %i %s for CAS numbers", ccol, s) break return ccol
def _find_data_start(sheet: xlrd.book.sheet) -> (int, int, bool): for row, col in xls.iter_cells(sheet): s = xls.cell_str(sheet, row, col) if s is None or s == "": continue if _eqstr(s, "I") or _containstr(s, "Individualist"): return row + 1, col, True if _eqstr(s, "all perspectives"): return row + 1, col, False return -1, -1
def _find_flow_column(sheet: xlrd.book.sheet) -> int: if _containstr(sheet.name, "land", "occupation"): ncol = 1 return ncol ncol = -1 for row, col in xls.iter_cells(sheet): s = xls.cell_str(sheet, row, col) if _containstr(s, "name") or _containstr(s, "substance"): ncol = col log.debug("identified column %i %s for flow names", ncol, s) break if ncol < 0: log.debug("no 'name' column in %s, take col=0 for that", sheet.name) ncol = 0 return ncol
def _determine_compartments(sheet: xlrd.book.sheet) -> (str, int): compartment_col = -1 for row, col in xls.iter_cells(sheet): if row > 5: break s = xls.cell_str(sheet, row, col) if _containstr(s, "compartment") \ or _containstr(s, "name", "in", "ReCiPe"): compartment_col = col break if compartment_col > -1: log.debug("found compartment column %i", compartment_col) return "", compartment_col elif _containstr(sheet.name, "global", "warming") \ or _containstr(sheet.name, "ozone") \ or _containstr(sheet.name, "particulate") \ or _containstr(sheet.name, "acidification"): log.debug("no compartment column; assuming 'air'") return "air", -1 elif _containstr(sheet.name, "mineral", "resource", "scarcity"): log.debug("no compartment column; assuming 'resource/ground'") return "resource/ground", -1 elif _containstr(sheet.name, "fossil", "resource", "scarcity"): log.debug("no compartment column; assuming 'resource'") return "resource", -1 if _containstr(sheet.name, "water", "consumption"): log.debug("no compartment column; assuming 'resource/fresh water'") return "resource/fresh water", -1 log.debug("no compartment column") return "", -1