Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify SQL queries in crypto tutorial part 2 to work with static crypto dataset #3668

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ CREATE UNIQUE INDEX time_hash_idx ON public.transactions (time, hash)

You created the hypertable and added proper indexes.
Next, ingest some Bitcoin transactions. The sample data file
contains Bitcoin transactions from the past five days. This CSV file is
updated daily so you always download recent Bitcoin transactions.
contains around 1.5 million Bitcoin transactions, the trades for five days.
Insert this dataset into your TimescaleDB instance.

<Procedure>
Expand Down
26 changes: 13 additions & 13 deletions tutorials/blockchain-analyze/analyze-blockchain-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,20 @@ fees to decrease.
tx_count as "tx volume",
average(stats_fee_sat) as fees
FROM one_hour_transactions
WHERE bucket > NOW() - INTERVAL '2 days'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-2 days')
jonatas marked this conversation as resolved.
Show resolved Hide resolved
ORDER BY 1;
```

1. The data you get back looks a bit like this:

```sql
time | tx volume | fees
time | tx volume | fees
------------------------+-----------+--------------------
2023-06-13 08:00:00+00 | 20063 | 7075.682450281613
2023-06-13 09:00:00+00 | 16984 | 7302.61716910033
2023-06-13 10:00:00+00 | 15856 | 9682.086402623612
2023-06-13 11:00:00+00 | 24967 | 5631.992550166219
2023-06-13 12:00:00+00 | 8575 | 17594.24256559767
2023-11-20 01:00:00+00 | 2602 | 105963.45810914681
2023-11-20 02:00:00+00 | 33037 | 26686.814117504615
2023-11-20 03:00:00+00 | 42077 | 22875.286546094067
2023-11-20 04:00:00+00 | 46021 | 20280.843180287262
2023-11-20 05:00:00+00 | 20828 | 24694.472969080085
...
```

Expand Down Expand Up @@ -212,7 +212,7 @@ transaction volume, along with the BTC to US Dollar conversion rate.
tx_count as "tx volume",
total_fee_usd / (total_fee_sat*0.00000001) AS "btc-usd rate"
FROM one_hour_transactions
WHERE bucket > NOW() - INTERVAL '2 days'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-2 days')
ORDER BY 1;
```

Expand Down Expand Up @@ -268,7 +268,7 @@ transactions in a block, the higher the mining fee becomes.
avg(tx_count) AS transactions,
avg(block_fee_sat)*0.00000001 AS "mining fee"
FROM one_hour_blocks
WHERE bucket > now() - INTERVAL '5 day'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
GROUP BY bucket
ORDER BY 1;
```
Expand Down Expand Up @@ -325,7 +325,7 @@ units, in which case it's impossible for a block to include more transactions.
avg(block_weight) as "block weight",
avg(block_fee_sat*0.00000001) as "mining fee"
FROM one_hour_blocks
WHERE bucket > now() - INTERVAL '5 day'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
group by bucket
ORDER BY 1;
```
Expand Down Expand Up @@ -383,7 +383,7 @@ few percentage points of overall revenue.
```sql
WITH coinbase AS (
SELECT block_id, output_total AS coinbase_tx FROM transactions
WHERE is_coinbase IS TRUE and time > NOW() - INTERVAL '5 days'
WHERE is_coinbase IS TRUE and time > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
)
SELECT
bucket as "time",
Expand Down Expand Up @@ -451,7 +451,7 @@ grow for individual blocks, and they could include even more transactions.
bucket,
stats_agg(block_weight, block_fee_sat) AS block_stats
FROM one_hour_blocks
WHERE bucket > NOW() - INTERVAL '5 days'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
GROUP BY bucket
)
SELECT
Expand Down Expand Up @@ -512,7 +512,7 @@ increase the time range.
average_y(rolling(stats_miner_revenue) OVER (ORDER BY bucket RANGE '12 hours' PRECEDING))*0.00000001 AS "revenue in BTC",
average_x(rolling(stats_miner_revenue) OVER (ORDER BY bucket RANGE '12 hours' PRECEDING)) AS "revenue in USD"
FROM one_hour_coinbase
WHERE bucket > NOW() - INTERVAL '5 days'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
ORDER BY 1;
```

Expand Down
10 changes: 3 additions & 7 deletions tutorials/blockchain-analyze/blockchain-dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ the past five days, in a hypertable named `transactions`.

<Collapsible heading="The dataset" defaultExpanded={false}>

The dataset is updated daily and contains data from the last five days,
typically around 1.5 million Bitcoin transactions. The data includes information
about each transaction, including the value of the transaction in
[satoshi][satoshi-def], the smallest denomination of Bitcoin. It also states if
a transaction is the first transaction in a block, known as a
[coinbase][coinbase-def] transaction, which includes the reward a coin miner
receives for mining the coin.
The dataset contains around 1.5 million Bitcoin transactions, the trades for five days. It includes
information about each transaction, along with the value in [satoshi][satoshi-def]. It also states if a
trade is a [coinbase][coinbase-def] transaction, and the reward a coin miner receives for mining the coin.

<CreateHypertableBlockchain />

Expand Down
10 changes: 3 additions & 7 deletions tutorials/blockchain-query/blockchain-dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ the past five days, in a hypertable named `transactions`.

<Collapsible heading="The dataset" defaultExpanded={false}>

The dataset is updated daily and contains data from the last five days,
typically around 1.5 million Bitcoin transactions. The data includes information
about each transaction, including the value of the transaction in
[satoshi][satoshi-def], the smallest denomination of Bitcoin. It also states if
a transaction is the first transaction in a block, known as a
[coinbase][coinbase-def] transaction, which includes the reward a coin miner
receives for mining the coin.
The dataset contains around 1.5 million Bitcoin transactions, the trades for five days. It includes
information about each transaction, along with the value in [satoshi][satoshi-def]. It also states if a
trade is a [coinbase][coinbase-def] transaction, and the reward a coin miner receives for mining the coin.

<CreateHypertableBlockchain />

Expand Down
Loading