Exemple #1
0
def log_action(user, action: str = "something"):
    try:
        log = Logs(user_id=user.id, username=user.username, action=action)
    except AttributeError:
        log = Logs(username="******", action=action)
    db.session.add(log)
    db.session.commit()
Exemple #2
0
def save_results(wells, run_id):
    run = Run.query.get(run_id)
    wells_done = []

    for well in wells:
        well_id = well.core()[0].well_data_id
        # well name without letters
        well_name = re.sub(regWellName, '', well.name.replace(' ', ''))
        # save las
        filepath = f"{current_app.config['SERVICES_PATH']}third/{str(run_id)}/output_data/{well_id}/{well_name}"
        if Path(filepath + ".png").is_file():
            wells_done.append(well)
            log_from = Logs.query.filter_by(well_id=well.id,
                                            project_id=run.project_id).first()
            res_filepath = log_from.filepath.split('.')[0] + '.png'
            log = Logs(well_id=well.id,
                       project_id=log_from.project_id,
                       run_id=run_id,
                       res_filepath=res_filepath)

            shutil.copyfile(filepath + ".png", 'app/static/' + res_filepath)

            # change las-path
            # importer = ImportLasFiles(filepath + ".las", project_id=run.project_id)
            # importer.import_data()
            add_log(filepath + ".las", project_id=run.project_id)
            las_path = f"{str(run.project_id)}_logs_{str(uuid.uuid4())}{well_name}.las"
            shutil.copyfile(filepath + ".las", 'uploads/' + las_path)
            log.filepath = las_path
            db.session.add(log)
    db.session.commit()
    # shutil.rmtree(f'{current_app.config["SERVICES_PATH"]}third/{str(run_id)}/')
    return wells_done
Exemple #3
0
def add_log(user, body, azs_id=None, sixdign=None):
    new_one = Logs(timestamp=datetime.utcnow(), user_id=user, body=body)
    print(new_one)
    if azs_id is not None:
        new_one.azs_id = azs_id
    if sixdign is not None:
        new_one.sixdign = sixdign
    db.session.add(new_one)
Exemple #4
0
    def loginLog(self):
        log = Logs()

        log.user_id = self.__user_id
        log.log_type = 'LOGIN'
        log.log_content = '用户 ' + self.__user_id + ' 登录系统成功'
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #5
0
    def deleteUser(self, userid):
        log = Logs()

        log.user_id = self.__user_id
        log.log_type = 'DELETEUSER'
        log.log_content = '用户 ' + self.__user_id + ' 删除了用户 ' + userid
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #6
0
    def updateUser(self, userid):
        log = Logs()

        log.user_id = self.__user_id
        log.log_type = 'UPDATEUSER'
        log.log_content = '用户 ' + self.__user_id + ' 更新用户 ' + userid + ' 信息'
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #7
0
    def addUser(self, userid):
        log = Logs()

        log.user_id = self.__user_id
        log.log_type = 'ADDUSER'
        log.log_content = '用户 ' + self.__user_id + ' 新增用户 ' + userid
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #8
0
def add_log(filepath, project_id):
    try:
        data = read_lasio(filepath)
    except:
        return None
    well = check_well(data['name'], project_id)

    for crv_name in data.keys():
        if (crv_name == 'name') or (crv_name == 'DEPT'):
            continue
        else:
            bottom = np.nanmin(data[crv_name])
            if bottom is not None:
                top = np.nanmax(data[crv_name])

                crv = db.session.query(Curve)\
                    .filter(Curve.well_id == well.id)\
                    .filter(Curve.name == crv_name)\
                    .first()
                if crv is None:
                    crv = Curve(project_id=project_id,
                                well_id=well.id,
                                name=crv_name,
                                top=top,
                                bottom=bottom,
                                data=data[crv_name])
                crv.data = data[crv_name]
                db.session.add(crv)

    db.session.commit()

    log = Logs(project_id=project_id, filepath=filepath, well_id=well.id)
    return log
    def create_well_obj(self, w_name, dept):
        well = Well.query.filter_by(name=w_name,
                                    project_id=self.project_id).first()
        if well is None:
            well = Well(name=w_name, project_id=self.project_id)
            db.session.add(well)
            db.session.flush()

        if Logs.query.filter_by(well_id=well.id,
                                project_id=self.project_id).first() is None:
            log = Logs(well_id=well.id, project_id=self.project_id)
            db.session.add(log)
        well.depth = dept
        db.session.flush()
        for i in range(len(self.wells_from_files[w_name]["las"])):
            list_crv_keys = self.wells_from_files[w_name]["las"][i].keys()
            list_crv_keys.remove(self.wells_from_files[w_name]["MD_keys"][i])
            for crv_k in list_crv_keys:
                new_crv = self.new_mesh(
                    self.wells_from_files[w_name]["las"][i].curves[crv_k].data,
                    self.wells_from_files[w_name]["las"][i].curves[
                        self.wells_from_files[w_name]["MD_keys"][i]].data,
                    dept)
                mnem = str(self.wells_from_files[w_name]["las"]
                           [i].curves[crv_k].mnemonic).split(".")[0].replace(
                               " ", "")
                unit = self.wells_from_files[w_name]["las"][i].curves[
                    crv_k].unit
                crv_i = self.create_curve_obj(
                    new_crv, mnem, unit,
                    self.wells_from_files[w_name]["path"][i], well)
                db.session.add(crv_i)
                # well.curves.append(crv_i)
        # db.session.add(well)
        return well
