Skip to content

Commit

Permalink
Fixed #196 (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
tieugene authored Dec 16, 2022
1 parent 2789261 commit d9ba349
Show file tree
Hide file tree
Showing 19 changed files with 90,338 additions and 44 deletions.
63 changes: 34 additions & 29 deletions iosc/core/mycomtrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:todo: exceptions
"""
# 1. std
from typing import Union
from typing import Union, Optional
import pathlib
# 2. 3rd
import chardet
Expand Down Expand Up @@ -166,49 +166,54 @@ def __load(self):
else:
self._raw.load(str(self.path))

def chk_gap_l(self) -> Optional[str]:
"""Check that OMP fits (left sife)"""
# FIXME: _sample.bad/short_L/live/R001_124-2014_05_26_05_09_46.cfg
# __gap_real: float = (self._raw.trigger_timestamp - self._raw.start_timestamp).total_seconds()
__gap_real = self._raw.trigger_time - self._raw.time[0]
__gap_min: float = 1 / self._raw.frequency
if __gap_real < __gap_min:
return ERR_DSC_GAPL % (__gap_min * 1000, __gap_real * 1000)

def chk_gap_r(self) -> Optional[str]:
"""Check that OMP fits (right sife)"""
__gap_real = self._raw.time[-1] - self._raw.trigger_time
__gap_min = 2 / self._raw.frequency
if __gap_real < __gap_min:
return ERR_DSC_GAPR % (__gap_min * 1000, __gap_real * 1000)

def __sanity_check(self):
"""
- rates (1, raw.total_samples, ?frequency)
- null values
:return:
"""

def __chk_freq():
def __chk_freq() -> Optional[str]:
"""Check freq = 50/60"""
if self._raw.cfg.frequency not in {50, 60}:
raise SanityChkError(ERR_DSC_FREQ % self._raw.cfg.frequency)
return ERR_DSC_FREQ % self._raw.cfg.frequency

def __chk_nrate(): # nrates
def __chk_nrate() -> Optional[str]: # nrates
"""Check that only 1 rate"""
if (nrates := self._raw.cfg.nrates) != 1:
raise SanityChkError(ERR_DSC_NRATES % nrates)
return ERR_DSC_NRATES % nrates

def __chk_rate_odd():
def __chk_rate_odd() -> Optional[str]:
"""Check that rate is deviding by main freq"""
if self.rate % self._raw.cfg.frequency:
raise SanityChkError(ERR_DSC_RATE_ODD % (self.rate, self._raw.cfg.frequency))

def __chk_gap_l():
"""Check that OMP fits (left sife)"""
# FIXME: _sample.bad/short_L/live/R001_124-2014_05_26_05_09_46.cfg
# __gap_real: float = (self._raw.trigger_timestamp - self._raw.start_timestamp).total_seconds()
__gap_real = self._raw.trigger_time - self._raw.time[0]
__gap_min: float = 1 / self._raw.frequency
if __gap_real < __gap_min:
raise SanityChkError(ERR_DSC_GAPL % (__gap_min * 1000, __gap_real * 1000))

def __chk_gap_r():
"""Check that OMP fits (right sife)"""
__gap_real = self._raw.time[-1] - self._raw.trigger_time
__gap_min = 2 / self._raw.frequency
if __gap_real < __gap_min:
raise SanityChkError(ERR_DSC_GAPR % (__gap_min * 1000, __gap_real * 1000))

__chk_freq()
__chk_nrate()
__chk_rate_odd()
__chk_gap_l()
__chk_gap_r()
return ERR_DSC_RATE_ODD % (self.rate, self._raw.cfg.frequency)

if e := __chk_freq():
raise SanityChkError(e)
if e := __chk_nrate():
raise SanityChkError(e)
if e := __chk_rate_odd():
raise SanityChkError(e)
# if e := self.chk_gap_l():
# raise SanityChkError(e)
# if e := self.chk_gap_r():
# raise SanityChkError(e)
# TODO: xz == sample ±½
# TODO: Δ samples == ±½ sample
# TODO: no null
Expand Down
22 changes: 13 additions & 9 deletions iosc/sig/mainwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class ComtradeWidget(QWidget):
col_ctrl_width: int
# inner vars
__main_ptr_i: int # current Main Ptr index in source arrays
__sc_ptr_i: int # current OMP SC Ptr index in source arrays
__sc_ptr_i: Optional[int] # current OMP SC Ptr index in source arrays
__tmp_ptr_i: dict[int, int] # current Tmp Ptr indexes in source arrays: ptr_uid => x_idx
msr_ptr_uids: set[int] # MsrPtr uids
lvl_ptr_uids: set[int] # LvlPtr uids
__omp_width: int # distance from OMP PR and SC pointers, periods
__omp_width: Optional[int] # distance from OMP PR and SC pointers, periods
__shifted: bool # original/shifted selector
x_zoom: int
show_sec: bool # pri/sec selector
Expand Down Expand Up @@ -99,11 +99,14 @@ def __init__(self, osc: mycomtrade.MyComtrade, parent: 'ComtradeTabWidget'):
self.osc = osc
self.col_ctrl_width = iosc.const.COL0_WIDTH_INIT
self.__main_ptr_i = self.x2i(0.0) # default: Z (Osc1: 600)
self.__sc_ptr_i = self.__main_ptr_i + 2 * self.osc.spp
if osc.chk_gap_l() or osc.chk_gap_r():
self.__sc_ptr_i = self.__omp_width = None
else:
self.__sc_ptr_i = self.__main_ptr_i + 2 * self.osc.spp
self.__omp_width = 3
self.__tmp_ptr_i = dict()
self.msr_ptr_uids = set()
self.lvl_ptr_uids = set()
self.__omp_width = 3
self.__shifted = False
self.x_zoom = len(iosc.const.X_PX_WIDTH_uS) - 1 # initial: max
self.show_sec = True
Expand Down Expand Up @@ -141,19 +144,20 @@ def main_ptr_x(self) -> float:
return self.i2x(self.__main_ptr_i)

@property
def sc_ptr_i(self) -> int: # Position of master (left) SC pointer
def sc_ptr_i(self) -> Optional[int]: # Position of master (left) SC pointer
return self.__sc_ptr_i

@property
def sc_ptr_x(self) -> float:
return self.i2x(self.__sc_ptr_i)
def sc_ptr_x(self) -> Optional[float]:
if self.__sc_ptr_i:
return self.i2x(self.__sc_ptr_i)

@property
def tmp_ptr_i(self) -> Dict[int, int]:
return self.__tmp_ptr_i

@property
def omp_width(self) -> int: # Distance between SC pointers, periods
def omp_width(self) -> Optional[int]: # Distance between SC pointers, periods
return self.__omp_width

@omp_width.setter
Expand Down Expand Up @@ -504,7 +508,7 @@ def __do_vector_diagram(self):
self.action_vector_diagram.setEnabled(False)
self.cvdwin.show()

def __do_harmonic_diagram(self, checked: bool):
def __do_harmonic_diagram(self):
if not self.hdwin:
self.hdwin = HDWindow(self)
self.action_harmonic_diagram.setEnabled(False)
Expand Down
9 changes: 5 additions & 4 deletions iosc/sig/pdfout/gsuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ def __helper(__item):
i_range = self.__plot.i_range
if i_range[0] <= (i := oscwin.main_ptr_i) <= i_range[1]: # 1. MainPtr
__helper(self.PtrItem(i, COLOR_PTR_MAIN, self.__plot))
if i_range[0] <= (i := oscwin.sc_ptr_i) <= i_range[1]: # 2. OMP ptrs
__helper(self.PtrItem(i, COLOR_PTR_OMP, self.__plot))
if i_range[0] <= (i := i - (oscwin.omp_width * oscwin.osc.spp)) <= i_range[1]:
__helper(self.PtrItem(i, COLOR_PTR_OMP, self.__plot))
if oscwin.sc_ptr_i:
if i_range[0] <= (i := oscwin.sc_ptr_i) <= i_range[1]: # 2. OMP ptrs
__helper(self.PtrItem(i, COLOR_PTR_OMP, self.__plot))
if i_range[0] <= (i := i - (oscwin.omp_width * oscwin.osc.spp)) <= i_range[1]:
__helper(self.PtrItem(i, COLOR_PTR_OMP, self.__plot))
for i in oscwin.tmp_ptr_i.values(): # 3. TmpPtr[]
if i_range[0] <= i <= i_range[1]:
__helper(self.PtrItem(i, COLOR_PTR_TMP, self.__plot, PENSTYLE_PTR_TMP))
Expand Down
6 changes: 4 additions & 2 deletions iosc/sig/widget/chart.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 1. std
from enum import IntEnum
from typing import Optional

# 2. 3rd
from PyQt5.QtCore import Qt, QMargins
from PyQt5.QtGui import QMouseEvent
Expand Down Expand Up @@ -82,7 +84,7 @@ def __slot_zoom_changed(self):
class BarPlot(QCustomPlot):
_oscwin: 'ComtradeWidget'
_main_ptr: MainPtr
_sc_ptr: SCPtr
_sc_ptr: Optional[SCPtr]
_tmp_ptr: dict[int, TmpPtr]
ptr_selected: bool

Expand All @@ -93,7 +95,7 @@ def __init__(self, parent: 'BarPlotWidget'):
self.__decorate()
self.__set_data()
self._main_ptr = MainPtr(self.graph(0), self._oscwin) # after graph()
self._sc_ptr = SCPtr(self.graph(0), self._oscwin)
self._sc_ptr = SCPtr(self.graph(0), self._oscwin) if self._oscwin.sc_ptr_i else None
self._tmp_ptr = dict() # FIXME: load existing
for uid in self._oscwin.tmp_ptr_i.keys():
self._slot_ptr_add_tmp(uid)
Expand Down
21 changes: 21 additions & 0 deletions samples/short_L/01.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
EMTDC_Simulation , 1,1999
12,12A, 0D
1, Ua1: Sub88,A,Sub88,kV, .270212E-05,-.885451E-01, .0, 0, 65535, 1.000000,1,S
2, Ub1: Sub88,B,Sub88,kV, .277414E-05,-.899979E-01, .0, 0, 65535, 1.000000,1,S
3, Uc1: Sub88,C,Sub88,kV, .270206E-05,-.885371E-01, .0, 0, 65535, 1.000000,1,S
4, Ia1: Sub88,A,Sub88,kA, .932928E-07,-.234279E-02, .0, 0, 65535, 1.000000,1,S
5, Ib1: Sub88,B,Sub88,kA, .522705E-07,-.185650E-02, .0, 0, 65535, 1.000000,1,S
6, Ic1: Sub88,C,Sub88,kA, .446956E-07,-.156161E-02, .0, 0, 65535, 1.000000,1,S
7, Ua2: Sub11A,A,Sub11A,kV, .306139E-05,-.100315 , .0, 0, 65535, 1.000000,1,S
8, Ub2: Sub11A,B,Sub11A,kV, .306138E-05,-.100313 , .0, 0, 65535, 1.000000,1,S
9, Uc2: Sub11A,C,Sub11A,kV, .306224E-05,-.100370 , .0, 0, 65535, 1.000000,1,S
10, Ia2: Sub11A,A,Sub11A,kA, .712932E-06,-.193543E-01, .0, 0, 65535, 1.000000,1,S
11, Ib2: Sub11A,B,Sub11A,kA, .113894E-06,-.435430E-02, .0, 0, 65535, 1.000000,1,S
12, Ic2: Sub11A,C,Sub11A,kA, .127568E-06,-.468892E-02, .0, 0, 65535, 1.000000,1,S
50
1
20000, 29999
26/03/2019,10:17:51.000000
26/03/2019,10:17:51.000000
ASCII
1
Loading

0 comments on commit d9ba349

Please sign in to comment.