def _exec_Numbering(dpath, fname):
    
    fpath = os.path.join(dpath, fname)
    
    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)
    
    print()
    print ("[%s:%d] mm => written : %s" % \
           (os.path.basename(libs.thisfile()), libs.linenum(), fpath_Out))

    return None
def test_2():
    
    #from : C:\WORKS_2\WS\WS_Others\JVEMV6\34\libs\labs.py
    a = 1
    
    s1 = [np.sin(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
    s2 = [np.sin(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]

    '''###################
        file path        
    ###################'''
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
    ### fpath full
    fpath_Full = "%s\\tmp.%s.a=%.1f.png" % (dpath_Out, libs.get_TimeLabel_Now(), a)
    
    '''###################
        plot
    ###################'''    
    plt.plot(s1, s2)
    
    plt.savefig(fpath_Full)

    print()
    print("[%s:%d] file saved => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , fpath_Full
            ), file=sys.stderr)
def test_1():
    '''###################
        vars        
    ###################'''
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\28_Physics\\1_\\_15"

    #ref https://stackoverflow.com/questions/9622163/save-plot-to-image-file-instead-of-displaying-it-using-matplotlib answered Apr 28 '15 at 22:35
    fig, ax = plt.subplots(nrows=1, ncols=1)

    x = np.arange(-100, 100, 0.1)
    #     x = np.arange(0, 100, 0.1)

    a = np.arange(-2, 2, 0.5)

    #     b = 2; d = 2
    #     a = 2; b = 2; d = 2
    a = -2.0
    b = 2
    d = 2
    #     a = 2.0; b = 2; d = 2

    y = [i**3 + a * i**2 + b * i + d for i in x]
    #
    ax.plot(x, y)
    #
    ax.show()

    #     ### fpath full
    fpath_Full = "%s\\tmp.%s.a=%.1f.png" % (dpath_Out,
                                            libs.get_TimeLabel_Now(), a)
    #     fpath_Full = "%s\\tmp.%s.png" % (dpath_Out, libs.get_TimeLabel_Now())
    #
    #     fig.savefig(fpath_Full)

    #     time_Label = libs.get_TimeLabel_Now()

    #     for num in a:
    #
    #         y = [i**3 + a * i**2 + b * i + d for i in x]
    #
    #         ax.plot(x,y)
    #
    #         ### fpath full
    #         fpath_Full = "%s\\tmp.%s.a=%s.png" % (dpath_Out, time_Label, str(num))
    #
    #         fig.savefig(fpath_Full)

    # #     fig.savefig('tmp.20180217_134221.png')
    #
    #         ### reset fig
    #         fig, ax = plt.subplots( nrows=1, ncols=1 )

    print()
    print("[%s:%d] file saved => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , fpath_Full
            ), file=sys.stderr)

    plt.close(fig)
示例#4
0
def test_1():
    
    '''###################
        vars
    ###################'''
    a1 = bin(random.randint(1, 100))[2:]
    a2 = bin(random.randint(1, 100))[2:]
    a3 = bin(random.randint(1, 100))[2:]
    
    ### length
    len1 = len(a1)
    len2 = len(a2)
    len3 = len(a3)
    
    s1 = ''.join(["0"]*(8 - len1)) + a1
    s2 = ''.join(["0"]*(8 - len2)) + a2
    s3 = ''.join(["0"]*(8 - len3)) + a3
    
    lo_1_tmp = list(s1)
    lo_2_tmp = list(s2)
    lo_3_tmp = list(s3)
    
    lo_1 = [int(x) for x in lo_1_tmp]
    lo_2 = [int(x) for x in lo_2_tmp]
    lo_3 = [int(x) for x in lo_3_tmp]
    
    '''###################
        pearson        
    ###################'''
    pr_1_2 = pearsonr(lo_1, lo_2)
    pr_1_3 = pearsonr(lo_1, lo_3)
    
    print()
    print("[%s:%d]\ns1 = %s (%s)\ns2 = %s (%s)\ns3 = %s (%s)" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , s1, lo_1, s2, lo_2, s3, lo_3
            ), file=sys.stderr)
#     print("[%s:%d] lo_1 = %s / lo_2 = %s" % \
#             (os.path.basename(libs.thisfile()), libs.linenum()
#             , lo_1, lo_2
#             ), file=sys.stderr)
    print("[%s:%d] pr_1_2 => %.6f / pr_1_3[0] => %.6f" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , pr_1_2[0], pr_1_3[0]
            ), file=sys.stderr)
示例#5
0
def exec_prog():
    '''###################
        ops        
    ###################'''
    test_1()

    print("[%s:%d] exec_prog() => done" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
def exec_prog():  # from :
    '''###################
        ops        
    ###################'''
    test_1()
    '''###################
        Report        
    ###################'''
    print("[%s:%d] exec_prog => done" %
          (os.path.basename(libs.thisfile()), libs.linenum()))
示例#7
0
def test_1():
    
    '''###################
        step : 1
            prep : vars
    ###################'''
    '''###################
        step : 2
            load : settings
    ###################'''
    confs = _tester_BuyUps_SellLows__BUSL_3__Set_Conf(DPATH_SETTINGS_FILE, FNAME_SETTINGS_FILE)
    
    msg = "[%s:%d] confs ==> (%d keys)" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , len(confs)
                    )
 
    print(confs)
    print(msg, file=sys.stderr)

    '''###################
        step : 2 : 2
            unpack
    ###################'''
    dpath_File_Log = confs['DPATH_FILE_LOG']
    
    fname_File_Log = confs['FNAME_FILE_LOG']
    
    
    '''###################
        step : 3
            load : log file
    ###################'''
    #_20191224_163832:next
#     get_ListOf_Ticket_Nums(dpath_File_Log, fname_File_Log)
    
    '''###################
        ops        
    ###################'''
    print("[%s:%d] test_1() => done" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            
            ), file=sys.stderr)
def _build_result_csv_data__Full_Data_List(_lo_TRs_With_Order_TDS, _lo_Order_Numbers):

#_20190903_124229:caller
#_20190903_124234:head
#_20190903_124239:wl

    '''###################
        step : 1
            vars
    ###################'''
    lo_Orders_Full = []
    
    '''###################
        step : 2
            build
    ###################'''
    for item in _lo_TRs_With_Order_TDS:
    
        lo_TDs = item[1]
        
        numOf_Order = int(lo_TDs[0].getText())
        
        # judge
        if numOf_Order in _lo_Order_Numbers : #if numOf_Order in lo_Order_Numbers
            
            # append
            lo_Orders_Full.append(item)
        
        #/if numOf_Order in lo_Order_Numbers

        
    #/for item in lo_TRs_With_Order_TDS:

    # report
    #debug
    if SWITCH_DEBUG == True : #if SWITCH_DEBUG == True
        
        # count
        lenOf_LO_Orders_Full = len(lo_Orders_Full)
        
        msg = "[%s:%d] lenOf_LO_Orders_Full ==> %d" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , lenOf_LO_Orders_Full
                        )

        print()
        print(msg, file=sys.stderr)
        
    #/if SWITCH_DEBUG == True

    '''###################
        step : 3
            return
    ###################'''
    return lo_Orders_Full
def exec_prog():
    '''###################
        ops        
    ###################'''
    #     test_8__Matplotlib__Bar_Chart()
    test_1()

    print("[%s:%d] exec_prog() => done" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
def test_4():
    
    '''###################
        vars        
    ###################'''
    tlabel = libs.get_TimeLabel_Now()
    
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\28_Physics\\1_\\_17" \
                + "\\images"

    '''###################
        file path        
    ###################'''
#         dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
    ### fpath full
    session_Label  = "1-17-2"
    
    fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)
    
    '''###################
        ops        
    ###################'''
    #ref https://stackoverflow.com/questions/30209187/matplotlib-chart-area-vs-plot-area answered May 13 '15 at 23:00
    x1 = np.random.randint(-5, 5, 50)
    x2 = np.random.randn(20)
    
    fig = plt.figure(figsize=(8,6))  # sets the window to 8 x 6 inches
    
    # left, bottom, width, height (range 0 to 1)
    # so think of width and height as a percentage of your window size
    big_ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) 
    small_ax = fig.add_axes([0.52, 0.15, 0.3, 0.3]) # left, bottom, width, height (range 0 to 1)
    
    big_ax.fill_between(np.arange(len(x1)), x1, color='blue', alpha=0.3)
#     big_ax.fill_between(np.arange(len(x1)), x1, color='green', alpha=0.3)
    small_ax.stem(x2)
    
    plt.setp(small_ax.get_yticklabels(), visible=False)
    plt.setp(small_ax.get_xticklabels(), visible=False)
#     plt.show()
    
    fig.savefig(fpath_Full)
#     plt.savefig(fpath_Full)
    plt.close(fig)
    
    print()
    print("[%s:%d] file saved : %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , fpath_Full
        ), file=sys.stderr)
