zcash-graphs/4467-sprout-usage/SproutUsage.ipynb

138 lines
3.9 KiB
Plaintext
Executable File

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"import numpy as np\n",
"\n",
"data = np.genfromtxt('zcash-sprout-data-805518.csv', delimiter=',', skip_header=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"COIN = 100000000\n",
"\n",
"def sum_chunk(x, chunk_size, axis=-1):\n",
" shape = x.shape\n",
" if axis < 0:\n",
" axis += x.ndim\n",
" shape = shape[:axis] + (-1, chunk_size) + shape[axis+1:]\n",
" x = x.reshape(shape)\n",
" return x.sum(axis=axis+1)\n",
"\n",
"from_height = 0\n",
"to_height = 805000\n",
"chunk = 1000\n",
"\n",
"# Slice the heights\n",
"height = sum_chunk(data[from_height:to_height,0], chunk)\n",
"\n",
"num_types = sum_chunk(data[from_height:to_height,1:4].transpose(), chunk)\n",
"percent_types = num_types / num_types.sum(axis=0).astype(float) * 100\n",
"\n",
"value_shielded = data[from_height:to_height,7]\n",
"value_unshielded = data[from_height:to_height,10]\n",
"print(value_shielded.max() / COIN)\n",
"print(value_unshielded.max() / COIN)\n",
"\n",
"value_shielded = sum_chunk(value_shielded, chunk)\n",
"value_unshielded = sum_chunk(value_unshielded, chunk)\n",
"\n",
"# Rescale for chunk size\n",
"height = height / chunk\n",
"num_types = num_types / chunk\n",
"value_shielded = value_shielded / (chunk * COIN)\n",
"value_unshielded = value_unshielded / (chunk * COIN)\n",
"\n",
"# Select the types char\n",
"chart_types = num_types.transpose()\n",
"\n",
"sprout = chart_types[:,2]\n",
"sapling = chart_types[:,1]\n",
"transparent = chart_types[:,0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(8,6))\n",
"ax = fig.add_subplot(1, 1, 1)\n",
"\n",
"ax.stackplot(height, sprout, sapling, transparent, labels=['Involves Sprout', 'Sapling + Transparent', 'Transparent-only'])\n",
"ax.set_title('Transaction types mined in the Zcash main chain')\n",
"ax.set_xlabel('Height')\n",
"ax.set_ylabel('Transactions per block (%d-block average)' % chunk)\n",
"ax.legend(loc='upper right')\n",
"ax.grid()\n",
"# ax.set_yscale('log')\n",
"plt.xticks(rotation=45)\n",
"plt.margins(x=0)\n",
"plt.savefig('tx-types-%d-%d-%d.png' % (from_height, to_height, chunk))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(8,6))\n",
"ax = fig.add_subplot(1, 1, 1)\n",
"\n",
"ax.fill_between(height, value_shielded, label='Shielding')\n",
"ax.fill_between(height, value_unshielded * -1, label='Unshielding')\n",
"ax.set_title('ZEC moving into and out of the Sprout value pool')\n",
"ax.set_xlabel('Height')\n",
"ax.set_ylabel('ZEC amount (%d-block average)' % chunk)\n",
"# ax.set_ylim(-1, 1)\n",
"ax.legend(loc='lower right')\n",
"ax.grid()\n",
"plt.xticks(rotation=45)\n",
"plt.margins(x=0)\n",
"plt.savefig('tx-values-%d-%d-%d.png' % (from_height, to_height, chunk))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}