#!/usr/bin/env python
# coding: utf-8
a = [10, 20, 30, 50, 70] # значения
b = [1, 2, 3, 4, 5] # доступное время сняти замеров
def frange(start, stop, step):
r = start
while r < stop:
yield r
r += step
assert tuple(frange(1.0, 5.0, 1.0)) == (1.0, 2.0, 3.0, 4.0)
def pairwise(iterable):
"""
#
# current = (0, b[0])
#
# for x in b[1:]:
# current = (current[1], x)
# print(current)
#
"""
iterable = iter(iterable)
current = next(iterable)
for x in iterable:
yield (current, x)
current = x
assert tuple(pairwise(iter(range(3)))) == ((0, 1), (1, 2))
a = [10, 20, 30, 50, 70] # значения
b = [1, 2, 3, 4, 5] # доступное время сняти замеров
def in_range(a, range):
return range[0] < a < range[1]
assert in_range(5, [1, 9])
def gen_timers(from_, to, number_of_tics=10):
# print(to)
# print(from_)
step = (to - from_) / number_of_tics
return frange(from_, to, step)
assert len((tuple(gen_timers(1, 10, number_of_tics=10)))) == 10
assert len(tuple(gen_timers(b[0], b[-1], number_of_tics=10))) == 10
assert len(tuple(gen_timers(b[0], b[-1], number_of_tics=15))) == 15 + 1
def pl(a):
print(len(tuple(a)))
def pt(a):
print(tuple(a))
a = [10, 20, 30, 50, 70] # значения
b = [1, 2, 3, 4, 5] # доступное время сняти замеров
def magic_function(time, data):
times = gen_timers(time[0], time[-1])
data = zip(pairwise(data), pairwise(time))
(start_data, end_data), (start_time, end_time) = next(data)
for time in times:
if start_time <= time < end_time:
delta = (end_data - start_data) / \
(end_time - start_time) # в секунду?
yield start_data + delta * (time - start_time)
else:
(start_data, end_data), (start_time, end_time) = next(data)
yield start_data + delta * (time - start_time)
p = tuple(magic_function(b, a))
import ipdb; ipdb.set_trace()