示例#11
0
def test_2():
    '''###################
        file path        
    ###################'''
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
    ### fpath full
    fpath_Full = "%s\\tmp.%s.png" % (dpath_Out, libs.get_TimeLabel_Now())
    '''###################
        ops        
    ###################'''
    #     print(cv2.__version__)

    fname_In = "image.1-17-2.20180219_093551.png"

    img = cv2.imread(fname_In)

    print()
    print("[%s:%d] img => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , img
        ), file=sys.stderr)
示例#12
0
def _build_result_csv_data__Write_Full_Data(\

            _lo_Orders_Full
            , _dpath_Log__ROOT
            , _strOf_Project
            , _dname_Log
            , _tlabel

                                            ):

    #_20190903_124741:caller
    #_20190903_124745:head
    #_20190903_124751:wl
    '''###################
        step : 1
            vars
    ###################'''
    #     fname_Log__Dat_Full = "%s.(%s).dat" % (_strOf_Project, _tlabel)

    fname_Log__Dat_Full = "%s.[data-full].(%s).dat" % (_strOf_Project, _tlabel)

    dpath_Log__Dat_Full = os.path.join(_dpath_Log__ROOT, _dname_Log)

    fpath_Log__Dat_Full = os.path.join(dpath_Log__Dat_Full,
                                       fname_Log__Dat_Full)
    '''###################
        step : 2
            gen : dirs
    ###################'''
    if not os.path.isdir(
            dpath_Log__Dat_Full):  #if not os.path.isdir(dpath_Log__Dat_Full)

        res = os.makedirs(dpath_Log__Dat_Full)

        #debug
        if SWITCH_DEBUG == True:  #if SWITCH_DEBUG == True

            msg = "[%s:%d] os.makedirs ==> %s" % \
                            (os.path.basename(libs.thisfile()), libs.linenum()
                             , res
                            )

            print()
            print(msg, file=sys.stderr)

        #/if SWITCH_DEBUG == True

    #/if not os.path.isdir(dpath_Log__Dat_Full)
    '''###################
        step : 3
            write
    ###################'''
    '''###################
        step : 3 : 1
            file : open
    ###################'''
    f_out_Dat_Full = open(fpath_Log__Dat_Full, "w")
    '''###################
        step : 2 : 5.2 : 5.2.1
            file : header
    ###################'''
    #"Ticket", "Open Time", "Type", "Size", "Item", "Price", "S / L", "T / P", "Close Time", "Price", "Commission", "Taxes", "Swap", "Profit"
    lo_Col_Names = [
        "Ticket", "Open Time", "Type", "Size", "Item", "Price", "S / L",
        "T / P", "Close Time", "Price", "Commission", "Taxes", "Swap", "Profit"
    ]

    f_out_Dat_Full.write("this file\t%s" % fname_Log__Dat_Full)
    f_out_Dat_Full.write("\n")

    #     f_out_Dat_Full.write("source dir\t%s" % DPATH_REPORT_FILE)
    #     f_out_Dat_Full.write("\n")
    #
    f_out_Dat_Full.write("\n")

    f_out_Dat_Full.write("s.n.")
    f_out_Dat_Full.write("\t")

    f_out_Dat_Full.write("\t".join(lo_Col_Names))
    f_out_Dat_Full.write("\n")
    f_out_Dat_Full.write("\n")
    '''###################
        step : 2 : 5.2 : 5.3
            file : write
    ###################'''
    #_20190902_130031:tmp
    cntOf_Loop = 0

    for item in _lo_Orders_Full:
        '''###################
            step : 2 : 5.2 : 5.3 : 0
                count
        ###################'''
        cntOf_Loop += 1
        '''###################
            step : 2 : 5.2 : 5.3 : 1
                get : TDs
        ###################'''
        # TDs
        lo_TDs = item[1]
        '''###################
            step : 2 : 5.2 : 5.3 : 2
                get : texts
        ###################'''
        lo_Tmp_TD_Texts = []

        # s.n.
        lo_Tmp_TD_Texts.append("%d" % cntOf_Loop)
        lo_Tmp_TD_Texts.append("\t")

        lo_Tmp_TD_Texts.append("\t".join([x.getText() for x in lo_TDs]))

        f_out_Dat_Full.write("".join(lo_Tmp_TD_Texts))
        f_out_Dat_Full.write("\n")

    #/for item in lo_TRs_With_Order_TDS:
    '''###################
        step : 2 : 5.2 : 5.X
            file : close
    ###################'''
    f_out_Dat_Full.close()
def test_3():
    
    '''###################
        vars        
    ###################'''
    tlabel = libs.get_TimeLabel_Now()
    
    '''###################
        dir        
    ###################'''
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\28_Physics\\1_\\_17" \
                + "\\images\\\images_%s" % (tlabel)
    
    ### make dir
    #ref https://www.tutorialspoint.com/python/os_mkdir.htm
    os.makedirs(dpath_Out)
    
    print()
    print("[%s:%d] dpath_Out => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , dpath_Out
        ), file=sys.stderr)
    
    #from : C:\WORKS_2\WS\WS_Others\JVEMV6\34\libs\labs.py
    
#     for a in np.arange(1,2):
#     for a in np.arange(1,10, 0.5):
#     for a in np.arange(1,2, 0.1):
#     for a in np.arange(1, 5, 0.1):
    
    maxnum = 30
    
#     tick = np.pi / 60
    tick = np.pi / 30

    ### counter
    cnt = 1
    
    for a in np.arange(0, np.pi * 4, tick):
#     for a in np.arange(0, np.pi * 2, tick):
#     for a in np.arange(0, maxnum, tick):
#     for a in np.arange(0, 10, 0.1):

#         a = 1
        
