Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -84,3 +84,61 @@ def updateStreamAnalysisFast(client, new_data, stream_id, branch_name, geometryG
|
|
| 84 |
print("commit created")
|
| 85 |
if return_original:
|
| 86 |
return objects_raw # as back-up
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
print("commit created")
|
| 85 |
if return_original:
|
| 86 |
return objects_raw # as back-up
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def getSpeckleStream(stream_id,
|
| 90 |
+
branch_name,
|
| 91 |
+
client,
|
| 92 |
+
commit_id=""
|
| 93 |
+
):
|
| 94 |
+
"""
|
| 95 |
+
Retrieves data from a specific branch of a speckle stream.
|
| 96 |
+
Args:
|
| 97 |
+
stream_id (str): The ID of the speckle stream.
|
| 98 |
+
branch_name (str): The name of the branch within the speckle stream.
|
| 99 |
+
client (specklepy.api.client.Client, optional): A speckle client. Defaults to a global `client`.
|
| 100 |
+
commit_id (str): id of a commit, if nothing is specified, the latest commit will be fetched
|
| 101 |
+
Returns:
|
| 102 |
+
dict: The speckle stream data received from the specified branch.
|
| 103 |
+
This function retrieves the last commit from a specific branch of a speckle stream.
|
| 104 |
+
It uses the provided speckle client to get the branch and commit information, and then
|
| 105 |
+
retrieves the speckle stream data associated with the last commit.
|
| 106 |
+
It prints out the branch details and the creation dates of the last three commits for debugging purposes.
|
| 107 |
+
"""
|
| 108 |
+
|
| 109 |
+
print("updated A")
|
| 110 |
+
|
| 111 |
+
# set stream and branch
|
| 112 |
+
try:
|
| 113 |
+
branch = client.branch.get(stream_id, branch_name, 3)
|
| 114 |
+
print(branch)
|
| 115 |
+
except:
|
| 116 |
+
branch = client.branch.get(stream_id, branch_name, 1)
|
| 117 |
+
print(branch)
|
| 118 |
+
|
| 119 |
+
print("last three commits:")
|
| 120 |
+
[print(ite.createdAt) for ite in branch.commits.items]
|
| 121 |
+
|
| 122 |
+
if commit_id == "":
|
| 123 |
+
latest_commit = branch.commits.items[0]
|
| 124 |
+
choosen_commit_id = latest_commit.id
|
| 125 |
+
commit = client.commit.get(stream_id, choosen_commit_id)
|
| 126 |
+
print("latest commit ", branch.commits.items[0].createdAt, " was choosen")
|
| 127 |
+
elif type(commit_id) == type("s"): # string, commit uuid
|
| 128 |
+
choosen_commit_id = commit_id
|
| 129 |
+
commit = client.commit.get(stream_id, choosen_commit_id)
|
| 130 |
+
print("provided commit ", choosen_commit_id, " was choosen")
|
| 131 |
+
elif type(commit_id) == type(1): #int
|
| 132 |
+
latest_commit = branch.commits.items[commit_id]
|
| 133 |
+
choosen_commit_id = latest_commit.id
|
| 134 |
+
commit = client.commit.get(stream_id, choosen_commit_id)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
print(commit)
|
| 138 |
+
print(commit.referencedObject)
|
| 139 |
+
# get transport
|
| 140 |
+
transport = ServerTransport(client=client, stream_id=stream_id)
|
| 141 |
+
#speckle stream
|
| 142 |
+
res = operations.receive(commit.referencedObject, transport)
|
| 143 |
+
|
| 144 |
+
return res
|