From 89880196e638cbeda84524a4cd21ad65308931a0 Mon Sep 17 00:00:00 2001 From: Mustafa Tuncay Date: Thu, 12 Dec 2024 13:21:44 +0300 Subject: [PATCH 1/2] README for the Accuracy module --- READMEs/accuracy.md | 105 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 READMEs/accuracy.md diff --git a/READMEs/accuracy.md b/READMEs/accuracy.md new file mode 100644 index 000000000..0eb5f9d89 --- /dev/null +++ b/READMEs/accuracy.md @@ -0,0 +1,105 @@ +# PDR Backend Accuracy Module + +## Overview +The Accuracy module is responsible for calculating and tracking prediction accuracy statistics for Ocean Protocol's Predictoor network. It provides a Flask-based web service that periodically collects prediction data and serves statistical information about prediction accuracy and staking amounts. + +## Key Features +- Periodic data collection (every 5 minutes) +- Support for different timeframes (5min and 1hr predictions) +- REST API endpoint for accessing statistics +- Persistent storage of statistics in JSON format + +## Related Subgraph Methods + +### Predictions (subgraph_predictions.py) + +#### `fetch_filtered_predictions()` +Retrieves predictions from the subgraph within a specified time range. Supports: +- Filtering by contract addresses +- Time-based querying with start and end timestamps +- Pagination with customizable chunk sizes +- Returns detailed prediction data including stakes, payouts, and true values + +#### `get_all_contract_ids_by_owner()` +Fetches contract IDs associated with a specific owner address: +- Retrieves all tokens owned by a given address +- Supports both mainnet and testnet queries +- Returns a list of contract IDs + +#### `fetch_contract_id_and_spe()` +Queries contract details including: +- Contract IDs +- Seconds per epoch (SPE) +- Token names +- Essential for accuracy calculations and contract identification + +### Subscriptions (subgraph_subscriptions.py) + +#### `fetch_filtered_subscriptions()` +Retrieves subscription data with features including: +- Time range filtering +- Contract-based filtering +- Pagination support +- Network selection +- Returns detailed subscription information including: + - Pair information + - Timeframe details + - Source data + - Transaction IDs + - User information + +## Technical Details + +### Main Components + +#### 1. Flask Web Service (`app.py`) +- Provides `/statistics` endpoint for retrieving accuracy data +- Runs a background thread for periodic data collection +- Implements CORS support for cross-origin requests + +#### 2. Statistics Calculation +- Calculates prediction accuracy for each asset +- Tracks staking amounts for different time periods +- Supports multiple timeframes: + - 5-minute predictions (1 week of historical data) + - 1-hour predictions (4 weeks of historical data) + +#### 3. Data Storage +- Statistics are stored in `accuracy_data.json` +- Location: `pdr_backend/accuracy/output/accuracy_data.json` + +### API Endpoint + +#### GET /statistics +Returns statistical data for all tracked prediction contracts. + +## Configuration +- Network selection: Currently configured for mainnet +- Whitelist feeds: Uses `WHITELIST_FEEDS_MAINNET` constant +- Update interval: 5 minutes (300 seconds) + +## Dependencies +- Flask +- enforce_typing +- threading +- datetime +- json +- logging + +## Usage + +### Running the Service + +To run the service, use the following command: + +```bash +python -m pdr_backend.accuracy.app +``` + +## Error Handling +- API endpoint returns 500 status code with error details if file access fails + +## Notes +- The service maintains separate statistics for 5-minute and 1-hour prediction contracts +- Accuracy calculations exclude canceled slots +- Staking amounts are tracked for both current and previous day \ No newline at end of file From 0e860829c6a3386c28c42bdd04fc36d32f4fe995 Mon Sep 17 00:00:00 2001 From: Mustafa Tuncay Date: Thu, 12 Dec 2024 13:27:51 +0300 Subject: [PATCH 2/2] fix the run code --- READMEs/accuracy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/READMEs/accuracy.md b/READMEs/accuracy.md index 0eb5f9d89..4b53734db 100644 --- a/READMEs/accuracy.md +++ b/READMEs/accuracy.md @@ -93,7 +93,7 @@ Returns statistical data for all tracked prediction contracts. To run the service, use the following command: ```bash -python -m pdr_backend.accuracy.app +python pdr_backend/accuracy/app.py ``` ## Error Handling