#         s1 = [np.sin(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
        s1 = [np.sin(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s1 = [np.sin(x * a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
        s2 = [np.cos(x * a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s2 = [np.cos(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s2 = [np.cos(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
        
#         s3 = [np.sin(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s4 = [np.cos(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
        
#         s2 = [np.sin(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s2 = [np.sin(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
    
        '''###################
            file path        
        ###################'''
#         dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
        ### fpath full
        fpath_Full = "%s\\tmp.%s.(%02d).a=%.3f.png" % (dpath_Out, tlabel, cnt, a)
#         fpath_Full = "%s\\tmp.%s.a=%.3f.png" % (dpath_Out, libs.get_TimeLabel_Now(), a)
#         fpath_Full = "%s\\tmp.%s.a=%.1f.png" % (dpath_Out, libs.get_TimeLabel_Now(), a)
#         fpath_Full = "%s\\tmp.%s.a=%.1f.png" % (dpath_Out, libs.get_TimeLabel_Now(), a)
        
        ### increment
        cnt += 1
        
        '''###################
            gca        
        ###################'''
        fig = plt.figure()
        ax = fig.gca()
        ax.set_xticks(np.arange(-1, 1, 0.1))
        ax.set_yticks(np.arange(-1, 1, 0.1))

        
        
        '''###################
            plot
        ###################'''    
        plt.plot(s1, s2)
#         plt.plot(s3, s4)
        
        ### ratio
        #ref https://matplotlib.org/examples/pylab_examples/equal_aspect_ratio.html
        #ref https://stackoverflow.com/questions/7965743/how-can-i-set-the-aspect-ratio-in-matplotlib
#         plt.axes().set_aspect('equal', 'datalim')
        plt.axes().set_aspect('equal')
#         plt.axes().set_aspect(2)
#         plt.set_aspect(2)
        
        #ref https://stackoverflow.com/questions/8209568/how-do-i-draw-a-grid-onto-a-plot-in-python answered Nov 21 '11 at 11:00
        
#         fig = plt.figure()
#         ax = fig.gca()
#         ax.set_xticks(np.arange(-1, 1, 0.1))
#         ax.set_yticks(np.arange(-1, 1, 0.1))
        
        plt.grid(b=None, which='major', axis='both')
        
        plt.xlabel("sin(x)")
#         plt.xlabel("sin(x + %.3f)" % a)
        plt.ylabel("cos(x * %.3f)" % a)
#         plt.ylabel("cos(x + %.3f)" % a)
#         plt.ylabel("cos(x)")
        
        plt.title("a = %.3f" % a)
        
#         plt.show()
        plt.savefig(fpath_Full)
        
        
        ### close
        plt.close(fig)
        Report        
    ###################'''
    print ("[%s:%d] exec_prog => done" % (os.path.basename(libs.thisfile()), libs.linenum()))
 
#/def exec_prog(): # from : 20180116_103908

'''
<usage>
'''
if __name__ == "__main__" :

    '''###################
        validate : help option        
    ###################'''

    '''###################
        get options        
    ###################'''

    '''###################
        evecute        
    ###################'''
    exec_prog()

    print()
    
    print ("[%s:%d] all done" % (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum()))



示例#15
0
def test_1():
    '''###################
        get : args
    ###################'''
    '''###################
        file path
    ###################'''
    #_20190307_144837
    dpath_CSV = "C:\\WORKS_2\\WS\\WS_Others.prog\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\curr\\data\\csv_raw"

    if len(sys.argv) > 1:  #if len(sys.argv)

        fname_CSV = sys.argv[1]

    else:  #if len(sys.argv)

        fname_CSV = "44_5.1_10_rawdata.(EURJPY).(Period-D1).(NumOfUnits-2000)"\
                    + ".(Bars-ALL).20190308_083617.csv"
    #     fname_CSV = "44_5.1_10_rawdata.(EURJPY).(Period-M15).(NumOfUnits-4500)"\
    #                 + ".(Bars-ALL).20190214_095445.csv"

    #/if len(sys.argv)

    fpath_CSV = os.path.join(dpath_CSV, fname_CSV)

    # validate
    if not os.path.isfile(fpath_CSV):  #if not os.path.isfile(fpath_CSV)

        print()
        print("[%s:%d] csv file NOT exist : %s" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()

                        ), file=sys.stderr)

        return

    #/if not os.path.isfile(fpath_CSV)
    '''###################
        file : open
    ###################'''
    f_in_CSV = open(fpath_CSV, "r")
    '''###################
        read file content
    ###################'''
    data = f_in_CSV.readlines()

    print("[%s:%d] len(data) = %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , len(data)
            ), file=sys.stderr)
    '''###################
        file : close
    ###################'''
    f_in_CSV.close()
    '''###################
        op : renumbering
    ###################'''
    '''###################
        step : A : 1
            prep
    ###################'''
    lo_New_CSV_Lines = []

    cntOf_Lines = 1

    lenOf_Lines = len(data)

    # file path
    #_20190307_144916
    dpath_CSV_Dst = dpath_CSV
    #     dpath_CSV_Dst = "C:\\WORKS_2\\WS\\WS_Others.prog\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\curr\\data\\csv_raw"

    # E/J, H1
    # build : fname
    # 44_5.1_10_rawdata.(EURJPY).(Period-D1).(NumOfUnits-2000).(Bars-ALL).20190308_083617.csv
    #     tokens = fname_CSV.split(".")

    fname_CSV_Dst = fname_CSV.replace("Bars-ALL",
                                      "Bars-ALL-%s" % libs.get_TimeLabel_Now())
    #     fname_CSV_Dst = "44_5.1_10_rawdata.(EURJPY).(Period-H1).(NumOfUnits-4500)"
    #     fname_CSV_Dst += ".(Bars-ALL-%s).20190307_144106.csv" % libs.get_TimeLabel_Now()

    #     # E/J, M15
    #     fname_CSV_Dst = "44_5.1_10_rawdata.(EURJPY).(Period-M15).(NumOfUnits-4500)"
    #     fname_CSV_Dst += ".(Bars-ALL-%s).20190214_095445" % libs.get_TimeLabel_Now()

    #     fname_CSV_Dst += ".csv"
    #     fname_CSV_Dst += ".(tmp-%s).csv" % libs.get_TimeLabel_Now()

    fpath_CSV_Dst = os.path.join(dpath_CSV_Dst, fname_CSV_Dst)
    '''###################
        step : A : 2.1
            read : header
    ###################'''
    lo_New_CSV_Lines.append(data[0])
    lo_New_CSV_Lines.append(data[1])
    '''###################
        step : A : 2.2
            read : body
    ###################'''
    # iteration
    for i in range(2, lenOf_Lines):

        # split
        tokens = data[i].split(";")

        # renumbering
        tokens[0] = str(cntOf_Lines)
        #         tokens[0] = cntOf_Lines

        # counter
        cntOf_Lines += 1

        # append
        lo_New_CSV_Lines.append(";".join(tokens))

    #/for i in range(2, lenOf_Lines):

    #debug
    print()
    print("[%s:%d] lo_New_CSV_Lines[0] = %s, lo_New_CSV_Lines[-1] = %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , lo_New_CSV_Lines[0]
                     , lo_New_CSV_Lines[-1]
                    ), file=sys.stderr)

    #ccc

    #     for line in data:
    #
    #         tokens = line.split(";")
    #
    #
    #
    #     #/for line in data:
    '''###################
        step : A : 3.1
            file : open
    ###################'''
    f_out_CSV = open(fpath_CSV_Dst, "w")
    '''###################
        step : A : 3.2
            file : write
    ###################'''
    f_out_CSV.write("".join(lo_New_CSV_Lines))
    #     f_out_CSV.write("\n".join(lo_New_CSV_Lines))
    '''###################
        step : A : 3.3
            file : close
    ###################'''
    f_out_CSV.close()

    #debug
    print()
    print("[%s:%d] file written ==> %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , fpath_CSV_Dst
                    ), file=sys.stderr)
    '''###################
        extract target tokesn from each line
    ###################'''
    '''###################
        report
    ###################'''
    '''###################
        message
    ###################'''
    print()
    print("[%s:%d] test_1 =======================" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)
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)
    ###################'''
    test_1()
    '''###################
        Report        
    ###################'''
    print("[%s:%d] exec_prog => done" %
          (os.path.basename(libs.thisfile()), libs.linenum()))


#/def exec_prog(): # from : 20180116_103908
'''
<usage>
'''
if __name__ == "__main__":
    '''###################
        validate : help option        
    ###################'''
    '''###################
        get options        
    ###################'''
    '''###################
        evecute        
    ###################'''
    exec_prog()

    print()

    print(
        "[%s:%d] all done" %
        (os.path.basename(os.path.basename(libs.thisfile())), libs.linenum()))
示例#18
0
def test_1():

    #_20190409_105129:head
    #_20190409_105133:caller
    '''###################
        step : 0.1
            prep : vars
    ###################'''

    numOf_Nouns_Chosen = 4
    numOf_Verbs_Chosen = 4
    numOf_Expressions_Chosen = 4
    '''###################
        step : 1
            load files
    ###################'''
    '''###################
        step : 1.1
            build : paths
    ###################'''
    dpath_Data_Files = "C:\\WORKS_2\\WS\\WS_Others.JVEMV6\\JVEMV6\\37_miscs\\9_prog_lang"

    fname_Data_Nouns = "data_nouns.dat"
    fname_Data_Verbs = "data_verbs.dat"
    fname_Data_Expressions = "data_expressions.dat"

    # paths
    fpath_Data_Nouns = os.path.join(dpath_Data_Files, fname_Data_Nouns)
    fpath_Data_Verbs = os.path.join(dpath_Data_Files, fname_Data_Verbs)
    fpath_Data_Expressions = os.path.join(dpath_Data_Files,
                                          fname_Data_Expressions)
    '''###################
        step : 1.2
            validate
    ###################'''
    if not os.path.isfile(
            fpath_Data_Nouns):  #if not os.path.isfile(fpath_Data_Nouns)

        print()
        print("[%s:%d] file ==> NOT exist : '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Data_Nouns
                        ), file=sys.stderr)

        return

    if not os.path.isfile(
            fpath_Data_Verbs):  #if not os.path.isfile(fpath_Data_Verbs)

        print()
        print("[%s:%d] file ==> NOT exist : '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Data_Verbs
                        ), file=sys.stderr)

        return

    if not os.path.isfile(fpath_Data_Expressions
                          ):  #if not os.path.isfile(fpath_Data_Expressions)

        print()
        print("[%s:%d] file ==> NOT exist : '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Data_Expressions
                        ), file=sys.stderr)

        return
    '''###################
        step : 1.2
            file : read
    ###################'''
    # load : files
    fin_Nouns = open(fpath_Data_Nouns, "r")
    fin_Verbs = open(fpath_Data_Verbs, "r")
    fin_Expressions = open(fpath_Data_Expressions, "r")

    # read lines
    lo_Nouns = fin_Nouns.readlines()
    lo_Verbs = fin_Verbs.readlines()
    lo_Expressions = fin_Expressions.readlines()

    # lines : strip
    # also, the last element ---> omit (return only line)
    lo_Nouns = [x.strip() for x in lo_Nouns[:-1]]
    lo_Verbs = [x.strip() for x in lo_Verbs[:-1]]
    lo_Expressions = [x.strip() for x in lo_Expressions[:-1]]
    #     lo_Nouns = [x.strip() for x in lo_Nouns]
    #     lo_Verbs = [x.strip() for x in lo_Verbs]

    # lengh
    lenOf_LO_Nouns = len(lo_Nouns)
    lenOf_LO_Verbs = len(lo_Verbs)
    lenOf_LO_Expressions = len(lo_Expressions)
    '''###################
        step : 1.x
            file : close
    ###################'''
    fin_Nouns.close()
    fin_Verbs.close()
    fin_Expressions.close()

    #     #debug
    #     print()
    #     print("[%s:%d] lo_Nouns ==>" % \
    #                     (os.path.basename(libs.thisfile()), libs.linenum()
    #
    #                     ), file=sys.stderr)
    #     print(lo_Nouns)
    #     print()
    '''######################################
        step : 2
            choose : words
    ######################################'''
    '''###################
        step : 2.1
            choose : nouns
    ###################'''
    lo_Nouns_Chosen = []

    flg_Unique = False

    for i in range(0, numOf_Nouns_Chosen):

        # choose
        #         while not flg_Unique :
        while True:

            noun_Chosen = lo_Nouns[random.randint(0, lenOf_LO_Nouns - 1)]

            #ref https://stackoverflow.com/questions/7936125/python-find-out-if-an-element-in-a-list-has-a-specific-string
            if not noun_Chosen in lo_Nouns_Chosen:  #if not noun_Chosen in lo_Nouns_Chosen

                break

            #/if not noun_Chosen in lo_Nouns_Chosen

        #/while not flg_Unique :
#         noun_Chosen = lo_Nouns[random.randint(0, lenOf_LO_Nouns - 1)]
#         noun_Chosen = lo_Nouns[random.randint(0, lenOf_LO_Nouns)]

# append
        lo_Nouns_Chosen.append(noun_Chosen)

    #/for i in range(0, numOf_Nouns_Chosen):
    '''###################
        step : 2.2
            choose : verbs
    ###################'''
    lo_Verbs_Chosen = []

    for i in range(0, numOf_Verbs_Chosen):

        # choose
        while True:

            verb_Chosen = lo_Verbs[random.randint(0, lenOf_LO_Verbs - 1)]

            if not verb_Chosen in lo_Verbs_Chosen:  #if not nou_

                break

            #/if not nou_

        # append
        lo_Verbs_Chosen.append(verb_Chosen)

    #/for i in range(0, numOf_Verbs_Chosen):
    '''###################

        step : 2.3
            choose : expression
    ###################'''
    lo_Expressions_Chosen = []

    for i in range(0, numOf_Expressions_Chosen):

        # choose
        while True:

            expression_Chosen = lo_Expressions[random.randint(
                0, lenOf_LO_Expressions - 1)]

            if not expression_Chosen in lo_Expressions_Chosen:  #if not expression_Chosen in lo_Expressions_Chosen

                break

            #/if not expression_Chosen in lo_Expressions_Chosen

        #/while True
#         expression_Chosen = lo_Expressions[random.randint(0, lenOf_LO_Expressions - 1)]

# append
        lo_Expressions_Chosen.append(expression_Chosen)

    #/for i in range(0, numOf_Expressions_Chosen):

#     #debug
#     print()
#     print("[%s:%d] lo_Expressions_Chosen ==>" % \
#                     (os.path.basename(libs.thisfile()), libs.linenum()
#
#                     ), file=sys.stderr)
#     print(lo_Expressions_Chosen)
#     print()
    '''###################
        step : 3
            show : lines
    ###################'''
    '''###################
        step : 3.1
            build : lines
    ###################'''
    strOf_Nouns = ", ".join(lo_Nouns_Chosen)
    strOf_Verbs = ", ".join(lo_Verbs_Chosen)
    strOf_Expressions = ", ".join(lo_Expressions_Chosen)

    strOf_Results = " / ".join([strOf_Nouns, strOf_Verbs, strOf_Expressions])

    #     #debug
    #     print()
    #     print("[%s:%d] strOf_Results ==>" % \
    #                     (os.path.basename(libs.thisfile()), libs.linenum()
    #
    #                     ), file=sys.stderr)
    #     print(strOf_Results)
    #     print()

    #/if not os.path.isfile(fpath_Data_Nouns)
    '''###################
        step : 4
            results --> clip
    ###################'''
    strOf_Cmd = "echo %s | clip" % (strOf_Results)

    # calll system
    os.system(strOf_Cmd)

    #debug
    print()

    print("[%s:%d] gen word set ==> done" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)
    print(strOf_Results)
    print()

    #_20190409_105137:wl:in-func
    '''###################
def test_3():
    '''###################
        file path        
    ###################'''
    PROJECT_ROOT = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\28_Physics\\1_\\_17"

    dpath_Out = "%s\\data_1_17.1" % (PROJECT_ROOT)

    ### fpath full
    tlabel = libs.get_TimeLabel_Now()

    session_Label = "1_17.1.test-3"

    #     fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)
    '''###################
        test : video        
    ###################'''
    '''###################
        get : file list        
    ###################'''
    dname_Images = "images"

    #     dpath_Full = "%s\\images_20180220_141141" % (dpath_Out)
    dpath_Full = "%s\\%s\\images_20180220_141141" % (dpath_Out, dname_Images)

    ### validate
    if not os.path.isdir(dpath_Full):  #if os.path.isdir(dpath_Full)

        print()
        print("[%s:%d] dir NOT exist => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , dpath_Full
        ), file=sys.stderr)

        return

    #/if os.path.isdir(dpath_Full)
    aa

    fpath_Glob = "%s\\*(*).png" % (dpath_Full)
    #     fpath_Glob = "%s\\*.png" % (dpath_Full)

    #ref glob https://stackoverflow.com/questions/14798220/how-can-i-search-sub-folders-using-glob-glob-module-in-python answered Feb 10 '13 at 13:31
    lo_Files = glob.glob(fpath_Glob)

    ### validate
    if len(lo_Files) < 1:  #if len(lo_Files) <+ 1

        print()
        print("[%s:%d] len(lo_Files) => less than 1" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , len(lo_Files), fpath_Glob
            ), file=sys.stderr)

        return

    else:

        print()
        print("[%s:%d] len(lo_Files) => %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , len(lo_Files)
            ), file=sys.stderr)
    #/if len(lo_Files) < 1
    '''###################
        sort : list        
    ###################'''
    #ref https://www.programiz.com/python-programming/methods/list/sort
    lo_Files.sort()

    #     for item in lo_Files:
    #
    #         print("[%s:%d] item => %s" % \
    #             (os.path.basename(libs.thisfile()), libs.linenum()
    #             , item
    #             ), file=sys.stderr)
    #
    #         print()

    #/for item in lo_Files:
    '''###################
        copy        
    ###################'''
    cnt = 0

    lo_CopiedFiles = []

    for item in lo_Files:

        dpath = os.path.dirname(item)

        fpath_Dst = "%s\\image.%03d.png" % (dpath, cnt)

        copyfile(item, fpath_Dst)

        # append new file path
        lo_CopiedFiles.append(fpath_Dst)

        print()
        print("[%s:%d] file copied : %s => %s" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , item, fpath_Dst
                ), file=sys.stderr)

        # increment
        cnt += 1

    #/for item in lo_Files:
    '''###################
        video : generate        
    ###################'''
    dpath_In = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research" \
            + "\\28_Physics\\1_\\_17\\data_1_17.1" \
            + "\\images\\images_20180220_141141"

    fpath_In = "%s\\image.%%03d.png" % (dpath_In)
    #     fpath_In = "%s\\image.%03d.png" % (dpath_In)

    fpath_Out = "%s\\movie.%s.mp4" % (dpath_In, libs.get_TimeLabel_Now())


    cmd = "ffmpeg -f image2 -r 2 -i " \
            + "%s -vcodec mpeg4 -y %s" % (fpath_In, fpath_Out)
    #     cmd = "ffmpeg -f image2 -r 2 -i image.%03d.png -vcodec mpeg4 -y movie.mp4"

    # execute
    os.system(cmd)

    print()
    print("[%s:%d] executing command => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , cmd
        ), file=sys.stderr)
    '''###################
        delete : copied files        
    ###################'''
    while (not os.path.isfile(fpath_Out)):

        pass

    #/while (not os.path.isfile(fpath_Out)) :

    print()
    print("[%s:%d] copied files ==> deleting..." % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)

    # remove files
    for item in lo_CopiedFiles:

        if os.path.isfile(item):  #if os.path.isfile(item)

            res = os.remove(item)

            print()
            print("[%s:%d] remove file : result => %s (%s)" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                    , res, item
                    ), file=sys.stderr)

        #/if os.path.isfile(item)

    print()
    print("[%s:%d] copied files ==> deleted" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
示例#20
0
def test_1(lenOf_Digits = 5):

#_20190407_174252:head
#_20190407_174303:wl:in-func
#_20190407_174258:caller
    
    '''###################
        step : A : 0
            prep : vars
    ###################'''
    lo_StrOf_Model_Patterns = []
    
    # for-loop var
    numOf_ForLoop_Tail = math.pow(2, 5)
#     numOf_ForLoop_Tail = math.pow(5, 2)
    
    numOf_ForLoop_Tail = int(numOf_ForLoop_Tail)
    
    '''###################
        step : A : 1
    ###################'''
#     for i in range(0, lenOf_Digits):
    
#     for i in range(0, lenOf_Digits):
    for i in range(0, numOf_ForLoop_Tail):
        '''###################
            step : A : 1.1, 1.2
                conv to : binary
        ###################'''
        #ref https://stackoverflow.com/questions/10411085/converting-integer-to-binary-in-python
        label = "0:0%sb" % str(lenOf_Digits)
        
#         strOf_Binary = ("0:0%sb" % str(lenOf_Digits)).format(i)
        strOf_Binary = "{0:05b}".format(i)
#         strOf_Binary = label.format(i)
#         bin = "{0:05b}".format(i)
        
#         print("[%s:%d] i = %d / label = %s / strOf_Binary = %s / test = %s" % \
        print("[%s:%d] i = %d / label = %s / strOf_Binary = %s" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , i
                , label
                , strOf_Binary
                ), file=sys.stderr)
        
        '''###################
            step : A : 1.3
                append
        ###################'''
        lo_StrOf_Model_Patterns.append(strOf_Binary)
        
    #/for i in range(0, lenOf_Digits):

    '''###################
        step : A : 2
            return
    ###################'''
    #debug
    print("[%s:%d] lo_StrOf_Model_Patterns =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
             
            ), file=sys.stderr)
    
    print(lo_StrOf_Model_Patterns)
    
    
    return lo_StrOf_Model_Patterns
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(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 numbering(request):
    
    '''###################
        test        
    ###################'''
    ### referer
#     req = HttpRequest()
    
#     print()
#     print("[%s:%d] req.META.get('REQUEST_METHOD ') => %s" % \
#         (os.path.basename(libs.thisfile()), libs.linenum()
#          #ref referer https://stackoverflow.com/questions/40627149/dict-object-has-no-attribute-http-referer answered Nov 16 '16 at 8:32
#         , req.META.get('REQUEST_METHOD ')
#         ), file=sys.stderr)
#     print("[%s:%d] req.META.get('HTTP_REFERER') => %s" % \
#         (os.path.basename(libs.thisfile()), libs.linenum()
#          #ref referer https://stackoverflow.com/questions/40627149/dict-object-has-no-attribute-http-referer answered Nov 16 '16 at 8:32
#         , req.META.get('HTTP_REFERER')
#         ), file=sys.stderr)
#     print("[%s:%d] req.META.get('HTTP_USER_AGENT') => %s" % \
#         (os.path.basename(libs.thisfile()), libs.linenum()
#          #ref referer https://stackoverflow.com/questions/40627149/dict-object-has-no-attribute-http-referer answered Nov 16 '16 at 8:32
#         , req.META.get('HTTP_USER_AGENT')
#         ), file=sys.stderr)
#     print()

    '''###################
        step : 1
            get : params
    ###################'''
    '''###################
        step : 1.1
            get : params : main dir for mm files
    ###################'''
    dpath_MainDir_MM_Files = request.GET.get('dir_Main_MM_File', False)
    
    if dpath_MainDir_MM_Files == False : #if dpath_MainDir_MM_Files == False

        dpath_MainDir_MM_Files = cons_mm.FPath.DPATH_MM_PROJECTS.value
        
    #/if dpath_MainDir_MM_Files == False
    
    #debug
    print()
    print("[%s:%d] dpath_MainDir_MM_Files => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
         , dpath_MainDir_MM_Files
        ), file=sys.stderr)
    
    '''###################
        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
    
    #_20190702_093843:tmp
    #ref https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory answered Jul 8 '10 at 21:01
    dpath_Main = dpath_MainDir_MM_Files
#     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 = "Where to store Django Templates?"
    
    dic = {
        
        "msg" : msg,
        
        "MAIN_DIR" : cons_mm.FPath.DPATH_MM_PROJECTS.value
        
        #_20190702_094407:tmp
        , "dpath_MainDir_MM_Files" : dpath_MainDir_MM_Files
        
        , "lo_Files" : lo_Files,
        
        }
    
    '''###################
        render        
    ###################'''
    if referer_Current == referer_MM : #if referer_Current == referer_MM
    
        return render(request, 'mm/numbering.html', dic)
    
    else : #if referer_Current == referer_MM
    
        return render(request, 'mm/numbering_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)
示例#25
0
def test_2__Korean():

    #_20190411_091337:head
    '''###################
        step : 0.1
            prep : vars
    ###################'''

    #    numOf_Nouns_Chosen = 4
    #    numOf_Verbs_Chosen = 4
    #    numOf_Expressions_Chosen = 4
    #
    #    numOf_Adverbs_Chosen = 4
    #    numOf_Ajectives_Chosen = 4
    '''###################
        step : 1
            load files
    ###################'''
    '''###################
        step : 1.1
            build : paths
    ###################'''
    dpath_Data_Files = "C:\\WORKS_2\\WS\\WS_Others.JVEMV6\\JVEMV6\\37_miscs\\9_prog_lang"

    fname_Data_Nouns = "data_nouns.dat"
    fname_Data_Verbs = "data_verbs.dat"
    fname_Data_Expressions = "data_expressions.dat"

    fname_Data_Topics = "data_topics.dat"

    fname_Data_Adverbs = "data_adverbs.dat"
    fname_Data_Ajectives = "data_ajectives.dat"

    # paths
    fpath_Data_Nouns = os.path.join(dpath_Data_Files, fname_Data_Nouns)
    fpath_Data_Verbs = os.path.join(dpath_Data_Files, fname_Data_Verbs)
    fpath_Data_Expressions = os.path.join(dpath_Data_Files,
                                          fname_Data_Expressions)
    fpath_Data_Topics = os.path.join(dpath_Data_Files, fname_Data_Topics)

    fpath_Data_Adverbs = os.path.join(dpath_Data_Files, fname_Data_Adverbs)
    fpath_Data_Ajectives = os.path.join(dpath_Data_Files, fname_Data_Ajectives)
    #_20190411_092504:fix
    '''###################
        step : 1.2
            validate
    ###################'''
    # nouns
    if not os.path.isfile(
            fpath_Data_Nouns):  #if not os.path.isfile(fpath_Data_Nouns)

        print()
        print("[%s:%d] file ==> NOT exist : '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Data_Nouns
                        ), file=sys.stderr)

        return

    # verbs
    if not os.path.isfile(
            fpath_Data_Verbs):  #if not os.path.isfile(fpath_Data_Verbs)

        print()
        print("[%s:%d] file ==> NOT exist : '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Data_Verbs
                        ), file=sys.stderr)

        return

    # expressions
    if not os.path.isfile(fpath_Data_Expressions
                          ):  #if not os.path.isfile(fpath_Data_Expressions)

        print()
        print("[%s:%d] file ==> NOT exist : '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Data_Expressions
                        ), file=sys.stderr)

        return

    # topics
    if not os.path.isfile(
            fpath_Data_Topics):  #if not os.path.isfile(fpath_Data_Topics)

        print()
        print("[%s:%d] file ==> NOT exist : '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Data_Topics
                        ), file=sys.stderr)

        return

    # adverbs
    if not os.path.isfile(
            fpath_Data_Adverbs):  #if not os.path.isfile(fpath_Data_Adverbs)

        print()
        print("[%s:%d] file ==> NOT exist : '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Data_Adverbs
                        ), file=sys.stderr)

        return

    # ajectives
    if not os.path.isfile(fpath_Data_Ajectives
                          ):  #if not os.path.isfile(fpath_Data_Ajectives)

        print()
        print("[%s:%d] file ==> NOT exist : '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Data_Ajectives
                        ), file=sys.stderr)

        return
    '''###################
        step : 1.2
            file : read
    ###################'''
    # load : files
    fin_Nouns = open(fpath_Data_Nouns, "r")
    fin_Verbs = open(fpath_Data_Verbs, "r")
    fin_Expressions = open(fpath_Data_Expressions, "r")
    fin_Topics = open(fpath_Data_Topics, "r")

    fin_Adverbs = open(fpath_Data_Adverbs, "r")
    fin_Ajectives = open(fpath_Data_Ajectives, "r")

    # read lines
    lo_Nouns = fin_Nouns.readlines()
    lo_Verbs = fin_Verbs.readlines()
    lo_Expressions = fin_Expressions.readlines()
    lo_Topics = fin_Topics.readlines()

    lo_Adverbs = fin_Adverbs.readlines()
    lo_Ajectives = fin_Ajectives.readlines()

    # lines : strip
    # also, the last element ---> omit (return only line)
    lo_Nouns = [x.strip() for x in lo_Nouns[:-1]]
    lo_Verbs = [x.strip() for x in lo_Verbs[:-1]]
    lo_Expressions = [x.strip() for x in lo_Expressions[:-1]]
    lo_Topics = [x.strip() for x in lo_Topics[:-1]]
    #     lo_Nouns = [x.strip() for x in lo_Nouns]
    #     lo_Verbs = [x.strip() for x in lo_Verbs]
    lo_Adverbs = [x.strip() for x in lo_Adverbs[:-1]]
    lo_Ajectives = [x.strip() for x in lo_Ajectives[:-1]]

    # lengh
    lenOf_LO_Nouns = len(lo_Nouns)
    lenOf_LO_Verbs = len(lo_Verbs)
    lenOf_LO_Expressions = len(lo_Expressions)
    lenOf_LO_Topics = len(lo_Topics)

    lenOf_LO_Adverbs = len(lo_Adverbs)
    lenOf_LO_Ajectives = len(lo_Ajectives)
    '''###################
        step : 1.x
            file : close
    ###################'''
    fin_Nouns.close()
    fin_Verbs.close()
    fin_Expressions.close()
    fin_Topics.close()

    fin_Adverbs.close()
    fin_Ajectives.close()
    '''######################################
        step : 2
            choose : words
    ######################################'''
    '''###################
        step : 2.1
            choose : nouns
    ###################'''
    lo_Nouns_Chosen = []

    flg_Unique = False

    for i in range(0, numOf_Nouns_Chosen):

        # choose
        #         while not flg_Unique :
        while True:

            noun_Chosen = lo_Nouns[random.randint(0, lenOf_LO_Nouns - 1)]

            #ref https://stackoverflow.com/questions/7936125/python-find-out-if-an-element-in-a-list-has-a-specific-string
            if not noun_Chosen in lo_Nouns_Chosen:  #if not noun_Chosen in lo_Nouns_Chosen

                break

            #/if not noun_Chosen in lo_Nouns_Chosen

        #/while not flg_Unique :
