Example #1
0
    def interpolation(self, small_gear_no=18, gear_type=1):
        SQLite連結 = Store(SQLiteWriter(_curdir + "/lewis.db", frozen=True))
        # 使用內插法求值
        # 找出比目標齒數大的其中的最小的,就是最鄰近的大值
        lewis_factor = SQLite連結.find_one("lewis", "gearno > ?",
                                         [small_gear_no])
        if (gear_type == 1):
            larger_formfactor = lewis_factor.type1
        elif (gear_type == 2):
            larger_formfactor = lewis_factor.type2
        elif (gear_type == 3):
            larger_formfactor = lewis_factor.type3
        else:
            larger_formfactor = lewis_factor.type4
        larger_toothnumber = lewis_factor.gearno

        # 找出比目標齒數小的其中的最大的,就是最鄰近的小值
        lewis_factor = SQLite連結.find_one("lewis",
                                         "gearno < ? order by gearno DESC",
                                         [small_gear_no])
        if (gear_type == 1):
            smaller_formfactor = lewis_factor.type1
        elif (gear_type == 2):
            smaller_formfactor = lewis_factor.type2
        elif (gear_type == 3):
            smaller_formfactor = lewis_factor.type3
        else:
            smaller_formfactor = lewis_factor.type4
        smaller_toothnumber = lewis_factor.gearno
        calculated_factor = larger_formfactor + (
            small_gear_no - larger_toothnumber) * (
                larger_formfactor - smaller_formfactor) / (larger_toothnumber -
                                                           smaller_toothnumber)
        # 只傳回小數點後五位數
        return str(round(calculated_factor, 5))
Example #2
0
def showPage(page):
    itemperpage = 16
    db = Store(SQLiteWriter("taobao.db", frozen=True))
    rs = []
    items = db.find(
        "freetry", "1 order by date desc,gailv  limit %s,%s" %
        ((page - 1) * itemperpage, itemperpage))
    for item in items:
        item.uuid = item.itemId
        rs.append(dict(item.__dict__))

    return json.dumps(rs)
Example #3
0
def 材料(序號):
    # 根據資料庫查詢傳回對應的材料 unsno 與 treatment
    # 利用 Store  建立資料庫檔案對應物件, 並且設定 frozen=True 表示不要開放動態資料表的建立
    SQLite連結 = Store(SQLiteWriter("lewis.db", frozen=True))
    material = SQLite連結.find_one("steel", "serialno = ?", [序號])
    # 針對 material.treatment 中的空白與 big5 資料進行處理
    treatment = material.treatment.replace(" ", "_")
    data = str(material.unsno) + "_" + str(treatment)
    # 以下的 split() 目的在測試如何分割 unsno 與 treatment
    # 只針對第一個底線進行分割
    unsno, treatment = data.split("_", 1)
    return unsno + "_" + treatment
Example #4
0
def doCheck():
    word = request.form["word"]
    if word == None:
        return "<br /><a href=\"/\">首頁</a>|<a href=\"./\">重新查詢</a>"
    vocabulary = Store(
        SQLiteWriter(data_dir + "/webster_vocabulary.sqlite", frozen=True))
    if (vocabulary.count("word", "lower(word) like ?", [word]) == 0):
        return "找不到與 " + word.title() + "有關的資料!"
    else:
        result = vocabulary.find("word", "lower(word) like ?", [word])
        output = "以下為 webster 字典查詢:" + word + " 所得到的結果<br /><br />"
        for item in result:
            output += word.title() + "<br /><br />" + str(
                nl2br(item.defn, True)) + "<br />"
        output += "<br /><a href=\"/\">首頁</a>|<a href=\"./\">重新查詢</a>"
        return output
