def __init__(self, edge): assert isinstance( edge, TopoDS_Edge), 'need a TopoDS_Edge, got a %s' % edge.__class__ assert not edge.IsNull() super(Edge, self).__init__() BaseObject.__init__(self, 'edge') # we need to copy the base shape using the following three # lines assert self.IsNull() self.TShape(edge.TShape()) self.Location(edge.Location()) self.Orientation(edge.Orientation()) assert not self.IsNull() # tracking state self._local_properties_init = False self._curvature_init = False self._geometry_lookup_init = False self._curve_handle = None self._curve = None self._adaptor = None self._adaptor_handle = None # instantiating cooperative classes # cooperative classes are distinct through CamelCaps from # normal method -> pep8 self.DiffGeom = DiffGeomCurve(self) self.Intersect = IntersectCurve(self) self.Construct = ConstructFromCurve(self) # GeomLProp object self._curvature = None
def __init__(self, edge): assert isinstance(edge, TopoDS_Edge), 'need a TopoDS_Edge, got a %s' % edge.__class__ assert not edge.IsNull() super(Edge, self).__init__() BaseObject.__init__(self, 'edge') # we need to copy the base shape using the following three # lines assert self.IsNull() self.TShape(edge.TShape()) self.Location(edge.Location()) self.Orientation(edge.Orientation()) assert not self.IsNull() # tracking state self._local_properties_init = False self._curvature_init = False self._geometry_lookup_init = False self._curve_handle = None self._curve = None self._adaptor = None self._adaptor_handle = None # instantiating cooperative classes # cooperative classes are distinct through CamelCaps from # normal method -> pep8 self.DiffGeom = DiffGeomCurve(self) self.Intersect = IntersectCurve(self) self.Construct = ConstructFromCurve(self) # GeomLProp object self._curvature = None
def __init__(self, x, y, z): super(Vertex, self).__init__() """Constructor for KbeVertex""" BaseObject.__init__(self, name='Vertex #{0}'.format(self._n)) self._n += 1 # should be a property of KbeObject self._pnt = gp_Pnt(x, y, z) self._vertex = make_vertex(self._pnt) TopoDS_Vertex.__init__(self, self._vertex)
def __init__(self, solid): assert isinstance(solid, TopoDS_Solid), 'need a TopoDS_Solid, got a %s' % solid.__class__ assert not solid.IsNull() super(Solid, self).__init__() BaseObject.__init__(self, 'solid') # we need to copy the base shape using the following three # lines assert self.IsNull() self.TShape(solid.TShape()) self.Location(solid.Location()) self.Orientation(solid.Orientation()) assert not self.IsNull() self.GlobalProperties = GlobalProperties(self)
def __init__(self, wire): ''' ''' assert isinstance(wire, TopoDS_Wire), 'need a TopoDS_Wire, got a %s' % wire.__class__ assert not wire.IsNull() super(Wire, self).__init__() BaseObject.__init__(self, 'wire') # we need to copy the base shape using the following three # lines assert self.IsNull() self.TShape(wire.TShape()) self.Location(wire.Location()) self.Orientation(wire.Orientation()) assert not self.IsNull()
def __init__(self, shell): assert isinstance(shell, TopoDS_Shell), 'need a TopoDS_Shell, got a %s' % shell.__class__ assert not shell.IsNull() super(Shell, self).__init__() BaseObject.__init__(self, 'shell') # we need to copy the base shape using the following three # lines assert self.IsNull() self.TShape(shell.TShape()) self.Location(shell.Location()) self.Orientation(shell.Orientation()) assert not self.IsNull() self.GlobalProperties = GlobalProperties(self) self._n += 1
def __init__(self, wire): ''' ''' assert isinstance( wire, TopoDS_Wire), 'need a TopoDS_Wire, got a %s' % wire.__class__ assert not wire.IsNull() super(Wire, self).__init__() BaseObject.__init__(self, 'wire') # we need to copy the base shape using the following three # lines assert self.IsNull() self.TShape(wire.TShape()) self.Location(wire.Location()) self.Orientation(wire.Orientation()) assert not self.IsNull()
def __init__(self, solid): assert isinstance( solid, TopoDS_Solid), 'need a TopoDS_Solid, got a %s' % solid.__class__ assert not solid.IsNull() super(Solid, self).__init__() BaseObject.__init__(self, 'solid') # we need to copy the base shape using the following three # lines assert self.IsNull() self.TShape(solid.TShape()) self.Location(solid.Location()) self.Orientation(solid.Orientation()) assert not self.IsNull() self.GlobalProperties = GlobalProperties(self)
def __init__(self, shell): assert isinstance( shell, TopoDS_Shell), 'need a TopoDS_Shell, got a %s' % shell.__class__ assert not shell.IsNull() super(Shell, self).__init__() BaseObject.__init__(self, 'shell') # we need to copy the base shape using the following three # lines assert self.IsNull() self.TShape(shell.TShape()) self.Location(shell.Location()) self.Orientation(shell.Orientation()) assert not self.IsNull() self.GlobalProperties = GlobalProperties(self) self._n += 1
def test_slugigfy(self): text = 'Mi nombre es muy largo' b = BaseObject('blibb','base') a = b.slugify(text) print a
def __init__(self, face): ''' ''' assert isinstance(face, TopoDS_Face), 'need a TopoDS_Face, got a %s' % face.__class__ assert not face.IsNull() super(Face, self).__init__() BaseObject.__init__(self, 'face') # we need to copy the base shape using the following three # lines assert self.IsNull() self.TShape(face.TShape()) self.Location(face.Location()) self.Orientation(face.Orientation()) assert not self.IsNull() # cooperative classes self.DiffGeom = DiffGeomSurface(self) # STATE; whether cooperative classes are yet initialized self._curvature_initiated = False self._geometry_lookup_init = False #=================================================================== # properties #=================================================================== self._h_srf = None self._srf = None self._adaptor = None self._adaptor_handle = None self._classify_uv = None # cache the u,v classifier, no need to rebuild for every sample self._topo = None # aliasing of useful methods def is_u_periodic(self): return self.adaptor.IsUPeriodic() def is_v_periodic(self): return self.adaptor.IsVPeriodic() def is_u_closed(self): return self.adaptor.IsUClosed() def is_v_closed(self): return self.adaptor.IsVClosed() def is_u_rational(self): return self.adaptor.IsURational() def is_v_rational(self): return self.adaptor.IsVRational() def u_degree(self): return self.adaptor.UDegree() def v_degree(self): return self.adaptor.VDegree() def u_continuity(self): return self.adaptor.UContinuity() def v_continuity(self): return self.adaptor.VContinuity()
def XMINUTE(m1, sfunc, _ts=None): ''' 1分钟以上周期 sfunc为确认周期结束的点 ''' if len(m1.sclose) == 0: return NullXMinute if not _ts.initialized: _ts.initialized = True _ts.sopen = [] _ts.sclose = [] _ts.shigh = [] _ts.slow = [] _ts.svol = [] _ts.sholding = [] _ts.iorder = [] _ts.xmin = [] #开盘分钟 _ts.cur = BaseObject( vopen=0, vclose=0, vhigh=0, vlow=99999999, xmin=0, svol=0, holding=0, iorder=0, ) _ts.ilast = 0 _ts.modified = False #上周期完成标志 scur = _ts.cur for i in range(_ts.ilast, len(m1.sclose)): morder = m1.iorder[i] if scur.vopen == 0: scur.vopen = m1.sopen[i] scur.xmin = m1.min1[i] scur.vclose = m1.sclose[i] scur.svol += m1.svol[i] scur.holding = m1.sholding[i] if m1.shigh[i] > scur.vhigh: scur.vhigh = m1.shigh[i] if m1.slow[i] < scur.vlow: scur.vlow = m1.slow[i] _ts.modified = False if sfunc(morder): #切换 _ts.sopen.append(scur.vopen) _ts.sclose.append(scur.vclose) _ts.shigh.append(scur.vhigh) _ts.slow.append(scur.vlow) _ts.svol.append(scur.svol) _ts.sholding.append(scur.holding) _ts.iorder.append(scur.iorder) _ts.xmin.append(scur.xmin) scur.vopen = 0 scur.vclose = 0 scur.vhigh = 0 scur.vlow = 99999999 scur.svol = 0 scur.xmin = 0 scur.holding = 0 scur.iorder += 1 _ts.modified = True _ts.ilast = len(m1.sclose) return _ts
def MINUTE(ticks, pre_min1=None, t2order=t2order_if, _ts=None): ''' 分钟切分 这个实现的最大问题是未处理最后一分钟的收尾 但这种场景仅用于保存数据, 可以在使用MINUTE之后, 由特别的语句去判断最后一个tick,并收尾最后一分钟 pre_min1为默认时,只能用当日分钟 反之延续之前的分钟 ''' if len(ticks) == 0: return NullMinute if not _ts.initialized: _ts.initialized = True if pre_min1 == None: #不接续 _ts.sopen = [] _ts.sclose = [] _ts.shigh = [] _ts.slow = [] _ts.svol = [] _ts.sholding = [] _ts.iorder = [] _ts.min1 = [] else: _ts.sopen = pre_min1.sopen _ts.sclose = pre_min1.sclose _ts.shigh = pre_min1.shigh _ts.slow = pre_min1.slow _ts.svol = pre_min1.svol _ts.sholding = pre_min1.sholding _ts.iorder = pre_min1.iorder _ts.min1 = pre_min1.min1 _ts.cur = BaseObject( vopen=ticks[0].price, vclose=ticks[0].price, vhigh=ticks[0].price, vlow=ticks[0].price, open_dvol=ticks[0].dvolume, #存在初始误差 close_dvol=ticks[0].dvolume, holding=ticks[0].holding, min1=ticks[0].min1, #当日第一min1 iorder=t2order[ticks[0].min1] ) #这里对dvol的处理,使得中断恢复也必须从当日最开始开始,否则所有前述成交量被归结到第一tick _ts.ilast = 0 _ts.modified = False #上周期完成标志 scur = _ts.cur for i in range(_ts.ilast, len(ticks)): tcur = ticks[i] #if tcur.min1 != scur.min1: #切换 if tcur.min1 > scur.min1: #切换, 避免ticks数据错误引发分钟序列紊乱,如20120905:958:59:500插入在20120905:959:00:00之后,虽然非常罕见,但会导致分钟序列出现958->959->958->959...这个情况 _ts.sopen.append(scur.vopen) _ts.sclose.append(scur.vclose) _ts.shigh.append(scur.vhigh) _ts.slow.append(scur.vlow) _ts.svol.append(scur.close_dvol - scur.open_dvol) _ts.sholding.append(scur.holding) _ts.min1.append(scur.min1) _ts.iorder.append(scur.iorder) scur.vopen = scur.vclose = scur.vhigh = scur.vlow = tcur.price scur.open_dvol = scur.close_dvol scur.close_dvol = tcur.dvolume scur.dvol = tcur.dvolume scur.holding = tcur.holding scur.min1 = tcur.min1 scur.iorder = t2order[tcur.min1] _ts.modified = True else: #未切换 scur.vclose = tcur.price scur.close_dvol = tcur.dvolume scur.holding = tcur.holding #print scur.min1,'close:',scur.vclose if tcur.price > scur.vhigh: scur.vhigh = tcur.price elif tcur.price < scur.vlow: scur.vlow = tcur.price _ts.modified = False _ts.ilast = len(ticks) return _ts
#print 'initialize REF' for i in range(len(_ts.ref), offset if offset <= len(source) else len(source)): _ts.ref.append(source[0]) for i in range(len(_ts.ref), len(source)): _ts.ref.append(source[i - offset]) return _ts.ref NullMinute = BaseObject(sopen=[], sclose=[], shigh=[], slow=[], svol=[], iorder=[], sholding=[]) @indicator def MINUTE(ticks, pre_min1=None, t2order=t2order_if, _ts=None): ''' 分钟切分 这个实现的最大问题是未处理最后一分钟的收尾 但这种场景仅用于保存数据, 可以在使用MINUTE之后, 由特别的语句去判断最后一个tick,并收尾最后一分钟 pre_min1为默认时,只能用当日分钟 反之延续之前的分钟 '''
def MINUTE(dates, times, prices, dvols, holdings, pre_min1=None, _ts=None): ''' 分钟切分, 参数不同 _ts用于暂存。同时可用于接续历史数据 如果pre_min1不为空,调用者需保证ticks[0].min1 > pre_min1.stime ''' if len(prices) == 0: return NullMinute if not _ts.initialized: _ts.initialized = True if pre_min1 == None: #不接续 _ts.sopen = [] _ts.sclose = [] _ts.shigh = [] _ts.slow = [] _ts.svol = [] _ts.sholding = [] _ts.sdate = [] _ts.stime = [] else: _ts.sopen = pre_min1.sopen _ts.sclose = pre_min1.sclose _ts.shigh = pre_min1.shigh _ts.slow = pre_min1.slow _ts.svol = pre_min1.svol _ts.sholding = pre_min1.sholding _ts.sdate = pre_min1.sdate _ts.stime = pre_min1.stime _ts.cur = BaseObject( vopen=prices[0], vclose=prices[0], vhigh=prices[0], vlow=prices[0], open_dvol=dvols[0], #存在初始误差 close_dvol=dvols[0], holding=holdings[0], xtime=time2min(times[0]), #启动后第一min1 xdate=dates[0], ) #这里对dvol的处理,使得中断恢复也必须从当日最开始开始,否则所有前述成交量被归结到第一tick _ts.ilast = 0 _ts.modified = False #上周期完成标志 _ts.modified = False #上周期完成标志 scur = _ts.cur for i in range(_ts.ilast, len(prices)): tmin1 = time2min(times[i]) if tmin1 > scur.xtime or (tmin1 == 0 and scur.xtime > 0) or ( dates[i] > scur.xdate and scur.xtime > 0): #tcur.min1 = 0, 分钟切换用,要求其它字段均为0 if scur.xtime > 0: #前一分钟不是切换标志 _ts.sopen.append(scur.vopen) _ts.sclose.append(scur.vclose) _ts.shigh.append(scur.vhigh) _ts.slow.append(scur.vlow) _ts.svol.append(scur.close_dvol - scur.open_dvol) _ts.sholding.append(scur.holding) _ts.sdate.append(scur.xdate) _ts.stime.append(scur.xtime) scur.vopen = scur.vclose = scur.vhigh = scur.vlow = prices[i] scur.open_dvol = scur.close_dvol scur.close_dvol = dvols[i] scur.dvol = dvols[i] scur.holding = holdings[i] scur.xdate = dates[i] scur.xtime = tmin1 _ts.modified = True else: #未切换 scur.vclose = prices[i] scur.close_dvol = dvols[i] scur.holding = holdings[i] #print tmin1,'close:',scur.vclose if prices[i] > scur.vhigh: scur.vhigh = prices[i] elif prices[i] < scur.vlow: scur.vlow = prices[i] _ts.ilast = len(prices) return _ts
_ts.ref.append(source[0]) for i in range(len(_ts.ref), len(source)): _ts.ref.append(source[i - offset]) return _ts.ref ####分钟切换 time2min = lambda t: t // 100000 NullMinute = BaseObject(sopen=[], sclose=[], shigh=[], slow=[], svol=[], sholding=[], sdate=[], stime=[], modified=False) @indicator def MINUTE_1(ticks, pre_min1=None, _ts=None): ''' 分钟切分, 以ticks为参数 _ts用于暂存。同时可用于接续历史数据 如果pre_min1不为空,调用者需保证ticks[0].min1 > pre_min1.stime ''' if len(ticks) == 0: