def __init__(self, depth: float, value: float, *args, **kwargs) -> None: """ Initialise the class """ self.depth = depth self.value = value AbstractDBObject.__init__(self, *args, **kwargs)
def __init__(self, depth: float, horizon: StratigraphicObject, *args, **kwargs) -> None: """ initialize the class """ AbstractDBObject.__init__(self, *args, **kwargs) self.depth = float(depth) self.horizon = horizon
def __init__(self, property_name: str, property_unit: str, *args, **kwargs) -> None: """ Initialises the class """ self.property_name = property_name self.property_unit = property_unit AbstractDBObject.__init__(self, *args, **kwargs)
def __init__(self, reference_system: str, easting: float, northing: float, altitude: float, *args, **kwargs) -> None: """ Initialise the AbstractGeoObject """ self.reference_system = reference_system self.easting = easting self.northing = northing self.altitude = altitude # call constructor of base class AbstractDBObject.__init__(self, *args, **kwargs)
def __init__(self, name: str, age: float = -1, *args, **kwargs) -> None: """ Initialize a stratigraphic unit """ AbstractDBObject.__init__(self, *args, **kwargs) try: age = int(age) except ValueError as e: raise ValueError("Cannot convert age to int:\n{}".format(str(e))) self.unit_name = str(name) self.age = -1 if (age < 0) else age
def __str__(self) -> str: text = "[{}] Well ({}: {})\n" \ .format(self.id, self.well.id, self.well.name) text += "DBObject: {}".format(AbstractDBObject.__str__(self)) for assoc in self.log_values: text += "{}".format(str(assoc)) return text
def __str__(self) -> str: text = "[{}] {} - {}\n".format(self.id, "closed" if self.closed else "not closed", str(self.horizon)) text += AbstractDBObject.__str__(self) text += "\npoints:\n" for point in self.points: text += "\n{}".format(str(point)) return text
def __init__(self, closed: bool, horizon: StratigraphicObject, points: List[GeoPoint], *args, **kwargs) -> None: """ Create a new line. """ for pnt in points: if type(pnt) is not GeoPoint: raise ValueError("At least on point in points is not of type GeoPoint!") self.is_closed = bool(closed) self.horizon = horizon self.points = points # check doubled values and stratigraphy in the line self.__remove_doubled_points() self.__check_line() # call base class constructor AbstractDBObject.__init__(self, *args, **kwargs) if self.name_col == "": self.name_col = "line_{}".format(self.id)
def __str__(self): text = "{} [{}]\n".format(self.property_name, self.property_unit) text += AbstractDBObject.__str__(self) return text
def __repr__(self) -> str: return "<WellMarker(id='{}', depth='{}', horizon='{}'\nAbstractObject: {}". \ format(self.id, self.depth, self.horizon, AbstractDBObject.__repr__(self))
def __repr__(self): text = "<AbstractLogClass property_name={}, property_unit={}\n".\ format(self.property_name, self.property_unit) text += AbstractDBObject.__repr__(self) return text
def __repr__(self) -> str: text = "<WellLogValue(id='{}', depth='{}', value='{}', log_id='{}'),\n". \ format(self.id, self.depth, self.value, self.log_id) text += "Additional DBObject: {}>".format(AbstractDBObject.__repr__(self)) return text
def __str__(self) -> str: text = "[{}] {}: {} (well_log.id: {})\n" \ .format(self.id, self.depth, self.value, self.log_id) text += "DBObject: {}".format(AbstractDBObject.__str__(self)) return text
def run(self): """ Save the Point Object(s) to the database :return: True if function executed successfully, else False """ self._mutex.lock() service = DatabaseService.get_instance() service.close_session() service.connect() session = DatabaseService.get_instance().get_session() try: onekey = self._data[next(iter(self._data.keys()))]["values"] # import json # self._logger.info(json.dumps(onekey, indent=2)) count = len(onekey) east = self._selection["easting"] north = self._selection["northing"] alt = self._selection["altitude"] strat = self._selection["strat"] age = self._selection["strat_age"] set_name = self._selection["set_name"] comment = self._selection["comment"] reference = ImportService.get_instance().get_crs() if reference is None: reference = "" else: reference = reference.toWkt() self._logger.debug("Saving with reference system\n{}".format(reference)) lines = dict() line = 0 maximum = count for i in range(count): _id = None if "gln_id" in self._data: try: _id = int(self._data["gln_id"]["values"][i]) except ValueError: pass if (self._data[east]["values"][i] == "") and (self._data[north]["values"][i] == ""): line += 1 continue e = float(self._data[east]["values"][i]) n = float(self._data[north]["values"][i]) h = None if alt == "" else float(self._data[alt]["values"][i]) s = "" if strat == "" else self._data[strat]["values"][i] a = -1 if age == "" else float(self._data[age]["values"][i]) sn = "" if set_name == "" else self._data[set_name]["values"][i] c = "" if comment == "" else self._data[comment]["values"][i] strat_obj = StratigraphicObject.init_stratigraphy(session, s, a) point = GeoPoint(None, False if (h is None) else True, reference, e, n, 0 if (h is None) else h, session, sn, c) # add / update properties for item in self._properties: self._logger.debug("Property: {}".format(item)) if point.has_property(item.name): p = point.get_property(item.name) p.property_unit = item.unit p.value = self._data[item.name]["values"][i] p.property_type = item.property_type else: p = Property(value=self._data[item.name]["values"][i], property_name=item.name, _type=item.property_type, property_unit=item.unit, session=session) point.add_property(p) if _id is not None: point.line_id = _id self._logger.debug("line point: {}".format(point)) if line in lines: lines[line]["points"].append(point) else: lines[line] = { "id": _id, "strat": strat_obj, "points": [point], "name": sn, "comment": c } maximum += 1 i += 1 self.update_progress.emit(100 * i / maximum) if self._cancel: self._logger.debug("Import canceled") self.import_failed.emit(self._message) break i = count if not self._cancel: for l in lines: i += 1 line = lines[l] closed = False if (len(line["points"]) > 1) and (line["points"][0] == line["points"][-1]): closed = True line["points"].pop() new_line = None if line["id"] is not None: new_line = Line.load_by_id_from_db(line["id"], session) if new_line is not None: for point in new_line.points: AbstractDBObject.delete_from_db(point, session) del point new_line.closed = closed new_line.points = line["points"] new_line.horizon = line["strat"] new_line.name = line["name"] new_line.comment = line["comment"] self._logger.debug("Updated existing line") if line["id"] is None or new_line is None: # new_line is None ? not in database -> create a new one new_line = Line(closed, line["strat"], line["points"], session, line["name"], line["comment"]) self._logger.debug("Created new line") new_line.save_to_db() self._logger.debug("Line: {}".format(str(new_line))) self.update_progress.emit(100 * i / maximum) if self._cancel: self._logger.debug("Import canceled") self.import_failed.emit(self._message) break if not self._cancel: self.update_progress.emit(100) self._logger.debug("Lines successfully imported") self.import_finished.emit() except Exception as e: msg = str(ExceptionHandler(e)) self.import_failed.emit(msg) self._logger.error("Error", msg) finally: service.close_session() self._mutex.unlock() self.quit()
def __str__(self) -> str: return "[{}] {}: {} - {}".format(self.id, self.depth, self.horizon, AbstractDBObject.__str__(self))
def __repr__(self) -> str: text = "<WellLog(id='{}', well_id='{}', log values='{}')>\n". \ format(self.id, self.well.id, str(self.log_values)) text += "Additional DBObject: {}".format(AbstractDBObject.__repr__(self)) return text
def __str__(self) -> str: text = "{} [{}]: {} - ".format(self.property_name, self.property_unit, self.prop_value) text += AbstractDBObject.__str__(self) return text
def __repr__(self) -> str: text = "<Line(id='{}', closed='{}', horizon='{}'\n)>".format(self.id, self.closed, str(self.horizon)) text += AbstractDBObject.__repr__(self) text += "\npoints=\n" + str(self.points) return text
def __str__(self) -> str: text = "{} - {} - {} - ".format(self.easting, self.northing, self.altitude) text += AbstractDBObject.__str__(self) return text
def __repr__(self) -> str: text = "<AbstractGeoObject(east='{}', north='{}', alt='{}')>\n".format(self.easting, self.northing, self.altitude) text += AbstractDBObject.__repr__(self) return text