#         noun_Chosen = lo_Nouns[random.randint(0, lenOf_LO_Nouns - 1)]
#         noun_Chosen = lo_Nouns[random.randint(0, lenOf_LO_Nouns)]

# append
        lo_Nouns_Chosen.append(noun_Chosen)

    #/for i in range(0, numOf_Nouns_Chosen):
    '''###################
        step : 2.2
            choose : verbs
    ###################'''
    lo_Verbs_Chosen = []

    for i in range(0, numOf_Verbs_Chosen):

        # choose
        while True:

            verb_Chosen = lo_Verbs[random.randint(0, lenOf_LO_Verbs - 1)]

            if not verb_Chosen in lo_Verbs_Chosen:  #if not nou_

                break

            #/if not nou_

        # append
        lo_Verbs_Chosen.append(verb_Chosen)

    #/for i in range(0, numOf_Verbs_Chosen):
    '''###################

        step : 2.3
            choose : expression
    ###################'''
    lo_Expressions_Chosen = []

    for i in range(0, numOf_Expressions_Chosen):

        # choose
        while True:

            expression_Chosen = lo_Expressions[random.randint(
                0, lenOf_LO_Expressions - 1)]

            if not expression_Chosen in lo_Expressions_Chosen:  #if not expression_Chosen in lo_Expressions_Chosen

                break

            #/if not expression_Chosen in lo_Expressions_Chosen

        #/while True
