This commit is contained in:
Jonathon Broughton 2023-01-06 13:56:08 +00:00 коммит произвёл GitHub
Родитель 0c74ce125b
Коммит fdc2972c6b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 48 добавлений и 27 удалений

Просмотреть файл

@ -15,18 +15,26 @@
"id": "b19579d1",
"metadata": {},
"source": [
"Notebook requirements👇"
"### Purpose\n",
"\n",
"We want to access data produced in Grasshopper and sent to a Speckle Stream. The intended destination is run some analytics using pandas' dataframes.\n",
"\n",
"### Setup\n",
"\n",
"The only dependency we'll need for this simeple example is Specklepy.\n",
"\n",
"If you are running jupyter in a venv, or don't have specklepy installed, we'll do that first👇"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 55,
"id": "d3d134f5",
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"# capture turns off the output for this cell which is the install log\n",
"# capture turns off the output for this cell which would just be the pip install log 🤫\n",
"%pip install specklepy"
]
},
@ -36,54 +44,64 @@
"id": "78e9c592",
"metadata": {},
"source": [
"Boilerplate for a basic specklepy script."
"With that installed, we'll use the StreamWrapper helper function to make accessing our Speckle data easy. This wrapper will automatically connect to the server you specify with any accounts you have already setup locally."
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 56,
"id": "023504e7",
"metadata": {},
"outputs": [],
"source": [
"from specklepy.api.client import SpeckleClient\n",
"from specklepy.api.wrapper import StreamWrapper\n",
"from specklepy.api import operations\n",
"\n",
"# speckle server url 👇\n",
"HOST_SERVER = \"https://speckle.xyz\"\n",
"# Your Speckle Stream URL goes here 👇\n",
"stream_url = \"https://speckle.xyz/streams/275f928307\"\n",
"\n",
"#wrapper\n",
"wrapper = StreamWrapper(stream_url)\n",
"#speckle client\n",
"client = wrapper.get_client()\n",
"#transport\n",
"transport = wrapper.get_transport()"
"# wrapper\n",
"wrapper = StreamWrapper(stream_url)\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "5027dbb4",
"metadata": {},
"source": [
"The wrapper automagically wrangles your accounts and the url into the connection parts we need.\n",
"\n",
"A `client` will interface with the Project Streams, and the `transport` will handle the data stuff. "
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "4108c1e6",
"metadata": {},
"source": [
"Receiving GH Data from Speckle server"
"With those in place, to receive our GH Data from Speckle server, we use the operations module."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 58,
"id": "e64ea704",
"metadata": {},
"outputs": [],
"source": [
"from specklepy.api import operations\n",
"\n",
"# Receive data in Python\n",
"commit = client.commit.list(wrapper.stream_id, limit=1)[0]\n",
"commit = wrapper.get_client().commit.list(wrapper.stream_id, limit=1)[0]\n",
"\n",
"# get obj id from commit\n",
"obj_id = commit.referencedObject\n",
"\n",
"# receive objects from speckle\n",
"commit_data = operations.receive(obj_id=obj_id,remote_transport=transport)"
"commit_data = operations.receive(\n",
" obj_id=obj_id, remote_transport=wrapper.get_transport()\n",
")\n"
]
},
{
@ -97,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"id": "2aa0fc73",
"metadata": {},
"outputs": [
@ -107,22 +125,25 @@
"[0, 20, 40, 60, 80, 100, 120, 140, 160, 180]"
]
},
"execution_count": 18,
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Describe what \"@\" does\n",
"# Special to GH commits, we access the data with the @Data reference.\n",
"# From there we can use familiar GH tree notation.\n",
"\n",
"gh_data = commit_data[\"@Data\"][\"@{0;0}\"]\n",
"#print out the result\n",
"gh_data"
"\n",
"# print out the result\n",
"gh_data\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
@ -136,11 +157,11 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
"hash": "3e11e7655d454b698ddf48653c0d53a36ba1baee337ad9c629b69c92c41d12c3"
"hash": "e6e7bf9e94236f6ef8a91c6f557ee35aa433a8d662d3ab91b5491708584927e4"
}
}
},