Bugfix for comparing of physical quantities
This commit is contained in:
parent
ab1edaa530
commit
aaf6597776
@ -1,12 +1,13 @@
|
|||||||
__all__ = ['DaqChannel']
|
__all__ = ['DaqChannel']
|
||||||
from ..lasp_common import Qty, SIQtys
|
import json, logging
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from dataclasses_json import dataclass_json
|
|
||||||
from typing import List
|
from typing import List
|
||||||
import json
|
from dataclasses_json import dataclass_json
|
||||||
|
from ..lasp_common import Qty, SIQtys
|
||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
@dataclass_json
|
||||||
@dataclass
|
@dataclass(eq=False)
|
||||||
class DaqChannel:
|
class DaqChannel:
|
||||||
channel_enabled: bool
|
channel_enabled: bool
|
||||||
channel_name: str = 'Unnamed channel'
|
channel_name: str = 'Unnamed channel'
|
||||||
@ -17,12 +18,12 @@ class DaqChannel:
|
|||||||
channel_metadata: str = ''
|
channel_metadata: str = ''
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
|
# logging.debug(f'__post_init__({self.channel_name})')
|
||||||
|
self._qty = SIQtys.default()
|
||||||
if len(self.channel_metadata) > 0:
|
if len(self.channel_metadata) > 0:
|
||||||
meta = json.loads(self.channel_metadata)
|
meta = json.loads(self.channel_metadata)
|
||||||
if '_qty' in meta:
|
if 'qty' in meta:
|
||||||
self._qty = Qty.from_json(meta['_qty'])
|
self._qty = Qty.from_json(meta['qty'])
|
||||||
else:
|
|
||||||
self._qty = SIQtys.default
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def qty(self):
|
def qty(self):
|
||||||
@ -31,7 +32,7 @@ class DaqChannel:
|
|||||||
@qty.setter
|
@qty.setter
|
||||||
def qty(self, newqty):
|
def qty(self, newqty):
|
||||||
self._qty = newqty
|
self._qty = newqty
|
||||||
self._store('_qty', newqty)
|
self._store('qty', newqty)
|
||||||
|
|
||||||
def _store(self, name, val):
|
def _store(self, name, val):
|
||||||
if len(self.channel_metadata) > 0:
|
if len(self.channel_metadata) > 0:
|
||||||
@ -42,3 +43,15 @@ class DaqChannel:
|
|||||||
meta[name] = val.to_json()
|
meta[name] = val.to_json()
|
||||||
self.channel_metadata = json.dumps(meta)
|
self.channel_metadata = json.dumps(meta)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
"""
|
||||||
|
We overwrite the default equal-check as the floating point values
|
||||||
|
cannot be exactly checked due to conversion from/to JSON
|
||||||
|
"""
|
||||||
|
return (self.channel_enabled == other.channel_enabled and
|
||||||
|
self.channel_name == other.channel_name and
|
||||||
|
self.range_index == other.range_index and
|
||||||
|
self.ACCoupling_enabled == other.ACCoupling_enabled and
|
||||||
|
self.IEPE_enabled == other.IEPE_enabled and
|
||||||
|
self.channel_metadata == other.channel_metadata)
|
||||||
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os, platform
|
import shelve, logging, sys, appdirs, os, platform
|
||||||
import shelve
|
|
||||||
import sys
|
|
||||||
import appdirs
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from .wrappers import Window as wWindow
|
from .wrappers import Window as wWindow
|
||||||
@ -59,21 +56,36 @@ class AvType(Enum):
|
|||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
@dataclass_json
|
||||||
@dataclass
|
@dataclass(eq=False)
|
||||||
class Qty:
|
class Qty:
|
||||||
name: str
|
name: str
|
||||||
unit_name: str
|
unit_name: str
|
||||||
unit_symb: str
|
unit_symb: str
|
||||||
level_unit: str
|
level_unit: object
|
||||||
level_ref_name: str
|
# Contains a tuple of possible level names, including its reference value.
|
||||||
level_ref_value: str
|
# For now, it is only able to compute for the first one. I.e.e we are not
|
||||||
|
# yet able to compute `dBPa's'
|
||||||
|
level_ref_name: object
|
||||||
|
level_ref_value: object
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name + f' [{self.unit_symb}]'
|
return f'{self.name} [{self.unit_symb}]'
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
# logging.debug('eq()')
|
||||||
|
"""
|
||||||
|
Comparison breaks for the other objects, level unit, level ref name,
|
||||||
|
etc as these are tuples / a single string.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return (self.name == other.name and
|
||||||
|
self.unit_name == other.unit_name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SIQtys:
|
|
||||||
|
@unique
|
||||||
|
class SIQtys(Enum):
|
||||||
N = Qty(name='Number',
|
N = Qty(name='Number',
|
||||||
unit_name='No unit / full scale',
|
unit_name='No unit / full scale',
|
||||||
unit_symb='-',
|
unit_symb='-',
|
||||||
@ -96,9 +108,6 @@ class SIQtys:
|
|||||||
level_ref_name=('1V',),
|
level_ref_name=('1V',),
|
||||||
level_ref_value=(1.0,),
|
level_ref_value=(1.0,),
|
||||||
)
|
)
|
||||||
types = (N, AP, V)
|
|
||||||
default = N
|
|
||||||
default_index = 0
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fillComboBox(cb):
|
def fillComboBox(cb):
|
||||||
@ -109,20 +118,18 @@ class SIQtys:
|
|||||||
cb: QComboBox to fill
|
cb: QComboBox to fill
|
||||||
"""
|
"""
|
||||||
cb.clear()
|
cb.clear()
|
||||||
for ty in SIQtys.types:
|
for ty in SIQtys:
|
||||||
cb.addItem(f'{ty.unit_name}')
|
cb.addItem(f'{ty.value.unit_name}')
|
||||||
cb.setCurrentIndex(SIQtys.default_index)
|
cb.setCurrentIndex(0)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default():
|
||||||
|
return SIQtys.N.value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getCurrent(cb):
|
def getCurrent(cb):
|
||||||
return SIQtys.types[cb.currentIndex()]
|
return list(SIQtys)[cb.currentIndex()]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def getIndex(qty):
|
|
||||||
for i, qtyi in enumerate(SIQtys.types):
|
|
||||||
if qtyi == qty:
|
|
||||||
return i
|
|
||||||
return -1
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CalSetting:
|
class CalSetting:
|
||||||
|
Loading…
Reference in New Issue
Block a user