Skip to main content

A lightweight performance tracker for python projects.

Project description

PerforMate Anomaly Detection and Exporting Data

PerforMate is a lightweight performance-tracking library designed to measure time spent in various sections and subsections of your code. It is optimized for low-resource environments like IoT projects. This extended feature detects anomalies in the time spent in sections or subsections using the Z-Score method. Additionally, PerforMate supports exporting performance data to various services such as HTTP or FTP using custom-defined services.

Features

  • Track Performance: Measure the time spent in different sections and subsections of your code.
  • Anomaly Detection: Automatically detect anomalies in time spent across sections and subsections using the Z-Score method.
  • Customizable Threshold: Define how sensitive the anomaly detection should be by setting the Z-Score threshold.
  • Section and Subsection Analysis: You can detect anomalies in both high-level sections and more granular subsections.
  • Export Data: Export your performance data to services such as HTTP, FTP, or custom services by defining export methods.
  • Detailed Information: Get the section/subsection name, the anomalous time spent, and the timestamp for each anomaly.

Installation

You can install PerforMate using pip:

pip install PerforMate

Usage

1. Initializing PerforMate

Start by creating an instance of the PerforMate object and begin tracking sections and subsections in your code.

from PerforMate import PerforMate
import time

# Initialize PerforMate
tracker = PerforMate("MyApp")

# Start a section and simulate work
section = tracker.start_section("Data Processing")
time.sleep(2)
section.add_subsection("Load Data").end_subsection("Load Data")
time.sleep(1)
tracker.end_section("Data Processing")

section = tracker.start_section("Model Training")
time.sleep(3)
tracker.end_section("Model Training")

Results Samples

Image 1 Image 2

2. Detecting Anomalies in Sections

To detect anomalies in the time spent across sections, use the detect_anomalies_in_sections() function:

# Detect anomalies in sections
anomalous_sections = detect_anomalies_in_sections(tracker, threshold=3, subsections=False)
print(f"Anomalous sections, times, and timestamps: {anomalous_sections}")

3. Detecting Anomalies in Subsections

Similarly, to detect anomalies in subsections:

# Detect anomalies in subsections
anomalous_subsections = detect_anomalies_in_sections(tracker, threshold=3, subsections=True)
print(f"Anomalous subsections, times, and timestamps: {anomalous_subsections}")

4. Exporting Data

PerforMate supports exporting your performance data to various services such as HTTP, FTP, or any custom service. You can define your own export service by extending the ExportService abstract class.

Example: Exporting Data via HTTP

class HTTPExportService(ExportService):
    def send_data(self, data):
        # Implement the HTTP request to send the performance data
        import requests
        response = requests.post("https://your-endpoint.com", json=data)
        print(f"Data exported via HTTP: {response.status_code}")

# Export the data using the defined HTTP export service
http_service = HTTPExportService()
tracker.dump_to_service(http_service)

Example: Exporting Data via FTP

class FTPExportService(ExportService):
    def send_data(self, data):
        # Implement FTP logic to upload the performance data
        import ftplib
        with ftplib.FTP('ftp.yourserver.com', 'username', 'password') as ftp:
            with open('data.json', 'rb') as f:
                ftp.storbinary('STOR data.json', f)
        print("Data exported via FTP")

# Export the data using the defined FTP export service
ftp_service = FTPExportService()
tracker.dump_to_service(ftp_service)

5. Output Example

The anomaly detection function will return a list of tuples containing the section/subsection name, the time spent, and the timestamp:

# Example output
Anomalous sections, times, and timestamps: [('Data Processing', 50, '2024-10-05T10:30:00'), ('Model Training', 200, '2024-10-05T11:00:00')]
Anomalous subsections, times, and timestamps: [('Load Data', 10, '2024-10-05T10:32:00'), ('Preprocess Data', 90, '2024-10-05T10:45:00')]

Customization

You can customize the threshold value for Z-Score to control how sensitive the anomaly detection is. For example:

  • A threshold of 2 will flag more anomalies (more sensitive).
  • A threshold of 4 will flag fewer anomalies (less sensitive).

License

This project is licensed under the MIT License.

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

performate-0.1.5.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

PerforMate-0.1.5-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file performate-0.1.5.tar.gz.

File metadata

  • Download URL: performate-0.1.5.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.11.1 readme-renderer/40.0 requests/2.28.1 requests-toolbelt/1.0.0 urllib3/1.26.13 tqdm/4.64.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.7

File hashes

Hashes for performate-0.1.5.tar.gz
Algorithm Hash digest
SHA256 327718dd143e995b7b12b358f047d237e704f6cbc786a5aa3fe166978d9f7405
MD5 afd39786d1bf8f6816a118c75b28fd1d
BLAKE2b-256 ccf4189119e9e97e7aa15e4e7dd84d98a33f8c2178af52149188caaf28e54215

See more details on using hashes here.

File details

Details for the file PerforMate-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: PerforMate-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.11.1 readme-renderer/40.0 requests/2.28.1 requests-toolbelt/1.0.0 urllib3/1.26.13 tqdm/4.64.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.7

File hashes

Hashes for PerforMate-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 17e24f28c489e31432f0a6e764f7a39595b9ac75b36d883e7cbc469fb97bbe28
MD5 105a33fad3e5e8f40b9d4f4a76579152
BLAKE2b-256 1c34a43a8089a9e838139a15329f22fafd485305ff7e6b23e995cce0657f6d2e

See more details on using hashes here.

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