#         expression_Chosen = lo_Expressions[random.randint(0, lenOf_LO_Expressions - 1)]

# append
        lo_Expressions_Chosen.append(expression_Chosen)

    #/for i in range(0, numOf_Expressions_Chosen):
    '''###################

        step : 2.4
            choose : Adverbs
    ###################'''
    lo_Adverbs_Chosen = []

    #_20190411_093247:fix
    for i in range(0, numOf_Adverbs_Chosen):

        # choose
        while True:

            expression_Chosen = lo_Adverbs[random.randint(
                0, lenOf_LO_Adverbs - 1)]

            if not expression_Chosen in lo_Adverbs_Chosen:  #if not expression_Chosen in lo_Adverbs_Chosen

                break

            #/if not expression_Chosen in lo_Adverbs_Chosen

        #/while True

        # append
        lo_Adverbs_Chosen.append(expression_Chosen)

    #/for i in range(0, numOf_Adverbs_Chosen):
    '''###################

        step : 2.5
            choose : Ajectives
    ###################'''
    lo_Ajectives_Chosen = []

    for i in range(0, numOf_Ajectives_Chosen):

        # choose
        while True:

            expression_Chosen = lo_Ajectives[random.randint(
                0, lenOf_LO_Ajectives - 1)]

            if not expression_Chosen in lo_Ajectives_Chosen:  #if not expression_Chosen in lo_Ajectives_Chosen

                break

            #/if not expression_Chosen in lo_Ajectives_Chosen

        #/while True

        # append
        lo_Ajectives_Chosen.append(expression_Chosen)

    #/for i in range(0, numOf_Ajectives_Chosen):
    '''###################
        step : 2.6
            choose : topics
    ###################'''
    lo_Topics_Chosen = []

    for i in range(0, numOf_Topics_Chosen):

        # choose
        while True:

            expression_Chosen = lo_Topics[random.randint(
                0, lenOf_LO_Topics - 1)]

            if not expression_Chosen in lo_Topics_Chosen:  #if not expression_Chosen in lo_Topics_Chosen

                break

            #/if not expression_Chosen in lo_Topics_Chosen

        #/while True

        # append
        lo_Topics_Chosen.append(expression_Chosen)

    #/for i in range(0, numOf_Topics_Chosen):

