operations in order

This commit is contained in:
KatKatKateryna
2024-09-24 01:17:39 +02:00
parent 079e8e5dda
commit 4e43085ef2
6 changed files with 43 additions and 6 deletions
+12 -2
View File
@@ -119,11 +119,16 @@ class SpeckleProvider(BaseProvider):
self.speckle_url = self.url.lower().split("speckleurl=")[-1].split("&")[0].split("@")[0].split("?")[0]
self.speckle_data = None
self.project_name = ""
self.model_name = ""
self.crs = None
self.crs_dict = None
self.commit_gis = False
self.url_params = {"url_data_type":"", "url_preserve_attributes":"", "url_crs_authid":"", "url_lat":"","url_lon":"","url_north_degrees":"","url_limit":""}
self.times = {}
self.requested_data_type: str = "polygons (default)" # points, lines, polygons, projectcomments
self.preserve_attributes: str = "true (default)"
self.lat: float = 48.76755913928929 #51.52486388756923
@@ -338,7 +343,7 @@ class SpeckleProvider(BaseProvider):
def load_speckle_data(self: str) -> Dict:
"""Receive and process Speckle data, return geojson."""
from pygeoapi.provider.speckle_utils.server_utils import get_stream_branch, get_client, get_comments
from pygeoapi.provider.speckle_utils.server_utils import get_stream_branch, get_client, get_comments, set_actions
from specklepy.objects.base import Base
from specklepy.logging.exceptions import SpeckleException
@@ -368,6 +373,7 @@ class SpeckleProvider(BaseProvider):
comments = {}
# set the Model name
self.project_name = stream['name']
self.model_name = branch['name']
commit = branch["commits"]["items"][0]
@@ -394,6 +400,7 @@ class SpeckleProvider(BaseProvider):
print(f"Rendering model '{branch['name']}' of the project '{stream['name']}'")
speckle_data = self.traverse_data(commit_obj, comments)
set_actions(self, client)
speckle_data["features"].extend(speckle_data["comments"])
speckle_data["comments"] = []
@@ -473,7 +480,10 @@ class SpeckleProvider(BaseProvider):
sorted_list[i]["properties"]["FID"] = i+1
data['features'] = sorted_list
time2 = datetime.now()
print(f"Sorting time: {(time2-time1).total_seconds()}")
time_operation = (time2-time1).total_seconds()
self.times["time_sort"] = time_operation
print(f"Sorting time: {time_operation}")
return data
@@ -13,7 +13,10 @@ def reproject_bulk(self, all_coords: List[List[List[float]]], all_coord_counts:
time1 = datetime.now()
flat_coords = reproject_2d_coords_list(self, all_coords)
time2 = datetime.now()
print(f"Reproject time: {(time2-time1).total_seconds()}")
time_operation = (time2-time1).total_seconds()
self.times["time_reproject"] = time_operation
print(f"Reproject time: {time_operation}")
# define type of features
feat_coord_group_is_multi = [True if None in x else False for x in all_coord_counts]
@@ -61,7 +64,10 @@ def reproject_bulk(self, all_coords: List[List[List[float]]], all_coord_counts:
geometry["coordinates"].extend(polygon_parts)
time3 = datetime.now()
print(f"Construct back geometry time: {(time3-time2).total_seconds()}")
time_operation = (time3-time2).total_seconds()
self.times["time_reconstruct_geometry"] = time_operation
print(f"Construct back geometry time: {time_operation}")
def reproject_2d_coords_list(self, coords_in: List[List[float]]) -> List[List[float]]:
"""Return coordinates in a CRS of SpeckleProvider."""
@@ -73,6 +73,7 @@ def get_set_crs_settings(self: "SpeckleProvider", commit_obj: "Base", context_li
offset_y = crs["offset_y"]
self.north_degrees = crs["rotation"]
create_crs_from_wkt(self, crs["wkt"])
self.commit_gis = True
if self.crs.to_authority() is not None:
data["model_crs"] = f"{self.crs.to_authority()}, {self.crs.name} "
@@ -173,7 +173,10 @@ def initialize_features(self: "SpeckleProvider", all_coords, all_coord_counts, d
time2 = datetime.now()
print(f"_____UTC time: {time2.astimezone(timezone.utc)}")
print(f"Creating features time: {(time2-time1).total_seconds()}")
time_operation = (time2-time1).total_seconds()
self.times["time_creating_features"] = time_operation
print(f"Creating features time: {time_operation}")
def get_feature_bbox(coords) -> List[float]:
"""Get min max coordinates of the feature."""
@@ -216,4 +216,14 @@ def get_attachment(project_id: str, attachment_id: str, attachment_name: str) ->
raise Exception(
f"Request not successful: Response code {r.status_code}"
)
def set_actions(self: "SpeckleProvider", client: "SpeckleClient"):
from specklepy.logging.metrics import track
try:
full_dict = {**self.url_params, **self.times}
full_dict["GIS commit"] = self.commit_gis
full_dict["model"] = f"{self.project_name}, {self.model_name}"
full_dict["time_TOTAL"] = sum([x[1] for x in self.times.items()])
track("GEO receive", client.account, full_dict)
except:
pass
@@ -31,6 +31,7 @@ def get_set_url_parameters(self: "SpeckleProvider"):
requested_data_type = item.split("datatype=")[1]
if requested_data_type in ["points", "lines", "polygons", "projectcomments"]:
self.requested_data_type = requested_data_type
self.url_params["url_data_type"] = requested_data_type
except:
raise ValueError(f"Provide valid dataType parameter (points/lines/polygons/projectcomments): {item}")
@@ -39,6 +40,7 @@ def get_set_url_parameters(self: "SpeckleProvider"):
preserve_attributes = item.split("preserveattributes=")[1]
if preserve_attributes in ["true", "false"]:
self.preserve_attributes = preserve_attributes
self.url_params["url_preserve_attributes"] = preserve_attributes
except:
ValueError(f"Provide valid preserverAttributes parameter (true/false): {item}")
@@ -47,23 +49,27 @@ def get_set_url_parameters(self: "SpeckleProvider"):
if isinstance(crs_authid, str) and len(crs_authid)>3:
crsauthid = True
self.crs_authid = crs_authid
self.url_params["url_crs_authid"] = crs_authid
elif "lat=" in item:
try:
lat = float(item.split("lat=")[1])
self.lat = lat
self.url_params["url_lat"] = lat
except:
raise ValueError(f"Invalid Lat input, must be numeric: {item}")
elif "lon=" in item:
try:
lon = float(item.split("lon=")[1])
self.lon = lon
self.url_params["url_lon"] = lon
except:
raise ValueError(f"Invalid Lon input, must be numeric: {item}")
elif "northdegrees=" in item:
try:
north_degrees = float(item.split("northdegrees=")[1])
self.north_degrees = north_degrees
self.url_params["url_north_degrees"] = north_degrees
except:
raise ValueError(f"Invalid northDegrees input, must be numeric: {item}")
elif "limit=" in item:
@@ -71,6 +77,7 @@ def get_set_url_parameters(self: "SpeckleProvider"):
limit = int(item.split("limit=")[1])
if limit>0:
self.limit = limit
self.url_params["url_limit"] = limit
except:
ValueError(f"Invalid limit input, must be a positive integer: {item}")