Example #5
0
    def index(self, *args, **kwargs):
        # 進行資料庫檔案連結,  並且取出所有資料
        try:
            # 利用 Store  建立資料庫檔案對應物件, 並且設定 frozen=True 表示不要開放動態資料表的建立
            # 因為程式以 application 所在目錄執行, 因此利用相對目錄連結 lewis.db 資料庫檔案
            SQLite連結 = Store(SQLiteWriter(_curdir + "/lewis.db", frozen=True))
            #material = SQLite連結.find_one("steel","serialno = ?",[序號])
            # str(SQLite連結.count("steel")) 將傳回 70, 表示資料庫中有 70 筆資料
            material = SQLite連結.find("steel")
            # 所傳回的 material 為 iterator
            '''
            outstring = ""
            for material_item in material:
                outstring += str(material_item.serialno) + ":" + material_item.unsno + "_" + material_item.treatment + "<br />"
            return outstring
            '''
        except:
            return "抱歉! 資料庫無法連線<br />"

        outstring = '''
        
<form method=\"post\" action=\"gear_width">
    請先下載齒輪的檔案,放在V槽跟目錄下,存成黨名gear.prt,在開creo打本網址即可使用<br />
    <a href="https://drive.google.com/open?id=0B1DlKZ6juyQeQ0ZMTnBLejJQVkE&authuser=0">creo2載點</a>

    PS:壓力角內定20度,不可更改<br />
請填妥下列參數,以完成適當的齒面寬尺寸大小設計。<br />
馬達馬力:<input type=text name=horsepower id=horsepower value=100 size=10>horse power<br />
馬達轉速:<input type=text name=rpm id=rpm value=1120 size=10>rpm<br />
齒輪減速比: <input type=text name=ratio id=ratio value=2 size=10><br />
齒形:<select name=toothtype id=toothtype>
<option value=type1>壓力角20度,a=0.8,b=1.0
<option value=type2>壓力角20度,a=1.0,b=1.25
</select><br />
安全係數:<input type=text name=safetyfactor id=safetyfactor value=3 size=10><br />
齒輪材質:<select name=material_serialno id=material_serialno><br />
'''
        for material_item in material:
            outstring += "<option value=" + str(material_item.serialno) + ">UNS - " + \
                material_item.unsno + " - " + material_item.treatment
        outstring += "</select><br />"

        outstring += "小齒輪齒數:<input type=text name=npinion id=npinion value=12 size=10><br />模數:<input type=\"text\" name=\"m\"><br />"
        outstring += "<input type=submit id=submit value=進行運算>"
        outstring += "</form>"

        return outstring
Example #6
0
    def index(self, *args, **kwargs):
        # 進行資料庫檔案連結,  並且取出所有資料
        try:
            # 利用 Store  建立資料庫檔案對應物件, 並且設定 frozen=True 表示不要開放動態資料表的建立
            # 因為程式以 application 所在目錄執行, 因此利用相對目錄連結 lewis.db 資料庫檔案
            SQLite連結 = Store(SQLiteWriter(_curdir + "/lewis.db", frozen=True))
            #material = SQLite連結.find_one("steel","serialno = ?",[序號])
            # str(SQLite連結.count("steel")) 將傳回 70, 表示資料庫中有 70 筆資料
            material = SQLite連結.find("steel")
            # 所傳回的 material 為 iterator
            '''
            outstring = ""
            for material_item in material:
                outstring += str(material_item.serialno) + ":" + material_item.unsno + "_" + material_item.treatment + "<br />"
            return outstring
            '''
        except:
            return "抱歉! 資料庫無法連線<br />"

        outstring = '''
<form id=entry method=post action="gear_width">
請填妥下列參數,以完成適當的齒尺寸大小設計。<br />
齒數:<input type=text name=n><br />
模數:<input type=text name=module><br />
馬達馬力:<input type=text name=horsepower id=horsepower value=100 size=10>horse power<br />
馬達轉速:<input type=text name=rpm id=rpm value=1120 size=10>rpm<br />
齒輪減速比: <input type=text name=ratio id=ratio value=4 size=10><br />
齒形:<select name=toothtype id=toothtype>
<option value=type1>壓力角20度,a=0.8,b=1.0
<option value=type2>壓力角20度,a=1.0,b=1.25
<option value=type3>壓力角25度,a=1.0,b=1.25
<option value=type4>壓力角25度,a=1.0,b=1.35
</select><br />
安全係數:<input type=text name=safetyfactor id=safetyfactor value=3 size=10><br />
齒輪材質:<select name=material_serialno id=material_serialno>
'''
        for material_item in material:
            outstring += "<option value=" + str(material_item.serialno) + ">UNS - " + \
                material_item.unsno + " - " + material_item.treatment
        outstring += "</select><br />"

        outstring += "小齒輪齒數:<input type=text name=npinion id=npinion value=18 size=10><br />"
        outstring += "<input type=submit id=submit value=進行運算>"
        outstring += "</form>"

        return outstring
Example #7
0
#encoding: utf-8
'''這個程式將配合 TCExam 所轉出來的 txt 成績檔案, 以遞迴方式讀取檔案
並將要取出的資料存入資料庫中
'''
import os, fnmatch
# 導入 pybean 模組與所要使用的 Store 及 SQLiteWriter 方法
from pybean import Store, SQLiteWriter
# 利用 Store  建立資料庫檔案對應物件, 並且設定 frozen=False 表示要開放動態資料表的建立
library = Store(SQLiteWriter("2013exam.sqlite", frozen=False))


# 定義一個可以遞迴進入目錄搜尋特定檔案的函式
def find_files(directory, pattern):
    for root, dirs, files in os.walk(directory):
        for basename in files:
            if fnmatch.fnmatch(basename, pattern):
                filename = os.path.join(root, basename)
                yield filename


# 定義一個讀取檔案所有內容的函式
def read_lines(input_filename):
    output_list = []
    f = open(input_filename, encoding="UTF-8")
    while True:
        l = f.readlines()
        if len(l) == 0:
            break
        output_list.append(l)
    f.close()
    return output_list
Example #8
0
    def gear_width(self,
                   horsepower=100,
                   rpm=1000,
                   ratio=4,
                   toothtype=1,
                   safetyfactor=2,
                   material_serialno=1,
                   npinion=18,
                   facewidth=None,
                   n=None,
                   m=None):
        SQLite連結 = Store(SQLiteWriter(_curdir + "/lewis.db", frozen=True))
        outstring = ""
        # 根據所選用的齒形決定壓力角
        if (toothtype == 1 or toothtype == 2):
            壓力角 = 20
        else:
            壓力角 = 25

        # 根據壓力角決定最小齒數
        if (壓力角 == 20):
            最小齒數 = 18
        else:
            最小齒數 = 12

        # 直接設最小齒數
        if int(npinion) <= 最小齒數:
            npinion = 最小齒數
        # 大於400的齒數則視為齒條(Rack)
        if int(npinion) >= 400:
            npinion = 400

        # 根據所選用的材料查詢強度值
        # 由 material之序號查 steel 表以得材料之降伏強度S單位為 kpsi 因此查得的值要成乘上1000
        # 利用 Store  建立資料庫檔案對應物件, 並且設定 frozen=True 表示不要開放動態資料表的建立
        #SQLite連結 = Store(SQLiteWriter("lewis.db", frozen=True))
        # 指定 steel 資料表
        steel = SQLite連結.new("steel")
        # 資料查詢
        #material = SQLite連結.find_one("steel","unsno=? and treatment=?",[unsno, treatment])
        material = SQLite連結.find_one("steel", "serialno=?",
                                     [material_serialno])
        # 列出 steel 資料表中的資料筆數
        #print(SQLite連結.count("steel"))
        #print (material.yield_str)
        strengthstress = material.yield_str * 1000
        # 由小齒輪的齒數與齒形類別,查詢lewis form factor
        # 先查驗是否有直接對應值
        on_table = SQLite連結.count("lewis", "gearno=?", [npinion])
        if on_table == 1:
            # 直接進入設計運算
            #print("直接運算")
            #print(on_table)
            lewis_factor = SQLite連結.find_one("lewis", "gearno=?", [npinion])
            #print(lewis_factor.type1)
            # 根據齒形查出 formfactor 值
            if (toothtype == 1):
                formfactor = lewis_factor.type1
            elif (toothtype == 2):
                formfactor = lewis_factor.type2
            elif (toothtype == 3):
                formfactor = lewis_factor.type3
            else:
                formfactor = lewis_factor.type4
        else:
            # 沒有直接對應值, 必須進行查表內插運算後, 再執行設計運算
            #print("必須內插")
            #print(interpolation(npinion, gear_type))
            formfactor = self.interpolation(npinion, toothtype)

        # 開始進行設計運算

        ngear = int(npinion) * int(ratio)

        # 重要的最佳化設計---儘量用整數的diametralpitch
        # 先嘗試用整數算若 diametralpitch 找到100 仍無所獲則改用 0.25 作為增量再不行則宣告 fail
        counter = 0
        i = 0.1
        facewidth = 0
        circularpitch = 0
        while (facewidth <= 3 * circularpitch
               or facewidth >= 5 * circularpitch):
            diametralpitch = i
            #circularpitch = 3.14159/diametralpitch
            circularpitch = math.pi / diametralpitch
            pitchdiameter = int(npinion) / diametralpitch
            #pitchlinevelocity = 3.14159*pitchdiameter*rpm/12
            pitchlinevelocity = math.pi * pitchdiameter * float(rpm) / 12
            transmittedload = 33000 * float(horsepower) / pitchlinevelocity
            velocityfactor = 1200 / (1200 + pitchlinevelocity)
            # formfactor is Lewis form factor
            # formfactor need to get from table 13-3 and determined ty teeth number and type of tooth
            # formfactor = 0.293
            # 90 is the value get from table corresponding to material type
            facewidth = transmittedload * diametralpitch * float(
                safetyfactor) / velocityfactor / formfactor / strengthstress
            if (counter > 5000):
                outstring += "超過5000次的設計運算,仍無法找到答案!<br />"
                outstring += "可能所選用的傳遞功率過大,或無足夠強度的材料可以使用!<br />"
                # 離開while迴圈
                break
            i += 0.1
            counter += 1
        facewidth = round(facewidth, 4)
        if (counter < 5000):
            # 先載入 cube 程式測試
            #outstring = self.cube_weblink()
            # 再載入 gear 程式測試
            outstring = '''<script type="text/javascript" src="/static/weblink/pfcUtils.js"></script>
    <script type="text/javascript" src="/static/weblink/wl_header.js">// <![CDATA[
    document.writeln ("Error loading Pro/Web.Link header!");
    // ]]></script>
    <script type="text/javascript" language="JavaScript">// <![CDATA[
    if (!pfcIsWindows()) netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    // 若第三輸入為 false, 表示僅載入 session, 但是不顯示
    // ret 為 model open return
     var ret = document.pwl.pwlMdlOpen("gear.prt", "v:/", false);
    if (!ret.Status) {
        alert("pwlMdlOpen failed (" + ret.ErrorCode + ")");
    }
        //將 ProE 執行階段設為變數 session
        var session = pfcGetProESession();
        // 在視窗中打開零件檔案, 並且顯示出來
        var window = session.OpenFile(pfcCreate("pfcModelDescriptor").CreateFromFileName("gear.prt"));
        var solid = session.GetModel("gear.prt",pfcCreate("pfcModelType").MDL_PART);
        var length,width,myf,myn,i,j,volume,count,d1Value,d2Value;
        // 將模型檔中的 length 變數設為 javascript 中的 length 變數
        length = solid.GetParam("n");
        // 將模型檔中的 width 變數設為 javascript 中的 width 變數
        width = solid.GetParam("face_width");
    //改變零件尺寸
        //myf=20;
        //myn=20;
        volume=0;
        count=0;
        try
        {
                // 以下採用 URL 輸入對應變數
                //createParametersFromArguments ();
                // 以下則直接利用 javascript 程式改變零件參數
                for(i=0;i<=5;i++)
                {
                    //for(j=0;j<=2;j++)
                    //{
                            myf=''' + str(n) + ''';
                            myn=''' + str(facewidth) + '''
                            mym=''' + str(m) + '''
    // 設定變數值, 利用 ModelItem 中的 CreateDoubleParamValue 轉換成 Pro/Web.Link 所需要的浮點數值
             //d1Value = pfcCreate ("MpfcModelItem").CreateDoubleParamValue(myf);
             d1Value = pfcCreate ("MpfcModelItem").CreateIntParamValue(myf);
             d2Value = pfcCreate ("MpfcModelItem").CreateDoubleParamValue(myn);

    // 將處理好的變數值, 指定給對應的零件變數
                        length.Value = d1Value;
                        width.Value = d2Value;
                        //零件尺寸重新設定後, 呼叫 Regenerate 更新模型
                        solid.Regenerate(void null);
                        //利用 GetMassProperty 取得模型的質量相關物件
                        properties = solid.GetMassProperty(void null);
                        //volume = volume + properties.Volume;
    volume = properties.Volume;
                        count = count + 1;
    alert("執行第"+count+"次,零件總體積:"+volume);
    // 將零件存為新檔案
    var newfile = document.pwl.pwlMdlSaveAs("gear.prt", "v:/", "mygear_"+count+".prt");
    if (!newfile.Status) {
        alert("pwlMdlSaveAs failed (" + newfile.ErrorCode + ")");
    }
    //} // 內圈 for 迴圈
                } //外圈 for 迴圈
                //alert("共執行:"+count+"次,零件總體積:"+volume);
                //alert("零件體積:"+properties.Volume);
                //alert("零件體積取整數:"+Math.round(properties.Volume));
            }
        catch(err)
            {
                alert ("Exception occurred: "+pfcGetExceptionType (err));
            }
    // ]]></script>
    '''
        outstring += "進行" + str(counter) + "次重複運算後,得到合用的facewidth值為:" + str(
            facewidth) + '' + str(n) + '' + str(m) + ''
        return outstring