#     #debug
#     print()
#     print("[%s:%d] lo_Topics_Chosen ==>" % \
#                     (os.path.basename(libs.thisfile()), libs.linenum()
#
#                     ), file=sys.stderr)
#     print(lo_Topics_Chosen)
#     print()
    '''###################
        step : 3
            show : lines
    ###################'''
    '''###################
        step : 3.1
            build : lines
    ###################'''
    #    charOf_Join_For_Words = ";"
    #    charOf_Join_For_Categories = " / "

    strOf_Nouns = charOf_Join_For_Words.join(lo_Nouns_Chosen)
    strOf_Verbs = charOf_Join_For_Words.join(lo_Verbs_Chosen)
    strOf_Expressions = charOf_Join_For_Words.join(lo_Expressions_Chosen)

    strOf_Topics = charOf_Join_For_Words.join(lo_Topics_Chosen)

    strOf_Adverbs = charOf_Join_For_Words.join(lo_Adverbs_Chosen)
    strOf_Ajectives = charOf_Join_For_Words.join(lo_Ajectives_Chosen)

    #     strOf_Results = " / ".join(\
    #     strOf_Results = "\n".join(\

    #strOf_Results = charOf_Join_For_Categories.join(\

    lo_Categories =             [ \
                strOf_Nouns
                , strOf_Verbs
                , strOf_Expressions
                , strOf_Adverbs
                , strOf_Ajectives
                , strOf_Topics
            ]

    lo_Categories = ["* " + x for x in lo_Categories]

    strOf_Results = charOf_Join_For_Categories__Display.join(\

            lo_Categories
    #            [
    #                strOf_Nouns
    #                , strOf_Verbs
    #                , strOf_Expressions
    #                , strOf_Adverbs
    #                , strOf_Ajectives
    #            ]
    )
    #     strOf_Results = " / ".join([strOf_Nouns, strOf_Verbs, strOf_Expressions])

    #debug
    print()

    strOf_Chosen_Lang = "Korean"
    #     print("[%s:%d] gen word set ==> done" % \
    print("[%s:%d] gen word set ==> done (lang = %s)" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , strOf_Chosen_Lang
                    ), file=sys.stderr)
    print(strOf_Results)
    print()

    #_20190411_091351:wl:in-func
    '''###################
        step : 4
            results --> clip
    ###################'''

    #lo_Categories = ["*" + x for x in lo_Categories]

    strOf_Results = charOf_Join_For_Categories__Clip.join(\

        lo_Categories

    )

    strOf_Cmd = "echo %s | clip" % (strOf_Results)

    # calll system
    os.system(strOf_Cmd)

    #_20190409_105137:wl:in-func
    '''###################
示例#26
0
def _build_result_csv_data__Report_File(\

            _dpath_Log__ROOT
            , _strOf_Project
            , dname_Log
            , _tlabel

                                        ):

    #_20190901_151726:caller
    #_20190901_151733:head
    #_20190901_151746:wl
    '''###################
        step : 1 : 1
            prep : vars : file names, paths
    ###################'''
    #C:\Users\iwabuchiken\AppData\Roaming\MetaQuotes\Terminal\34B08C83A5AAE27A4079DE708E60511E\MQL4\Logs\logs_trading
    #     DPATH_REPORT_FILE = "C:\\Users\\iwabuchiken\\AppData\\Roaming\\MetaQuotes\\Terminal\\34B08C83A5AAE27A4079DE708E60511E\\MQL4\\Logs\\logs_trading"
    #
    #     FNAME_REPORT_FILE = "DetailedStatement.[20190901_145309].htm"

    fpath_Report_File = os.path.join(DPATH_REPORT_FILE, FNAME_REPORT_FILE)

    #_20190902_124906:tmp
    #     _tlabel = libs.get_TimeLabel_Now()

    #     #C:\WORKS_2\WS\WS_Others.prog\prog\D-7\2_2\VIRTUAL\Admin_Projects\curr\data\log
    #     _dpath_Log__ROOT = "C:\\WORKS_2\\WS\\WS_Others.prog\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\curr\\data\\log"
    #
    #     _strOf_Project = "[44_8.5].[order-csv-data]"
    #
    #     dname_Log = "%s.(%s).dir" % (_strOf_Project, _tlabel)

    fname_Log__Dat = "%s.(%s).dat" % (_strOf_Project, _tlabel)

    fname_Log__Dat_Report_File = "%s.[report-file].(%s).dat" % (_strOf_Project,
                                                                _tlabel)
    '''###################
        step : 1 : 1.1
            gen : dirs
    ###################'''
    #_20190902_125615:tmp
    dpath_Log__Dat = os.path.join(_dpath_Log__ROOT, dname_Log)

    if not os.path.isdir(
            dpath_Log__Dat):  #if not os.path.isdir(dpath_Log__Dat)

        res = os.makedirs(dpath_Log__Dat)

        #debug
        if SWITCH_DEBUG == True:  #if SWITCH_DEBUG == True

            msg = "[%s:%d] os.makedirs ==> %s" % \
                            (os.path.basename(libs.thisfile()), libs.linenum()
                             , res
                            )

            print()
            print(msg, file=sys.stderr)

        #/if SWITCH_DEBUG == True

    #/if not os.path.isdir(dpath_Log__Dat)
    '''###################
        step : 1 : 2
            prep : vars : lists
    ###################'''
    #
    lo_Orders = []

    # [ [tag_TR, lo_TDs], [], ...]
    lo_TR_and_TDs = []

    #
    lo_Orders_From_Report_File = []

    # list of TRs with order TDs
    lo_TRs_With_Order_TDS = []
    '''###################
        step : 2 : 1
            read : source file
    ###################'''
    f_in_Report_File = open(fpath_Report_File, "r")

    contentOf_Report_File = f_in_Report_File.read()
    '''###################
        step : 2 : 1.1
            source file : close
    ###################'''
    f_in_Report_File.close()
    '''###################
        step : 2 : 2
            read : as html
    ###################'''
    #ref https://tonari-it.com/python-beautiful-soup-html-parse/#toc2
    soup = bs4.BeautifulSoup(contentOf_Report_File, "html.parser")

    print()
    print(soup.title)
    '''###################
        step : 2 : 3
            read : TR tags
    ###################'''
    #ref https://tonari-it.com/python-html-tag-list-bs4/#toc5
    lo_TRs = soup.select("tr")

    #debug
    if SWITCH_DEBUG == True:  #if SWITCH_DEBUG == True

        # count
        cntOf_LO_TRs = len(lo_TRs)

        msg = "[%s:%d] cntOf_LO_TRs ==> %d" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , cntOf_LO_TRs
                        )

        print()
        print(msg, file=sys.stderr)

    #/if SWITCH_DEBUG == True
    '''###################
        step : 2 : 4
            read : TD tags
    ###################'''
    for item in lo_TRs:
        '''###################
            step : 2 : 4.1
                select : TD tags
        ###################'''
        lo_TDs = item.select("td")
        '''###################
            step : 2 : 4.2
                append
        ###################'''
        lo_TR_and_TDs.append([item, lo_TDs])

    #/for item in lo_TRs:

    #debug
    if SWITCH_DEBUG == True:  #if SWITCH_DEBUG == True

        # count
        cntOf_LO_TR_and_TDs = len(lo_TR_and_TDs)

        msg = "[%s:%d] cntOf_LO_TR_and_TDs ==> %d" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , cntOf_LO_TR_and_TDs
                        )

        print()
        print(msg, file=sys.stderr)

#         print(lo_TR_and_TDs[10])

#/if SWITCH_DEBUG == True
    '''###################
        step : 2 : 5
            read : TD texts
    ###################'''
    #     for item in lo_TR_and_TDs:
    #     for item in lo_TR_and_TDs[:50] :
    #     for item in lo_TR_and_TDs[:20] :
    for item in lo_TR_and_TDs:
        '''###################
            step : 2 : 5.1
                get : TDs
        ###################'''
        lo_TDs = item[1]
        '''###################
            step : 2 : 5.2
                get : texts
        ###################'''
        for item_2 in lo_TDs:
            '''###################
                step : 2 : 5.2 : 1
                    get : "title" attribute value
            ###################'''
            # get text
            textOf_TD_With_Title_Attribute = item_2.get("title")
            #             textOf_TD = item_2.getText()
            '''###################
                step : 2 : 5.2 : 2
                    validate
            ###################'''
            if textOf_TD_With_Title_Attribute == None:  #if textOf_TD == None

                #                 #debug
                #                 if SWITCH_DEBUG == True : #if SWITCH_DEBUG == True
                #
                #                     msg = "[%s:%d] textOf_TD_With_Title_Attribute ==> none" % \
                #                                     (os.path.basename(libs.thisfile()), libs.linenum()
                #
                #                                     )
                #
                #                     print(item_2)
                #                     print(msg, file=sys.stderr)
                #
                #                 #/if SWITCH_DEBUG == True

                # continue
                continue

            #/if textOf_TD == None
            '''###################
                step : 2 : 5.2 : 3
                    if "My order" in the text ==> append
            ###################'''
            '''###################
                step : 2 : 5.2 : 3.1
                    log
            ###################'''
            #_20190901_161624:next

            if "My order" in textOf_TD_With_Title_Attribute:  #if "My order" in textOf_TD_With_Title_Attribute
                '''###################
                    step : 2 : 5.2 : 3.2
                        append
                ###################'''
                # append
                lo_TRs_With_Order_TDS.append(item)

                #_20190901_161249:tmp
#                 #debug
#                 if SWITCH_DEBUG == True : #if SWITCH_DEBUG == True
#
#                     msg = "[%s:%d] My order ==> detected" % \
#                                     (os.path.basename(libs.thisfile()), libs.linenum()
#
#                                     )
#
#                     print(item_2)
#                     print(msg, file=sys.stderr)
#
#                 #/if SWITCH_DEBUG == True

#/if "My order" in textOf_TD_With_Title_Attribute

#             #debug
#             if SWITCH_DEBUG == True : #if SWITCH_DEBUG == True
#
#                 msg = "[%s:%d] textOf_TD ==> %s" % \
#                                 (os.path.basename(libs.thisfile()), libs.linenum()
#                                  , textOf_TD
#                                 )
#
#                 print()
#                 print(msg, file=sys.stderr)
#
#             #/if SWITCH_DEBUG == True

#             #
#             #ref https://www.afternerd.com/blog/python-string-contains/
#             if "My order" in textOf_TD : #if "My order" in textoff
#
#                 #debug
#                 if SWITCH_DEBUG == True : #if SWITCH_DEBUG == True
#
#                     msg = "[%s:%d] My order ==> detected" % \
#                                     (os.path.basename(libs.thisfile()), libs.linenum()
#
#                                     )
#
#                     print()
#                     print(msg, file=sys.stderr)
#
#                     print(item)
#
#                 #/if SWITCH_DEBUG == True
#
#             #/if "My order" in textoff

#             #debug
#             if SWITCH_DEBUG == True : #if SWITCH_DEBUG == True
#
#                 # count
#                 cntOf_LO_TR_and_TDs = len(lo_TR_and_TDs)
#
#                 msg = "[%s:%d] cntOf_LO_TR_and_TDs ==> %d" % \
#                                 (os.path.basename(libs.thisfile()), libs.linenum()
#                                  , cntOf_LO_TR_and_TDs
#                                 )
#
#                 print()
#                 print(msg, file=sys.stderr)
#
#                 print(lo_TR_and_TDs[10])
#
#             #/if SWITCH_DEBUG == True

#/for item_2 in lo_TDs:

#/for item in lo_TR_and_TDs:
    '''###################
        step : 2 : 5.2 : 4
            extract texts
    ###################'''
    #_20190902_124052:tmp
    #debug
    if SWITCH_DEBUG == True:  #if SWITCH_DEBUG == True

        msg = "[%s:%d] len(lo_TRs_With_Order_TDS) ==> %d" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , len(lo_TRs_With_Order_TDS)
                        )

        print(msg, file=sys.stderr)

    #/if SWITCH_DEBUG == True
    '''###################
        step : 2 : 5.2 : 5
            write to file
    ###################'''
    #_20190902_124906:tmp
    '''###################
        step : 2 : 5.2 : 5.1
            file path
    ###################'''
    fpath_Log__Dat_Report_File = os.path.join(_dpath_Log__ROOT, dname_Log,
                                              fname_Log__Dat_Report_File)
    #     fpath_Log__Dat = os.path.join(_dpath_Log__ROOT, dname_Log, fname_Log__Dat)
    '''###################
        step : 2 : 5.2 : 5.2
            file : open
    ###################'''
    f_out_Dat_Report_File = open(fpath_Log__Dat_Report_File, "w")
    '''###################
        step : 2 : 5.2 : 5.2.1
            file : header
    ###################'''
    #"Ticket", "Open Time", "Type", "Size", "Item", "Price", "S / L", "T / P", "Close Time", "Price", "Commission", "Taxes", "Swap", "Profit"
    lo_Col_Names = [
        "Ticket", "Open Time", "Type", "Size", "Item", "Price", "S / L",
        "T / P", "Close Time", "Price", "Commission", "Taxes", "Swap", "Profit"
    ]

    f_out_Dat_Report_File.write("source file\t%s" % fname_Log__Dat_Report_File)
    f_out_Dat_Report_File.write("\n")

    f_out_Dat_Report_File.write("source dir\t%s" % DPATH_REPORT_FILE)
    f_out_Dat_Report_File.write("\n")

    f_out_Dat_Report_File.write("\n")

    f_out_Dat_Report_File.write("s.n.")
    f_out_Dat_Report_File.write("\t")

    f_out_Dat_Report_File.write("\t".join(lo_Col_Names))
    f_out_Dat_Report_File.write("\n")
    f_out_Dat_Report_File.write("\n")
    '''###################
        step : 2 : 5.2 : 5.3
            file : write
    ###################'''
    #_20190902_130031:tmp
    cntOf_Loop = 0

    for item in lo_TRs_With_Order_TDS:
        '''###################
            step : 2 : 5.2 : 5.3 : 0
                count
        ###################'''
        cntOf_Loop += 1
        '''###################
            step : 2 : 5.2 : 5.3 : 1
                get : TDs
        ###################'''
        # TDs
        lo_TDs = item[1]
        '''###################
            step : 2 : 5.2 : 5.3 : 2
                get : texts
        ###################'''
        lo_Tmp_TD_Texts = []

        # s.n.
        lo_Tmp_TD_Texts.append("%d" % cntOf_Loop)
        lo_Tmp_TD_Texts.append("\t")

        lo_Tmp_TD_Texts.append("\t".join([x.getText() for x in lo_TDs]))

        #         for item_2 in lo_TDs:
        #
        #             textOf_TD = item_2.getText()
        #
        #             lo_Tmp_TD_Texts.append(textOf_TD)
        #             lo_Tmp_TD_Texts.append("\t")
        #
        #         #/for item_2 in lo_TDs:

        #         # separator
        #         lo_Tmp_TD_Texts.append("\n")

        #         # first TD
        #         TD_0 = lo_TDs[0]
        #
        #         textOf_TD = TD_0.getText()
        #
        #         f_out_Dat.write(textOf_TD)
        f_out_Dat_Report_File.write("".join(lo_Tmp_TD_Texts))
        f_out_Dat_Report_File.write("\n")

    #/for item in lo_TRs_With_Order_TDS:
    '''###################
        step : 2 : 5.2 : 5.X
            file : close
    ###################'''
    f_out_Dat_Report_File.close()
    '''###################
        step : X
            return
    ###################'''
    return lo_TRs_With_Order_TDS
示例#27
0
def exec_prog():
    '''###################
        step : 1
            args
    ###################'''
    #debug
    print()

    print("[%s:%d] sys.argv ==> " % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)
    print(sys.argv)
    print()

    #     return
    '''###################
        step : 1.1
            get : args
    ###################'''
    strOf_Lang__Korean = "Korean"
    strOf_Lang__Korean_Lower = "korean"

    strOf_Lang__Chinese = "Chinese"
    strOf_Lang__Chinese_Lower = "chinese"

    strOf_Chosen_Lang = ""

    if len(sys.argv) > 1:  #if len(sys.argv) > 1 and sys.arg

        if sys.argv[1] == strOf_Lang__Korean \
            or sys.argv[1] == strOf_Lang__Korean_Lower : #if sys.argv[1] == strOf_Lang__Korean

            strOf_Chosen_Lang = strOf_Lang__Korean
#             strOf_Chosen_Lang = "korean"

        elif sys.argv[1] == strOf_Lang__Chinese \
            or sys.argv[1] == strOf_Lang__Chinese_Lower : #if sys.argv[1] == strOf_Lang__Korean

            strOf_Chosen_Lang = strOf_Lang__Chinese

        else:  #if sys.argv[1] == strOf_Lang__Korean

            strOf_Chosen_Lang = strOf_Lang__Korean

        #/if sys.argv[1] == strOf_Lang__Korean

    else:  #if len(sys.argv) > 1 and sys.argv

        strOf_Chosen_Lang = strOf_Lang__Korean
#         strOf_Chosen_Lang = "korean"

#/if len(sys.argv) > 1 and sys.argv
    '''###################
        ops        
    ###################'''

    #_20190411_091344:caller
    #     if strOf_Chosen_Lang == strOf_Lang__Korean : #if strOf_Chosen_Lang == strOf_Lang__Korean
    if strOf_Chosen_Lang == strOf_Lang__Korean:  #if strOf_Chosen_Lang == strOf_Lang__Korean

        test_2__Korean()

    elif strOf_Chosen_Lang == strOf_Lang__Chinese:  #if strOf_Chosen_Lang == strOf_Lang__Korean

        test_2__Chinese()

    else:  #if strOf_Chosen_Lang == strOf_Lang__Korean

        #debug
        print()

        print("[%s:%d] unknown lang name ==> '%s'" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , strOf_Chosen_Lang
                        ), file=sys.stderr)
        #         print(sys.argv)
        print()
示例#28
0
def _build_result_csv_data__Dat_File():
    '''###################
        step : 1
            prep : vars
    ###################'''
    #     DPATH_DAT_FILE = "C:\\Users\\iwabuchiken\\AppData\\Roaming\\MetaQuotes\\Terminal\\34B08C83A5AAE27A4079DE708E60511E\\MQL4\\Files\\Logs\\20190829_223434[eap-2.id-1].[EURJPY-1].dir"
    #
    #     FNAME_DAT_FILE = "[eap-2.id-1].(20190829_223434).dat"

    fpath_Dat_File = os.path.join(DPATH_DAT_FILE, FNAME_DAT_FILE)

    # lists
    lo_Order_Numbers = []
    '''###################
        step : 2
            read : file
    ###################'''
    '''###################
        step : 2 : 1
            open
    ###################'''
    f_in_Dat_File = open(fpath_Dat_File, "r")
    '''###################
        step : 2 : 2
            read
    ###################'''
    linesOf_Dat_File = f_in_Dat_File.readlines()

    # [2019.08.29 22:34:35 / lib_ea_2.mqh:249]    17307984    117.639    117.636    4    8    117.632    117.647

    #debug
    if SWITCH_DEBUG == True:  #if SWITCH_DEBUG == True

        # count
        cntOf_Lines = len(linesOf_Dat_File)

        msg = "[%s:%d] cntOf_Lines ==> %d" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , cntOf_Lines
                        )

        print()
        print(msg, file=sys.stderr)

    #/if SWITCH_DEBUG == True
    '''###################
        step : 3
            build list
    ###################'''
    for item in linesOf_Dat_File:
        '''###################
            step : 3 : 1
                split each line
        ###################'''
        tokens = item.split("\t")
        '''###################
            step : 3 : 2
                get : order number
        ###################'''
        tokeOf_Order_Number = tokens[1]

        # append
        lo_Order_Numbers.append(int(tokeOf_Order_Number))

    #/for item in linesOf_Dat_File:

    #debug
    if SWITCH_DEBUG == True:  #if SWITCH_DEBUG == True

        msg = "[%s:%d] len(lo_Order_Numbers) ==> %d" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , len(lo_Order_Numbers)
                        )

        print()
        print(msg, file=sys.stderr)

        print(lo_Order_Numbers[0:10])

    #/if SWITCH_DEBUG == True
    '''###################
        step : 4
            file : close
    ###################'''
    f_in_Dat_File.close()

    #_20190901_150006:tmp
    #debug
    if SWITCH_DEBUG == True:  #if SWITCH_DEBUG == True

        msg = "[%s:%d] file ==> closed : %s" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Dat_File
                        )

        print()
        print(msg, file=sys.stderr)

    #/if SWITCH_DEBUG == True
    '''###################
        step : X
            return
    ###################'''
    return lo_Order_Numbers
示例#29
0
def test_2(lenOf_Digits = 5):

#_20190408_161511:head
#_20190408_161518:caller
#_20190408_161524:wl:in-func    

    '''###################
        step : A : 0
            prep : vars
    ###################'''
    lo_StrOf_Model_Patterns = []
    
    # for-loop var
    numOf_ForLoop_Tail = math.pow(2, lenOf_Digits)
#     numOf_ForLoop_Tail = math.pow(2, 5)
#     numOf_ForLoop_Tail = math.pow(5, 2)
    
    numOf_ForLoop_Tail = int(numOf_ForLoop_Tail)
    
    '''###################
        step : A : 1
    ###################'''
    for i in range(0, numOf_ForLoop_Tail):
        '''###################
            step : A : 1, 2
                conv to : binary
        ###################'''
#         #ref https://stackoverflow.com/questions/10411085/converting-integer-to-binary-in-python
#         label = "0:0%sb" % str(lenOf_Digits)
#         
#         strOf_Binary = "{0:05b}".format(i)
        strOf_Binary = "{0:0b}".format(i)
        
        print("[%s:%d] i = %d / strOf_Binary = %s" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , i
                , strOf_Binary
                ), file=sys.stderr)
        
        '''###################
            step : A : 3
                fill zero
        ###################'''
        strOf_Zeros = "0" * (lenOf_Digits - len(strOf_Binary))
        
        strOf_Binary = strOf_Zeros + strOf_Binary

        #debug
        print()
        print("[%s:%d] zero filled ==> %s" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , strOf_Binary
                ), file=sys.stderr)
        print()
        
        
        '''###################
            step : A : 4
                append
        ###################'''
        lo_StrOf_Model_Patterns.append(strOf_Binary)
        
    #/for i in range(0, lenOf_Digits):

    '''###################
        step : A : 2
            return
    ###################'''
    #debug
    print("[%s:%d] lo_StrOf_Model_Patterns =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
              
            ), file=sys.stderr)
     
    print(lo_StrOf_Model_Patterns)
    
    
    return lo_StrOf_Model_Patterns
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