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