Skip to main content

- Integeration test for signal added.

Project description

Analytics Ingest Client

A lightweight Python library to batch and push automotive telemetry data—such as signals, Diagnostic Trouble Codes (DTCs), GPS data, and network statistics—to a GraphQL backend.


🔧 Features

  • Supports Python 3.11+
  • Clean, single-class interface: IcsAnalytics
  • In-memory caching for resolved IDs (message id or configuration)
  • Batching support (by interval, count, or signal limit)
  • Async-safe request queuing (only 1 request at a time)
  • Minimal dependency footprint
  • Easy to test and integrate
  • Supports signals, DTCs, GPS, and network stats ingestion

📦 Installation

pip install analytics-ingest

🚀 Usage

Basic Example

from analytics_ingest import IcsAnalytics

client = IcsAnalytics(
    device_id=123,
    vehicle_id=456,
    fleet_id=789,
    org_id=1011,
    graphql_endpoint="https://your-backend/graphql",
    batch_size=100,
    batch_interval_seconds=10,
    max_signal_count=100
)

# Add signals (list of dicts)
client.add_signal([
    {'name': 'VehicleIdentificationNumber', 'unit': '', 'messageName': 'BusQuery_IDDecoding_F190_VSSAL', 'networkName': 'Cluster_6_TestTool', 'ecuName': '', 'arbId': '', 'fileId': '1234', 'paramType': 'TEXT', 'signalType': 'DID', 'messageDate': '2025-07-15T01:40:00.000000', 'paramId': 'F190', 'data': [{'value': 0.04, 'time': '1970-01-07T18:28:54Z'}]},
    # ... more signals ...
])

# Add DTCs (list of dicts)
client.add_dtc([{'messageName': 'DTC Message99B049', 'name': 'DTC Message99B049', 'networkName': 'Cluster_6_TestTool', 'ecuName': 'VCU_Android_GAS', 'ecuId': '14DA80F1', 'messageDate': '2025-07-15T01:42:20.385429', 'fileId': '1234', 'data': [{'dtcId': 'B19B0-49', 'description': 'Head-Up Display - Internal Electronic Failure', 'status': '2F', 'time': '2025-07-15T01:42:15.979524'}]} 
# ... more DTCs ...
])

# Add GPS data (dict)
client.add_gps([
    {"time": "2025-07-28T12:34:56.789Z", "latitude": 37.7749, "longitude": -122.4194, "accuracy": 10.5, "altitude": 120.3, "speed": 45.2, "bearing": 75.0, "available": {"accuracy": True, "altitude": True, "bearing": False, "speed": True, "time": True}},
    {"time": "2025-07-28T12:35:56.789Z", "latitude": 37.7750, "longitude": -122.4195}
    # ... more GPS ...
])


# Add network stats (dict)
client.add_network_stats({
    "name": "CAN1",
    "vehicleId": 456,
    "uploadId": 1,
    "totalMessages": 1000,
    "matchedMessages": 950,
    "unmatchedMessages": 50,
    "errorMessages": 0,
    "longMessageParts": 0,
    "rate": 500.0
})

# Graceful shutdown (flushes any remaining data)
client.close()

⚙️ Configuration

You can configure the client via constructor arguments or environment variables (e.g., GRAPH_ENDPOINT).

  • device_id, vehicle_id, fleet_id, org_id: Required identifiers
  • graphql_endpoint: URL to your GraphQL backend
  • batch_size: Number of items per batch (default: 100)
  • batch_interval_seconds: Max seconds between batch sends (default: 10)
  • max_signal_count: Max signals per batch (default: 100)

🛠️ Error Handling & Logging

  • Uses exceptions for invalid input or backend errors
  • Replaceable print statements with logging recommended for production
  • Retries failed batch sends on next interval

🧪 Testing

Run all test cases:

PYTHONPATH=src python3 -m unittest discover -s tests -v

Build and upload package:

python3 -m build
python -m twine upload dist/*

💡 Improvements & Roadmap

  • Add more usage examples and API documentation
  • Integrate a logging framework
  • Increase test coverage and add integration tests
  • Allow dynamic runtime configuration
  • Expose a fully async API
  • Add metrics and monitoring hooks
  • Enforce linting and type checking in CI

🤝 Contributing

Pull requests and issues are welcome! Please add tests for new features and follow PEP8 style guidelines.

Setup (Only Once) After cloning the repo, run:

pip install pre-commit
pre-commit install


📄 License

MIT License Readme.txt 4 KB

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

analytics_ingest-0.1.70.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

analytics_ingest-0.1.70-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file analytics_ingest-0.1.70.tar.gz.

File metadata

  • Download URL: analytics_ingest-0.1.70.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for analytics_ingest-0.1.70.tar.gz
Algorithm Hash digest
SHA256 31597fbeba68d558de9302460bc0ce8889fc94fe058b4283cf5a7dcbcdf59d18
MD5 bbaaaf6cf7007297d85b13ef026d720c
BLAKE2b-256 503c21055e4dcc2bdf81096418da1b0f5d9d67eb7220c7cb9857bea8d97faacd

See more details on using hashes here.

File details

Details for the file analytics_ingest-0.1.70-py3-none-any.whl.

File metadata

File hashes

Hashes for analytics_ingest-0.1.70-py3-none-any.whl
Algorithm Hash digest
SHA256 ca3087d60a20d70cd1be30702beb35a3762818f84edb3c49039415c21460df15
MD5 b92c0b9c15567913c46e4ec727d10b0a
BLAKE2b-256 203988fa99ff51cc99558a39e1c32dc5790d1cf5053b898fbc0de82f52506431

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