Skip to content

Commit

Permalink
Merge pull request #24 from domarm-comat/dc_append_array
Browse files Browse the repository at this point in the history
Append data array
  • Loading branch information
domarm-comat authored Jul 19, 2023
2 parents 27fe005 + a753b29 commit 672b185
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 124 deletions.
51 changes: 51 additions & 0 deletions pglive/examples_pyqt5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ def sin_wave_generator(*data_connectors, flip=False):
sleep(0.01)


def sin_wave_array_generator(*data_connectors, flip=False, points=10):
"""Sine wave generator"""
x = 0
while running:
for data_connector in data_connectors:
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)),
[sin((x + xi) * 0.025) for xi in range(points)])
else:
data_connector.cb_append_data_array([sin((x + xi) * 0.025) for xi in range(points)],
list(range(x, x + points)))
x += points
sleep(0.01)


def cos_wave_generator(*data_connectors, flip=False):
"""Cosine wave generator"""
x = 0
Expand Down Expand Up @@ -62,6 +77,28 @@ def candle_generator(*data_connectors, flip=False):
sleep(0.01)


def candle_array_generator(*data_connectors, flip=False, points=10):
"""Candle stick generator"""
x = 0

def candle(xc):
a, b = sin(xc * 0.025), sin(xc * 0.020)
s = min(a, b) - random.randint(0, 1000) * 1e-3
e = max(a, b) + random.randint(0, 1000) * 1e-3
return (a, b, s, e)

while running:
for data_connector in data_connectors:
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)),
[candle(x + xi) for xi in range(points)])
else:
data_connector.cb_append_data_array([candle(x + xi) for xi in range(points)],
list(range(x, x + points)))
x += 1
sleep(0.01)


def category_generator(*data_connectors, categories: List, flip: bool = False):
"""Category generator"""
x = 0
Expand All @@ -76,6 +113,20 @@ def category_generator(*data_connectors, categories: List, flip: bool = False):
sleep(0.01)


def category_array_generator(*data_connectors, categories: List, flip: bool = False, points=10):
"""Category generator"""
x = 0
while running:
for data_connector in data_connectors:
random_categories = [random.sample(categories, random.randint(0, len(categories))) for xi in range(points)]
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)), random_categories)
else:
data_connector.cb_append_data_array(random_categories, list(range(x, x + points)))
x += 1
sleep(0.01)


def colors():
"""Primitive color cycler"""
while True:
Expand Down
51 changes: 51 additions & 0 deletions pglive/examples_pyqt6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ def sin_wave_generator(*data_connectors, flip=False):
sleep(0.01)


def sin_wave_array_generator(*data_connectors, flip=False, points=10):
"""Sine wave generator"""
x = 0
while running:
for data_connector in data_connectors:
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)),
[sin((x + xi) * 0.025) for xi in range(points)])
else:
data_connector.cb_append_data_array([sin((x + xi) * 0.025) for xi in range(points)],
list(range(x, x + points)))
x += points
sleep(0.01)


def cos_wave_generator(*data_connectors, flip=False):
"""Cosine wave generator"""
x = 0
Expand Down Expand Up @@ -62,6 +77,28 @@ def candle_generator(*data_connectors, flip=False):
sleep(0.01)


def candle_array_generator(*data_connectors, flip=False, points=10):
"""Candle stick generator"""
x = 0

def candle(xc):
a, b = sin(xc * 0.025), sin(xc * 0.020)
s = min(a, b) - random.randint(0, 1000) * 1e-3
e = max(a, b) + random.randint(0, 1000) * 1e-3
return (a, b, s, e)

while running:
for data_connector in data_connectors:
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)),
[candle(x + xi) for xi in range(points)])
else:
data_connector.cb_append_data_array([candle(x + xi) for xi in range(points)],
list(range(x, x + points)))
x += 1
sleep(0.01)


def category_generator(*data_connectors, categories: List, flip: bool = False):
"""Category generator"""
x = 0
Expand All @@ -76,6 +113,20 @@ def category_generator(*data_connectors, categories: List, flip: bool = False):
sleep(0.01)


def category_array_generator(*data_connectors, categories: List, flip: bool = False, points=10):
"""Category generator"""
x = 0
while running:
for data_connector in data_connectors:
random_categories = [random.sample(categories, random.randint(0, len(categories))) for xi in range(points)]
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)), random_categories)
else:
data_connector.cb_append_data_array(random_categories, list(range(x, x + points)))
x += 1
sleep(0.01)


def colors():
"""Primitive color cycler"""
while True:
Expand Down
51 changes: 51 additions & 0 deletions pglive/examples_pyside2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ def sin_wave_generator(*data_connectors, flip=False):
sleep(0.01)


def sin_wave_array_generator(*data_connectors, flip=False, points=10):
"""Sine wave generator"""
x = 0
while running:
for data_connector in data_connectors:
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)),
[sin((x + xi) * 0.025) for xi in range(points)])
else:
data_connector.cb_append_data_array([sin((x + xi) * 0.025) for xi in range(points)],
list(range(x, x + points)))
x += points
sleep(0.01)


