code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
''' np.array: The grid points in y. ''' if None not in (self.y_min, self.y_max, self.y_step) and \ self.y_min != self.y_max: y = np.arange(self.y_min, self.y_max-self.y_step*0.1, self.y_step) else: y = np.array([]) return y
def y(self)
np.array: The grid points in y.
3.148201
2.472328
1.273375
''' function: a function that when passed a `x` and `y` values, returns the permittivity profile of the structure, interpolating if necessary. ''' interp_real = interpolate.interp2d(self.x, self.y, self.eps.real) interp_imag = interpolate.interp2d(self.x, ...
def eps_func(self)
function: a function that when passed a `x` and `y` values, returns the permittivity profile of the structure, interpolating if necessary.
3.705488
1.957679
1.892797
''' function: a function that when passed a `x` and `y` values, returns the refractive index profile of the structure, interpolating if necessary. ''' return interpolate.interp2d(self.x, self.y, self.n)
def n_func(self)
function: a function that when passed a `x` and `y` values, returns the refractive index profile of the structure, interpolating if necessary.
9.863134
2.547859
3.871146
''' A low-level function that allows writing a rectangle refractive index profile to a `Structure`. Args: x_bot_left (float): The bottom-left x-coordinate of the rectangle. y_bot_left (float): The bottom-left y-coordinate of the re...
def _add_material(self, x_bot_left, y_bot_left, x_top_right, y_top_right, n_material, angle=0)
A low-level function that allows writing a rectangle refractive index profile to a `Structure`. Args: x_bot_left (float): The bottom-left x-coordinate of the rectangle. y_bot_left (float): The bottom-left y-coordinate of the rectangle. ...
2.707813
1.587883
1.705297
''' Write the refractive index profile to file. Args: filename (str): The nominal filename the refractive index data should be saved to. plot (bool): `True` if plots should be generates, otherwise `False`. Default is `True`. ''' ...
def write_to_file(self, filename='material_index.dat', plot=True)
Write the refractive index profile to file. Args: filename (str): The nominal filename the refractive index data should be saved to. plot (bool): `True` if plots should be generates, otherwise `False`. Default is `True`.
2.793279
2.268281
1.231452
''' Creates and adds a :class:`Slab` object. Args: height (float): Height of the slab. n_background (float): The nominal refractive index of the slab. Default is 1 (air). Returns: str: The name of the slab. ''' assert...
def add_slab(self, height, n_background=1., position='top')
Creates and adds a :class:`Slab` object. Args: height (float): Height of the slab. n_background (float): The nominal refractive index of the slab. Default is 1 (air). Returns: str: The name of the slab.
3.012681
2.446064
1.231645
''' Changes the wavelength of the structure. This will affect the mode solver and potentially the refractive indices used (provided functions were provided as refractive indices). Args: wavelength (float): The new wavelength. ''' for name, sl...
def change_wavelength(self, wavelength)
Changes the wavelength of the structure. This will affect the mode solver and potentially the refractive indices used (provided functions were provided as refractive indices). Args: wavelength (float): The new wavelength.
6.457124
2.914433
2.215568
''' np.array: The refractive index profile matrix of the current slab. ''' try: n_mat = self.slabs['0'].n for s in range(1, self.slab_count): n_mat = np.vstack((self.slabs[str(s)].n, n_mat)) except KeyError: n_mat = None...
def n(self)
np.array: The refractive index profile matrix of the current slab.
5.042882
2.771497
1.819552
''' Add a refractive index between two x-points. Args: x_min (float): The start x-point. x_max (float): The stop x-point. n (float, function): Refractive index between `x_min` and `x_max`. Either a constant (`float`), or a ...
def add_material(self, x_min, x_max, n, angle=0)
Add a refractive index between two x-points. Args: x_min (float): The start x-point. x_max (float): The stop x-point. n (float, function): Refractive index between `x_min` and `x_max`. Either a constant (`float`), or a function that accept...
5.087145
1.674999
3.037104
''' Write the refractive index profile to file. Args: filename (str): The nominal filename the refractive index data should be saved to. plot (bool): `True` if plots should be generates, otherwise `False`. Default is `True`. ''' ...
def write_to_file(self, filename='material_index.dat', plot=True)
Write the refractive index profile to file. Args: filename (str): The nominal filename the refractive index data should be saved to. plot (bool): `True` if plots should be generates, otherwise `False`. Default is `True`.
2.931083
2.490172
1.17706
''' Changes the wavelength of the structure. This will affect the mode solver and potentially the refractive indices used (provided functions were provided as refractive indices). Args: wavelength (float): The new wavelength. ''' for axis in ...
def change_wavelength(self, wavelength)
Changes the wavelength of the structure. This will affect the mode solver and potentially the refractive indices used (provided functions were provided as refractive indices). Args: wavelength (float): The new wavelength.
7.765923
2.827654
2.746419
try: ret = int(s) except ValueError: ret = float(s) return ret
def covstr(s)
convert string to int or float.
4.94147
3.290156
1.501895
#re = "{%(time)s} %(name)s %(stock_no)s %(c)s %(range)+.2f(%(pp)+.2f%%) %(value)s" % { ''' re = % { ''' if covstr(self.g['range']) > 0: css = "red" elif covstr(self.g['range']) < 0: css = "green" else: css = "gray" re = { 'name': self.g['name'], 'stock_no'...
def output(self)
re = """<table> <tr><td>%(name)s</td><td>%(c)s</td><td>%(range)+.2f(%(pp)+.2f%%)</td></tr> <tr><td>%(stock_no)s</td><td>%(value)s</td><td>%(time)s</td></tr></table>""" % {
3.306484
2.498648
1.323309
a = twsk(stock_no).real if a: re = "{%(time)s} %(stock_no)s %(c)s %(range)+.2f(%(pp)+.2f%%) %(value)s" % { 'stock_no': stock_no, 'time': a['time'], 'c': a['c'], 'range': covstr(a['range']), 'value': a['value'], 'pp': covstr(a['pp']) } return re else...
def Rt_display(stock_no)
For real time stock display 即時盤用,顯示目前查詢各股的股價資訊。
5.763866
6.045054
0.953485
pattern = re.compile(r"[0-9]{2}/[0-9]{2}/[0-9]{2}") b = re.search(pattern, oo[0]) try: b.group() return True except: return False
def ckinv(self,oo)
check the value is date or not 檢查是否為日期格式
3.777221
3.232783
1.168411
if rev == 0: if one > two: re = '↑'.decode('utf-8') elif one < two: re = '↓'.decode('utf-8') else: re = '-'.decode('utf-8') else: if one > two: re = 1 elif one < two: re = -1 else: re = 0 return re
def high_or_low(self,one,two,rev=0)
Return ↑↓- for high, low or equal. 回傳漲跌標示 rev = 0 回傳 ↑↓- rev = 1 回傳 1 -1 0
2.17533
1.905485
1.141615
for i in xrange(days): self.raw_data.pop() self.data_date.pop() self.stock_range.pop() self.stock_vol.pop() self.stock_open.pop() self.stock_h.pop() self.stock_l.pop()
def goback(self,days = 1)
Go back days 刪除最新天數資料數據 days 代表刪除多少天數(倒退幾天)
3.308074
3.409962
0.970121
url = 'http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/STOCK_DAY_print.php?genpage=genpage/Report%(year)d%(mon)02d/%(year)d%(mon)02d_F3_1_8_%(stock)s.php&type=csv&r=%(rand)s' % {'year': nowdatetime.year, 'mon': nowdatetime.month, 'stock': stock_no, 'rand': random.randrange(1,1000000)} self.debug_print...
def fetch_data(self, stock_no, nowdatetime, firsttime = 1)
Fetch data from twse.com.tw return list. 從 twse.com.tw 下載資料,回傳格式為 list
3.558044
3.617072
0.983681
getr = [] getdate = [] getrange = [] getvol = [] getopen = [] geth = [] getl = [] otherinfo = [] fetch_data_raw = 1 for i in csv_read: if self.ckinv(i): #if len(i) > 1: self.debug_print(i) getr.append(self.covstr(i[6])) getdate.append(i[0]...
def list_data(self, csv_read)
將資料 list 化 return dictionary: [stock_price]: Closing price (list) 收盤價格 [stock_name]: Stock name (str) and encode form big5 to utf-8 該股名稱,big5 → UTF-8 [data_date]: Stock date (list) 數據日期資訊 [stock...
2.91171
2.461109
1.183088
rp = float((self.raw_data[-1] - self.raw_data[-2]) / self.raw_data[-2] * 100) return rp
def range_per(self)
Range percentage 計算最新日之漲跌幅度百分比
5.402702
4.443576
1.215846
if len(self.raw_data) >= days: data = self.raw_data[-days:] data_avg = float(sum(data) / days) data2 = [] for x in data: data2.append((x - data_avg ) ** 2) return math.sqrt(sum(data2) / len(data2)) else: return 0
def SD(self, days=45)
Standard Deviation. 計算 days 日內之標準差,預設 45 日
3.044217
3.00465
1.013169
if len(self.raw_data) >= days: data = self.raw_data[-days:] data_avg = float(sum(data) / days) return data_avg else: return 0
def SDAVG(self, days=45)
the last 45 days average. 計算 days 日內之平均數,預設 45 日
3.599822
3.685804
0.976672
if len(self.raw_data) >= days: data_avg = sum(self.raw_data[-days:]) / days return self.SD / data_avg else: return 0
def CV(self, days=45)
Coefficient of Variation. 計算 days 日內之變異數,預設 45 日
4.718739
5.137988
0.918402
now = TWTime().now.hour if now >= 9 and now <= 14: return True else: return False
def TimeinOpen(self)
In open market time. 在當日開市時刻,9 - 14
9.102536
7.705656
1.18128
yesterday = self.raw_data[:] yesterday.pop() yes_MA = float(sum(yesterday[-days:]) / days) today_MA = self.MA(days) return self.high_or_low(today_MA, yes_MA, rev)
def MAC(self,days,rev = 0)
Comparing yesterday price is high, low or equal. return ↑,↓ or - 與前一天 days 日收盤價移動平均比較 rev = 0 回傳 ↑,↓ or - rev = 1 回傳 1,-1 or 0
7.471723
6.762627
1.104855
return self.make_serial(self.raw_data,days,rev)
def MA_serial(self,days,rev=0)
see make_serial() 收盤價移動平均 list 化,資料格式請見 def make_serial()
9.738008
7.818158
1.245563
yesterday = self.stock_vol[:] yesterday.pop() yes_MAVOL = float(sum(yesterday[-days:]) / days) today_MAVOL = self.MAVOL(days) return self.high_or_low(today_MAVOL, yes_MAVOL,rev)
def MACVOL(self,days,rev=0)
Comparing yesterday volume is high, low or equal. return ↑,↓ or - 與前一天 days 日成交量移動平均比較 rev = 0 回傳 ↑,↓ or - rev = 1 回傳 1,-1 or 0
8.661421
8.091585
1.070423
return self.make_serial(self.stock_vol,days,rev=0)
def MAVOL_serial(self,days,rev=0)
see make_serial() 成較量移動平均 list 化,資料格式請見 def make_serial()
12.259433
10.187272
1.203407
if self.stock_vol[-1] > self.stock_vol[-2] and self.stock_vol[-1] > self.stock_vol[-3]: return True else: return False
def VOLMAX3(self)
Volume is the max in last 3 days. 三日內最大成交量
3.555097
3.157491
1.125925
day1MA = self.MA_serial(day1)[1] day2MA = self.MA_serial(day2)[1] bw = abs(day1-day2) if len(day1MA) > len(day2MA): day1MAs = day1MA[bw:] day2MAs = day2MA[:] elif len(day1MA) < len(day2MA): day1MAs = day1MA[:] day2MAs = day2MA[bw:] else: day1MAs = day1MA[:] ...
def MAO(self,day1,day2,rev=0)
This is MAO(Moving Average Oscillator), not BIAS. It's only 'MAday1 - MAday2'. 乖離率,MAday1 - MAday2 兩日之移動平均之差 return list: [0] is the times of high, low or equal [0] is times [1] is the MAO data [1] rev=0:↑ ↓ or -,rev=1:1 -1 0 回傳: [0] ...
2.498413
2.502688
0.998292
c = data[-s:] if pm: ckvalue = max(c) preckvalue = max(c) > 0 else: ckvalue = min(c) preckvalue = max(c) < 0 return [s - c.index(ckvalue) < 4 and c.index(ckvalue) != s-1 and preckvalue, s - c.index(ckvalue) - 1, ckvalue]
def ckMAO(self,data,s=5,pm=False)
判斷正負乖離位置 s = 取樣判斷區間 pm = True(正)/False(負) 乖離 return [T/F, 第幾個轉折日, 乖離值]
4.679273
4.27515
1.094528
A = self.raw_data[-3]*2 - self.raw_data[-6] B = self.raw_data[-2]*2 - self.raw_data[-5] C = self.raw_data[-1]*2 - self.raw_data[-4] return '(%.2f,%.2f,%.2f)' % (A,B,C)
def RABC(self)
Return ABC 轉折點 ABC
2.453754
2.267348
1.082213
raw = data[:] result = [] try: while len(raw) >= days: result.append(float(sum(raw[-days:]) / days)) raw.pop() self.debug_print(len(result)) result.reverse() re = [self.cum_serial(result,rev), result] return re except: return '?'
def make_serial(self,data,days,rev=0)
make data in list if data enough, will return: [0] is the times of high, low or equal [1] is the serial of data. or return '?' 資料數據 list 化,days 移動平均值 [0] 回傳次數 [1] 回傳數據
6.654728
5.346945
1.244585
org = raw[1:] diff = raw[:-1] result = [] for i in xrange(len(org)): result.append(self.high_or_low(org[i], diff[i],rev)) times = 0 try: if result[-1] == result[-2]: signal = result[-1] re_signal = result[:] try: while signal == re_signal[-1]: ...
def cum_serial(self, raw,rev=0)
Cumulate serial data and return times(int) 計算數據重複(持續)次數
4.263641
4.17359
1.021576
print self.stock_name,self.stock_no print '%s %s %s(%+.2f%%)' % (self.data_date[-1],self.raw_data[-1],self.stock_range[-1],self.range_per) for i in arg: print ' - MA%02s %.2f %s(%s)' % (i,self.MA(i),self.MAC(i),self.MA_serial(i)[0]) print ' - Volume: %s %s(%s)' % (self.MAVOL(1)/1000,self.MAC...
def display(self,*arg)
For simple Demo 測試用顯示樣式。
5.300175
5.35133
0.990441
MA = '' for i in arg: MAs = '- MA%02s: %.2f %s(%s)\n' % ( unicode(i), self.MA(i), self.MAC(i), unicode(self.MA_serial(i)[0]) ) MA = MA + MAs vol = '- Volume: %s %s(%s)' % ( unicode(self.MAVOL(1)/1000), unicode(self.MACVOL(1)), unicod...
def XMPP_display(self,*arg)
For XMPP Demo 輸出到 XMPP 之樣式。
4.437037
4.42055
1.00373
re = % { 'stock_name': unicode(self.stock_name), 'stock_no': unicode(self.stock_no), 'stock_date': unicode(self.data_date[-1]), 'stock_price': unicode(self.raw_data[-1]), 'stock_range': unicode(self.stock_range[-1]), } return re
def Task_display(self)
For Task overall stock display 顯示資訊樣式之一,兩行資訊。
5.158422
4.592244
1.12329
re = "%(stock_no)s %(stock_name)s %(stock_date)s %(stock_price)s %(stock_range)s %(stock_range_per).2f%% %(RABC)s %(stock_vol)s" % { 'stock_name': unicode(self.stock_name), 'stock_no': unicode(self.stock_no), 'stock_date': unicode(self.data_date[-1]), 'stock_price': unicode(self...
def Cmd_display(self)
For Task overall stock display 一行顯示資訊,用於終端機顯示樣式。
3.290188
3.261088
1.008923
if s == 0: s = len(self.raw_data) if len(size) == 2: sw,sh = size else: sh = 300 sw = 25 * s if sw > 1000: sw = 1000 candle = 950/s stc = '' for i in self.raw_data[-s:]: stc += str(i) + ',' sto = '' for i in self.stock_open[-s:]: ...
def gchart(self, s = 0, size = [], candle = 20)
Chart for serious stocks 輸出 Google Chart 圖表。 s = 資料筆數 size = 圖表寬度、高度 [寬度,高度] candle = K 棒的寬度
2.757765
2.764326
0.997627
''' 買 ''' self.money += -price*value try: self.store[no] += value except: self.store[no] = value try: self.avgprice[no]['buy'] += [price] except: try: self.avgprice[no]['buy'] = [price] except: self.avgprice[no] = {} self.avgprice[no]['buy'] ...
def buy(self, no, price, value)
2.993094
2.827321
1.058632
''' 賣 ''' self.money += price*value try: self.store[no] += -value except: self.store[no] = -value try: self.avgprice[no]['sell'] += [price] except: try: self.avgprice[no]['sell'] = [price] except: self.avgprice[no] = {} self.avgprice[no]['sel...
def sell(self, no, price, value)
3.153344
2.813255
1.120888
''' 總覽顯示 ''' print 'money:',self.money print 'store:',self.store print 'avgprice:',self.avgprice
def showinfo(self)
總覽顯示
11.445085
6.90048
1.658593
import re pattern = re.compile("%s" % q) result = {} for i in self.allstockno: b = re.search(pattern, self.allstockno[i]) try: b.group() result[i] = self.allstockno[i] except: pass return result
def search(self,q)
Search.
4.006309
4.042735
0.99099
return numpy.trapz(numpy.trapz(f, x=y, dx=dy), x=x, dx=dx)
def trapz2(f, x=None, y=None, dx=1.0, dy=1.0)
Double integrate.
2.872863
3.037573
0.945776
from scipy.sparse.linalg import eigen self.nmodes = neigs self.tol = tol A = self.build_matrix() if guess is not None: # calculate shift for eigs function k = 2 * numpy.pi / self.wl shift = (guess * k) ** 2 else: ...
def solve(self, neigs=4, tol=0, guess=None, mode_profiles=True, initial_mode_guess=None)
This function finds the eigenmodes. Parameters ---------- neigs : int number of eigenmodes to find tol : float Relative accuracy for eigenvalues. The default value of 0 implies machine precision. guess : float a guess for the refractive index....
2.84192
2.746354
1.034797
try: unch = sum([covstr(self.stock[3]),covstr(self.stock[4])])/2 re = {'name': unicode(self.stock[36].replace(' ',''), 'cp950'), 'no': self.stock[0], 'range': self.stock[1], 'time': self.stock[2], 'max': self.stock[3], 'min': self.stock[4]...
def real(self)
Real time data
2.744923
2.731197
1.005026
''' Display Taiwan Time now 顯示台灣此刻時間 ''' localtime = datetime.datetime.now() return localtime + datetime.timedelta(hours = time.timezone/60/60 + self.TimeZone)
def now(self)
Display Taiwan Time now 顯示台灣此刻時間
13.316648
5.496635
2.422691
''' Display Taiwan date now 顯示台灣此刻日期 ''' localtime = datetime.date.today() return localtime + datetime.timedelta(hours = time.timezone/60/60 + self.TimeZone)
def date(self)
Display Taiwan date now 顯示台灣此刻日期
15.03652
6.052945
2.484166
''' 檢查所有股票買賣點,剔除$10以下、成交量小於1000張的股票。 ''' for i in twseno().allstockno: a = goristock.goristock(i) try: if a.stock_vol[-1] > 1000*1000 and a.raw_data[-1] > 10: #a.goback(3) ## 倒退天數 ck4m(a) except: pass
def allck()
檢查所有股票買賣點,剔除$10以下、成交量小於1000張的股票。
14.054977
7.554813
1.8604
''' Calculates the coherence length (100% power transfer) of a directional coupler. Args: wavelength_nm (float): The wavelength in [nm] the directional coupler should operate at. n_eff_1 (float): n_eff of the fundamental (even) supermode of the directional couple...
def directional_coupler_lc(wavelength_nm, n_eff_1, n_eff_2)
Calculates the coherence length (100% power transfer) of a directional coupler. Args: wavelength_nm (float): The wavelength in [nm] the directional coupler should operate at. n_eff_1 (float): n_eff of the fundamental (even) supermode of the directional coupler. n...
3.403846
1.583243
2.14992
''' Calculate the period needed for a grating coupler. Args: wavelength (float): The target wavelength for the grating coupler. n_eff (float): The effective index of the mode of a waveguide with the width of the grating coupler. n_clad (float): Th...
def grating_coupler_period(wavelength, n_eff, n_clad, incidence_angle_deg, diffration_order=1)
Calculate the period needed for a grating coupler. Args: wavelength (float): The target wavelength for the grating coupler. n_eff (float): The effective index of the mode of a waveguide with the width of the grating coupler. n_clad (float): The refractive...
3.465254
1.681266
2.061098
return ('%s %s %s %.2f %+.2f %s %s %s %s %+.2f %s %s %.2f %.4f %.4f' % (aa.stock_no, aa.stock_name, aa.data_date[-1], aa.raw_data[-1], aa.range_per, aa.MAC(3), aa.MAC(6), aa.MAC(18), aa.MAO(3,6)[1], aa.MAO(3,6)[0][1][-1], aa.MAO(3,6)[0][0], aa.RABC, aa.stock_vol[-1]/1000, aa.SD, aa.CV)).encode('utf-8')
def oop(aa)
For cmd output.
5.60463
5.615554
0.998055
from twseno import twseno for i in twseno().allstock: #timetest(i) try: if case == 1: try: a = goristock(i) if goback: a.goback(goback) if a.MAO(3,6)[1] == '↑'.decode('utf-8') and (a.MAO(3,6)[0][1][-1] < 0 or ( a.MAO(3,6)[0][1][-1] < 1 and a.MAO(3,...
def overall(goback = 0, case = 1)
To run all over the stock and to find who match the 'case' 'goback' is back to what days ago. 0 is the last day.
2.33749
2.335256
1.000957
if prepend_paths is True: prepend_paths = [ os.path.abspath(os.path.dirname(__file__)), ] if prepend_paths: prepend_paths.append(filename) filename = os.path.join(*prepend_paths) print(filename) with open(filename, encoding='utf-8') as f: return f.read()
def read_file(filename, prepend_paths=[])
Returns the contents of *filename* (UTF-8). If *prepend_paths* is set, join those before the *fielname*. If it is `True`, prepend the path to `setup.py`.
2.574168
2.389216
1.077411
''' 載入檔案 檔案依據 http://www.twse.com.tw/ch/trading/trading_days.php ''' ld = csv.reader(open('./%s/opendate.csv' % _CSVFILEPATH, 'r')) re = {} re['close'] = [] re['open'] = [] for i in ld: ''' 0 = 休市, 1 = 開市 ''' if i[1] == '0': re['close'] += [datetime.strptime(i[0]...
def loaddate(self)
載入檔案 檔案依據 http://www.twse.com.tw/ch/trading/trading_days.php
3.747973
2.822941
1.327684
''' Open or close 回傳 True:開市,False:休市。 ''' if self.ptime.date() in self.ocdate['close']: ## 判對是否為法定休市 return False elif self.ptime.date() in self.ocdate['open']: ## 判對是否為法定開市 return True else: ''' 判斷是否為每週開休市 ''' if self.ptime.weekday() <= 4: return True ...
def ooc(self)
Open or close 回傳 True:開市,False:休市。
6.228461
4.307316
1.446019
''' 3-6負乖離且向上,三日內最大量,成交量大於 1000 張,收盤價大於 10 元。(較嚴謹的選股)''' return self.a.MAO(3,6)[1] == '↑'.decode('utf-8') and (self.a.MAO(3,6)[0][1][-1] < 0 or ( self.a.MAO(3,6)[0][1][-1] < 1 and self.a.MAO(3,6)[0][1][-1] > 0 and self.a.MAO(3,6)[0][1][-2] < 0 and self.a.MAO(3,6)[0][0] == 3)) and self.a.VOLMAX3 and self.a.stoc...
def ck_portf_001(self)
3-6負乖離且向上,三日內最大量,成交量大於 1000 張,收盤價大於 10 元。(較嚴謹的選股)
5.497509
2.675037
2.055115
''' 3日均價大於6日均價,6日均價大於18日均價。(短中長線呈現多頭的態勢) ''' return self.a.MA(3) > self.a.MA(6) > self.a.MA(18) and self.a.MAC(18) == '↑'.decode('utf-8') and self.a.stock_vol[-1] > 1000*1000 and self.a.raw_data[-1] > 10
def ck_portf_002(self)
3日均價大於6日均價,6日均價大於18日均價。(短中長線呈現多頭的態勢)
8.483212
3.438612
2.467046
''' 當日成交量,大於前三天的總成交量。(短線多空動能) ''' return self.a.stock_vol[-1] > sum(self.a.stock_vol[-4:-1]) and self.a.stock_vol[-1] > 1000*1000 and self.a.raw_data[-1] > 10
def ck_portf_003(self)
當日成交量,大於前三天的總成交量。(短線多空動能)
7.747419
3.335535
2.322691
''' 價走平一個半月。(箱型整理、盤整) ''' return self.a.SD < 0.25 and self.a.stock_vol[-1] > 1000*1000 and self.a.raw_data[-1] > 10
def ck_portf_004(self)
價走平一個半月。(箱型整理、盤整)
23.57057
6.045921
3.89859
''' 判斷乖離 ''' return list(self.a.ckMAO(self.a.MAO(3,6)[0][1], pm=pm))[0]
def GLI(self, pm=False)
判斷乖離
23.09548
13.623141
1.695312
''' 量大收紅 ''' return self.a.stock_vol[-1] > self.a.stock_vol[-2] and self.a.PUPTY
def B1(self)
量大收紅
24.779459
10.215481
2.425677
''' 量縮價不跌 ''' return self.a.stock_vol[-1] < self.a.stock_vol[-2] and self.a.PUPTY
def B2(self)
量縮價不跌
26.168095
9.5695
2.734531
''' 量大收黑 ''' return self.a.stock_vol[-1] > self.a.stock_vol[-2] and not self.a.PUPTY
def S1(self)
量大收黑
27.295038
11.417506
2.39063
''' 量縮價跌 ''' return self.a.stock_vol[-1] < self.a.stock_vol[-2] and not self.a.PUPTY
def S2(self)
量縮價跌
25.786928
11.106614
2.321763
''' 判斷是否為四大買點 ''' return self.ckMinsGLI and (self.B1 or self.B2 or self.B3 or self.B4)
def B4PB(self)
判斷是否為四大買點
15.617154
6.825696
2.287994
''' 判斷是否為四大賣點 ''' return self.ckPlusGLI and (self.S1 or self.S2 or self.S3 or self.S4)
def B4PS(self)
判斷是否為四大賣點
19.318737
7.086468
2.726145
''' Calculate the power reflection at the interface of two refractive index materials. Args: n1 (float): Refractive index of material 1. n2 (float): Refractive index of material 2. Returns: float: The percentage of reflected power. ''' r = abs((n1-n2) / (n1+n2))**2 ...
def reflection(n1, n2)
Calculate the power reflection at the interface of two refractive index materials. Args: n1 (float): Refractive index of material 1. n2 (float): Refractive index of material 2. Returns: float: The percentage of reflected power.
4.065303
1.97772
2.05555
''' Finds the coupling efficiency between a solved fundamental mode and a fibre of given MFD. Args: mode_solver (_ModeSolver): Mode solver that has found a fundamental mode. fibre_mfd (float): The mode-field diameter (MFD) of the fibre. fibre_offset_x (fl...
def coupling_efficiency(mode_solver, fibre_mfd, fibre_offset_x=0, fibre_offset_y=0, n_eff_fibre=1.441)
Finds the coupling efficiency between a solved fundamental mode and a fibre of given MFD. Args: mode_solver (_ModeSolver): Mode solver that has found a fundamental mode. fibre_mfd (float): The mode-field diameter (MFD) of the fibre. fibre_offset_x (float): Offset...
3.466043
1.85621
1.867269
''' Find the reference folder using the location of the script file Create the index, test if successful ''' if reference: reffas = reference else: parent_directory = path.dirname(path.abspath(path.dirname(__file__))) reffas = path.join(parent_directory, "reference/DNA_CS...
def getIndex(reference)
Find the reference folder using the location of the script file Create the index, test if successful
6.207943
4.213793
1.473244
''' Test if reads can get aligned to the lambda genome, if not: write to stdout ''' i = 0 for record in SeqIO.parse(reads, "fastq"): try: next(aligner.map(str(record.seq))) i += 1 except StopIteration: print(record.format("fastq"), end='') ...
def align(aligner, reads)
Test if reads can get aligned to the lambda genome, if not: write to stdout
7.16669
3.944344
1.816954
''' Converts the response to tables class. ''' if response is None or response.body is None: return None entities = _list() entities.next_marker = _get_continuation_from_response_headers(response) root = loads(response.body.decode('utf-8')) if 'value' in root: for entity ...
def _convert_json_response_to_entities(response, property_resolver, require_encryption, key_encryption_key, key_resolver)
Converts the response to tables class.
4.187893
3.675894
1.139286
ipmi_cmd = ("ipmitool -H %(address)s" " -I lanplus -U %(user)s -P %(passwd)s %(cmd)s" % {'address': driver_info['address'], 'user': driver_info['username'], 'passwd': driver_info['password'], 'cmd': command}) out = No...
def _exec_ipmitool(driver_info, command)
Execute the ipmitool command. This uses the lanplus interface to communicate with the BMC device driver. :param driver_info: the ipmitool parameters for accessing a node. :param command: the ipmitool command to be executed.
1.976077
2.277439
0.867675
i = 0x0 value = None ilo_fw_rev = get_ilo_version(ilo_fw) or DEFAULT_FW_REV # Note(vmud213): iLO firmware versions >= 2.3 support reading the FRU # information in a single call instead of iterating over each FRU id. if ilo_fw_rev < MIN_SUGGESTED_FW_REV: for i in range(0xff): ...
def get_nic_capacity(driver_info, ilo_fw)
Gets the FRU data to see if it is NIC data Gets the FRU data in loop from 0-255 FRU Ids and check if the returned data is NIC data. Couldn't find any easy way to detect if it is NIC data. We should't be hardcoding the FRU Id. :param driver_info: Contains the access credentials to access ...
3.770625
3.784557
0.996319
if (("Device not present" in nic_out) or ("Unknown FRU header" in nic_out) or not nic_out): return None capacity = None product_name = None data = nic_out.split('\n') for item in data: fields = item.split(':') if len(fields) > 1: first_field = fields[...
def _parse_ipmi_nic_capacity(nic_out)
Parse the FRU output for NIC capacity Parses the FRU output. Seraches for the key "Product Name" in FRU output and greps for maximum speed supported by the NIC adapter. :param nic_out: the FRU output for NIC adapter. :returns: the max capacity supported by the NIC adapter.
4.395852
4.135821
1.062873
return logical_drive.HPELogicalDriveCollection( self._conn, utils.get_subresource_path_by( self, ['Links', 'LogicalDrives']), redfish_version=self.redfish_version)
def logical_drives(self)
Gets the resource HPELogicalDriveCollection of ArrayControllers
7.223423
4.375566
1.650855
return physical_drive.HPEPhysicalDriveCollection( self._conn, utils.get_subresource_path_by( self, ['Links', 'PhysicalDrives']), redfish_version=self.redfish_version)
def physical_drives(self)
Gets the resource HPEPhysicalDriveCollection of ArrayControllers
6.076555
4.007037
1.516471
return utils.max_safe([member.logical_drives.maximum_size_mib for member in self.get_members()])
def logical_drives_maximum_size_mib(self)
Gets the biggest logical drive :returns the size in MiB.
8.345242
10.025962
0.832363
return utils.max_safe([member.physical_drives.maximum_size_mib for member in self.get_members()])
def physical_drives_maximum_size_mib(self)
Gets the biggest disk :returns the size in MiB.
8.752318
10.278767
0.851495
for member in self.get_members(): if member.physical_drives.has_ssd: return True return False
def has_ssd(self)
Return true if any of the drive under ArrayControllers is ssd
7.780179
6.207592
1.253333
for member in self.get_members(): if member.physical_drives.has_rotational: return True return False
def has_rotational(self)
Return true if any of the drive under ArrayControllers is ssd
8.2616
6.684499
1.235934
lg_raid_lvls = set() for member in self.get_members(): lg_raid_lvls.update(member.logical_drives.logical_raid_levels) return lg_raid_lvls
def logical_raid_levels(self)
Gets the raid level for each logical volume :returns the set of list of raid levels configured
3.949955
4.5191
0.874058
for member in self.get_members(): if member.location == location: return member
def array_controller_by_location(self, location)
Returns array controller instance by location :returns Instance of array controller
4.789507
6.711198
0.713659
for member in self.get_members(): if member.model == model: return member
def array_controller_by_model(self, model)
Returns array controller instance by model :returns Instance of array controller
5.174683
6.640856
0.779219
if isinstance(subresource_path, six.string_types): subresource_path = [subresource_path] elif not subresource_path: raise ValueError('"subresource_path" cannot be empty') body = resource.json for path_item in subresource_path: body = body.get(path_item, {}) if not body...
def get_subresource_path_by(resource, subresource_path)
Helper function to find the resource path :param resource: ResourceBase instance from which the path is loaded. :param subresource_path: JSON field to fetch the value from. Either a string, or a list of strings in case of a nested field. It should also include the '@odata.id' :raise...
2.420223
2.204195
1.098008
boot_mode_bios = 'false' boot_mode_uefi = 'false' if (supported_boot_mode == sys_cons.SUPPORTED_LEGACY_BIOS_ONLY): boot_mode_bios = 'true' elif (supported_boot_mode == sys_cons.SUPPORTED_UEFI_ONLY): boot_mode_uefi = 'true' ...
def get_supported_boot_mode(supported_boot_mode)
Return bios and uefi support. :param supported_boot_mode: Supported boot modes :return: A tuple of 'true'/'false' based on bios and uefi support respectively.
2.087973
1.95409
1.068514
uri = get_subresource_path_by(resource, subresouce_path) response = resource._conn.get(path=uri) return response.headers['Allow']
def get_allowed_operations(resource, subresouce_path)
Helper function to get the HTTP allowed methods. :param resource: ResourceBase instance from which the path is loaded. :param subresource_path: JSON field to fetch the value from. Either a string, or a list of strings in case of a nested field. :returns: A list of allowed HTTP methods.
6.170954
7.153084
0.862698
''' A function which sets the next host location on the request, if applicable. :param ~azure.storage.models.RetryContext context: The retry context containing the previous host location and the request to evaluate and possibly modify. ''' if len(conte...
def _set_next_host_location(self, context)
A function which sets the next host location on the request, if applicable. :param ~azure.storage.models.RetryContext context: The retry context containing the previous host location and the request to evaluate and possibly modify.
5.552775
2.442109
2.273762
resp = super(HPEConnector, self)._op(method, path, data, headers, allow_redirects=False) # With IPv6, Gen10 server gives redirection response with new path with # a prefix of '/' so this check is required if resp.status_code == 308: ...
def _op(self, method, path='', data=None, headers=None)
Overrides the base method to support retrying the operation. :param method: The HTTP method to be used, e.g: GET, POST, PUT, PATCH, etc... :param path: The sub-URI path to the resource. :param data: Optional JSON data. :param headers: Optional dictionary of headers. ...
5.755624
6.276699
0.916983
''' Sets the properties of a storage account's File service, including Azure Storage Analytics. If an element (ex HourMetrics) is left as None, the existing settings on the service for that functionality are preserved. :param Metrics hour_metrics: The hour metrics s...
def set_file_service_properties(self, hour_metrics=None, minute_metrics=None, cors=None, timeout=None)
Sets the properties of a storage account's File service, including Azure Storage Analytics. If an element (ex HourMetrics) is left as None, the existing settings on the service for that functionality are preserved. :param Metrics hour_metrics: The hour metrics settings provide a su...
2.766907
1.440073
1.921366
''' Returns a generator to list the shares under the specified account. The generator will lazily follow the continuation tokens returned by the service and stop when all shares have been returned or num_results is reached. If num_results is specified and the account ha...
def list_shares(self, prefix=None, marker=None, num_results=None, include_metadata=False, timeout=None)
Returns a generator to list the shares under the specified account. The generator will lazily follow the continuation tokens returned by the service and stop when all shares have been returned or num_results is reached. If num_results is specified and the account has more than that num...
2.721279
1.402535
1.940257
''' Returns all user-defined metadata and system properties for the specified share. The data returned does not include the shares's list of files or directories. :param str share_name: Name of existing share. :param int timeout: The timeout param...
def get_share_properties(self, share_name, timeout=None)
Returns all user-defined metadata and system properties for the specified share. The data returned does not include the shares's list of files or directories. :param str share_name: Name of existing share. :param int timeout: The timeout parameter is expressed in...
2.315124
1.488496
1.555344
''' Sets service-defined properties for the specified share. :param str share_name: Name of existing share. :param int quota: Specifies the maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5 TB (5120 GB). ...
def set_share_properties(self, share_name, quota, timeout=None)
Sets service-defined properties for the specified share. :param str share_name: Name of existing share. :param int quota: Specifies the maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5 TB (5120 GB). :param int time...
1.865655
1.467805
1.271051
''' Returns all user-defined metadata for the specified share. :param str share_name: Name of existing share. :param int timeout: The timeout parameter is expressed in seconds. :return: A dictionary representing the share metadata name, value ...
def get_share_metadata(self, share_name, timeout=None)
Returns all user-defined metadata for the specified share. :param str share_name: Name of existing share. :param int timeout: The timeout parameter is expressed in seconds. :return: A dictionary representing the share metadata name, value pairs. :rtyp...
2.11276
1.451742
1.455328
''' Gets the approximate size of the data stored on the share, rounded up to the nearest gigabyte. Note that this value may not include all recently created or recently resized files. :param str share_name: Name of existing share. :param int ...
def get_share_stats(self, share_name, timeout=None)
Gets the approximate size of the data stored on the share, rounded up to the nearest gigabyte. Note that this value may not include all recently created or recently resized files. :param str share_name: Name of existing share. :param int timeout: ...
2.472788
1.468078
1.684371
''' Returns a generator to list the directories and files under the specified share. The generator will lazily follow the continuation tokens returned by the service and stop when all directories and files have been returned or num_results is reached. If num_results is s...
def list_directories_and_files(self, share_name, directory_name=None, num_results=None, marker=None, timeout=None)
Returns a generator to list the directories and files under the specified share. The generator will lazily follow the continuation tokens returned by the service and stop when all directories and files have been returned or num_results is reached. If num_results is specified and the sha...
2.350826
1.313254
1.790076
''' Returns a list of the directories and files under the specified share. :param str share_name: Name of existing share. :param str directory_name: The path to the directory. :param str marker: A string value that identifies the portion of th...
def _list_directories_and_files(self, share_name, directory_name=None, marker=None, max_results=None, timeout=None)
Returns a list of the directories and files under the specified share. :param str share_name: Name of existing share. :param str directory_name: The path to the directory. :param str marker: A string value that identifies the portion of the list t...
1.655716
1.260597
1.313438
''' Sets system properties on the file. If one property is set for the content_settings, all properties will be overriden. :param str share_name: Name of existing share. :param str directory_name: The path to the directory. :param str file_name: ...
def set_file_properties(self, share_name, directory_name, file_name, content_settings, timeout=None)
Sets system properties on the file. If one property is set for the content_settings, all properties will be overriden. :param str share_name: Name of existing share. :param str directory_name: The path to the directory. :param str file_name: Name of e...
1.75513
1.376115
1.275424
''' Copies a blob or file to a destination file within the storage account. :param str share_name: Name of existing share. :param str directory_name: The path to the directory. :param str file_name: Name of existing file. :param str c...
def copy_file(self, share_name, directory_name, file_name, copy_source, metadata=None, timeout=None)
Copies a blob or file to a destination file within the storage account. :param str share_name: Name of existing share. :param str directory_name: The path to the directory. :param str file_name: Name of existing file. :param str copy_source: ...
2.488065
1.27764
1.947392
''' Creates a new file. See create_file_from_* for high level functions that handle the creation and upload of large files with automatic chunking and progress notifications. :param str share_name: Name of existing share. :param str directory_name: ...
def create_file(self, share_name, directory_name, file_name, content_length, content_settings=None, metadata=None, timeout=None)
Creates a new file. See create_file_from_* for high level functions that handle the creation and upload of large files with automatic chunking and progress notifications. :param str share_name: Name of existing share. :param str directory_name: The path ...
1.778751
1.350686
1.316924