def sqlBed(bedID):
     with Other.sqlQuery() as connection:
         cursor = connection.cursor()
         cursor.execute(
             '''SELECT ots_bn.sosbed.bedname from ots_bn.sosbed
                         WHERE ots_bn.sosbed.bedid = :bedid''',
             bedid=bedID)
         row = cursor.fetchone()
     return row[0]
    def getWellParams(self):
        def sqlBed(bedID):
            with Other.sqlQuery() as connection:
                cursor = connection.cursor()
                cursor.execute(
                    '''SELECT ots_bn.sosbed.bedname from ots_bn.sosbed
                                WHERE ots_bn.sosbed.bedid = :bedid''',
                    bedid=bedID)
                row = cursor.fetchone()
            return row[0]

        with Other.sqlQuery() as connection:
            cursor = connection.cursor()
            cursor.execute(
                '''SELECT ots_bn.sosperforation.PRFPERFORATEDZONETOP,
                            ots_bn.sosperforation.PRFBEDID
                            from ots_bn.sosperforation
                            WHERE ots_bn.sosperforation.prfwellid = :wellid''',
                wellid=self.otsWellID)
            rows = cursor.fetchall()
            rows.sort()
            self.vdp = rows[0][0]
            self.layersIDs = [i[1] for i in rows]
            layer = [sqlBed(i[1]) for i in rows]
            self.layer = set(layer)
            cursor.execute('''SELECT ots_bn.soswell.WELANGULARITYTESTDEPTH,
                            ots_bn.soswell.WELANGULARITYTESTELONGATION,
                            ots_bn.soswell.welorganizationid,
                            ots_bn.soswell.welfieldid,
                            ots_bn.soswell.WELALTITUDE
                            from ots_bn.soswell
                            WHERE ots_bn.soswell.welid = :wellid''',
                           wellid=self.otsWellID)
            rows = cursor.fetchone()
            self.tzehID = rows[2]
            self.otsFieldID = rows[3]
            self.altitude = rows[4]
            try:
                bytesLen = int.from_bytes(rows[0].read()[3:7],
                                          byteorder=byteorder)
                depth = pd.Series(
                    np.frombuffer(pylzma.decompress(rows[0].read()[7:],
                                                    maxlength=bytesLen),
                                  dtype=np.dtype('f')))
                if len(depth) == 0: raise
            except:
                try:
                    depth = pd.Series(
                        np.frombuffer(rows[0].read()[3:], dtype=np.dtype('f')))
                except:
                    depth = pd.Series([0., 0.])
            try:
                bytesLen = int.from_bytes(rows[1].read()[3:7],
                                          byteorder=byteorder)
                elong = pd.Series(
                    np.frombuffer(pylzma.decompress(rows[1].read()[7:],
                                                    maxlength=bytesLen),
                                  dtype=np.dtype('f')))
                if len(elong) == 0: raise
            except:
                try:
                    elong = pd.Series(
                        np.frombuffer(rows[1].read()[3:], dtype=np.dtype('f')))
                except:
                    elong = pd.Series([0., 0.])

            self.incl = pd.concat([depth, elong], axis=1)
            self.vdpElong = round(
                Other.searchAndInterpolate(self.incl, self.vdp), 2)
            tempPressureTimeSeries = self.data.iloc[:, 0]
            tempPressureTimeSeries.dropna(inplace=True)
            self.researchDate = str(
                tempPressureTimeSeries[len(tempPressureTimeSeries) // 2])[:10]
            self.resMid = tempPressureTimeSeries[len(tempPressureTimeSeries) //
                                                 2]
            self.firstMeasureDatetime = tempPressureTimeSeries.iloc[0]
            self.lastMeasureDatetime = tempPressureTimeSeries.iloc[-1]
            self.tpID = dict_suborg[self.tzehID]
            self.maxDepth = self.data.iloc[:, 4].max()
            self.discretMan = round(
                (self.data.iloc[1, 0] - self.data.iloc[0, 0]).total_seconds(),
                0)
            self.discretSPS = round(
                (self.data.iloc[1, 3] - self.data.iloc[0, 3]).total_seconds(),
                0)