def cos_wave_generator(*data_connectors, flip=False):
"""Cosine wave generator"""
x = 0
Expand Down Expand Up @@ -62,6 +77,28 @@ def candle_generator(*data_connectors, flip=False):
sleep(0.01)


def candle_array_generator(*data_connectors, flip=False, points=10):
"""Candle stick generator"""
x = 0

def candle(xc):
a, b = sin(xc * 0.025), sin(xc * 0.020)
s = min(a, b) - random.randint(0, 1000) * 1e-3
e = max(a, b) + random.randint(0, 1000) * 1e-3
return (a, b, s, e)

while running:
for data_connector in data_connectors:
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)),
[candle(x + xi) for xi in range(points)])
else:
data_connector.cb_append_data_array([candle(x + xi) for xi in range(points)],
list(range(x, x + points)))
x += 1
sleep(0.01)


def category_generator(*data_connectors, categories: List, flip: bool = False):
"""Category generator"""
x = 0
Expand All @@ -76,6 +113,20 @@ def category_generator(*data_connectors, categories: List, flip: bool = False):
sleep(0.01)


def category_array_generator(*data_connectors, categories: List, flip: bool = False, points=10):
"""Category generator"""
x = 0
while running:
for data_connector in data_connectors:
random_categories = [random.sample(categories, random.randint(0, len(categories))) for xi in range(points)]
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)), random_categories)
else:
data_connector.cb_append_data_array(random_categories, list(range(x, x + points)))
x += 1
sleep(0.01)


def colors():
"""Primitive color cycler"""
while True:
Expand Down
51 changes: 51 additions & 0 deletions pglive/examples_pyside6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ def sin_wave_generator(*data_connectors, flip=False):
sleep(0.01)


def sin_wave_array_generator(*data_connectors, flip=False, points=10):
"""Sine wave generator"""
x = 0
while running:
for data_connector in data_connectors:
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)),
[sin((x + xi) * 0.025) for xi in range(points)])
else:
data_connector.cb_append_data_array([sin((x + xi) * 0.025) for xi in range(points)],
list(range(x, x + points)))
x += points
sleep(0.01)


def cos_wave_generator(*data_connectors, flip=False):
"""Cosine wave generator"""
x = 0
Expand Down Expand Up @@ -62,6 +77,28 @@ def candle_generator(*data_connectors, flip=False):
sleep(0.01)


def candle_array_generator(*data_connectors, flip=False, points=10):
"""Candle stick generator"""
x = 0

def candle(xc):
a, b = sin(xc * 0.025), sin(xc * 0.020)
s = min(a, b) - random.randint(0, 1000) * 1e-3
e = max(a, b) + random.randint(0, 1000) * 1e-3
return (a, b, s, e)

while running:
for data_connector in data_connectors:
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)),
[candle(x + xi) for xi in range(points)])
else:
data_connector.cb_append_data_array([candle(x + xi) for xi in range(points)],
list(range(x, x + points)))
x += 1
sleep(0.01)


def category_generator(*data_connectors, categories: List, flip: bool = False):
"""Category generator"""
x = 0
Expand All @@ -76,6 +113,20 @@ def category_generator(*data_connectors, categories: List, flip: bool = False):
sleep(0.01)


def category_array_generator(*data_connectors, categories: List, flip: bool = False, points=10):
"""Category generator"""
x = 0
while running:
for data_connector in data_connectors:
random_categories = [random.sample(categories, random.randint(0, len(categories))) for xi in range(points)]
if flip:
data_connector.cb_append_data_array(list(range(x, x + points)), random_categories)
else:
data_connector.cb_append_data_array(random_categories, list(range(x, x + points)))
x += 1
sleep(0.01)


def colors():
"""Primitive color cycler"""
while True:
Expand Down
35 changes: 35 additions & 0 deletions pglive/sources/data_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,38 @@ def cb_append_data_point(self, y: Union[int, float], x: Optional[Union[int, floa
self._update_data(**kwargs)
self.sig_data_roll_tick.emit(self, self.rolling_index)
self.rolling_index += 1

def cb_append_data_array(self, y: List[Union[int, float]], x: Optional[NUM_LIST] = None, **kwargs) -> None:
"""Append array of data to existing dataset"""
if self._skip_update():
return

with self.data_lock:
if self.max_points == inf:
# Concat two lists
self.y += y
if x is not None:
self.x += x
else:
self.x += list(range(self.x[-1], self.x[-1] + len(y), 1))
else:
# Concat two queues
self.y += deque(y)
if x is not None:
self.x += deque(x)
else:
self.x += deque(range(self.x[-1], self.x[-1] + len(y), 1))

if self.tick_position_indexes is not None:
if len(self.tick_position_indexes) == 0:
self.tick_position_indexes.append(0.0)
elif len(self.tick_position_indexes) == self.tick_position_indexes.maxlen:
self.tick_position_indexes.rotate(-1)
else:
self.tick_position_indexes.append(self.tick_position_indexes[-1] + 1.0)
self.last_update = time.perf_counter()

if not self._skip_plot():
self._update_data(**kwargs)
self.sig_data_roll_tick.emit(self, self.rolling_index)
self.rolling_index += len(y)
Loading

0 comments on commit 672b185

Please sign in to comment.