From ee47e3a8f32415cc63161b0be73dc3d67e86f407 Mon Sep 17 00:00:00 2001 From: molotgor Date: Wed, 16 Oct 2024 18:28:14 +0400 Subject: [PATCH] add example of notebook --- example/example.ipynb | 93 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 example/example.ipynb diff --git a/example/example.ipynb b/example/example.ipynb new file mode 100644 index 0000000..a571a29 --- /dev/null +++ b/example/example.ipynb @@ -0,0 +1,93 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "tags": [ + "parameters" + ] + }, + "outputs": [], + "source": [ + "output_path='output.jsonl'\n", + "lambda_pycode = \"\"\"lambda a:a['weight'] < 300\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 5 50\n" + ] + } + ], + "source": [ + "import json\n", + "import asyncio\n", + "import random\n", + "from datetime import datetime\n", + "amount = 100\n", + "\n", + "displayTable = [\n", + " ['bid order', 'bid rate', 'bid qty', 'ask order', 'ask rate', 'ask qty'],\n", + " ['424', '0.61500000', '101', '', '', ''],\n", + " ['424', '0.61500000', '101', '', '', ''],\n", + "]\n", + "\n", + "drift = 5\n", + "drift_range = [5, 10]\n", + "group = 50\n", + "group_range = [50, 100]\n", + "timestamp = 1725539650\n", + "amount = 200\n", + "pos = 0\n", + "conver = 1000000000\n", + "\n", + "testArr = []\n", + "\n", + "print(pos, drift, group)\n", + "while pos < amount:\n", + " timestamp_in_nano = timestamp*1000000000\n", + " weight = random.randrange(1, 1000)\n", + " timest_obj = datetime.fromtimestamp(timestamp)\n", + " testArr.append({ '#display-timestamp': timestamp_in_nano, '#display-name': str(pos) + ' ' + str(timest_obj), '#display-table': displayTable, 'weight': weight})\n", + " pos = pos + 1\n", + " timestamp += random.randrange(1, 100)\n", + "\n", + "filtered = list(filter(eval(lambda_pycode), testArr))\n", + "\n", + "with open(output_path, \"w\") as out_file:\n", + " for orig_order in filtered:\n", + " json.dump(orig_order, out_file)\n", + " out_file.write('\\n')" + ] + } + ], + "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.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}