Skip to content

Commit 2f6f4e2

Browse files
authored
Merge pull request #5 from AM1729/main
fixes geometry defn &comma with ,
2 parents bc10108 + 5bed072 commit 2f6f4e2

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

klab/engine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def post(self, endpoint:str, request: any, pathVariables:list = None):
152152
jsonResponse = response.json()
153153
return jsonResponse
154154

155+
155156
def makeUrl(self, endpoint, parameters=[]):
156157
parms = ""
157158
if parameters:

klab/geometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def encodeVal(val: any):
506506
ret += sp + str(v)
507507
ret += "]"
508508
else:
509-
ret = str(val)
509+
ret = KlabGeometry.decodeForSerialization(str(val))
510510

511511
return ret
512512

klab/observation.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,23 @@ def __init__(self, urn: str = None, contextId: str = None, contextSearchId: str
165165
self._states = {}
166166
self._objects = {}
167167

168+
def toDict(self):
169+
ret = {
170+
"urn": self._urn,
171+
"contextId": self._contextId,
172+
"estimate": self._estimate,
173+
"estimatedCost": self._estimatedCost,
174+
"scenarios": list(self._scenarios), # ensure it's a list
175+
"states": list(self._states),
176+
"objects": list(self._objects)
177+
}
178+
179+
# Include searchContextId if present
180+
if getattr(self, "searchContextId", None):
181+
ret["contextSearchId"] = self.searchContextId
182+
183+
return ret
184+
168185
def toJson(self):
169186
es = str(self._estimate).lower()
170187

@@ -263,17 +280,28 @@ def __init__(self) -> None:
263280
self._estimate = False
264281
self._estimatedCost = -1
265282

283+
def toDict(self):
284+
return {
285+
"urn": self._urn,
286+
"geometry": self._geometry,
287+
"contextType": self._contextType,
288+
"observables": [str(o) for o in self._observables],
289+
"scenarios": [str(s) for s in self._scenarios],
290+
"estimate": self._estimate,
291+
"estimatedCost": self._estimatedCost
292+
}
293+
266294
def toJson(self):
267295
es = str(self._estimate).lower()
268-
269296
obs = [str(o) for o in self._observables]
270297
obs = str(obs).replace("'", "\"")
271298
scen = [str(s) for s in self._scenarios]
272299
scen = str(scen).replace("'", "\"")
300+
urn = "null" if self._urn is None else self._urn
273301

274-
ret = """{{"geometry":"{0}","contextType":"{1}","observables":{2},"scenarios":{3},"estimate":{4},"estimatedCost":{5}}}"""
302+
ret = """{{"geometry":"{0}","contextType":"{1}","observables":{2},"scenarios":{3},"estimate":{4},"estimatedCost":{5}, "urn": {6}}}"""
275303
ret = ret.format(self._geometry, self._contextType,
276-
obs, scen, es, self._estimatedCost)
304+
obs, scen, es, self._estimatedCost, urn)
277305

278306
ret = ret.encode('utf-8').decode('unicode-escape')
279307
return ret

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "klab-client-py"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "Python client to interact with a running k.LAB Engine."
55
authors = [
66
{name = "Ferdinando Villa"},

0 commit comments

Comments
 (0)