跳转至

Instrument

labridge.func_modules.reference.instrument

labridge.func_modules.reference.instrument.InstrumentInfo

Bases: RefInfoBase

This class contains the information of an instrument, including:

PARAMETER DESCRIPTION
instrument_id

The name of the instrument.

TYPE: str

super_users

The super-users of the instrument.

TYPE: List[str]

Source code in labridge\func_modules\reference\instrument.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class InstrumentInfo(RefInfoBase):
	r"""
	This class contains the information of an instrument, including:

	Args:
		instrument_id (str): The name of the instrument.
		super_users (List[str]): The super-users of the instrument.
	"""
	def __init__(
		self,
		instrument_id: str,
		super_users: List[str],
	):
		self.instrument_id = instrument_id
		self.super_users = super_users
		super().__init__()

	def dumps(self) -> str:
		r""" Dump to a string in JSON format. """
		info_dict = {
			REF_TYPE: InstrumentInfo.__name__,
			"instrument_id": self.instrument_id,
			"super_users": self.super_users,
		}
		return json.dumps(info_dict)

	@classmethod
	def loads(
		cls,
		info_str: str,
	):
		r""" Load from a string in JSON format. """
		try:
			info_dict = json.loads(info_str)
			instrument_id = info_dict["instrument_id"]
			super_users = info_dict["super_users"]
			return cls(
				instrument_id=instrument_id,
				super_users=super_users,
			)
		except Exception:
			raise ValueError("Invalid Instrument info string.")

labridge.func_modules.reference.instrument.InstrumentInfo.dumps()

Dump to a string in JSON format.

Source code in labridge\func_modules\reference\instrument.py
25
26
27
28
29
30
31
32
def dumps(self) -> str:
	r""" Dump to a string in JSON format. """
	info_dict = {
		REF_TYPE: InstrumentInfo.__name__,
		"instrument_id": self.instrument_id,
		"super_users": self.super_users,
	}
	return json.dumps(info_dict)

labridge.func_modules.reference.instrument.InstrumentInfo.loads(info_str) classmethod

Load from a string in JSON format.

Source code in labridge\func_modules\reference\instrument.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@classmethod
def loads(
	cls,
	info_str: str,
):
	r""" Load from a string in JSON format. """
	try:
		info_dict = json.loads(info_str)
		instrument_id = info_dict["instrument_id"]
		super_users = info_dict["super_users"]
		return cls(
			instrument_id=instrument_id,
			super_users=super_users,
		)
	except Exception:
		raise ValueError("Invalid Instrument info string.")