-
Notifications
You must be signed in to change notification settings - Fork 0
Measurement Testing
This guide explains how to test the measurement averaging system in O Blockchain.
The O Blockchain measurement system calculates averages from multiple measurements to determine:
- Water Prices: Average price of water per currency
- Exchange Rates: Average exchange rates between O currencies and fiat currencies
- Gaussian Averaging: Filters outliers using statistical analysis
- Confidence Levels: Provides confidence information based on sample size
- Statistical Significance: Requires minimum measurements (5+) for significance
- Standard Deviation: Calculates variance to measure data quality
# Basic average (returns average only if statistically significant)
bitcoin-cli -regtest -rpcwallet=test_wallet getaveragewaterprice "USD" 30
# Average with confidence information
bitcoin-cli -regtest -rpcwallet=test_wallet getaveragewaterpricewithconfidence "USD" 30Response includes:
-
average_price: The calculated average -
measurement_count: Number of measurements used -
standard_deviation: Statistical spread -
confidence_level: INSUFFICIENT_DATA, LOW_CONFIDENCE, HIGH_CONFIDENCE, or VERY_HIGH_CONFIDENCE -
is_statistically_significant: Whether enough measurements exist (5+)
# Average exchange rate with confidence
bitcoin-cli -regtest -rpcwallet=test_wallet getaverageexchangeratewithconfidence "OUSD" "USD" 7Response includes:
-
average_rate: The calculated average exchange rate -
measurement_count: Number of measurements used -
standard_deviation: Statistical spread -
confidence_level: Confidence rating -
is_statistically_significant: Whether enough measurements exist
The system uses the following confidence levels based on measurement count:
- INSUFFICIENT_DATA: < 5 measurements (not statistically significant)
- LOW_CONFIDENCE: 5-9 measurements (statistically significant but low confidence)
- HIGH_CONFIDENCE: 10-19 measurements (good confidence)
- VERY_HIGH_CONFIDENCE: 20+ measurements (very reliable)
To test averaging, you need to submit multiple measurements with varying values:
# Create an invite first
INVITE_ID=$(openssl rand -hex 32)
EXPIRES_AT=$(($(date +%s) + 86400))
ADDRESS=$(bitcoin-cli -regtest -rpcwallet=test_wallet getnewaddress)
PUBKEY=$(bitcoin-cli -regtest -rpcwallet=test_wallet getaddressinfo "$ADDRESS" | grep -o '"pubkey": "[^"]*' | cut -d'"' -f4)
bitcoin-cli -regtest -rpcwallet=test_wallet submitinvitetx "$INVITE_ID" "$PUBKEY" "water_price" "USD" "$EXPIRES_AT"
# Submit multiple measurements with different prices
bitcoin-cli -regtest -rpcwallet=test_wallet submitwaterpricetx "USD" "1500000" "$INVITE_ID" "url" "https://store1.com/water"
bitcoin-cli -regtest -rpcwallet=test_wallet submitwaterpricetx "USD" "1520000" "$INVITE_ID" "url" "https://store2.com/water"
bitcoin-cli -regtest -rpcwallet=test_wallet submitwaterpricetx "USD" "1480000" "$INVITE_ID" "url" "https://store3.com/water"
# ... submit 10-20 more measurements with variations around $1.50Measurements need to be included in blocks to be available for averaging. In regtest mode, you may need to generate blocks:
# Generate blocks to include transactions
bitcoin-cli -regtest -generate 1After submitting measurements and generating blocks:
# Get average with confidence info
bitcoin-cli -regtest -rpcwallet=test_wallet getaveragewaterpricewithconfidence "USD" 30Here's a conceptual example of what happens with 20 water price measurements:
1500000, 1520000, 1480000, 1510000, 1490000,
1505000, 1495000, 1525000, 1475000, 1503000,
1512000, 1488000, 1500000, 1515000, 1485000,
1498000, 1522000, 1492000, 1508000, 1482000
- Filter Outliers: Removes values that deviate > 2 standard deviations
- Calculate Mean: Averages the remaining values
- Calculate Standard Deviation: Measures spread
- Determine Confidence: 20 measurements = VERY_HIGH_CONFIDENCE
{
"currency": "USD",
"average_price": 1.501,
"measurement_count": 20,
"standard_deviation": 0.014,
"confidence_level": "VERY_HIGH_CONFIDENCE",
"is_statistically_significant": true,
"days": 30
}- Blockchain Storage Required: Measurements must be in blockchain transactions to be included in averages
- Time Windows: Averages are calculated over time periods (default 30 days for water price, 7 days for exchange rates)
- Outlier Filtering: The Gaussian averaging system automatically filters outliers to prevent manipulation
- Minimum Measurements: At least 5 measurements are needed for statistical significance
- Ensure measurements were successfully submitted and included in blocks
- Check that the time window (days parameter) includes when measurements were submitted
- Verify the currency code matches exactly
- Submit at least 5 measurements for the same currency
- Measurements must be within the time window specified
- Ensure the wallet is unlocked:
bitcoin-cli -regtest -rpcwallet=test_wallet walletpassphrase "" 0 - The wallet must have the private key for the address used in measurements
-
test_bulk_measurements.py: Script for automated bulk measurement testing - RPC documentation:
bitcoin-cli -regtest help getaveragewaterpricewithconfidence - Measurement system code:
src/measurement/measurement_helpers.cpp
Β© O International
A Nonprofit Association Focused on the Creation of a Water Price-Based Stable Coin
Association de Loi 1901 β France NumΓ©ro de Siret (French SIREN): 924 014 467 00014