Example #9
0
    def gear_width(self,
                   horsepower=100,
                   rpm=1000,
                   ratio=4,
                   toothtype=1,
                   safetyfactor=2,
                   material_serialno=1,
                   npinion=18):
        SQLite連結 = Store(SQLiteWriter(_curdir + "/lewis.db", frozen=True))
        outstring = ""
        # 根據所選用的齒形決定壓力角
        if (toothtype == 1 or toothtype == 2):
            壓力角 = 20
        else:
            壓力角 = 25

        # 根據壓力角決定最小齒數
        if (壓力角 == 20):
            最小齒數 = 18
        else:
            最小齒數 = 12

        # 直接設最小齒數
        if int(npinion) <= 最小齒數:
            npinion = 最小齒數
        # 大於400的齒數則視為齒條(Rack)
        if int(npinion) >= 400:
            npinion = 400

        # 根據所選用的材料查詢強度值
        # 由 material之序號查 steel 表以得材料之降伏強度S單位為 kpsi 因此查得的值要成乘上1000
        # 利用 Store  建立資料庫檔案對應物件, 並且設定 frozen=True 表示不要開放動態資料表的建立
        #SQLite連結 = Store(SQLiteWriter("lewis.db", frozen=True))
        # 指定 steel 資料表
        steel = SQLite連結.new("steel")
        # 資料查詢
        #material = SQLite連結.find_one("steel","unsno=? and treatment=?",[unsno, treatment])
        material = SQLite連結.find_one("steel", "serialno=?",
                                     [material_serialno])
        # 列出 steel 資料表中的資料筆數
        #print(SQLite連結.count("steel"))
        #print (material.yield_str)
        strengthstress = material.yield_str * 1000
        # 由小齒輪的齒數與齒形類別,查詢lewis form factor
        # 先查驗是否有直接對應值
        on_table = SQLite連結.count("lewis", "gearno=?", [npinion])
        if on_table == 1:
            # 直接進入設計運算
            #print("直接運算")
            #print(on_table)
            lewis_factor = SQLite連結.find_one("lewis", "gearno=?", [npinion])
            #print(lewis_factor.type1)
            # 根據齒形查出 formfactor 值
            if (toothtype == 1):
                formfactor = lewis_factor.type1
            elif (toothtype == 2):
                formfactor = lewis_factor.type2
            elif (toothtype == 3):
                formfactor = lewis_factor.type3
            else:
                formfactor = lewis_factor.type4
        else:
            # 沒有直接對應值, 必須進行查表內插運算後, 再執行設計運算
            #print("必須內插")
            #print(interpolation(npinion, gear_type))
            formfactor = self.interpolation(npinion, toothtype)

        # 開始進行設計運算

        ngear = int(npinion) * int(ratio)

        # 重要的最佳化設計---儘量用整數的diametralpitch
        # 先嘗試用整數算若 diametralpitch 找到100 仍無所獲則改用 0.25 作為增量再不行則宣告 fail
        counter = 0
        i = 0.1
        facewidth = 0
        circularpitch = 0
        while (facewidth <= 3 * circularpitch
               or facewidth >= 5 * circularpitch):
            diametralpitch = i
            #circularpitch = 3.14159/diametralpitch
            circularpitch = math.pi / diametralpitch
            pitchdiameter = int(npinion) / diametralpitch
            #pitchlinevelocity = 3.14159*pitchdiameter*rpm/12
            pitchlinevelocity = math.pi * pitchdiameter * float(rpm) / 12
            transmittedload = 33000 * float(horsepower) / pitchlinevelocity
            velocityfactor = 1200 / (1200 + pitchlinevelocity)
            # formfactor is Lewis form factor
            # formfactor need to get from table 13-3 and determined ty teeth number and type of tooth
            # formfactor = 0.293
            # 90 is the value get from table corresponding to material type
            facewidth = transmittedload * diametralpitch * float(
                safetyfactor) / velocityfactor / formfactor / strengthstress
            if (counter > 5000):
                outstring += "超過5000次的設計運算,仍無法找到答案!<br />"
                outstring += "可能所選用的傳遞功率過大,或無足夠強度的材料可以使用!<br />"
                # 離開while迴圈
                break
            i += 0.1
            counter += 1
        facewidth = round(facewidth, 4)
        if (counter < 5000):
            # 先載入 cube 程式測試
            #outstring = self.cube_weblink()
            # 再載入 gear 程式測試
            outstring = self.gear_weblink()

            outstring += "進行" + str(
                counter) + "次重複運算後,得到合用的facewidth值為:" + str(facewidth)
        return outstring
