def exec_prog(): # from : 20180116_103908 ### test 2 test_2() # x = Symbol('x') # y = Symbol('y') # z = Symbol('z') # y_ = Symbol('y_') # b = Symbol('b') # # y = log(b) * b ** 2 / (b - 2) # # y_ = diff(y, b) # # print ("[%s:%d] y =>" % (os.path.basename(libs.thisfile()), libs.linenum())) # print(y) # # print ("[%s:%d] y diff =>" % (os.path.basename(libs.thisfile()), libs.linenum())) # print(y_) # # # print ("[%s:%d] solve y diff =>" % (os.path.basename(libs.thisfile()), libs.linenum())) # # print(solve(y_, b)) # # NotImplementedError: multiple generators [b, log(b)] # print() # # b = 2 # # print ("[%s:%d] b = 2" % (os.path.basename(libs.thisfile()), libs.linenum())) # # print(y_) # # print() # # print ("[%s:%d] use 'subs'" % (os.path.basename(libs.thisfile()), libs.linenum())) # # print(y_.subs([(b,1)])) # # print() '''################### Report ###################''' print ("[%s:%d] exec_prog => done" % (os.path.basename(libs.thisfile()), libs.linenum()))
def build_History__Exec(node): # def _add_Numbering(node) : #debug print() print ("[%s:%d] node.tag = '%s'\nnode.attrib = '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum(), node.tag, node.attrib)) lenOf_Node = len(node) '''################### history ###################''' lo_Histories = [] _get_Histories(node, lo_Histories) '''################### return ###################''' return lo_Histories
def test_1(): strOf_FuncName = "test_1" '''################### step : 1 opening, vars ###################''' print() print ("[%s:%d] starting : %s (time=%s)" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , strOf_FuncName , libs.get_TimeLabel_Now() ) ) '''################### step : 2 ###################''' fig = plt.figure() # syntax for 3-D projection ax = plt.axes(projection ='3d') # defining all 3 axes x = [1,1,-1, 2,2,2,2] y = [-1,1,1, -1,1,2,-2] z = [1,-1,1, 1/2,-1/2,-1/4,1/4] # z = np.linspace(0, 1, 100) # x = z * np.sin(25 * z) # y = z * np.cos(25 * z) # plotting ax.plot3D(x, y, z, 'green') ax.set_title('3D line plot geeks for geeks') plt.show() '''###################
def test_2_statistics_StdDev(): strOf_FuncName = "test_2_statistics_StdDev" '''################### step : 1 std ###################''' print() print ("[%s:%d] starting : %s (time=%s)" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , strOf_FuncName , libs.get_TimeLabel_Now() ) ) # from scipy import stats speed = [99,86,87,88,111,86,103,87,94,78,77,85,86] x_std = numpy.std(speed) print() print("speed : ", speed) print() print("x_std : ", x_std) '''################### step : 2 variance ###################''' x_var = numpy.var(speed) print() print("x_var : ", x_var)
def exec_Numbering__Test_1(request): #ref https://stackoverflow.com/questions/204017/how-do-i-execute-a-program-from-python-os-system-fails-due-to-spaces-in-path answered Oct 15 '08 at 8:37 command = "C:\WORKS_2\Programs\Python\Python_3.5.1\python.exe" #=> arg1 = "C:/WORKS_2/WS/WS_Others/free/VX7GLZ_science-research/31_Materials/1_/1_1.3.py" # arg2 = "numbering" cmd_Full = [command, arg1] #=> # cmd_Full = [command, arg1, arg2] #=> res = test_31.test_1() # res = subprocess.call(cmd_Full) #debug #ref https://stackoverflow.com/questions/4558879/python-django-log-to-console-under-runserver-log-to-file-under-apache cardamom Jul 7 '17 at 11:25 # print >>sys.stderr, 'Goodbye, cruel world!' # dbg = "[%s:%d] messsage" % (os.path.basename(libs.thisfile()), libs.linenum()) # # print(dbg, file=sys.stderr) # print("Goodbye cruel world!", file=sys.stderr) # print("[%s:%d] %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , "this is.") # , file=sys.stderr) msg = "However there are other options" # print("[%s:%d] %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , msg # ) # # , file=sys.stderr) print("[%s:%d] %s" % \ (os.path.basename(libs.thisfile()), libs.linenum() , msg ), file=sys.stderr) return HttpResponse(res, content_type='text/plain')
def test_3_stats_Percentile(): strOf_FuncName = "test_2_statistics_StdDev" '''################### step : 1 opening, vars ###################''' print() print ("[%s:%d] starting : %s (time=%s)" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , strOf_FuncName , libs.get_TimeLabel_Now() ) ) #code:20210411_171845 ages = [5,31,43,48,50,41,7,11,15,39,80,82,32,2,8,6,25,36,27,61,31] numOf_Percentile = 75 '''################### step : 2 percentile ###################''' x_Percentile = numpy.percentile(ages, numOf_Percentile) print() print("ages : ", ages) print() print("x_Percentile : ", x_Percentile) '''###################
def test_2(): #ref http://programming.blogo.jp/python/sympy/%E9%96%A2%E6%95%B0%E3%81%AB%E4%BB%A3%E5%85%A5 #ref search https://duckduckgo.com/?q=python+sympy+%E5%A4%89%E6%95%B0+%E4%BB%A3%E5%85%A5&atb=v84-1__&ia=web var("a:z") var("y_") y = log(b) * b ** 2 / (b - 2) y_ = diff(y, b) print ("[%s:%d] y diff" % (os.path.basename(libs.thisfile()), libs.linenum())) print(y_) print() ### insert val to 'b' print() print(y_.subs([(b, 3)])) #ref http://docs.sympy.org/latest/modules/evalf.html numerical print(N(y_.subs([(b, 3)]))) print()
def test_2(): strOf_FuncName = "test_2" '''################### step : 1 opening, vars ###################''' print() print ("[%s:%d] starting : %s (time=%s)" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , strOf_FuncName , libs.get_TimeLabel_Now() ) ) '''################### step : 2 prep ###################''' '''################### step : 2 : 1 prep : data : x ###################''' #mark:20211030_153553 # numOf_Data_X = 24 numOf_Data_X = 36 valOf_Linspace_Start = - math.pi / 2 valOf_Linspace_End = math.pi / 2 #ref https://matplotlib.org/stable/tutorials/introductory/customizing.html#sphx-glr-tutorials-introductory-customizing-py data_x = np.linspace( valOf_Linspace_Start , valOf_Linspace_End , numOf_Data_X) # print() # # print ("[%s:%d] data_x =>" % ( # os.path.basename(os.path.basename(libs.thisfile())) # , libs.linenum() # ) # ) # # print(data_x) '''################### step : 2 : 2 prep : data : y --> cos(x) ###################''' #mark:20211030_154118 k = 3 # k = 1 # k = 2 coord_1 = math.pow(-1, k) / (2*k+1) data_y = [math.cos(x) for x in data_x] data_y_with_coord = [coord_1 * y for y in data_y] # y vals --> add #mark:20211030_155934 data_y_sum = data_y + data_y_with_coord #mark:20211030_162412 lenOf_data_y = len(data_y) data_y_sum_2 = [data_y[i] + data_y_with_coord[i] for i in range(lenOf_data_y)] #debug:20211030_160239 print() print ("[%s:%d] len(data_y) => %d / len(data_y_with_coord) => %d" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , len(data_y) , len(data_y_with_coord) ) ) print ("[%s:%d] len(data_y_sum) => %d / len(data_y_sum_2) => %d" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , len(data_y_sum) , len(data_y_sum_2) ) ) print() # #debug # return # print() # # print ("[%s:%d] data_y =>" % ( # os.path.basename(os.path.basename(libs.thisfile())) # , libs.linenum() # ) # ) # # print(data_y) # # print() # # print ("[%s:%d] data_y_with_coord =>" % ( # os.path.basename(os.path.basename(libs.thisfile())) # , libs.linenum() # ) # ) # # print(data_y_with_coord) '''################### step : 3 plot ###################''' '''################### step : 3 : 1 plot : prep ###################''' # folder strOf_Time_Label = libs.get_TimeLabel_Now() # dpath_data = "./data" dpath_data = "data" dname_PlotImage = "plot_%s" % (strOf_Time_Label) # dname_PlotImage = "plot_image_%s" % (strOf_Time_Label) dpath_PlotImage = os.path.join(dpath_data, dname_PlotImage) # file name #mark:20211030_163128 fname_Plot = "plot_%s_(k=%d)" % (strOf_Time_Label, k) # fname_Plot = "plot_%s" % (strOf_Time_Label) fpath_PlotImage = os.path.join(dpath_PlotImage, fname_Plot) #ref https://www.askpython.com/python/examples/create-a-directory-in-python res = os.mkdir(dpath_PlotImage) print() print ("[%s:%d] os.mkdir for => : %s" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , dpath_PlotImage ) ) print(res) '''################### step : 3 : 2 plot : plot ###################''' #ref C:\WORKS_2\WS\WS_Others.JVEMV6\JVEMV6\73_ai\1_start\1_1.py fig = plt.figure() # title # plt.title("cos(a), data_y_1_final\n numOf_Data_X = %d\n x [%.02f, %.02f]" # plt.title("cos(a), data_y_with_coord\n numOf_Data_X = %d\n x [%.02f, %.02f]" plt.title("cos(a), data_y_with_coord\n numOf_Data_X = %d\n x [%.02f, %.02f] / k = %d" % ( numOf_Data_X , valOf_Linspace_Start , valOf_Linspace_End , k ) ) # axis #ref https://matplotlib.org/stable/tutorials/introductory/pyplot.html#sphx-glr-tutorials-introductory-pyplot-py plt.axis([- math.pi/2, math.pi/2, -1.5, 1.5]) # plot #mark:20211030_154535 plt.plot(data_x, data_y,'b-o') plt.plot(data_x, data_y_with_coord,'r-o') #mark:20211030_160000 plt.plot(data_x, data_y_sum_2,'y-+') # plt.plot(data_x, data_y_sum,'y-+') # grid #ref https://www.w3schools.com/python/matplotlib_grid.asp plt.grid() # save image res = fig.savefig(fpath_PlotImage) print() print ("[%s:%d] result for 'fig.savefig' : %s" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , fpath_PlotImage ) ) print(res) '''################### step : 4 ###################''' '''###################
def build_history(request): '''################### get : referer ###################''' referer_MM = "http://127.0.0.1:8000/mm/" referer_Current = request.META.get('HTTP_REFERER') # referer_Current = req.META.get('HTTP_REFERER') '''################### var : list of files ###################''' MAIN_DIR = cons_mm.FPath.DPATH_MM_PROJECTS.value mypath = MAIN_DIR #ref https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory answered Jul 8 '10 at 21:01 dpath_Main = cons_mm.FPath.DPATH_MM_PROJECTS.value #ref glob https://stackoverflow.com/questions/2225564/get-a-filtered-list-of-files-in-a-directory lo_Entries = glob.glob(dpath_Main + "\\" + "*.mm") # lo_Entries = glob.glob('*.mm') # lo_Entries = listdir(mypath) #ref splitext https://stackoverflow.com/questions/37896386/how-to-get-file-extension-correctly answered Jun 18 '16 at 11:29 # lo_Files = [f for f in lo_Entries if isfile(join(mypath, f)) and splitext(f)] # lo_Files = [f for f in lo_Entries if isfile(join(mypath, f))] #ref basename https://stackoverflow.com/questions/678236/how-to-get-the-filename-without-the-extension-from-a-path-in-python answered Mar 24 '09 at 16:43 lo_Files = [ os.path.basename(f) for f in lo_Entries if isfile(join(mypath, f)) ] # lo_Files = [f for f in lo_Entries if isfile(join(mypath, f))] # lo_Files = [f for f in listdir(mypath) if isfile(join(mypath, f))] # print() # print("[%s:%d] files => %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , lo_Files # ), file=sys.stderr) # print() '''################### sort list ###################''' #ref sort https://stackoverflow.com/questions/4183506/python-list-sort-in-descending-order answered Nov 15 '10 at 10:42 lo_Files.sort(reverse=False) # sorted(lo_Files, reverse = True) # print() # print("sorting...") # print("[%s:%d] files => %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , lo_Files # ), file=sys.stderr) # print() '''################### dict ###################''' msg = "build history!!" dic = { "msg": msg, "MAIN_DIR": cons_mm.FPath.DPATH_MM_PROJECTS.value, "lo_Files": lo_Files, } '''################### render ###################''' print() print("[%s:%d] referer_Current = '%s' / referer_MM = '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum() , referer_Current, referer_MM ), file=sys.stderr) print() # if True : #if referer_Current == referer_MM if referer_Current == referer_MM: #if referer_Current == referer_MM return render(request, 'mm/build_history.html', dic) # return render(request, 'mm/numbering.html', dic) else: #if referer_Current == referer_MM return render(request, 'mm/build_history_full.html', dic)
def exec_BuildHistory(request): '''################### requests ###################''' dpath = request.GET.get('dpath', False) fname = request.GET.get('fname', False) '''################### data ###################''' ### count time #ref https://stackoverflow.com/questions/3620943/measuring-elapsed-time-with-the-time-module answered Sep 1 '10 at 18:22 time_Start = time.time() if not dpath == False and not fname == False: # if dpath == True or fname == True : # if dpath == False or fname == False : msg = "params obtained" else: msg = "params NOT enough" dic = { cons_mm.ExecNumbering.DICKEY_MSG.value: msg, cons_mm.ExecNumbering.DICKEY_DPATH.value: dpath, cons_mm.ExecNumbering.DICKEY_FNAME.value: fname, } # dic = {"msg" : msg, "dpath" : dpath, "fname" : fname} print() print("[%s:%d] dic => '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum() , dic ), file=sys.stderr) print() '''################### render : params not sufficient ###################''' return render(request, 'mm/exec_BuildHistory.html', dic) # msg = None if dpath == False or fname == False else "params obtained" # print() # print("[%s:%d] msg => '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , msg # ), file=sys.stderr) # print() dic = { cons_mm.ExecNumbering.DICKEY_MSG.value: msg, cons_mm.ExecNumbering.DICKEY_DPATH.value: dpath, cons_mm.ExecNumbering.DICKEY_FNAME.value: fname, } # dic = {"msg" : msg, "dpath" : dpath, "fname" : fname} print() print("[%s:%d] dic => '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum() , dic ), file=sys.stderr) print() '''################### exec numbering ###################''' '''################### validate : file exists ###################''' fpath = os.path.join(dpath, fname) #ref https://stackoverflow.com/questions/82831/how-do-i-check-whether-a-file-exists-using-python answered Sep 17 '08 at 12:57 my_file = Path(fpath) if not my_file.is_file(): print() print("[%s:%d] file NOT exists : '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum() , fpath ), file=sys.stderr) print() dic[cons_mm.ExecNumbering.DICKEY_MSG.value] = \ "File does NOT exist : %s" % (fpath) '''################### render : params not sufficient ###################''' return render(request, 'mm/exec_DeNumbering.html', dic) # return render(request, 'mm/exec_Numbering.html', dic) '''################### execute ###################''' #debgu # res = cons_mm.RetVal.RET_OK.value res = _exec_BuildHistory(dpath, fname) # # res = _exec_Numbering(dpath, fname) # # res = _exec_Numbering(fpath) '''################### time ###################''' time_Elapsed = time.time() - time_Start ### add info if not res == cons_mm.RetVal.RET_OK.value: #if res == -1 # if res == -1 : #if res == -1 dic[cons_mm.ExecNumbering.DICKEY_MSG.value] = \ "EXCEPTION : %s" % (res[0]) # "EXCEPTION " # "<font color='red'>EXCEPTION</font>" else: #/if res == -1 dic[cons_mm.ExecNumbering.DICKEY_MSG.value] += \ " (time : %02.3f sec)" % (time_Elapsed) #/#/if res == -1 # dic[cons_mm.ExecNumbering.DICKEY_MSG.value] += \ # " (time : %02.3f sec)" % (time_Elapsed) # " (time : %d)" % (time_Elapsed) '''################### render : params not sufficient ###################''' return render(request, 'mm/exec_BuildHistory.html', dic)
def _exec_DeNumbering(dpath, fname): fpath = os.path.join(dpath, fname) '''################### replace ###################''' '''################### file : open ###################''' fin = open(fpath, "r") content = fin.read() fin.close() # #debug # print() # print ("[%s:%d] len(content) : %d\ncontent[:20] = '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , len(content) # , content[:20] # ) # # ) '''################### replace ###################''' #ref https://stackoverflow.com/questions/16720541/python-string-replace-regular-expression answered May 23 '13 at 17:53 reg = re.compile("[\d\-]+\) ") content = reg.sub("", content) # tree = ET.parse(fpath) # # tree = libmt.add_Numbering__Through(tree) # # '''################### # save xml # ###################''' # label = "add-numbering-through" # fpath_Out = os.path.join( dpath, fname # fname + "." + libs.get_TimeLabel_Now() \ # + "." \ # + "mm" ) # # fpath_Out = "new.%s.%s.mm" % (label, libs.get_TimeLabel_Now()) # # tree.write(fpath_Out) '''################### file : write ###################''' try: fout = open(fpath_Out, "w") res = fout.write(content) fout.close() except: e = sys.exc_info() # e = sys.exc_info()[0] print() print ("[%s:%d] exception : %s" % \ (os.path.basename(libs.thisfile()), libs.linenum() , e ) ) return e # return -1 print() # print ("[%s:%d] mm => written : %s" % \ # print ("[%s:%d] DeNumbering : %s" % \ print ("[%s:%d] file written : %s ( result = %s)" % \ (os.path.basename(libs.thisfile()), libs.linenum() , fpath_Out , res ) ) return cons_mm.RetVal.RET_OK.value
def exec_prog(): # upto : 20180109_161654 '''###################################### get data : raw csv rows ######################################''' #ref enum https://qiita.com/methane/items/8612bdefd8fa4238cc44 #ref https://docs.python.org/3.5/library/enum.html fname_In = cons.FPath.dpath_In_CSV.value \ + "/" \ + cons.FPath.fname_In_CSV.value # fname_In = cons.FPath.fpath_In_CSV.value # fname_In = cons.FPath.fname_In_CSV.value # fname_In = "../data/49_11_file-io.USDJPY.Period-H1.Days-720.Bars-17280.20171231_233725.csv" #=> '''### ###''' header_Length = 2 # header_Length = 3 # skip_Header = True skip_Header = False result = libfx.get_ChartData_CSV(\ fname_In, header_Length, skip_Header) ### Validate if result == None: #if result == None print ("[%s:%d] get_ChartData_CSV => Returned 'None'" % \ (libs.thisfile(), libs.linenum())) # print "[%s:%d] get_ChartData_CSV => Returned 'None'" % \ # (libs.thisfile(), libs.linenum()) return #/if result == None ### report print() print("[%s:%d] CSV rows => %d" % (os.path.basename(libs.thisfile()), libs.linenum(), len(result))) print() print("[%s:%d] row[%d] => %s" % (os.path.basename(libs.thisfile()), libs.linenum(), 0, result[0])) print() '''###################################### Conv : CSV rows ---> array of BarData class instances ######################################''' # aryOf_BarDatas = libfx.conv_CSVRows_2_BarDatas(result) aryOf_BarDatas = libfx.conv_CSVRows_2_BarDatas(result[header_Length:]) ### Validate if aryOf_BarDatas == None: #if aryOf_BarDatas == None print("[%s:%d] aryOf_BarDatas => None" % (os.path.basename(libs.thisfile()), libs.linenum())) print() return #/if aryOf_BarDatas == None '''################### get : high-lows ###################''' id_Start = cons.BarData.HighLowDiff_ID_Start.value id_End = cons.BarData.HighLowDiff_ID_End.value # typeOf_Data = cons.typeOf_Data_OPENCLOSE # typeOf_Data = "OpenClose" result_HighLowDiffs = libfx.get_HighLowDiffs(aryOf_BarDatas, id_Start, id_End) # result = libfx.get_HighLowDiffs(aryOf_BarDatas, typeOf_Data, id_Start, id_End) print ("[%s:%d] result => %s" % \ (libs.thisfile(), libs.linenum(), result_HighLowDiffs)) # print "[%s:%d] result[%s] => %s" % \ # (libs.thisfile(), libs.linenum(), cons.LABEL_OC, result_HighLowDiffs[cons.LABEL_OC]) # print "[%s:%d] result[%s] => %s" % \ # (libs.thisfile(), libs.linenum(), cons.LABEL_HL, result_HighLowDiffs[cons.LABEL_HL]) print() '''################### add : data ###################''' whole_Data = {} whole_Data['data'] = result_HighLowDiffs print() print("[%s:%d] whole data =>" % (os.path.basename(libs.thisfile()), libs.linenum())) print(whole_Data) '''################### build : meta info ###################''' dictOf_MetaInfo = libfx.get_BarData_MetaInfo(fname_In, header_Length) print() print ("[%s:%d] dictOf_MetaInfo => %s" % \ (os.path.basename(libs.thisfile()), libs.linenum(), dictOf_MetaInfo)) print() ### add : meta info whole_Data['meta'] = dictOf_MetaInfo '''################### write to file ###################''' # [82_1.py:163] dictOf_MetaInfo => {'PAIR': 'USDJPY', 'PERIOD': 'H1', 'DAYS': '720 # ', 'SHIFT': '1'} # fname_Out_HighLowDiffs = \ fpath_Out_HighLowDiffs = \ cons.FPath.fpath_Out_HighLowDiff.value \ + "/" \ + "_HighLowDiff_." \ + cons.Label_ColNames.PAIR.value + "-" \ + dictOf_MetaInfo[cons.Label_ColNames.PAIR.value] \ + "." \ + cons.Label_ColNames.PERIOD.value + "-" \ + dictOf_MetaInfo[cons.Label_ColNames.PERIOD.value] \ + "." \ + cons.Label_ColNames.DAYS.value + "-" \ + dictOf_MetaInfo[cons.Label_ColNames.DAYS.value] \ + "." \ + cons.Label_ColNames.SHIFT.value + "-" \ + dictOf_MetaInfo[cons.Label_ColNames.SHIFT.value] \ + "." \ + libs.get_TimeLabel_Now() \ + ".csv" # + ".txt" print ("[%s:%d] fname out => %s" % \ (os.path.basename(libs.thisfile()), libs.linenum(), fpath_Out_HighLowDiffs)) ### write to file f_Out = open(fpath_Out_HighLowDiffs, "w") '''################### meta info ###################''' f_Out.write( '\t'.join( [cons.Label_ColNames.PAIR.value, \ cons.Label_ColNames.PERIOD.value, \ cons.Label_ColNames.DAYS.value, \ cons.Label_ColNames.SHIFT.value, \ "id_Start", \ "id_End", \ "source csv" ]) ) f_Out.write('\n') f_Out.write( '\t'.join( [ dictOf_MetaInfo[cons.Label_ColNames.PAIR.value], \ dictOf_MetaInfo[cons.Label_ColNames.PERIOD.value], \ dictOf_MetaInfo[cons.Label_ColNames.DAYS.value], \ dictOf_MetaInfo[cons.Label_ColNames.SHIFT.value], \ str(id_Start), \ str(id_End), \ cons.FPath.fname_In_CSV.value ]) ) f_Out.write('\n') f_Out.write("\t\t\t\t" \ + aryOf_BarDatas[id_Start - 1].dateTime_Local \ + '\t' \ + aryOf_BarDatas[id_End - 1].dateTime_Local ) f_Out.write('\n') '''################### High, low, diff ###################''' # f_Out.write('\t'.join([cons.BarData.LABEL_OC.value].extend(result_HighLowDiffs[cons.BarData.LABEL_OC.value]))) # tmp = [cons.BarData.LABEL_OC.value] # tmp = result_HighLowDiffs[cons.BarData.LABEL_OC.value] # tmp = [cons.BarData.LABEL_OC.value].extend(['aaa']) # tmp = [cons.BarData.LABEL_OC.value] \ # .extend(result_HighLowDiffs[cons.BarData.LABEL_OC.value]) ### OC tmp = [cons.BarData.LABEL_OC.value] tmp.extend(result_HighLowDiffs[cons.BarData.LABEL_OC.value]) f_Out.write('\t'.join([str(x) for x in tmp])) # f_Out.write('\t'.join(tmp)) f_Out.write('\n') ### HL tmp = [cons.BarData.LABEL_HL.value] tmp.extend(result_HighLowDiffs[cons.BarData.LABEL_HL.value]) f_Out.write('\t'.join([str(x) for x in tmp])) # f_Out.write('\t'.join(tmp)) f_Out.write('\n') ### RSI tmp = [cons.BarData.LABEL_RSI.value] tmp.extend(result_HighLowDiffs[cons.BarData.LABEL_RSI.value]) f_Out.write('\t'.join([str(x) for x in tmp])) # f_Out.write('\t'.join(tmp)) f_Out.write('\n') ### MFI tmp = [cons.BarData.LABEL_MFI.value] tmp.extend(result_HighLowDiffs[cons.BarData.LABEL_MFI.value]) f_Out.write('\t'.join([str(x) for x in tmp])) # f_Out.write('\t'.join(tmp)) f_Out.write('\n') ### BB_MAIN tmp = [cons.BarData.LABEL_BB_MAIN.value] tmp.extend(result_HighLowDiffs[cons.BarData.LABEL_BB_MAIN.value]) f_Out.write('\t'.join([str(x) for x in tmp])) # f_Out.write('\t'.join(tmp)) f_Out.write('\n') ### BB_1S tmp = [cons.BarData.LABEL_BB_1S.value] tmp.extend(result_HighLowDiffs[cons.BarData.LABEL_BB_1S.value]) f_Out.write('\t'.join([str(x) for x in tmp])) # f_Out.write('\t'.join(tmp)) f_Out.write('\n') ### BB_2S tmp = [cons.BarData.LABEL_BB_2S.value] tmp.extend(result_HighLowDiffs[cons.BarData.LABEL_BB_2S.value]) f_Out.write('\t'.join([str(x) for x in tmp])) # f_Out.write('\t'.join(tmp)) f_Out.write('\n') ### BB_M1S tmp = [cons.BarData.LABEL_BB_M1S.value] tmp.extend(result_HighLowDiffs[cons.BarData.LABEL_BB_M1S.value]) f_Out.write('\t'.join([str(x) for x in tmp])) # f_Out.write('\t'.join(tmp)) f_Out.write('\n') ### BB_M2S tmp = [cons.BarData.LABEL_BB_M2S.value] tmp.extend(result_HighLowDiffs[cons.BarData.LABEL_BB_M2S.value]) f_Out.write('\t'.join([str(x) for x in tmp])) # f_Out.write('\t'.join(tmp)) f_Out.write('\n') # print() # print ("[%s:%d] OC data => " % (os.path.basename(libs.thisfile()), libs.linenum())) # print(tmp) # print() '''################### file : close ###################''' f_Out.close() print() print ("[%s:%d] file closed => %s" % \ (os.path.basename(libs.thisfile()), libs.linenum(), fpath_Out_HighLowDiffs)) print() # #test # print() # print ("[%s:%d] aryOf_BarDatas[id_Start(%d)] => %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum(), # id_Start, aryOf_BarDatas[id_Start])) # # print(aryOf_BarDatas[id_Start].dateTime_Local) # # print(aryOf_BarDatas[id_Start]) # # print() '''################### Report ###################''' print("[%s:%d] exec_prog => done" % (os.path.basename(libs.thisfile()), libs.linenum()))
def test_S_14_No_2_Scipy(): strOf_FuncName = "test_S_14_No_2_Scipy" '''################### step : 1 opening, vars ###################''' #ref https://stackoverflow.com/questions/56711424/how-can-i-count-time-in-python-3 t_start = time.time() print() print("[%s:%d] starting : %s (time=%s)" % (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum(), strOf_FuncName, libs.get_TimeLabel_Now())) print() '''################### step : 2 data : prep ###################''' x = np.array([[1, 2], [3, 4]]) y = np.array([[5, 6], [7, 8]]) #debug print("[%s:%d] x, y :" % (os.path.basename(libs.thisfile()), libs.linenum())) print(x) print(y) v = np.array([9, 10]) w = np.array([11, 12]) '''################### step : 2 : 1 inner prod ###################''' valOf_InnerProd = np.dot(v, w) #debug print("[%s:%d] valOf_InnerProd :" % (os.path.basename(libs.thisfile()), libs.linenum())) print(v) print(w) print(valOf_InnerProd) print() '''################### step : 2 : 2 vector prod ###################''' valOf_Vector_Prod = np.dot(x, v) #debug print("[%s:%d] valOf_Vector_Prod :" % (os.path.basename(libs.thisfile()), libs.linenum())) print(x) print(v) print(valOf_Vector_Prod) print() '''################### step : 2 : 3 prod : matrix ###################''' valOf_Prod_Matrix = np.dot(x, y) #debug print("[%s:%d] valOf_Prod_Matrix :" % (os.path.basename(libs.thisfile()), libs.linenum())) print(x) print(y) print(valOf_Prod_Matrix) print() '''################### step : 2 : 1 data : store ###################''' '''################### step : 6 results ###################''' '''################### step : 6 : 1 time ###################''' t_end = time.time() #debug # print ("[%s:%d] time => %s" #ref https://www.pythonpool.com/python-float-to-string/#5_Using_NumPy print("[%s:%d] time => %.03f sec" % (os.path.basename(libs.thisfile()), libs.linenum(), (t_end - t_start))) print() '''###################
def test_2_2(): '''################### ops ###################''' init_Val = 10 a = [10 for x in range(10)] b = [10 for x in range(10)] # de-homogenize #ref mean https://stackoverflow.com/questions/9039961/finding-the-average-of-a-list answered Jan 28 '12 at 3:59 # a[-1] = 5 # b[-1] = 5 val = 5 a[-1] = val b[-1] = val # a[-1] = 9 # b[-1] = 9 '''################### write file ###################''' # fname_Out = "data/pval.a-%d.%s.txt" % \ label = "test_2_2(val-%d)" % (val) fname_Out = "data/pval.%s.%s.txt" % \ ( label , libs.get_TimeLabel_Now() ) # fname_Out = "/data/pval.%s.txt" % (libs.get_TimeLabel_Now()) fout = open(fname_Out, "w") '''################### correl : basic ###################''' msg = "[%s:%d] a=\n" % (os.path.basename(libs.thisfile()), libs.linenum()) fout.write(msg) # fout.write("a=\n") fout.write(','.join([str(x) for x in a])) # fout.write(','.join(a)) fout.write('\n') fout.write('\n') msg = "[%s:%d] b=\n" % (os.path.basename(libs.thisfile()), libs.linenum()) fout.write(msg) # fout.write("b=\n") fout.write(','.join([str(x) for x in b])) # fout.write(','.join(b)) fout.write('\n') fout.write('\n') '''################### correl : basic ###################''' lo_Final = [] for i in range(10): # tmp list lo_Tmp = [] ### copy a #ref copy https://stackoverflow.com/questions/2612802/how-to-clone-or-copy-a-list answered Apr 10 '10 at 8:55 a_ = copy.copy(a) lo_Tmp.append(i) lo_Tmp.append(a[0]) a1 = stats.pearsonr(a_, b) lo_Tmp.append(a1) ### append lo_Final.append(lo_Tmp) # decrement a[0] -= 1 '''################### write ###################''' fout.write("index\ta[0]\tcorrel") fout.write("\n") for item in lo_Final: fout.write("%d\t%d\t%.10f" % \ # fout.write("%d\t%.4f\t%.4f\t%.4f" % \ ( item[0], item[1], item[2][0] ) ) # print("%.4f %.4f %.4f" % (item[1][0], item[2][0], item[3][0])) fout.write('\n') '''################### file : close ###################''' fout.close() # msg = "[%s:%d] \na[%d]\tcorrel" % \ # ( # os.path.basename(libs.thisfile()), libs.linenum() # , index_a # ) # fout.write(msg) # # fout.write('\n') # fout.write('\n') return None
def test_1(): '''################### ops ###################''' a = np.arange(1, 11) b = np.arange(1, 11) pval = stats.pearsonr(a, b) print(a) '''################### write file ###################''' index_a = -2 fname_Out = "data/pval.a[%d].%s.txt" % \ ( index_a , libs.get_TimeLabel_Now() ) # fname_Out = "/data/pval.%s.txt" % (libs.get_TimeLabel_Now()) fout = open(fname_Out, "w") '''################### correl : basic ###################''' msg = "[%s:%d] a=\n" % (os.path.basename(libs.thisfile()), libs.linenum()) fout.write(msg) # fout.write("a=\n") fout.write(','.join([str(x) for x in a])) # fout.write(','.join(a)) fout.write('\n') fout.write('\n') msg = "[%s:%d] b=\n" % (os.path.basename(libs.thisfile()), libs.linenum()) fout.write(msg) # fout.write("b=\n") fout.write(','.join([str(x) for x in b])) # fout.write(','.join(b)) fout.write('\n') fout.write('\n') correl = stats.pearsonr(a, b) msg = "[%s:%d] correl=%.4f\n" % \ (os.path.basename(libs.thisfile()), libs.linenum() , correl[0] ) fout.write(msg) fout.write('\n') fout.write('\n') '''################### correl : basic ###################''' # index_a = -2 test_1_2(fout, a, b) # test_1_1(fout, a, b, index_a) # test_1_1(fout, a, b) '''################### file : close ###################''' fout.close() return None
def test_1(): strOf_FuncName = "test_1" '''################### step : 1 opening, vars ###################''' print() print("[%s:%d] starting : %s (time=%s)" % (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum(), strOf_FuncName, libs.get_TimeLabel_Now())) '''################### step : 2 prep ###################''' '''################### step : 3 ###################''' a = math.pi cos_a = math.cos(a) print() print("[%s:%d] a = %.03f / cos(a) = %.03f" % (os.path.basename( os.path.basename(libs.thisfile())), libs.linenum(), a, cos_a)) '''################### step : 4 ###################''' '''################### step : 4 : 1 prep : data ###################''' '''################### step : 4 : 1 : prep : data : basics ###################''' #ref https://numpy.org/doc/stable/reference/generated/numpy.linspace.html # numOf_Data_X = 12 numOf_Data_X = 24 valOf_Linspace_Start = -math.pi / 2 valOf_Linspace_End = math.pi / 2 # valOf_Linspace_Start = 0 # valOf_Linspace_End = math.pi #ref https://matplotlib.org/stable/tutorials/introductory/customizing.html#sphx-glr-tutorials-introductory-customizing-py data_x = np.linspace(valOf_Linspace_Start, valOf_Linspace_End, numOf_Data_X) '''################### step : 4 : 1 : 2 prep : data : cosine values ###################''' k = 1 data_x_1 = [(2 * k + 1) * x for x in data_x] data_y = np.cos(data_x) data_y_1 = np.cos(data_x_1) data_y_1_final = [math.pow(-1, k) / (2 * k + 1) * x for x in data_y_1] print() print("[%s:%d] numOf_Data_X = %d" % (os.path.basename( os.path.basename(libs.thisfile())), libs.linenum(), numOf_Data_X)) print() # print ("[%s:%d] data_x =>" % ( # os.path.basename(os.path.basename(libs.thisfile())) # , libs.linenum() # ) # ) # # print(data_x) # # print ("[%s:%d] data_y =>" % ( # os.path.basename(os.path.basename(libs.thisfile())) # , libs.linenum() # ) # ) # # print(data_y) '''################### step : 4 : 2 plot ###################''' '''################### step : 4 : 2 : 1 plot : prep savefig ###################''' strOf_Time_Label = libs.get_TimeLabel_Now() #ref C:\WORKS_2\WS\WS_Others.JVEMV6\JVEMV6\73_ai\1_start\1_1.py fig = plt.figure() dpath_PlotImage = "./data" fname_PlotImage = "plot_image_%s_[test]" % (strOf_Time_Label) fpath_PlotImage = os.path.join(dpath_PlotImage, fname_PlotImage) # title # plt.title("cos(a)\n numOf_Data_X = %d\n x [%.02f, %.02f]" # plt.title("cos(a), data_y_1\n numOf_Data_X = %d\n x [%.02f, %.02f]" plt.title("cos(a), data_y_1_final\n numOf_Data_X = %d\n x [%.02f, %.02f]" % (numOf_Data_X, valOf_Linspace_Start, valOf_Linspace_End)) # axis #ref https://matplotlib.org/stable/tutorials/introductory/pyplot.html#sphx-glr-tutorials-introductory-pyplot-py plt.axis([-math.pi / 2, math.pi / 2, -1.5, 1.5]) # plt.axis([- math.pi/2, math.pi/2, -1.0, 1.0]) '''################### step : 4 : 2 : 2 plot : set data ###################''' plt.plot(data_x, data_y + data_y_1_final, 'y-o') plt.plot(data_x, data_y_1_final, 'b-o') plt.plot(data_x, data_y, 'r-o') # plt.plot(data_x, data_y_1, 'r-o') # plt.plot(data_x, data_y, 'r-o') # plt.show() '''################### step : 4 : 2 : 3 plot : save image ###################''' fig.savefig(fpath_PlotImage) print("[%s:%d] plot image saved => %s" % (os.path.basename( os.path.basename(libs.thisfile())), libs.linenum(), fpath_PlotImage))
def test_1(): strOf_FuncName = "test_1" '''################### step : 1 opening, vars ###################''' print() print("[%s:%d] starting : %s (time=%s)" % (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum(), strOf_FuncName, libs.get_TimeLabel_Now())) print() '''################### step : 2 data : load ###################''' #mark:20210421_164025 iris_dataset = load_iris() #debug print("[%s:%d] load_iris => done" % (os.path.basename(libs.thisfile()), libs.linenum())) # print("iris_dataset['DESCR'] ==>") # print(iris_dataset['DESCR']) # print(iris_dataset) '''################### step : 3 data : train ###################''' X_train, X_test, y_train, y_test = train_test_split(iris_dataset["data"], iris_dataset["target"], random_state=0) #debug print("[%s:%d] train_test_split => done" % (os.path.basename(libs.thisfile()), libs.linenum())) # print("X_train ==>") # print(X_train) # # print() # print("X_test ==>") # print(X_test) '''################### step : 4 data : neighbor ###################''' '''################### step : 4 : 1 data : setup ###################''' kn = KNeighborsClassifier(n_neighbors=1) #debug print("[%s:%d] KNeighborsClassifier => done" % (os.path.basename(libs.thisfile()), libs.linenum())) print("kn ==>") print(kn) '''################### step : 4 : 2 data : fit ###################''' kn.fit(X_train, y_train) #debug print("[%s:%d] KNeighborsClassifier : fit => done" % (os.path.basename(libs.thisfile()), libs.linenum())) print("kn ==>") print(kn) '''################### step : 4 : 3 data : prep ###################''' x_new = np.array([[5, 2.9, 1, 0.2]]) #debug print("[%s:%d] np.array => done" % (os.path.basename(libs.thisfile()), libs.linenum())) print("x_new ==>") print(x_new) '''################### step : 5 data : predict ###################''' prediction = kn.predict(x_new) #debug print("[%s:%d] predict => done" % (os.path.basename(libs.thisfile()), libs.linenum())) # print("prediction ==>") # print(prediction) '''################### step : 6 results ###################''' prediction = kn.predict(x_new) #debug print("[%s:%d] results => " % (os.path.basename(libs.thisfile()), libs.linenum())) print("probe data =>") print(x_new) print() print("Predicted target value: {}\n".format(prediction)) print("Predicted feature name: {}\n".format( iris_dataset["target_names"][prediction])) print("Test score: {:.2f}".format(kn.score(X_test, y_test))) #debug print("[%s:%d] X_test => " % (os.path.basename(libs.thisfile()), libs.linenum())) print("X_test =>") print(X_test) print() print("y_test =>") print(y_test) '''###################
def test_2_Multiple_Tsp(): strOf_FuncName = "test_2_Multiple_Tsp" '''################### step : 1 opening, vars ###################''' print() print("[%s:%d] starting : %s (time=%s)" % (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum(), strOf_FuncName, libs.get_TimeLabel_Now())) '''################### step : 2 prep ###################''' aryOf_Numbers__Orig = [1, 2, 3, 4, 5] #ref https://www.geeksforgeeks.org/array-copying-in-python/ aryOf_Numbers__Copy = aryOf_Numbers__Orig.copy() # aryOf_Numbers__Copy = aryOf_Numbers__Orig print() print( "[%s:%d] aryOf_Numbers__Orig =>" % (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum())) print(aryOf_Numbers__Orig) print() '''################### step : 3 transposition ###################''' #code:20210728_132436 # pointOf_Tsp = 0 pointsOf_Tsp = [3, 1, 4, 1] # pointsOf_Tsp = [1,3,4,1] # pointsOf_Tsp = [1,1,3,4] # pointsOf_Tsp = [1,3,1,4] # pointOf_Tsp = 3 print( "[%s:%d] pointsOf_Tsp =>" % (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum())) print(pointsOf_Tsp) print() cntr = 0 for pointOf_Tsp in pointsOf_Tsp: '''################### counter ###################''' cntr += 1 print("[%s:%d] ----------------- for : %d" % (os.path.basename( os.path.basename(libs.thisfile())), libs.linenum(), cntr)) print() print("[%s:%d] calling ... => tsp()" % (os.path.basename( os.path.basename(libs.thisfile())), libs.linenum())) print() #code:20210728_132743 aryOf_Numbers__Copy = tsp(aryOf_Numbers__Copy, pointOf_Tsp) # aryOf_Numbers = tsp(aryOf_Numbers, pointOf_Tsp) # tsp(aryOf_Numbers, pointOf_Tsp) print("[%s:%d] tsp() => complete" % (os.path.basename( os.path.basename(libs.thisfile())), libs.linenum())) print("[%s:%d] aryOf_Numbers__Copy is now ... =>" % (os.path.basename( os.path.basename(libs.thisfile())), libs.linenum())) print(aryOf_Numbers__Copy) print() #/for pointOf_Tsp in pointsOf_Tsp: print( "[%s:%d] aryOf_Numbers : compare =>" % (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum())) print("orig / tsp / pointsOf_Tsp") print(aryOf_Numbers__Orig) print(aryOf_Numbers__Copy) print(pointsOf_Tsp)
# # #def exec_prog() ''' <usage> ''' if __name__ == "__main__": '''################### validate : help option ###################''' '''################### get options ###################''' '''################### evecute ###################''' exec_prog() print() # msg = "[%s:%d] done" % (___FILE, ___FILE) # msg = "[%s:%d] done" % (thisfile(), linenum()) # msg = "[%s:%d] get_ChartData_Between(fname, id_Start, id_End) => done" % \ # (libs.thisfile(), libs.linenum()) # print (msg) print( "[%s:%d] all done" % (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum())) # print ("[%s:%d] all done" % (libs.thisfile(), libs.linenum())) #####################################/EOF
# train_set, valid_set, test_set = cPickle.load(f) #d.4,#2 test_set_x, test_set_y = shared_dataset(test_set) valid_set_x, valid_set_y = shared_dataset(valid_set) train_set_x, train_set_y = shared_dataset(train_set) batch_size = 500 # size of the minibatch # accessing the third minibatch of the training set data = train_set_x[2 * batch_size:3 * batch_size] label = train_set_y[2 * batch_size:3 * batch_size] f.close() print("[%s:%d] exec_Prog => done" % (os.path.basename(libs.thisfile()), libs.linenum())) #/exec_Prog() if __name__ == "__main__": '''################### evecute ###################''' exec_Prog() print print("[%s:%d] done" % (libs.thisfile(), libs.linenum()))
def task_1_PyBullet_Hello_World(): strOf_FuncName = "task_1_PyBullet_Hello_World" '''################### step : 1 opening, vars ###################''' print() print ("[%s:%d] starting : %s (time=%s)" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , strOf_FuncName , libs.get_TimeLabel_Now() ) ) '''################### step : 2 tut codes https://docs.google.com/document/d/10sXEhzFRSnvFcl3XxNGhnD4N2SedqwdAvK3dsihxVUA/edit# ###################''' physicsClient = p.connect(p.GUI)#or p.DIRECT for non-graphical version p.setAdditionalSearchPath(pybullet_data.getDataPath()) #optionally p.setGravity(0,0,-10) print() print ("[%s:%d] tut : first 3 lines" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() ) ) print("type(physicsClient).__name__ ==> ", type(physicsClient).__name__) print() # separator line '''################### step : 2 : 2 ###################''' planeId = p.loadURDF("plane.urdf") startPos = [0,0,1] startOrientation = p.getQuaternionFromEuler([0,0,0]) boxId = p.loadURDF("r2d2.urdf",startPos, startOrientation) print ("[%s:%d] tut : next 4 lines" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() ) ) print("type(planeId).__name__ ==> ", type(planeId).__name__) print() # separator line #n:20210715_180327 #set the center of mass frame (loadURDF sets base link frame) startPos/Ornp.resetBasePositionAndOrientation(boxId, startPos, startOrientation) for i in range (10000): p.stepSimulation() time.sleep(1./240.) #debug:20210717_174601 print ("[%s:%d] for loop ==> ended" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() ) ) print() # separator line cubePos, cubeOrn = p.getBasePositionAndOrientation(boxId) print("cubePos = %d, cubeOrn = %d" % (cubePos, cubeOrn)) # print(cubePos,cubeOrn) p.disconnect() print ("[%s:%d] pybullet ==> disconnected" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() ) ) print() # separator line '''###################
ax = fig.add_subplot(1, 1, 1) p = pat.Polygon(xy=triangle, fc="white", ec="black") ax.add_patch(p) produce_fractal1(triangle, 6) fname_Out = "./fractal." + libs.get_TimeLabel_Now() + ".png" fig.savefig(fname_Out) #画像の保存 # fig.savefig("./fractal.png") #画像の保存 '''################### Report ###################''' print("[%s:%d] file gen-ed => %s" % (os.path.basename( os.path.basename(libs.thisfile())), libs.linenum(), fname_Out)) '''################### validate : help option ###################''' '''################### get options ###################''' '''################### evecute ###################''' exec_prog() print() print( "[%s:%d] all done" %
def exec_Numbering(request): '''################### requests ###################''' dpath = request.GET.get('dpath', False) fname = request.GET.get('fname', False) '''################### data ###################''' ### count time #ref https://stackoverflow.com/questions/3620943/measuring-elapsed-time-with-the-time-module answered Sep 1 '10 at 18:22 time_Start = time.time() if not dpath == False and not fname == False: # if dpath == True or fname == True : # if dpath == False or fname == False : msg = "params obtained" else: msg = "params NOT enough" dic = { cons_mm.ExecNumbering.DICKEY_MSG.value: msg, cons_mm.ExecNumbering.DICKEY_DPATH.value: dpath, cons_mm.ExecNumbering.DICKEY_FNAME.value: fname, } # dic = {"msg" : msg, "dpath" : dpath, "fname" : fname} print() print("[%s:%d] dic => '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum() , dic ), file=sys.stderr) print() '''################### render : params not sufficient ###################''' return render(request, 'mm/exec_Numbering.html', dic) # msg = None if dpath == False or fname == False else "params obtained" # print() # print("[%s:%d] msg => '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , msg # ), file=sys.stderr) # print() dic = { cons_mm.ExecNumbering.DICKEY_MSG.value: msg, cons_mm.ExecNumbering.DICKEY_DPATH.value: dpath, cons_mm.ExecNumbering.DICKEY_FNAME.value: fname, } # dic = {"msg" : msg, "dpath" : dpath, "fname" : fname} print() print("[%s:%d] dic => '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum() , dic ), file=sys.stderr) print() '''################### exec numbering ###################''' '''################### validate : file exists ###################''' fpath = os.path.join(dpath, fname) #ref https://stackoverflow.com/questions/82831/how-do-i-check-whether-a-file-exists-using-python answered Sep 17 '08 at 12:57 my_file = Path(fpath) if not my_file.is_file(): print() print("[%s:%d] file NOT exists : '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum() , fpath ), file=sys.stderr) print() dic[cons_mm.ExecNumbering.DICKEY_MSG.value] = \ "File does NOT exist : %s" % (fpath) '''################### render : params not sufficient ###################''' return render(request, 'mm/exec_Numbering.html', dic) # '''################### # validate : file not used # ###################''' # #ref https://stackoverflow.com/questions/7132861/building-full-path-filename-in-python answered Aug 20 '11 at 16:49 # fpath = os.path.join(dpath, fname) # # res = libs.is_Open(fpath) # # print() # print("[%s:%d] file opened => '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , res # ), file=sys.stderr) # print() '''################### execute ###################''' res = _exec_Numbering(dpath, fname) # res = _exec_Numbering(fpath) '''################### time ###################''' time_Elapsed = time.time() - time_Start ### add info dic[cons_mm.ExecNumbering.DICKEY_MSG.value] += \ " (time : %02.3f sec)" % (time_Elapsed) # " (time : %d)" % (time_Elapsed) '''################### render : params not sufficient ###################''' return render(request, 'mm/exec_Numbering.html', dic)
def exec_prog(): # '''################### prep : text ###################''' # fin = open("article.txt", "r", encoding='CP932') # # fin = open("article.txt", "r", encoding='shift-jis') # # fin = open("article.txt", "r", encoding='UTF-8') # # fin = open("article.txt", "r") # # text = fin.read() # # fin.close() # # print(text) # regex #ref https://stackoverflow.com/questions/4995892/python-split-string-on-regex p = re.compile('[。、]') ary = p.split(text) # ary = text.split("。") # ary of num aryOf_TokenLen = [] for item in ary: lenOf_Item = len(item) # print ("len => %d [%s]" % (lenOf_Item, item)) if lenOf_Item > 5: aryOf_TokenLen.append(lenOf_Item) # aryOf_TokenLen.append(lenOf_Item) ### report print ("[%s:%d] average => %.3f" % \ (os.path.basename(libs.thisfile()), libs.linenum(), #ref sum https://stackoverflow.com/questions/4362586/sum-a-list-of-numbers-in-python sum(aryOf_TokenLen) / len(aryOf_TokenLen))) # aryOf_TokenLen.sum() / len(aryOf_TokenLen))) print(aryOf_TokenLen) '''################### write to file ###################''' fname = "data/report.%s.txt" % (libs.get_TimeLabel_Now()) f = open(fname, "w") #ref sort https://www.tutorialspoint.com/python/list_sort.htm aryOf_TokenLen__Sorted = aryOf_TokenLen.sort() # get max len_Max = -1 for item in aryOf_TokenLen: # get max if len_Max < item: len_Max = item for i in range(item): f.write("*") # return f.write("\n") f.close() print ("[%s:%d] file => closed : %s" % \ (os.path.basename(libs.thisfile()), libs.linenum(), fname)) print ("[%s:%d] max len => %d" % \ (os.path.basename(libs.thisfile()), libs.linenum(), len_Max)) '''################### Out : histogram ###################''' aryOf_Histogram = {} #test print() print(range(len_Max)) # init for i in range(len_Max + 1): aryOf_Histogram[i] = 0 # for i in range(len_Max) : aryOf_Histogram[i] = 0 for item in aryOf_TokenLen: aryOf_Histogram[item] += 1 ### report print() print(aryOf_Histogram) ### write to file fname = "data/report.histogram.%s.txt" % (libs.get_TimeLabel_Now()) f = open(fname, "w") for i in range(len_Max + 1): f.write("%d : " % (i)) for j in range(aryOf_Histogram[i]): f.write("*") # return f.write("\n") f.close() print ("[%s:%d] file => closed : %s" % \ (os.path.basename(libs.thisfile()), libs.linenum(), fname)) '''################### Out : raw data ###################''' ### write to file fname = "data/report.rawdata.%s.txt" % (libs.get_TimeLabel_Now()) f = open(fname, "w") for i in aryOf_TokenLen: f.write("%d" % i) # return f.write("\n") f.close() print ("[%s:%d] file => closed : %s" % \ (os.path.basename(libs.thisfile()), libs.linenum(), fname)) # '''################### # Out : sentences # ###################''' # ### write to file # fname = "data/report.sentences.%s.txt" % (libs.get_TimeLabel_Now()) # # f = open(fname, "wb") # # f = open(fname, "w") # # for i in ary : # # # f.write(i) #=> UnicodeEncodeError: 'cp932' codec can't encode character '\u2003' # # f.write("%s" % i) #=> UnicodeEncodeError: 'cp932' codec can't encode character '\u2003' # # f.write(i.encode('utf-8')) # # f.write(i.decode('utf-8')) #=> AttributeError: 'str' object has no attribute 'decode' # # f.write(i.encode('utf-8')) #=> TypeError: write() argument must be str, not bytes # # f.write("%s" % i.encode('utf-8')) #=> TypeError: write() argument must be str, not bytes # f.write(i.encode('utf-8')) #=> # # f.write(i.decode('ascii', 'ignore')) #=> AttributeError: 'str' object has no attribute 'decode' # # return # f.write("\n") # # f.close() # # print ("[%s:%d] file => closed : %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum(), fname)) # '''################### Report ###################''' print("[%s:%d] exec_prog => done" % (os.path.basename(libs.thisfile()), libs.linenum()))
def _exec_BuildHistory(dpath, fname): fpath = os.path.join(dpath, fname) '''################### replace ###################''' '''################### file : open ###################''' fin = open(fpath, "r") content = fin.read() fin.close() '''################### history ###################''' tree = ET.parse(fpath) tree = libmt.build_History(tree) '''################### save xml ###################''' fpath_Out = fpath # fpath_Out = os.path.join( # dpath, # # fname # fname + "." + libs.get_TimeLabel_Now() \ # + "." \ # + "mm" # # ) # fpath_Out = "new.%s.%s.mm" % (label, libs.get_TimeLabel_Now()) # tree.write(fpath_Out) # '''################### # file : write # ###################''' # try : # # fout = open(fpath_Out, "w") # # res = fout.write(content) # # fout.close() # # except : # # e = sys.exc_info() # # e = sys.exc_info()[0] # # print() # print ("[%s:%d] exception : %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , e # ) # ) # # return e # return -1 print() print ("[%s:%d] file written : %s" % \ # print ("[%s:%d] file written : %s ( result = %d)" % \ # print ("[%s:%d] file written : %s ( result = %s)" % \ (os.path.basename(libs.thisfile()), libs.linenum() , fpath_Out # , res ) ) return cons_mm.RetVal.RET_OK.value
def test_4(): '''################### prep : get root ###################''' fpath = cons31.FPath.dpath_In_CSV.value \ + "/" \ + cons31.FPath.fname_In_XML.value ### backup fname_Out_Backup = "%s.copy.%s.mm" % (fpath, libs.get_TimeLabel_Now()) copyfile(fpath, fname_Out_Backup) '''################### parse ###################''' tree = ET.parse(fpath) tree = libmt.add_Node_Attribute_Created(tree) # root = tree.getroot() # # '''################### # nodes : g-1 # ###################''' # print() # print ("[%s:%d] root.tag => '%s' / root.attrib => '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , root.tag, root.attrib)) # # g1 = root[0] # # print() # print ("[%s:%d] g1.tag => '%s' / g1.attrib => '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , g1.tag, g1.attrib)) # # '''################### # nodes : g-2 # ###################''' # g2 = [] # # lenOf_g2 = len(g1) # # for i in range(lenOf_g2): # # g2.append(g1[i]) # # #/for i in range(lenOf_g2): # # #debug # for item in g2: # # for subitem in item: # # if subitem.tag == 'attribute' : #if subitem.tag == 'attribute' # # item.remove(subitem) # # print() # print ("[%s:%d] item.tag = '%s', subitem.tag = '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , item.tag, subitem.tag)) #/if subitem.tag == 'attribute' #/for subitem in item: # attrib_Created = item.get('CREATED') # # #ref append child https://stackoverflow.com/questions/31259847/python-appending-children-to-an-already-created-xml-files-root-using-xml-dom "answered Jul 8 '15 at 11:26" # data2 = ET.Element("attribute" # , {"NAME": "created" # , "VALUE" : attrib_Created # }) # item.remove('attribute') # item.append(data2) # print() # print ("[%s:%d] item.tag = '%s' | item.get('CREATED') = '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , item.tag, item.get('CREATED'))) #/for item in g2: '''################### append : child ###################''' # #ref https://stackoverflow.com/questions/31259847/python-appending-children-to-an-already-created-xml-files-root-using-xml-dom # data1 = ET.Element("node", {"TEXT": "something_" + libs.get_TimeLabel_Now()}) # # data1 = ET.Element("node", {"TEXT": "something_v001.0002.ma"}) # # data2 = ET.Element("attribute", {"NAME": "created" # # , "VALUE" : "18/01/23" # }) # # data1.append(data2) # # g2[0].append(data1) # '''################### save xml ###################''' label = "add-attribute-CREATED" fpath_Out = fpath # fpath_Out = "new.%s.%s.mm" % (label, libs.get_TimeLabel_Now()) tree.write(fpath_Out) print() print("[%s:%d] xml => written : %s" % (os.path.basename(libs.thisfile()), libs.linenum(), fpath_Out))
'''################### import : orig files ###################''' sys.path.append('.') sys.path.append('..') sys.path.append('C:/WORKS_2/WS/WS_Others/free/fx/82_') print(sys.path) from libs import libs print() print ("[%s:%d] 'from libs import libs' ==> comp." % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() ) ) '''################### import : math ###################''' # from math import pi, sin, cos import math '''################### import : scipy, numpy, matplotlib ###################''' import numpy as np import matplotlib.pyplot as plt
def exec_prog(): # from : '''################### params ###################''' args = sys.argv if len(args) < 2: #if len(args) < 2 print() print ("[%s:%d] param needed : len(args) = %d" % \ (os.path.basename(libs.thisfile()), libs.linenum(), len(args))) print() print("<Usage> python 1_1.3.py <numbering|created>") return param = args[1] print() print("param => %s" % (param)) #/if len(args) < 2 '''################### dispatch ###################''' if param == "numbering": #if param == "numbering" test_5__Numbering() elif param == "created": #if param == "numbering" test_4() else: #if param == "numbering" print() print ("[%s:%d] unknown param => '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum(), param)) print() return #/if param == "numbering" # test_5__Numbering() # test_4() # test_3() # test_2() # '''################### # prep # ###################''' # fpath = cons31.FPath.dpath_In_CSV.value \ # + "/" \ # + cons31.FPath.fname_In_XML.value # # tree = ET.parse(fpath) # # root = tree.getroot() # # #debug # print() # print ("[%s:%d] root => %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum(), root)) # # '''################### # nodes : g-1 # ###################''' # print() # print ("[%s:%d] root.tag => '%s' / root.attrib => '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , root.tag, root.attrib)) # # g1 = root[0] # # print() # print ("[%s:%d] g1.tag => '%s' / g1.attrib => '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , g1.tag, g1.attrib)) # # g2 = [] # # lenOf_g2 = len(g1) # # for i in range(lenOf_g2): # # g2.append(g1[i]) # # #/for i in range(lenOf_g2): # # print() # print ("[%s:%d] g2 => %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum(), g2)) # # '''################### # report : g2 # ###################''' # for i in range(lenOf_g2): # # node = g2[i] # # print ("[%s:%d] g2[%d] => %s" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , i, node.attrib)) # # [1_1.3.py:108] g2 => [<Element 'node' at 0x0000000007E1EA48>, <Element 'node' at # # 0x0000000007E22138>, <Element 'node' at 0x0000000007E22368>] # #/for node in g2: # # '''################### # append : child # ###################''' # #ref https://stackoverflow.com/questions/31259847/python-appending-children-to-an-already-created-xml-files-root-using-xml-dom # data1 = ET.Element("node", {"TEXT": "something_" + libs.get_TimeLabel_Now()}) # # data1 = ET.Element("node", {"TEXT": "something_v001.0002.ma"}) # # data2 = ET.Element("attribute", {"NAME": "created" # # , "VALUE" : "18/01/23" # }) # # data1.append(data2) # # g2[0].append(data1) # # '''################### # save xml # ###################''' # fpath_Out = "new.%s.mm" % (libs.get_TimeLabel_Now()) # # tree.write(fpath_Out) # # print() # print ("[%s:%d] xml => written : %s" % (os.path.basename(libs.thisfile()), libs.linenum(), fpath_Out)) '''################### Report ###################''' print("[%s:%d] exec_prog => done" % (os.path.basename(libs.thisfile()), libs.linenum()))
def test_1(): strOf_FuncName = "test_1" '''################### step : 1 opening, vars ###################''' print() print ("[%s:%d] starting : %s (time=%s)" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , strOf_FuncName , libs.get_TimeLabel_Now() ) ) '''################### step : 2 prep ###################''' '''################### step : 2 : 1 prep : data : x ###################''' #mark:20211030_153553 # numOf_Data_X = 24 numOf_Data_X = 36 valOf_Linspace_Start = - math.pi / 2 valOf_Linspace_End = math.pi / 2 #ref https://matplotlib.org/stable/tutorials/introductory/customizing.html#sphx-glr-tutorials-introductory-customizing-py data_x = np.linspace( valOf_Linspace_Start , valOf_Linspace_End , numOf_Data_X) print() print ("[%s:%d] data_x =>" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() ) ) print(data_x) '''################### step : 2 : 2 prep : data : y --> cos(x) ###################''' data_y = [math.cos(x) for x in data_x] print() print ("[%s:%d] data_y =>" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() ) ) print(data_y) '''################### step : 3 plot ###################''' '''################### step : 3 : 1 plot : prep ###################''' # folder strOf_Time_Label = libs.get_TimeLabel_Now() # dpath_data = "./data" dpath_data = "data" dname_PlotImage = "plot_%s" % (strOf_Time_Label) # dname_PlotImage = "plot_image_%s" % (strOf_Time_Label) dpath_PlotImage = os.path.join(dpath_data, dname_PlotImage) # file name fname_Plot = "plot_%s" % (strOf_Time_Label) fpath_PlotImage = os.path.join(dpath_PlotImage, fname_Plot) #ref https://www.askpython.com/python/examples/create-a-directory-in-python res = os.mkdir(dpath_PlotImage) print() print ("[%s:%d] os.mkdir for => : %s" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , dpath_PlotImage ) ) print(res) '''################### step : 3 : 2 plot : plot ###################''' #ref C:\WORKS_2\WS\WS_Others.JVEMV6\JVEMV6\73_ai\1_start\1_1.py fig = plt.figure() # title plt.title("cos(a), data_y_1_final\n numOf_Data_X = %d\n x [%.02f, %.02f]" % ( numOf_Data_X , valOf_Linspace_Start , valOf_Linspace_End ) ) # axis #ref https://matplotlib.org/stable/tutorials/introductory/pyplot.html#sphx-glr-tutorials-introductory-pyplot-py plt.axis([- math.pi/2, math.pi/2, -1.5, 1.5]) # plot plt.plot(data_x, data_y,'b-o') # grid #ref https://www.w3schools.com/python/matplotlib_grid.asp plt.grid() # save image res = fig.savefig(fpath_PlotImage) print() print ("[%s:%d] result for 'fig.savefig' : %s" % ( os.path.basename(os.path.basename(libs.thisfile())) , libs.linenum() , fpath_PlotImage ) ) print(res) '''################### step : 4 ###################''' '''###################
def test_2(): '''################### prep : get root ###################''' fpath = cons31.FPath.dpath_In_CSV.value \ + "/" \ + cons31.FPath.fname_In_XML.value tree = ET.parse(fpath) root = tree.getroot() '''################### nodes : g-1 ###################''' print() print ("[%s:%d] root.tag => '%s' / root.attrib => '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum() , root.tag, root.attrib)) g1 = root[0] print() print ("[%s:%d] g1.tag => '%s' / g1.attrib => '%s'" % \ (os.path.basename(libs.thisfile()), libs.linenum() , g1.tag, g1.attrib)) '''################### nodes : g-2 ###################''' g2 = [] lenOf_g2 = len(g1) for i in range(lenOf_g2): g2.append(g1[i]) #/for i in range(lenOf_g2): #debug for item in g2: attrib_Created = item.get('CREATED') #ref append child https://stackoverflow.com/questions/31259847/python-appending-children-to-an-already-created-xml-files-root-using-xml-dom "answered Jul 8 '15 at 11:26" data2 = ET.Element("attribute", { "NAME": "created", "VALUE": attrib_Created }) item.append(data2) # print() # print ("[%s:%d] item.tag = '%s' | item.get('CREATED') = '%s'" % \ # (os.path.basename(libs.thisfile()), libs.linenum() # , item.tag, item.get('CREATED'))) #/for item in g2: '''################### append : child ###################''' # #ref https://stackoverflow.com/questions/31259847/python-appending-children-to-an-already-created-xml-files-root-using-xml-dom # data1 = ET.Element("node", {"TEXT": "something_" + libs.get_TimeLabel_Now()}) # # data1 = ET.Element("node", {"TEXT": "something_v001.0002.ma"}) # # data2 = ET.Element("attribute", {"NAME": "created" # # , "VALUE" : "18/01/23" # }) # # data1.append(data2) # # g2[0].append(data1) # '''################### save xml ###################''' label = "add_Attrib_Created" fpath_Out = "new.%s.%s.mm" % (label, libs.get_TimeLabel_Now()) tree.write(fpath_Out) print() print("[%s:%d] xml => written : %s" % (os.path.basename(libs.thisfile()), libs.linenum(), fpath_Out))