Exemple #10
0
    def addDevice(self):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = 'ADDDEVICE'
        log.log_content = '用户 ' + self.__user_id + ' 新增设备 ' + self.__device_id
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #11
0
    def updateDevice(self):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = 'UPDATEDEVICE'
        log.log_content = '用户 ' + self.__user_id + ' 更新了设备 ' + self.__device_id + ' 信息'
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #12
0
    def deleteDevice(self):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = 'DELETEDEVICE'
        log.log_content = '用户 ' + self.__user_id + ' 删除了设备 ' + self.__device_id
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #13
0
    def returnDevice(self, lenderid):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = 'RETURNDEVICE'
        log.log_content = '用户 ' + lenderid + ' 归还设备 ' + self.__device_id + ' 操作人 ' + self.__user_id
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #14
0
    def info(self):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = self.__log_type
        log.log_content = self.__log_content
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #15
0
    def loginLog(self):
        log = Logs()

        log.user_id = self.__user_id
        log.log_type = 'LOGIN'
        log.log_content = '用户 ' + self.__user_id + ' 登录系统成功'
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #16
0
    def updateUser(self, userid):
        log = Logs()

        log.user_id = self.__user_id
        log.log_type = 'UPDATEUSER'
        log.log_content = '用户 ' + self.__user_id + ' 更新用户 ' + userid + ' 信息'
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #17
0
    def deleteUser(self, userid):
        log = Logs()

        log.user_id = self.__user_id
        log.log_type = 'DELETEUSER'
        log.log_content = '用户 ' + self.__user_id + ' 删除了用户 ' + userid
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #18
0
    def addUser(self, userid):
        log = Logs()

        log.user_id = self.__user_id
        log.log_type = 'ADDUSER'
        log.log_content = '用户 ' + self.__user_id + ' 新增用户 ' + userid
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #19
0
    def addDevice(self):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = 'ADDDEVICE'
        log.log_content = '用户 ' + self.__user_id + ' 新增设备 ' + self.__device_id
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #20
0
    def updateDevice(self):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = 'UPDATEDEVICE'
        log.log_content = '用户 ' + self.__user_id + ' 更新了设备 ' + self.__device_id + ' 信息'
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #21
0
    def deleteDevice(self):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = 'DELETEDEVICE'
        log.log_content = '用户 ' + self.__user_id + ' 删除了设备 ' + self.__device_id
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #22
0
    def returnDevice(self, lenderid):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = 'RETURNDEVICE'
        log.log_content = '用户 ' + lenderid + ' 归还设备 ' + self.__device_id + ' 操作人 ' + self.__user_id
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #23
0
    def info(self):
        log = Logs()

        log.user_id = self.__user_id
        log.device_id = self.__device_id
        log.log_type = self.__log_type
        log.log_content = self.__log_content
        log.log_time = datetime.utcnow()

        db.session.add(log)
        db.session.commit()