Example #10
0
# 利用 len() 求出數列元素個數
total = len(st_array)
# 每組人數設為 num
num = 6
# 辨識組別的變數 order, 由第 1 組開始
order = 1
# 用來計算學生序號的 count 變數
count = 0

# 利用 for 迴圈逐一進行分組資料列印
for i in range(0, total):
    學生分組資料.append(st_array[i][0] + st_array[i][1].strip() + "," +
                  str(seat2(10)[i][0]) + "," + str(seat2(10)[i][1]) + "," +
                  str(order))
    # 以 pybean 儲存資料, 若非在每次存檔之前都執行下兩行,  資料庫只會儲存最後一筆資料 (會進行資料覆蓋?)
    library = Store(SQLiteWriter("student.sqlite", frozen=False))
    # 動態建立 student 資料表
    grouping = library.new("st908306")
    grouping.stud_number = st_array[i][0]
    grouping.stud_name = st_array[i][1].strip()
    grouping.col = seat2(10)[i][0]
    grouping.row = seat2(10)[i][1]
    grouping.grp = order
    # 儲存資料表內容
    library.save(grouping)
    if (i % num == 0):
        fileout2.write("第" + str(order) + "組:------\n")
    count = count + 1
    # 寫出學號, 姓名
    fileout2.write(st_array[i][0] + st_array[i][1].strip())
    # 寫出座號, seat2 為電腦教室編號, seat 則為 spread sheet 上的編號
