def convert_attribute(value: ResultVariable): try: rawvalue = value.get_value() except OptionalValueException: return {"nones": [0]} if isinstance(rawvalue, Unknown): return {"unknowns": [0]} if isinstance(rawvalue, NoneValue): return {"nones": [0]} if not isinstance(rawvalue, list): rawvalue = [rawvalue] return {"values": rawvalue} else: unknowns = [] offset = 0 for i in range(0, len(rawvalue)): value = rawvalue[i - offset] if isinstance(value, Unknown): unknowns.append(i) del rawvalue[i - offset] offset += 1 if len(unknowns) > 0: return {"values": rawvalue, "unknowns": unknowns} else: return {"values": rawvalue}
def convert_relation(value: ResultVariable): if value.is_ready() and value.value is not None: rawvalue = value.get_value() else: # no value present return {"values": []} if not isinstance(rawvalue, list): rawvalue = [rawvalue] return {"values": [convert(v) for v in rawvalue]}