Exemple #24
0
   user_obj = db.session.query(User).filter_by(qr_data = scanned[8:-1]).all()
   if scanned!='':
          GPIO.output(LEDGrn, GPIO.HIGH);
          GPIO.output(LEDRed, GPIO.LOW);
          sleep(8)
          if debug == True:
             print "Scanned hash %s User ID %s" % (scanned, user_obj[0].get_id())
          return user_obj[0].get_id()

def blinkRED():
   GPIO.output(LEDGrn, GPIO.LOW)
   GPIO.output(LEDRed, GPIO.HIGH)
   sleep(0.2)
   GPIO.output(LEDRed, GPIO.LOW)
   sleep(0.8)

if __name__ == "__main__":
   while True:
      if (GPIO.input(IRPin)):
         global flagProx
         flagProx=True
         userid=scan()
         logger = Logs()
         logger.user_id = userid
         logger.timestamp = datetime.datetime.now()
         db.session.add(logger)
         db.session.commit()
         # Here goes something to add for Front-end
      else:
         blinkRED() # When nothing is there blink red LED with some predefined period
Exemple #25
0
def info():
    log = Logs(spider_id='asdasd')
    log.save()
    return jsonify({})
Exemple #26
0
def db_check():
    """ will do some sanity checks on the db and will flash the errors """

    # db = get_database_connection()
    # cur = db.cursor()
    new_log = Logs(
        log_name='db_check',
        log_value=
        'DB check started... wait for the results. it may take a while')
    db.session.add(new_log)
    db.session.commit()

    def collision(s1, e1, s2, e2):
        if s2 <= s1 <= e2:
            return True
        if s2 <= e1 <= e2:
            return True
        if s1 <= s2 <= e1:
            return True
        if s1 <= e2 <= e1:
            return True
        return False

    def separate(input_string):
        """ gets AA0000000000000000000000000090 and returns AA, 90 """
        digit_part = ''
        alpha_part = ''
        for character in input_string:
            if character.isalpha():
                alpha_part += character
            elif character.isdigit():
                digit_part += character
        return alpha_part, int(digit_part)

    serials = Serials.query.all()
    raw_data = [(serial.id, serial.start_serial, serial.end_serial)
                for serial in serials]
    all_problems = []

    data = {}
    flashed = 0
    for row in raw_data:
        id_row, start_serial, end_serial = row
        start_serial_alpha, start_serial_digit = separate(start_serial)
        end_serial_alpha, end_serial_digit = separate(end_serial)
        if start_serial_alpha != end_serial_alpha:
            all_problems.append(
                f'start serial and end serial of row {id_row} start with different letters'
            )
        else:
            if start_serial_alpha not in data:
                data[start_serial_alpha] = []
            data[start_serial_alpha].append(
                (id_row, start_serial_digit, end_serial_digit))

    flashed = 0
    for letters in data:
        for i in range(len(data[letters])):
            for j in range(i + 1, len(data[letters])):
                id_row1, ss1, es1 = data[letters][i]
                id_row2, ss2, es2 = data[letters][j]
                if collision(ss1, es1, ss2, es2):
                    all_problems.append(
                        f'there is a collision between row ids {id_row1} and {id_row2}'
                    )

    all_problems.reverse()
    output = "\n".join(all_problems)
    logs = Logs.query.filter_by(log_name='db_check').all()
    for log in logs:
        log.log_value = output
    db.session.commit()