Example #11
0
 def get_fluid_save(self):
     return Store(SQLiteWriter(":memory:", False))
Example #12
0
 def get_frozen_save(self):
     return Store(SQLiteWriter(":memory:"))
Example #13
0
"其中 S 為齒面的材料彎曲應力強度";
"設計要求:控制所選齒的尺寸大小,在滿足強度與傳輸負載的要求下,讓齒面厚度介於3倍周節與5倍周節之間。";
"設計者可以選擇的參數:";
"安全係數(建議值為3以上)";
"齒輪減速比";
"馬達傳輸功率,單位為 horse power";
"馬達轉速,單位為 rpm";
"齒制(Gear System)";
"齒輪材料與強度";
'''
# 這個程式要計算正齒輪的齒面寬, 資料庫連結希望使用 pybean 與 SQLite
# 導入 pybean 模組與所要使用的 Store 及 SQLiteWriter 方法
from pybean import Store, SQLiteWriter
import math

SQLite連結 = Store(SQLiteWriter("lewis.db", frozen=True))

# 執行 formfactor 內插運算的函式
def interpolation(小齒輪齒數, 齒形):
    global SQLite連結
    # 使用內插法求值
    # 找出比目標齒數大的其中的最小的,就是最鄰近的大值
    lewis_factor = SQLite連結.find_one("lewis","gearno > ?",[小齒輪齒數])
    if(齒形 == 1):
        larger_formfactor = lewis_factor.type1
    elif(齒形 == 2):
        larger_formfactor = lewis_factor.type2
    elif(齒形 == 3):
        larger_formfactor = lewis_factor.type3
    else:
        larger_formfactor = lewis_factor.type4
Example #14
0
def gear_width(馬力, 轉速, 減速比, 齒形, 安全係數, 材料, 小齒輪齒數):
    # 根據所選用的齒形決定壓力角
    if(齒形 == 1 or 齒形 == 2):
        壓力角 = 20
    else:
        壓力角 = 25

    # 根據壓力角決定最小齒數
    if(壓力角== 20):
        最小齒數 = 18
    else:
        最小齒數 = 12

    # 直接設最小齒數
    if 小齒輪齒數 <= 最小齒數:
        小齒輪齒數 = 最小齒數
    # 大於400的齒數則視為齒條(Rack)
    if 小齒輪齒數 >= 400:
        小齒輪齒數 = 400

    # 根據所選用的材料查詢強度值
    # 由 material之序號查 steel 表以得材料之降伏強度S單位為 kpsi 因此查得的值要成乘上1000
    # 利用 Store  建立資料庫檔案對應物件, 並且設定 frozen=True 表示不要開放動態資料表的建立
    SQLite連結 = Store(SQLiteWriter("lewis.db", frozen=True))
    # 指定 steel 資料表
    steel = SQLite連結.new("steel")
    # 資料查詢
    # 將 unsno 與 treatment 從材料字串中隔開
    unsno, treatment = 材料.split("_")
    #print(unsno, treatment)

    material = SQLite連結.find_one("steel","unsno=? and treatment=?",[unsno, treatment])
    # 列出 steel 資料表中的資料筆數
    #print(SQLite連結.count("steel"))
    print (material.yield_str)
    strengthstress = material.yield_str*1000
    # 由小齒輪的齒數與齒形類別,查詢lewis form factor
    # 先查驗是否有直接對應值
    on_table = SQLite連結.count("lewis","gearno=?",[小齒輪齒數])
    if on_table == 1:
        # 直接進入設計運算
        print("直接運算")
        print(on_table)
        lewis_factor = SQLite連結.find_one("lewis","gearno=?",[小齒輪齒數])
        #print(lewis_factor.type1)
        # 根據齒形查出 formfactor 值
        if(齒形 == 1):
            formfactor = lewis_factor.type1
        elif(齒形 == 2):
            formfactor = lewis_factor.type2
        elif(齒形 == 3):
            formfactor = lewis_factor.type3
        else:
            formfactor = lewis_factor.type4
    else:
        # 沒有直接對應值, 必須進行查表內插運算後, 再執行設計運算
        print("必須內插")
        #print(interpolation(小齒輪齒數, 齒形))
        formfactor = interpolation(小齒輪齒數, 齒形)

    # 開始進行設計運算

    ngear = 小齒輪齒數 * 減速比

    # 重要的最佳化設計---儘量用整數的diametralpitch
    # 先嘗試用整數算若 diametralpitch 找到100 仍無所獲則改用 0.25 作為增量再不行則宣告 fail
    counter = 0
    i = 0.1
    facewidth = 0
    circularpitch = 0
    while (facewidth <= 3 * circularpitch or facewidth >= 5 * circularpitch):
        diametralpitch = i
        #circularpitch = 3.14159/diametralpitch
        circularpitch = math.pi/diametralpitch
        pitchdiameter = 小齒輪齒數/diametralpitch
        #pitchlinevelocity = 3.14159*pitchdiameter*轉速/12
        pitchlinevelocity = math.pi * pitchdiameter * 轉速/12
        transmittedload = 33000 * 馬力/pitchlinevelocity
        velocityfactor = 1200/(1200 + pitchlinevelocity)
        # formfactor is Lewis form factor
        # formfactor need to get from table 13-3 and determined ty teeth number and type of tooth
        # formfactor = 0.293
        # 90 is the value get from table corresponding to material type
        facewidth = transmittedload * diametralpitch * 安全係數/velocityfactor/formfactor/strengthstress
        if(counter>5000):
            print("超過5000次的設計運算,仍無法找到答案!")
            print("可能所選用的傳遞功率過大,或無足夠強度的材料可以使用!")
            # 離開while迴圈
            break
        i += 0.1
        counter += 1
    facewidth = round(facewidth, 4)
    if(counter<5000):
        print("進行"+str(counter)+"次重複運算後,得到合用的facewidth值為:"+str(facewidth))
Example #15
0
from pybean import Store, SQLiteWriter

library = Store(SQLiteWriter(":memory:", frozen=False))

book = library.new("book")
book.title = "Boost development with pybean"
book.author = "Charles Xavier"
library.save(book)

for book in library.find("book", "author like ?", ["Charles Xavier"]):
    print book.title

library.delete(book)
library.commit()
Example #16
0
# -*- coding: utf-8 -*-
# http://try.taobao.com/json/ajax_get_item_list.htm?tab=2&page=13&anchor=true&t=1367128346939&_input_charset=utf-8

import urllib2
import time
import json

from pybean import Store, SQLiteWriter
db = Store(SQLiteWriter("taobao.db", frozen=False))


def getList(page):
    # page >=1
    print "page:", page
    url = "http://try.taobao.com/json/ajax_get_item_list.htm?tab=2&page=%s&anchor=true&t=1367128346939&_input_charset=utf-8" % (
        page, )
    js = urllib2.urlopen(url).read()
    items = json.loads(js)
    now = time.time()
    tm = time.gmtime(now + 8 * 3600)
    date = tm.tm_year * 10000 + tm.tm_mon * 100 + tm.tm_mday
    for item in items["data"]:
        print item["itemId"]
        tb = db.new("freetry")
        for key in item:
            tb.__setattr__(key, item[key])

        tb.gailv = item["requestNum"] / item["totalNum"]
        # item["_id"] = item["itemId"]
        # item["gailv"] = item["requestNum"] / item["totalNum"]
        if db.find_one("freetry", "itemId=?", (item["itemId"], )):