Skip to content

Measurement Testing

O edited this page Dec 23, 2025 · 1 revision

Testing Measurement Averages

This guide explains how to test the measurement averaging system in O Blockchain.

Overview

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

Averaging System Features

  1. Gaussian Averaging: Filters outliers using statistical analysis
  2. Confidence Levels: Provides confidence information based on sample size
  3. Statistical Significance: Requires minimum measurements (5+) for significance
  4. Standard Deviation: Calculates variance to measure data quality

RPC Commands for Averages

Get Average Water Price

# 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" 30

Response 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+)

Get Average Exchange Rate

# Average exchange rate with confidence
bitcoin-cli -regtest -rpcwallet=test_wallet getaverageexchangeratewithconfidence "OUSD" "USD" 7

Response 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

Confidence Levels

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)

Testing Strategy

1. Submit Multiple Measurements

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.50

2. Wait for Processing

Measurements 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 1

3. Check Averages

After submitting measurements and generating blocks:

# Get average with confidence info
bitcoin-cli -regtest -rpcwallet=test_wallet getaveragewaterpricewithconfidence "USD" 30

Example: Testing with 20 Measurements

Here's a conceptual example of what happens with 20 water price measurements:

Submitted Values (in micro-USD, representing $1.50 Β± $0.10):

1500000, 1520000, 1480000, 1510000, 1490000,
1505000, 1495000, 1525000, 1475000, 1503000,
1512000, 1488000, 1500000, 1515000, 1485000,
1498000, 1522000, 1492000, 1508000, 1482000

System Processing:

  1. Filter Outliers: Removes values that deviate > 2 standard deviations
  2. Calculate Mean: Averages the remaining values
  3. Calculate Standard Deviation: Measures spread
  4. Determine Confidence: 20 measurements = VERY_HIGH_CONFIDENCE

Expected Result:

{
  "currency": "USD",
  "average_price": 1.501,
  "measurement_count": 20,
  "standard_deviation": 0.014,
  "confidence_level": "VERY_HIGH_CONFIDENCE",
  "is_statistically_significant": true,
  "days": 30
}

Important Notes

  1. Blockchain Storage Required: Measurements must be in blockchain transactions to be included in averages
  2. Time Windows: Averages are calculated over time periods (default 30 days for water price, 7 days for exchange rates)
  3. Outlier Filtering: The Gaussian averaging system automatically filters outliers to prevent manipulation
  4. Minimum Measurements: At least 5 measurements are needed for statistical significance

Troubleshooting

"No measurements found"

  • 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

"Not statistically significant"

  • Submit at least 5 measurements for the same currency
  • Measurements must be within the time window specified

Signing Errors

  • 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

See Also

  • 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

Clone this wiki locally