Skip to content

Commit

Permalink
Use dataclass to convert dict to class for Magnetic 3d graph data.
Browse files Browse the repository at this point in the history
  • Loading branch information
james-packer committed Oct 23, 2024
1 parent 3f69c7c commit 7488c2f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/ansys/motorcad/core/methods/rpc_methods_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@
# SOFTWARE.

"""RPC methods for graphs."""
from dataclasses import dataclass

from ansys.motorcad.core.rpc_client_core import MotorCADError


@dataclass
class Magnetic3dGraph:
"""Class for x, y and data from a magnetic 3d graph."""

x: list
y: list
data: list


class _RpcMethodsGraphs:
def __init__(self, mc_connection):
self.connection = mc_connection
Expand Down Expand Up @@ -312,10 +323,11 @@ def get_magnetic_3d_graph(self, graph_name, slice_number):
Returns
-------
dict
Dictionary of x, y and data
Magnetic3dGraph
Class containing x, y and data as lists
"""
self.connection.ensure_version_at_least("2025.0")
method = "GetMagnetic3DGraph"
params = [{"variant": graph_name}, slice_number]
return self.connection.send_and_receive(method, params)
graph_3d_dict = self.connection.send_and_receive(method, params)
return Magnetic3dGraph(**graph_3d_dict)

0 comments on commit 7488c2f

Please sign in to comment.