Skip to content

Instantly share code, notes, and snippets.

@Tschucker
Created October 24, 2021 23:38
Show Gist options
  • Select an option

  • Save Tschucker/891f05d148b0b12bebc190e7b6e65d2d to your computer and use it in GitHub Desktop.

Select an option

Save Tschucker/891f05d148b0b12bebc190e7b6e65d2d to your computer and use it in GitHub Desktop.
compress score list analysis
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "stupid-fight",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2, 3, 4, 6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 19, 20]\n",
"15\n",
"[[2, 4], [6, 7], [9, 12], [14, 17], [19, 20]]\n"
]
}
],
"source": [
"score_data_bank = [1,5,8,13,18]\n",
"acq_list = []\n",
"acq_comp_list = []\n",
"for n in range(20):\n",
" if n+1 not in score_data_bank:\n",
" acq_list.append(n+1)\n",
" if len(acq_list)>0:\n",
" if len(acq_list)==1:\n",
" pair = [acq_list[-1],acq_list[-1]]\n",
" elif acq_list[-1] == pair[1]+1:\n",
" pair[1] = acq_list[-1]\n",
" else:\n",
" acq_comp_list.append(pair)\n",
" pair = [acq_list[-1],acq_list[-1]]\n",
" if n+1 == 20:\n",
" acq_comp_list.append(pair)\n",
"\n",
"print(acq_list)\n",
"print(len(acq_list))\n",
"print(acq_comp_list)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "burning-ancient",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2, 3, 4, 6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 19, 20]\n",
"15\n"
]
}
],
"source": [
"acq_recon_list = []\n",
"for r in acq_comp_list:\n",
" for i in range(r[0],r[1]+1):\n",
" acq_recon_list.append(i)\n",
" \n",
"print(acq_recon_list)\n",
"print(len(acq_recon_list))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "drawn-seafood",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"acq_recon_list == acq_list"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "stopped-housing",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"380\n"
]
}
],
"source": [
"score1 = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXEiOjY3NCwicGF5bG9hZCI6IjNlOTM5Y2EzMmFhMTM5NDkzZDY0YzFkMmRlNzA3ODA2ZmE1ZDk1OTcxMmE3ZDE2ZGNlNGY0YjgyM2FkNmEzOGQyYmFmYWVhZjVhZDk3OGFlYmZmNjY2MDYzOTZmNDEyZGRhNzRiYWZiZDY3ODJjMGVlZTY1Njg3N2JmOThmMjhlYWI0NTk4ODZiMWI4Mzc3MWViZDQ5ODlhNDUzNmJjNmY3ZTE5OGMwOTI1ZGVmYWY4MWQ3NDk1MDg4NDg0ZTVmNTA3ZDY2OTExIn0.RMDJe5-yzPtwk-P2X-SxhigfQI0njAro7WfOualXjJ0'\n",
"score2 = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXEiOjY3NSwicGF5bG9hZCI6IjcxMjA3YWMxM2EyMzMyZTJkNTk1ZmQzOTEyNWZmMTcyMGMzYzgxYzBkZmNlNDM3MTBjMzA4ZWNmMjc2NDM2ZjAwOGMxOGY0YTIzNDIyYjE5MTAyZmJmY2MwNDc2MDBhNGJiN2JjNTE2ZmMxMGJhOGRhOWY4NzMyYjVhNWQyOTExZDlkMmE2MDdmMTBjM2E2ZDMxYTJjZWRlMTc5N2QxZGZiNjQ0ZWIyOTVlNzNjNDM1ZDU1NTIxNmEzOTIzM2I4ODI2MjliN2M0In0.ZCKt1A2p8lKbr3NcCKMvwNByDhUc-MTQMsxRikOzTMo'\n",
"score3 = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXEiOjY3NiwicGF5bG9hZCI6Ijc4N2VjY2E1OTFjMWE5NmU1OGFmNzc5MzcxODMxNGE3YjA1NGMwMTBlM2JmNTdiMTJmNTIwMzYyNmQyOGZlNjVlOTZlMTc4YWIxOTVhZjAwZjE4ZDI4ZDI5MzZkMDA5MmExMGM4ZjNhZjNhMWQzZTUxODQyMTM1YzRmOWRiMzRjZjJmMWE0NDBjMGYwYmVmZWFiMjExZDQxMTZlY2MwYTUwZjA1NDYwMTU5NjRiMzJlYmNhZWM1N2UxZTMzNTAzY2Q2YzQ4MTZkIn0.O9gQHKJWLfB8tYJ1Vo9CQUjMncJNw5cof5klm0Ul3zs'\n",
"print(len(score1))\n",
"scores = [score1, score2, score3]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "closing-render",
"metadata": {},
"outputs": [],
"source": [
"import jwt\n",
"import xdelta3\n",
"import zlib"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "liquid-calculator",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Base 620\n",
"Base comp 469\n",
"score 2 delta- 496\n",
"score 2 delta_comp- 419\n",
"score 3 delta- 498\n",
"score 3 delta_comp- 412\n"
]
}
],
"source": [
"compressed_encoded = []\n",
"score_count = 1\n",
"for sa in scores:\n",
" p = {\"score\": score_count, \"payload\": sa}\n",
" if score_count == 1:\n",
" pld_base = jwt.encode(p, 'teaandtechtime', algorithm=\"HS256\")\n",
" pld_base_comp = zlib.compress(pld_base)\n",
" compressed_encoded = pld_base_comp\n",
" print(\"Base \",len(pld_base))\n",
" print(\"Base comp\",len(pld_base_comp))\n",
" score_count = score_count + 1\n",
" else:\n",
" pld = jwt.encode(p, 'teaandtechtime', algorithm=\"HS256\")\n",
" pld_delta = xdelta3.encode(pld_base,pld)\n",
" pld_delta_comp = zlib.compress(pld_delta)\n",
" print(\"score \", score_count, \" delta-\", len(pld_delta))\n",
" print(\"score \", score_count, \" delta_comp-\", len(pld_delta_comp))\n",
" score_count = score_count + 1\n",
" compressed_encoded = pld_delta_comp"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "extended-continent",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'score': 3, 'payload': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXEiOjY3NiwicGF5bG9hZCI6Ijc4N2VjY2E1OTFjMWE5NmU1OGFmNzc5MzcxODMxNGE3YjA1NGMwMTBlM2JmNTdiMTJmNTIwMzYyNmQyOGZlNjVlOTZlMTc4YWIxOTVhZjAwZjE4ZDI4ZDI5MzZkMDA5MmExMGM4ZjNhZjNhMWQzZTUxODQyMTM1YzRmOWRiMzRjZjJmMWE0NDBjMGYwYmVmZWFiMjExZDQxMTZlY2MwYTUwZjA1NDYwMTU5NjRiMzJlYmNhZWM1N2UxZTMzNTAzY2Q2YzQ4MTZkIn0.O9gQHKJWLfB8tYJ1Vo9CQUjMncJNw5cof5klm0Ul3zs'}\n"
]
}
],
"source": [
"pld_delta_rec = zlib.decompress(compressed_encoded)\n",
"pld_rec = xdelta3.decode(pld_base,pld_delta_rec)\n",
"pld_rec2 = jwt.decode(pld_rec, 'teaandtechtime', algorithms=[\"HS256\"], verify=True)\n",
"print(pld_rec2)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "hybrid-lease",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.6758064516129032"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"419/620"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "every-rider",
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment