optimising rule based gearing
--HG-- branch : sandbox
This commit is contained in:
@@ -281,7 +281,7 @@ class SlidingWindow:
|
|||||||
"""
|
"""
|
||||||
n, cdt, last = tick
|
n, cdt, last = tick
|
||||||
max_distance = self.bias
|
max_distance = self.bias
|
||||||
segment_added = False
|
rc = None
|
||||||
self.xs.append(cdt)
|
self.xs.append(cdt)
|
||||||
self.ys.append(last)
|
self.ys.append(last)
|
||||||
x0, y0 = (self.xs[0], self.ys[0])
|
x0, y0 = (self.xs[0], self.ys[0])
|
||||||
@@ -290,7 +290,7 @@ class SlidingWindow:
|
|||||||
self.segx.append(x0)
|
self.segx.append(x0)
|
||||||
self.segy.append(y0)
|
self.segy.append(y0)
|
||||||
if len(self.xs) < 2:
|
if len(self.xs) < 2:
|
||||||
return (self.segx, self.segy, segment_added)
|
return None
|
||||||
# check distance
|
# check distance
|
||||||
coefs = interpolate_line((x0, x1), (y0, y1))
|
coefs = interpolate_line((x0, x1), (y0, y1))
|
||||||
ip_ys = np.polyval(coefs, self.xs)
|
ip_ys = np.polyval(coefs, self.xs)
|
||||||
@@ -311,10 +311,11 @@ class SlidingWindow:
|
|||||||
# slope of current segment
|
# slope of current segment
|
||||||
x0, y0 = (self.xs[0], self.ys[0])
|
x0, y0 = (self.xs[0], self.ys[0])
|
||||||
b1, a1 = interpolate_line((x0, x1), (y0, y1))
|
b1, a1 = interpolate_line((x0, x1), (y0, y1))
|
||||||
self.add_type(b0, b1)
|
lohi = self.get_type(b0, b1)
|
||||||
return (self.segx + [x1], self.segy + [y1], segment_added)
|
rc = (x2, y2, lohi)
|
||||||
|
return (self.segx + [x1], self.segy + [y1], rc)
|
||||||
|
|
||||||
def add_type(self, b0, b1):
|
def get_type(self, b0, b1):
|
||||||
""" calculate gearing
|
""" calculate gearing
|
||||||
y: previous slope, x: current slope
|
y: previous slope, x: current slope
|
||||||
<0 ~0 >0
|
<0 ~0 >0
|
||||||
@@ -323,30 +324,26 @@ class SlidingWindow:
|
|||||||
>0 H H H
|
>0 H H H
|
||||||
"""
|
"""
|
||||||
if b0 < -SMALL and b1 < -SMALL and b0 > b1:
|
if b0 < -SMALL and b1 < -SMALL and b0 > b1:
|
||||||
type = "H"
|
lohi = "d+"
|
||||||
elif b0 < -SMALL and b1 < -SMALL and b0 < b1:
|
elif b0 < -SMALL and b1 < SMALL and b0 < b1:
|
||||||
type = "L"
|
lohi = "d-"
|
||||||
elif b0 < -SMALL and abs(b1) < SMALL:
|
|
||||||
type = "L"
|
|
||||||
elif b0 < -SMALL and b1 > SMALL:
|
elif b0 < -SMALL and b1 > SMALL:
|
||||||
type = "L"
|
lohi = "L"
|
||||||
elif abs(b0) < SMALL and b1 < -SMALL:
|
elif abs(b0) < SMALL and b1 < -SMALL:
|
||||||
type = "H"
|
lohi = "d+"
|
||||||
elif abs(b0) < SMALL and abs(b1) < SMALL:
|
elif abs(b0) < SMALL and abs(b1) < SMALL:
|
||||||
type = "0"
|
lohi = "0"
|
||||||
elif abs(b0) < SMALL and b1 > SMALL:
|
elif abs(b0) < SMALL and b1 > SMALL:
|
||||||
type = "L"
|
lohi = "u+"
|
||||||
elif b0 > SMALL and b1 < -SMALL:
|
elif b0 > SMALL and b1 < -SMALL:
|
||||||
type = "H"
|
lohi = "H"
|
||||||
elif b0 > SMALL and abs(b1) < SMALL:
|
elif b0 > SMALL and b1 > -SMALL and b0 > b1:
|
||||||
type = "H"
|
lohi = "u-"
|
||||||
elif b0 > SMALL and b1 > SMALL and b0 > b1:
|
|
||||||
type = "H"
|
|
||||||
elif b0 > SMALL and b1 > SMALL and b0 < b1:
|
elif b0 > SMALL and b1 > SMALL and b0 < b1:
|
||||||
type = "L"
|
lohi = "u+"
|
||||||
else:
|
else:
|
||||||
type = "?"
|
lohi = "?"
|
||||||
self.types.append(type)
|
return lohi
|
||||||
|
|
||||||
|
|
||||||
SMALL = 1E-10
|
SMALL = 1E-10
|
||||||
@@ -401,7 +398,7 @@ class Main:
|
|||||||
|
|
||||||
# create artists
|
# create artists
|
||||||
LOG.debug("Loading ticks...")
|
LOG.debug("Loading ticks...")
|
||||||
self.xs, self.ys, self.vs = tdl(datetime.datetime(2009, 7, 3))
|
self.xs, self.ys, self.vs = tdl(datetime.datetime(2009, 7, 2))
|
||||||
LOG.debug("Ticks loaded.")
|
LOG.debug("Ticks loaded.")
|
||||||
lows, highs = find_lows_highs(self.xs, self.ys)
|
lows, highs = find_lows_highs(self.xs, self.ys)
|
||||||
self.mas = self.ys[:]
|
self.mas = self.ys[:]
|
||||||
@@ -511,27 +508,33 @@ class Main:
|
|||||||
def mark_segments(self, n):
|
def mark_segments(self, n):
|
||||||
x = self.xs
|
x = self.xs
|
||||||
y = self.ys
|
y = self.ys
|
||||||
segx, segy, seg_add = self.osw((n, x[n], y[n]))
|
rc = self.osw((n, x[n], y[n]))
|
||||||
self.seg.set_data(segx, segy)
|
if rc is not None:
|
||||||
if seg_add:
|
segx, segy, lohi = rc
|
||||||
text = self.osw.types[-1]
|
self.seg.set_data(segx, segy)
|
||||||
if text == "H":
|
if lohi is not None:
|
||||||
fc = "green"
|
text = lohi[2]
|
||||||
dy = +15
|
if text == "u+":
|
||||||
elif text == "L":
|
fc = "blue"
|
||||||
fc = "red"
|
dy = -15
|
||||||
dy = -15
|
elif text == "d+":
|
||||||
else:
|
fc = "blue"
|
||||||
fc = "blue"
|
dy = +15
|
||||||
dy = +15
|
elif text == "H":
|
||||||
self.ax1.annotate(text,
|
fc = "green"
|
||||||
xy=(segx[-2], segy[-2]),
|
dy = +15
|
||||||
xytext=(segx[-1], segy[-2]+dy),
|
elif text == "L":
|
||||||
arrowprops=dict(facecolor=fc,
|
fc = "red"
|
||||||
frac=0.3,
|
dy = -15
|
||||||
shrink=0.1))
|
else:
|
||||||
|
fc = None
|
||||||
|
if fc:
|
||||||
|
self.ax1.annotate(text,
|
||||||
|
xy=(lohi[0], lohi[1]),
|
||||||
|
xytext=(segx[-1], segy[-2]+dy),
|
||||||
|
arrowprops=dict(facecolor=fc,
|
||||||
|
frac=0.3,
|
||||||
|
shrink=0.1))
|
||||||
|
|
||||||
def mark_low_high(self, n):
|
def mark_low_high(self, n):
|
||||||
x = self.xs
|
x = self.xs
|
||||||
|
|||||||
Reference in New Issue
Block a user