Skip to main content

A logger based on SQLite3

Project description

MetricDB

MetricDB is a lightweight SQLite3 based logger with pandas integration.

Installation

pip install MetricDB

Usage Examples

Basic Logging

from MetricDB import MetricDB

# Initialize the logger
logger = MetricDB(datafile_dir="my_project.db")

# Log single metrics
logger.log({"epoch": 1, "loss": 0.5, "accuracy": 0.85})

# Log to different tables
logger.log({"loss": 0.3, "accuracy": 0.9}, name_table="training")
logger.log({"loss": 0.4, "accuracy": 0.87}, name_table="validation")

# Calculate moving averages
train_loss_avg = logger.get_moving_average(key="loss", name_table="training", window_size=10)
print(f"Average training loss: {train_loss_avg}")

# Close the connection when done
logger.on_end()

Data Export and Analysis

from MetricDB import MetricDB

logger = MetricDB(datafile_dir="analysis.db")

# Log some data
for epoch in range(10):
    logger.log({
        "epoch": epoch,
        "train_loss": epoch * 0.1,
        "train_acc": 0.85 + epoch * 0.01
    }, name_table="metrics")

# Export to CSV
logger.save_as_csv(name_table="metrics", save_dir="training_results.csv")

# Get data as pandas DataFrame with automatic type conversion
df = logger.get_dataframe(name_table="metrics")
print(df.dtypes)  # Shows column data types

logger.on_end()

Working with Pandas Integration

from MetricDB import MetricDB

logger = MetricDB(datafile_dir="pandas_example.db")

# Log mixed data types
logger.log({
    "text_data": "hello",
    "numeric_data": 42.5,
    "integer_data": 100
})

# Get as pandas DataFrame with automatic type inference
df = logger.get_dataframe()
print("Data Types:")
print(df.dtypes)

# Perform pandas operations
print("\nDataFrame Summary:")
print(df.describe())

# Export specific tables
logger.save_as_csv(name_table="main", save_dir="output.csv")

logger.on_end()

Plateau Detection

from MetricDB import MetricDB

logger = MetricDB(datafile_dir="training.db")

for epoch in range(100):

    accuracy = 0.95 / (1 + 2.71828 ** (-0.3 * (epoch - 20)))  # Will plateau around 0.95
    logger.log({
        "epoch": epoch,
        "accuracy": accuracy
    })
    
    # Check for plateau
    # Parameters:
    # - window_short=8: Compare against last 8 points
    # - window_long=32: Compare against last 32 points
    # - threshold_ratio=1.01: Need 1% improvement to not be considered plateaued
    # - min_points=32: Wait for at least 32 points before checking
    if logger.has_plateaued(
        key="accuracy",
        window_short=8,
        window_long=32,
        threshold_ratio=1.01,
        min_points=32
    ):
        print(f"Training has plateaued at epoch {epoch}")
        break

logger.on_end()

Debugging and Monitoring

from MetricDB import MetricDB

logger = MetricDB(datafile_dir="debug.db", verbose=True)

# Log some metrics
logger.log({"step": 1, "loss": 0.5})

# Print database structure and contents
logger.print_header()  # Shows all tables and their contents

# Show the most recent logged values
logger.show_last_row(name_table="main")

logger.on_end()

Development Tools

from MetricDB import MetricDB

logger = MetricDB(datafile_dir="dev.db")

# Write dummy data for testing
logger._write_dummy_data(name_table="test_table")

# Print database contents
logger.print_header()

logger.on_end()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metricdb-0.0.13.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

MetricDB-0.0.13-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file metricdb-0.0.13.tar.gz.

File metadata

  • Download URL: metricdb-0.0.13.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for metricdb-0.0.13.tar.gz
Algorithm Hash digest
SHA256 3b0ecac483fdad82bda3ea656992903686ba6fc7e518dba821c8dac9c2bcb4eb
MD5 e2f895e4207b3098fb1f6a76bb80bc02
BLAKE2b-256 c6e36c7444ef39df5ffa03e9edc5d621a366abcce47e77c66f30100372f0bbc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for metricdb-0.0.13.tar.gz:

Publisher: pypi.yml on Don-Yin/MetricDB

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file MetricDB-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: MetricDB-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for MetricDB-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 d12bfc7b58989358d94e65b1e4e1aade7659baffca21ba7849bdba371fa05ea4
MD5 5b0cb85e71b92f617d4cee23e225efb4
BLAKE2b-256 f6960283df2593fa2fb0f9050af94f90225cb400a680aa310979f1a13e061edc

See more details on using hashes here.

Provenance

The following attestation bundles were made for MetricDB-0.0.13-py3-none-any.whl:

Publisher: pypi.yml on Don-Yin/MetricDB

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page