From 6eb1d2607b6365c9aa14bf233942404e0cbe65c2 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 28 Apr 2020 11:04:39 +1200 Subject: [PATCH] Add Jupyter notebooks for making graphs for zcash/zcash#4467 --- 4467-sprout-usage/ShieldedUsage.ipynb | 190 ++++++++++++++++++++++++++ 4467-sprout-usage/SproutUsage.ipynb | 137 +++++++++++++++++++ 2 files changed, 327 insertions(+) create mode 100755 4467-sprout-usage/ShieldedUsage.ipynb create mode 100755 4467-sprout-usage/SproutUsage.ipynb diff --git a/4467-sprout-usage/ShieldedUsage.ipynb b/4467-sprout-usage/ShieldedUsage.ipynb new file mode 100755 index 0000000..66b15d5 --- /dev/null +++ b/4467-sprout-usage/ShieldedUsage.ipynb @@ -0,0 +1,190 @@ +{ + "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-shielded-data-811497.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 = 720000\n", + "to_height = 811000\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", + "num_migrating = data[from_height:to_height,10]\n", + "num_mixed = data[from_height:to_height,9] - num_migrating\n", + "num_shielding = data[from_height:to_height,5]\n", + "num_unshielding = data[from_height:to_height,6] - num_migrating - num_mixed\n", + "num_shielded = data[from_height:to_height,3] - data[from_height:to_height,5] - data[from_height:to_height,6]\n", + "\n", + "num_shielded = sum_chunk(num_shielded, chunk)\n", + "num_shielding = sum_chunk(num_shielding, chunk)\n", + "num_unshielding = sum_chunk(num_unshielding, chunk)\n", + "num_mixed = sum_chunk(num_mixed, chunk)\n", + "num_migrating = sum_chunk(num_migrating, chunk)\n", + "\n", + "# percent_split = num_split / num_split.sum(axis=0).astype(float) * 100\n", + "\n", + "sprout_shielded = data[from_height:to_height,11]\n", + "sapling_shielded = data[from_height:to_height,12]\n", + "sprout_unshielded = data[from_height:to_height,13]\n", + "sapling_unshielded = data[from_height:to_height,14]\n", + "print(sprout_shielded.max() / COIN)\n", + "print(sprout_unshielded.max() / COIN)\n", + "print(sapling_shielded.max() / COIN)\n", + "print(sapling_unshielded.max() / COIN)\n", + "\n", + "sprout_shielded = sum_chunk(sprout_shielded, chunk)\n", + "sprout_unshielded = sum_chunk(sprout_unshielded, chunk)\n", + "sapling_shielded = sum_chunk(sapling_shielded, chunk)\n", + "sapling_unshielded = sum_chunk(sapling_unshielded, chunk)\n", + "\n", + "# Rescale for chunk size\n", + "height = height / chunk\n", + "num_types = num_types / chunk\n", + "num_shielded = num_shielded / chunk\n", + "num_shielding = num_shielding / chunk\n", + "num_unshielding = num_unshielding / chunk\n", + "num_mixed = num_mixed / chunk\n", + "num_migrating = num_migrating / chunk\n", + "sprout_shielded = sprout_shielded / (chunk * COIN)\n", + "sprout_unshielded = sprout_unshielded / (chunk * COIN)\n", + "sapling_shielded = sapling_shielded / (chunk * COIN)\n", + "sapling_unshielded = sapling_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, sprout_shielded, label='Sprout Shielding')\n", + "# ax.fill_between(height, sprout_unshielded * -1, label='Sprout Unshielding')\n", + "# ax.fill_between(height, sapling_shielded, label='Sprout Shielding')\n", + "# ax.fill_between(height, sapling_unshielded * -1, label='Sprout Unshielding')\n", + "ax.stackplot(height, sprout_shielded, sapling_shielded, labels=['Sprout Shielding', 'Sapling Shielding'])\n", + "ax.stackplot(height, sprout_unshielded * -1, sapling_unshielded * -1, labels=['Sprout Unshielding', 'Sapling Unshielding'])\n", + "\n", + "ax.set_title('ZEC moving into and out of the shielded value pools')\n", + "ax.set_xlabel('Height')\n", + "ax.set_ylabel('ZEC amount (%d-block average)' % chunk)\n", + "# ax.set_ylim(-10, 10)\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": [ + "fig = plt.figure(figsize=(8,6))\n", + "ax = fig.add_subplot(1, 1, 1)\n", + "\n", + "ax.stackplot(height, num_mixed, num_migrating, num_shielded, num_unshielding, num_shielding, labels=['Mixed', 'Migrating', 'Shielded', 'Unshielding', 'Shielding'])\n", + "ax.set_title('Sprout 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-sprout-splits-%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 +} diff --git a/4467-sprout-usage/SproutUsage.ipynb b/4467-sprout-usage/SproutUsage.ipynb new file mode 100755 index 0000000..2bc51d3 --- /dev/null +++ b/4467-sprout-usage/SproutUsage.ipynb @@ -0,0 +1,137 @@ +{ + "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 +}