def main():
    logger.info("Application started")

    parser = base_arg_parser()

    args = parser.parse_args()
    logger.debug(f"args: {args}")

    timestamp_begin = time.perf_counter_ns()
    count_records_stat(args.input_file)
    timestamp_end = time.perf_counter_ns()

    execution_time_ns = (timestamp_end - timestamp_begin)
    execution_time_ms = execution_time_ns / 1_000_000
    human_readable_memory_usage = humanize.naturalsize(
        get_current_memory_usage())

    stat_data = {
        "Valid entries count": valid_entries_count,
        "Invalid entries count": invalid_entries_count,
        "Execution time (ms)": round(execution_time_ms, 3),
        "Execution time (ns)": execution_time_ns,
        "Current memory usage": human_readable_memory_usage
    }

    stat_output = render_stat(stat_data)
    logger.info(f"Execution stat:\n{stat_output}")

    logger.info("Application finished")
Exemplo n.º 2
0
def main():
    logger.info("Application started")

    parser = base_arg_parser()

    args = parser.parse_args()
    logger.debug(f"args: {args}")

    pipeline = DataProcessingPipeline(args.input_file, DATA_LIMIT)

    timestamp_begin = time.perf_counter_ns()
    pipeline.run()
    timestamp_end = time.perf_counter_ns()

    execution_time_ns = (timestamp_end - timestamp_begin)
    execution_time_ms = execution_time_ns / 1_000_000
    execution_time_secs = execution_time_ms / 1_000
    human_readable_memory_usage = humanize.naturalsize(get_current_memory_usage())
    human_readable_execution_time = humanize.naturaldelta(execution_time_secs)

    stat_data = {
        "Valid entries count": pipeline.valid_entries_count,
        "Invalid entries count": pipeline.invalid_entries_count,
        "Execution time (ms)": round(execution_time_ms, 3),
        "Execution time (ns)": execution_time_ns,
        "Execution time (human readable)": human_readable_execution_time,
        "Current memory usage": human_readable_memory_usage
    }

    stat_output = render_stat(stat_data)
    logger.info(f"Execution stat:\n{stat_output}")

    logger.info("Application finished")
Exemplo n.º 3
0
def main():
    logger.info("Application started")

    parser = base_arg_parser()

    args = parser.parse_args()
    logger.debug(f"args: {args}")

    if os.path.exists(DATABASE_FILE):
        logger.info(f"Removing file {DATABASE_FILE}")
        os.remove(DATABASE_FILE)

    db_dir = os.path.dirname(DATABASE_FILE)
    logger.debug(f"Database directory: {db_dir}")

    if not os.path.exists(db_dir):
        logger.warning(f"Making directory '{db_dir}'")
        os.makedirs(db_dir)

    connection = sqlite3.connect(DATABASE_FILE)
    connection.execute(SQL_CREATE_TABLE)

    logger.info("Uploading records into database")
    timestamp_begin = time.monotonic()
    load_records_into_database(connection, args.input_file)
    timestamp_end = time.monotonic()

    time_elapsed = timestamp_end - timestamp_begin
    logger.info(f"Time elapsed: {humanize.precisedelta(time_elapsed)}")

    connection.commit()
    connection.close()

    logger.info("Application finished")
Exemplo n.º 4
0
def main():
    logger.info("Application started")

    parser = base_arg_parser()

    args = parser.parse_args()
    logger.debug(f"args: {args}")

    logger.info("Uploading records into database")
    timestamp_begin = time.monotonic()
    load_expired_passports_into_set(args.input_file)
    timestamp_end = time.monotonic()

    time_elapsed = timestamp_end - timestamp_begin
    logger.info(f"Time elapsed for data uploading: {humanize.precisedelta(time_elapsed)}")

    while True:
        passport_series = input("Passport series: ")
        passport_number = input("Passport series: ")

        passport_series = passport_series.strip()
        passport_number = passport_number.strip()

        if (not passport_series) and (not passport_number):
            logger.info("Empty request, going exit...")
            break

        passport_series = int(passport_series)
        passport_number = int(passport_number)
        query = (passport_series, passport_number)

        timestamp_begin = time.perf_counter_ns()
        passport_expired = query in expired_passports
        timestamp_end = time.perf_counter_ns()

        lookup_time_ns = (timestamp_end - timestamp_begin)
        lookup_time_ms = lookup_time_ns / 1_000_000
        logger.info(
            f"Lookup time {round(lookup_time_ms, 3)} ms ({lookup_time_ns} ns). Is passport expired: {passport_expired}"
        )

    human_readable_memory_usage = humanize.naturalsize(get_current_memory_usage())
    logger.info(f"Used memory: {human_readable_memory_usage}")

    logger.info("Application finished")
Exemplo n.º 5
0
def main():
    logger.info("Application started")

    parser = base_arg_parser()

    args = parser.parse_args()
    logger.debug(f"args: {args}")

    if os.path.exists(LMDB_DATABASE_FILE):
        logger.warning(f"Removing file {LMDB_DATABASE_FILE}")
        os.remove(LMDB_DATABASE_FILE)

    database_file_name_without_extension, _ = os.path.splitext(
        LMDB_DATABASE_FILE)
    lock_file = database_file_name_without_extension + ".lmdb-lock"
    if os.path.exists(lock_file):
        logger.warning(f"Removing file {lock_file}")
        os.remove(lock_file)

    logger.debug(f"lock_file: {lock_file}")

    db_dir = os.path.dirname(LMDB_DATABASE_FILE)
    logger.debug(f"Database directory: {db_dir}")

    if not os.path.exists(db_dir):
        logger.info(f"Making directory '{db_dir}'")
        os.makedirs(db_dir)

    logger.info("Uploading records into database")
    timestamp_begin = time.monotonic()
    load_records_into_lmdb_database(LMDB_DATABASE_FILE, args.input_file)
    timestamp_end = time.monotonic()

    time_elapsed = timestamp_end - timestamp_begin
    logger.info(f"Time elapsed: {humanize.precisedelta(time_elapsed)}")

    logger.info("Application finished")
Exemplo n.º 6
0
def main():
    logger.info("Application started")

    parser = base_arg_parser()

    args = parser.parse_args()
    logger.debug(f"args: {args}")

    while True:
        passport_series = input("Passport series: ")
        passport_number = input("Passport series: ")

        passport_series = passport_series.strip()
        passport_number = passport_number.strip()

        if (not passport_series) and (not passport_number):
            logger.info("Empty request, going exit...")
            break

        timestamp_begin = time.perf_counter_ns()
        passport_expired = is_passport_expired(args.input_file,
                                               passport_series,
                                               passport_number)
        timestamp_end = time.perf_counter_ns()

        lookup_time_ns = (timestamp_end - timestamp_begin)
        lookup_time_ms = lookup_time_ns / 1_000_000
        logger.info(
            f"Lookup time {round(lookup_time_ms, 3)} ms ({lookup_time_ns} ns). Is passport expired: {passport_expired}"
        )

    human_readable_memory_usage = humanize.naturalsize(
        get_current_memory_usage())
    logger.info(f"Used memory: {human_readable_memory_usage}")

    logger.info("Application finished")