We want to use an export-import option for our app.
To do so, I made a TableView and want to use the button with download csv.
Then there is another page where the csv can be uploaded.
This way it is possible to transfer input from say a production app to a development app for testing or create standard test input.
Problem I run into is that the geographic coordinates are rounded to 3 decimals. For latlon this is not sufficient. The geometry moves about 100 m to another location.
Is there an easier way to transfer input from one instance of an app to another? Or could this accuracy issue be solved?
Hi Thomas,
You could leverage VIKTOR’s API to transfer parameters from one workspace to another. Here is a snippet that could help you:
import viktor as vkt
import re
def parse_ids(url: str) -> tuple[int, int]:
pattern = r"/workspaces/(\d+)/app/editor/(\d+)"
m = re.search(pattern, url)
if m is None:
raise ValueError("URL does not match expected VIKTOR pattern")
workspace_id, entity_id = map(int, m.groups())
return workspace_id, entity_id
##### USER INPUT #####
PROJECT_A = f"https://my-company.viktor.ai/workspaces/234/app/editor/1714"
PROJECT_B = f"https://my-company.viktor.ai/workspaces/350/app/editor/3044"
ACESS_TOKEN = "vktrpat_xxxx"
######################
api = vkt.api_v1.API(token=ACESS_TOKEN)
# WORKSPACE_A
workspace_id_a, entity_id_a = parse_ids(PROJECT_A)
workspace_a = api.get_workspace(workspace_id_a)
entity_a = workspace_a.get_entity(entity_id_a)
params_a = entity_a.last_saved_params
# WORKSPACE_B
workspace_id_b, entity_id_b = parse_ids(PROJECT_B)
workspace_b = api.get_workspace(workspace_id_b)
entity_b = workspace_b.get_entity(entity_id_b)
entity_b.set_params(params_a)
print("Parameters transferred successfully!")
Thank you @mslootweg
I found another solution:
With DownloadResult(json.dumps(export, default=vars), "file_name.json")
the GeoPoints are reduced to dictionaries with lat and lon as keys and enough decimal places. These can then later be strung together to a GeoPolyline.
That works for me.