rename src to pylib and in data.seq float rounding uses start as well

This commit is contained in:
2019-10-15 13:10:11 +02:00
parent 3309613871
commit 23a3da9aaf
15 changed files with 34 additions and 8 deletions

View File

@@ -11,6 +11,7 @@
.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
"""
from __future__ import print_function
import math
import pickle
def read(file_name, x_column, y_column, default=None, verbose=False):
@@ -143,12 +144,20 @@ def seq(start, stop=None, step=1):
if stop is None:
return seq(0, start, step)
start_str = str(start)
start_exp = 0
if '.' in start_str:
start_exp = len(start_str.split('.')[1])
step_str = str(step)
exponent = 0
step_exp = 0
if '.' in step_str:
exponent = len(step_str.split('.')[1])
step_exp = len(step_str.split('.')[1])
exponent = max(start_exp, step_exp) # no stop because it is an open bound
n = int(math.ceil((stop - start)/float(step)))
#n = int((stop - start)/float(step)) # in py3 math.ceil returns int
lst = []
if n > 0:
lst = [round(start + step*i, exponent) for i in range(n)]

View File

@@ -12,8 +12,8 @@ import unittest
import os
import sys
sys.path.insert(0, os.path.abspath('../src'))
from data import read, unique_ending, get_id
sys.path.insert(0, os.path.abspath('../pylib'))
from data import read, unique_ending, get_id, seq
class TestData(unittest.TestCase):
@@ -51,6 +51,23 @@ class TestData(unittest.TestCase):
'837c5378-9e6e-4bd0-b6a7-460d02fb62a3'
)
def test_seq(self):
"""test seq function"""
self.assertEqual(seq(0), [])
self.assertEqual(seq(1), [0])
self.assertEqual(seq(2), [0, 1])
self.assertEqual(seq(0, 3), [0, 1, 2])
self.assertEqual(seq(3, 3), [])
self.assertEqual(seq(3, 4), [3])
self.assertEqual(seq(3, 5), [3, 4])
self.assertEqual(seq(3, 5, 1), [3, 4])
self.assertEqual(seq(3, 5, 0.5), [3, 3.5, 4, 4.5])
self.assertEqual(seq(3, 5, 0.2), [3, 3.2, 3.4, 3.6, 3.8, 4, 4.2, 4.4, 4.6, 4.8])
self.assertEqual(seq(4, 0, -0.4), [4, 3.6, 3.2, 2.8, 2.4, 2, 1.6, 1.2, 0.8, 0.4])
self.assertEqual(seq(4, 0, -0.41), [4, 3.59, 3.18, 2.77, 2.36, 1.95, 1.54, 1.13, 0.72, 0.31])
self.assertEqual(seq(3.03, 5.07), [3.03, 4.03, 5.03])
self.assertEqual(seq(3, 5.07), [3, 4, 5])
if __name__ == '__main__':
unittest.main()

View File

@@ -13,7 +13,7 @@ import unittest
import os
import sys
from pylab import array, argmax, subplot, plot, title, xlim, show, gradient, linspace
sys.path.insert(0, os.path.abspath('../src'))
sys.path.insert(0, os.path.abspath('../pylib'))
from data import data_read
from numerical.fit import gauss_fit

View File

@@ -14,7 +14,7 @@ import os
import sys
import math
from numpy import allclose
sys.path.insert(0, os.path.abspath('../src'))
sys.path.insert(0, os.path.abspath('../pylib'))
from data import fold_list
from geometry import translate_xy, rotate_xy, interpolate_hermite, lines, cubics
from geometry_plot import plot_lines, plot_cubic_lines

View File

@@ -19,7 +19,7 @@ from matplotlib.pyplot import figure, subplots, plot, show
import os
import sys
sys.path.insert(0, os.path.abspath('../src'))
sys.path.insert(0, os.path.abspath('../pylib'))
from numerical.ode import (e1, e2, e4, i1, newmark_newtonraphson,
newmark_newtonraphson_rdk)
from numerical.ode_model import disk, disk_nm, disk_nmmdk

View File

@@ -14,7 +14,7 @@ from time import mktime
import os
import sys
sys.path.insert(0, os.path.abspath('../src'))
sys.path.insert(0, os.path.abspath('../pylib'))
from time_of_day import (in_seconds, seconds, seconds_norm,
minutes, minutes_norm, hours, hours_norm, days, days_norm,
transform)