Merge pull request #1 from specklesystems/pavol/data-pack
Added the first example
This commit is contained in:
Коммит
59e9c65602
|
@ -0,0 +1,142 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Speckle Data Pack\n",
|
||||
"### Get Room Data - Model\n",
|
||||
"This is a simple example how to get room data from all model (branch) versions (commits)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%capture\n",
|
||||
"# capture turns off the output for this cell which would just be the pip install log\n",
|
||||
"%pip install specklepy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from specklepy.api.wrapper import StreamWrapper\n",
|
||||
"\n",
|
||||
"# Speckle Data Pack model (branch) link\n",
|
||||
"stream_url = \"https://speckle.xyz/streams/729cb7c74b/branches/all_in_one\"\n",
|
||||
"\n",
|
||||
"# wrapper\n",
|
||||
"wrapper = StreamWrapper(stream_url)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from specklepy.api import operations\n",
|
||||
"\n",
|
||||
"# get model (branch) data\n",
|
||||
"branch = wrapper.get_client().branch.get(stream_id=wrapper.stream_id, name=wrapper.branch_name, commits_limit=40)\n",
|
||||
"\n",
|
||||
"data = []\n",
|
||||
"\n",
|
||||
"for commit in branch.commits.items:\n",
|
||||
"\n",
|
||||
" # get obj id from commit\n",
|
||||
" obj_id = commit.referencedObject\n",
|
||||
"\n",
|
||||
" # receive objects from speckle\n",
|
||||
" commit_data = operations.receive(\n",
|
||||
" obj_id=obj_id, remote_transport=wrapper.get_transport()\n",
|
||||
" )\n",
|
||||
" data.append(commit_data)\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# filter room data \n",
|
||||
"\n",
|
||||
"rooms = []\n",
|
||||
"\n",
|
||||
"for item in data: \n",
|
||||
"\n",
|
||||
" elements = item['elements']\n",
|
||||
"\n",
|
||||
" # get Rooms collection\n",
|
||||
" for el in elements:\n",
|
||||
" if el['name'] == 'Rooms':\n",
|
||||
" for r in el['elements']:\n",
|
||||
" rooms.append(r) \n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(6613.85, 33.07, 200)"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# calculate total and average rooms area\n",
|
||||
"\n",
|
||||
"total_area = 0\n",
|
||||
"count_rooms = 0\n",
|
||||
"\n",
|
||||
"for r in rooms:\n",
|
||||
" # filter rooms with no area in case of unplaced rooms\n",
|
||||
" if r['area'] != 0:\n",
|
||||
" total_area += r['area']\n",
|
||||
" count_rooms += 1\n",
|
||||
"\n",
|
||||
"average_area = total_area / count_rooms\n",
|
||||
"\n",
|
||||
"round(total_area,2), round(average_area,2), count_rooms\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.11"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Speckle Data Pack\n",
|
||||
"### Get Room Data - Project\n",
|
||||
"This is a simple example how to get room data from models (branches) in project (stream)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%capture\n",
|
||||
"# capture turns off the output for this cell which would just be the pip install log\n",
|
||||
"%pip install specklepy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from specklepy.api.wrapper import StreamWrapper\n",
|
||||
"\n",
|
||||
"# Speckle Data Pack project (stream) link\n",
|
||||
"stream_url = \"https://speckle.xyz/streams/729cb7c74b\"\n",
|
||||
"\n",
|
||||
"# wrapper\n",
|
||||
"wrapper = StreamWrapper(stream_url)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from specklepy.api import operations\n",
|
||||
"\n",
|
||||
"# get project (stream) data\n",
|
||||
"stream = wrapper.get_client().stream.get(id=wrapper.stream_id, branch_limit=40)\n",
|
||||
"\n",
|
||||
"data = []\n",
|
||||
"\n",
|
||||
"# models (branches) to skip\n",
|
||||
"exclude_models = ['main', 'all_in_one']\n",
|
||||
"\n",
|
||||
"for branch in stream.branches.items:\n",
|
||||
" \n",
|
||||
" if branch.commits.items and branch.name not in exclude_models:\n",
|
||||
" # get obj id from the latest version (commit)\n",
|
||||
" obj_id = branch.commits.items[0].referencedObject\n",
|
||||
"\n",
|
||||
" # receive objects from speckle\n",
|
||||
" commit_data = operations.receive(\n",
|
||||
" obj_id=obj_id, remote_transport=wrapper.get_transport()\n",
|
||||
" )\n",
|
||||
" data.append(commit_data)\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# filter room data \n",
|
||||
"\n",
|
||||
"rooms = []\n",
|
||||
"\n",
|
||||
"for item in data: \n",
|
||||
"\n",
|
||||
" elements = item['elements']\n",
|
||||
"\n",
|
||||
" # get Rooms collection\n",
|
||||
" for el in elements:\n",
|
||||
" if el['name'] == 'Rooms':\n",
|
||||
" for r in el['elements']:\n",
|
||||
" rooms.append(r) \n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(6613.85, 33.07, 200)"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# calculate total and average rooms area\n",
|
||||
"\n",
|
||||
"total_area = 0\n",
|
||||
"count_rooms = 0\n",
|
||||
"\n",
|
||||
"for r in rooms:\n",
|
||||
" # filter rooms with no area in case of unplaced rooms\n",
|
||||
" if r['area'] != 0:\n",
|
||||
" total_area += r['area']\n",
|
||||
" count_rooms += 1\n",
|
||||
"\n",
|
||||
"average_area = total_area / count_rooms\n",
|
||||
"\n",
|
||||
"round(total_area,2), round(average_area,2), count_rooms\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.11"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
Загрузка…
Ссылка в новой задаче