orca-python 0.7.3__tar.gz → 0.7.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: orca-python
3
- Version: 0.7.3
3
+ Version: 0.7.4
4
4
  Summary: Python SDK for the Predixus Orca product
5
5
  Author: Frederick Mannings
6
6
  Author-email: contact@predixus.com
@@ -415,61 +415,37 @@ class Processor(OrcaProcessorServicer): # type: ignore
415
415
 
416
416
  algoResult = await loop.run_in_executor(None, algo.exec_fn, params)
417
417
 
418
- # create result based on the return type
419
- current_time = int(time.time()) # Current timestamp in seconds
420
-
421
- if isinstance(algoResult, dict):
422
- # for dictionary results, use struct_value
418
+ # depending on algo result type, map to whatever instance
419
+ if algo.result_type == StructResult: # type: ignore
423
420
  struct_value = struct_pb2.Struct()
424
- json_format.ParseDict(algoResult, struct_value)
421
+ json_format.ParseDict(algoResult.value, struct_value)
425
422
 
426
423
  resultPb = pb.Result(
427
- status=pb.ResultStatus.RESULT_STATUS_SUCEEDED, # Note: Using the actual enum from the proto
424
+ status=pb.ResultStatus.RESULT_STATUS_SUCEEDED,
428
425
  struct_value=struct_value,
429
- timestamp=current_time,
430
426
  )
431
- elif isinstance(algoResult, float) or isinstance(algoResult, int):
427
+
428
+ elif algo.result_type == ValueResult: # type: ignore
432
429
  # for single numeric values
433
430
  resultPb = pb.Result(
434
431
  status=pb.ResultStatus.RESULT_STATUS_SUCEEDED,
435
- single_value=float(algoResult), # Convert to float as per proto
436
- timestamp=current_time,
432
+ single_value=algoResult.value,
437
433
  )
438
- elif isinstance(algoResult, list) and all(
439
- isinstance(x, (int, float)) for x in algoResult
440
- ):
434
+ elif algo.result_type == ArrayResult: # type: ignore
441
435
  # for lists of numeric values
442
436
  float_array = pb.FloatArray(values=algoResult)
443
437
  resultPb = pb.Result(
444
438
  status=pb.ResultStatus.RESULT_STATUS_SUCEEDED,
445
- float_values=float_array,
446
- timestamp=current_time,
439
+ float_values=float_array.values,
447
440
  )
448
441
  else:
449
- # try to convert to struct as a fallback
450
- try:
451
- struct_value = struct_pb2.Struct()
452
- # convert to dict if possible, otherwise use string representation
453
- if hasattr(algoResult, "__dict__"):
454
- result_dict = algoResult.__dict__
455
- else:
456
- result_dict = {"value": str(algoResult)}
457
-
458
- json_format.ParseDict(result_dict, struct_value)
459
- resultPb = pb.Result(
460
- status=pb.ResultStatus.RESULT_STATUS_SUCEEDED,
461
- struct_value=struct_value,
462
- timestamp=current_time,
463
- )
464
- except Exception as conv_error:
465
- LOGGER.error(
466
- f"Failed to convert result to protobuf: {str(conv_error)}"
467
- )
468
- # create a handled failure result
469
- resultPb = pb.Result(
470
- status=pb.ResultStatus.RESULT_STATUS_HANDLED_FAILED,
471
- timestamp=current_time,
472
- )
442
+ LOGGER.error(
443
+ f"Algorithm {algo.name} {algo.version} has unhandled return type {algo.result_type}"
444
+ )
445
+ # create a handled failure result
446
+ resultPb = pb.Result(
447
+ status=pb.ResultStatus.RESULT_STATUS_HANDLED_FAILED,
448
+ )
473
449
 
474
450
  # create the algorithm result
475
451
  algoResultPb = pb.AlgorithmResult(
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "orca-python"
3
- version = "0.7.3"
3
+ version = "0.7.4"
4
4
  description = "Python SDK for the Predixus Orca product"
5
5
  authors = [
6
6
  "Frederick Mannings <contact@predixus.com>"
File without changes
File without changes