Exemple #27
0
def import_database_from_excel(filepath):
    """ gets an excel file name and imports lookup data (data and failures) from it
    the first (0) sheet contains serial data like:
     Row	Reference Number	Description	Start Serial	End Serial	Date
    and the 2nd (1) contains a column of invalid serials. 

    This data will be writeen into the sqlite database located at config.DATABASE_FILE_PATH
    in two tables. "serials" and "invalids"

    returns two integers: (number of serial rows, number of invalid rows)
    """

    # df contains lookup data in the form of
    # Row	Reference Number	Description	Start Serial	End Serial	Date
    def model_exists(model_class):
        return model_class.metadata.tables[model_class.__tablename__].exists(
            bind=db.session.bind)

    for model_class in (Logs, Serials, Invalids):
        if model_exists(model_class) == True:
            model_class.__table__.drop(bind=db.session.bind, checkfirst=True)
        if model_exists(model_class) == False:
            model_class.__table__.create(bind=db.session.bind, checkfirst=True)

    total_flashes = 0
    output = []
    first_log = Logs(log_name='db_filename', log_value=filepath)
    db.session.add(first_log)
    db.session.commit()

    # insert some place holder logs
    second_log = Logs(
        log_name='import',
        log_value='Import started. logs will appear when its done')
    third_log = Logs(
        log_name='db_check',
        log_value='DB check will be run after the insert is finished')
    db.session.add_all([second_log, third_log])
    db.session.commit()
    # db.commit()
    df = read_excel(filepath, 0)
    serials_counter = 1
    line_number = 1

    for _, (line, ref, description, start_serial, end_serial,
            date) in df.iterrows():
        line_number += 1
        if not ref or (ref != ref):
            ref = ""
        if not description or (description != description):
            description = ""
        if not date or (date != date):
            date = "7/2/12"
        try:
            start_serial = normalize_string(start_serial)
            end_serial = normalize_string(end_serial)
            new_serial = Serials(id=line,
                                 ref=ref,
                                 description=description,
                                 start_serial=start_serial,
                                 end_serial=end_serial,
                                 date=date)
            db.session.add(new_serial)
            db.session.commit()
            serials_counter += 1
        except Exception as e:
            total_flashes += 1
            if total_flashes < MAX_FLASH:
                output.append(
                    f'Error inserting line {line_number} from serials sheet SERIALS, {e}'
                )
            elif total_flashes == MAX_FLASH:
                output.append(f'Too many errors!')
        if line_number % 1000 == 0:
            try:
                db.commit()
            except Exception as e:
                output.append(
                    f'Problem commiting serials into db at around record {line_number} (or previous 1000 ones); {e}'
                )
    db.session.commit()
    # db.commit()

    # now lets save the invalid serials.

    invalid_counter = 1
    line_number = 1
    df = read_excel(filepath, 1)
    for _, (failed_serial, ) in df.iterrows():
        line_number += 1
        try:
            failed_serial = normalize_string(failed_serial)
            new_invalid = Invalids(invalid_serial=failed_serial)
            db.session.add(new_invalid)
            db.session.commit()
            invalid_counter += 1
        except Exception as e:
            total_flashes += 1
            if total_flashes < MAX_FLASH:
                output.append(
                    f'Error inserting line {line_number} from serials sheet SERIALS, {e}'
                )
            elif total_flashes == MAX_FLASH:
                output.append(f'Too many errors!')

        if line_number % 1000 == 0:
            try:
                db.commit()
            except Exception as e:
                output.append(
                    f'Problem commiting invalid serials into db at around record {line_number} (or previous 1000 ones); {e}'
                )
    db.session.commit()

    # save the logs
    output.append(
        f'Inserted {serials_counter} serials and {invalid_counter} invalids')
    output.reverse()
    logs = Logs.query.filter_by(log_name='import').all()
    for log in logs:
        log.log_value = '\n'.join(output)
    db.session.commit()

    return
Exemple #28
0
        sleep(8)
        if debug == True:
            print "Scanned hash %s User ID %s" % (scanned,
                                                  user_obj[0].get_id())
        return user_obj[0].get_id()


def blinkRED():
    GPIO.output(LEDGrn, GPIO.LOW)
    GPIO.output(LEDRed, GPIO.HIGH)
    sleep(0.2)
    GPIO.output(LEDRed, GPIO.LOW)
    sleep(0.8)


if __name__ == "__main__":
    while True:
        if (GPIO.input(IRPin)):
            global flagProx
            flagProx = True
            userid = scan()
            logger = Logs()
            logger.user_id = userid
            logger.timestamp = datetime.datetime.now()
            db.session.add(logger)
            db.session.commit()
            # Here goes something to add for Front-end
        else:
            blinkRED(
            )  # When nothing is there blink red LED with some predefined period