【问题标题】:search table for value in column 1 and print data in colum 2 of same row搜索表中第 1 列中的值并在同一行的第 2 列中打印数据
【发布时间】:2018-03-14 13:20:01
【问题描述】:

我已尽我所能找到这个——grep、awk、sed——我想在 linux shell、javaScript 或 python(或其他任何东西,但我最了解这 3 个)中执行此操作。我发布的代码是 JavaScript(我最喜欢的),但我愿意用任何东西来回答——见鬼,我会学习一门新语言,或者在 Scratch 中做它,如果它让我无法编写 bajillion 行。 ..

我有一组齿轮单元的扭矩值列表及其对应的 ID 号(我使用整数进行简化 - 左侧的扭矩值和右侧的零件号):

maxTorq:Unit ID#
100:6100
200:6105
300:6110
.......and this goes for HUNDREDS of lines.....
99990:6985
100000:6990

我当前的代码是“if...else if”语句的简单重复。 这里是! (运行它,它并不太糟糕。需要更多的 CSS,在我的网站上它有一些很酷的图形和样式。)

    <!DOCTYPE html>
<html lang="en">
<style>
body {
    background-image: url("../media/sumi.jpeg");
    background-repeat: no-repeat;
    background-position: right top;
}
#main {
  max-width: 800px;
  margin: 20px auto; 
  border: solid;
  background: #87CEEB;
  padding: 50px;
  position: relative; 
}
#answer {
  max-width: 200px;
  margin: 20px auto; 
  border: solid;
  background: #FFEFD5;
  padding: 50px;
  position: relative;
  padding: 10px;
  right: 300px; 
}
</style>

<body>
<head>
    <meta charset="utf-8">
    <title>Sumitomo Sizer</title><br>

</head>
<body>
<h6> here it is:
<h1><b>Sumitomo Cyclo sizer!!</b></h1>
<div id="main">
<P> I am only showing 8 of the 18 available ratios.  Sure, you might need       the others for some reason, but you can do most things with these 8.</p>

<p>  What output speed is closest AND OVER what you need:
  <select id="vara">
<option value="11">159 RPM (11:1)</option>
<option value="17">103 RPM (17:1)</option>
<option value="29">60 RPM (29:1)</option>
<option value="35">50 RPM (35:1)</option>
<option value="43">40 RPM (43:1)</option>
<option value="59">30 RPM (59:1</option>
<option value="71">25 RPM (71:1)</option>
<option value="87">20 RPM (87:1)</option>
</select>
</p>

<P>What is your motor Horsepower @1750:
   <select id="varb">
<option value="0.5">1/2</option>
<option value="1">1</option>
<option value="1.5">1-1/2</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="5">5</option>
<option value="7.5">7.5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
</select>
</p>
<p>belt drive ratio: 
<input id="varc" type="text" value="1"/>:1
</p>
<P>Input style:
   <select id="vard">
<option value="0">Standard</option>
<option value="1">Top motor mount</option>
<option value="2">C-face (w/coupling)</option>
</select>
</p>
<p>Click the button to get your Sumitomo size</p>

<button onclick="sumisize()">Find it</button>
</p>
<div id="answer">
Sumitomo part number: <h2><p id="resultd"></h2></p><p id="resulta"></p>
Actual output speed: <p id="resultb"> </p>
Torque in inch-lbs.:<p id="resultc"></p>
</div>
<script type="text/javascript" language="javascript" charset="utf-8">

function sumisize()
{
var y = (document.getElementById('vara').value);
var v = (document.getElementById('varb').value);
var u = (document.getElementById('varc').value);
var q = (document.getElementById('vard').value);
var w=(v*36);
var t=(w*u);
var s=(t*y);
var r=((1750/u)/y);
var x="";
var z=(y);
var p=(q);
var o="";
var n="";
var m="";

if (p>0 && v==0.5)
  {
  m="-56"
  }
else if (p>0 && v==1)
  {
  m="-143"
  }
else if (p>0 && v==1.5)
  {
  m="-145"
  }
else if (p>0 && v==2)
  {
  m="-145"
  }
else if (p>0 && v==3)
  {
  m="-182"
  }
else if (p>0 && v==5)
  {
  m="-184"
  }
else if (p>0 && v==7.5)
  {
  m="-213"
  }
else if (p>0 && v==10)
  {
  m="-215"
  }
else if (p>0 && v==15)
  {
  m="-254"
  }
else if (p>0 && v==20)
  {
  m="-256"
  }
if (p==0)
  {
  o="CHH";
  }
else if (p==1)
  {
  o="CHHP";
  }
else if (p==2 && u==1)
  {
  o="CHHJ";
  }
else 
  {
  n=" Please Set 'Belt Drive Ratio' to 1 ";
  }
if (z==11 && s<=298)
  {
  x="-6080-Y11";
  }
else if (z==11 && s<=393)
  {
  x="-6085-Y11";
  }
else if (z==11 && s<=579)
  {
  x="-6090-Y11";
  }
else if (z==11 && s<=765)
  {
  x="-6095-Y11";
  }
else if (z==11 && s<=1190)
  {
  x="-6100-Y11";
  }
else if (z==11 && s<=1610)
  {
  x="-6105-Y11";
  }
else if (z==11 && s<=1790)
  {
  x="-6110-Y11";
  }
else if (z==11 && s<=1970)
  {
  x="-6115-Y11";
  }
else if (z==11 && s<=2560)
  {
  x="-6120-Y11";
  }
else if (z==11 && s<=2990)
  {
  x="-6125-Y11";
  }
else if (z==11 && s<=4730)
  {
  x="-6130-Y11";
  }
else if (z==11 && s<=5700)
  {
  x="-6135-Y11";
  }
else if (z==11 && s<=6570)
  {
  x="-6140-Y11";
  }
else if (z==11 && s<=7650)
  {
  x="-6145-Y11";
  }
else if (z==11 && s<=9900)
  {
  x="-6160-Y11";
  }
else if (z==17 && s<=408)
  {
  x="-6080-Y17";
  }
else if (z==17 && s<=536)
  {
  x="-6085-Y17";
  }
else if (z==17 && s<=788)
  {
  x="-6090-Y17";
  }
else if (z==17 && s<=1040)
  {
  x="-6095-Y17";
  }
else if (z==17 && s<=1620)
  {
  x="-6100-Y17";
  }
else if (z==17 && s<=2190)
  {
  x="-6105-Y17";
  }
else if (z==17 && s<=2440)
  {
  x="-6110-Y17";
  }
else if (z==17 && s<=2680)
  {
  x="-6115-Y17";
  }
else if (z==17 && s<=3490)
  {
  x="-6120-Y17";
  }
else if (z==17 && s<=4070)
  {
  x="-6125-Y17";
  }
else if (z==17 && s<=5360)
  {
  x="-6130-Y17";
  }
else if (z==17  && s<=6160)
  {
  x="-6135-Y17"
  }
else if (z==17  && s<=8250)
  {
  x="-6140-Y17"
  }
else if (z==17  && s<=9370)
  {
  x="-6145-Y17"
  }
else if (z==17  && s<=10200)
  {
  x="-6160-Y17"
  }
else if (z==17  && s<=14700)
  {
  x="-6165-Y17"
  }
else if (z==29 && s<=621)
  {
  x="-6085-Y29";
  }
else if (z==29 && s<=832)
  {
  x="-6090-Y29";
  }
else if (z==29 && s<=1040)
  {
  x="-6095-29";
  }
else if (z==29 && s<=1610)
  {
  x="-6100-Y29";
  }
else if (z==29 && s<=2120)
  {
  x="-6105-Y29";
  }
else if (z==29 && s<=2530)
  {
  x="-6110-29";
  }
else if (z==29 && s<=2950)
  {
  x="-6115-Y29";
  }
else if (z==29 && s<=3980)
  {
  x="-6120-Y29";
  }
else if (z==29 && s<=5010)
  {
  x="-6125-29";
  }
else if (z==29 && s<=5960)
  {
  x="-6130-Y29";
  }
else if (z==29 && s<=7500)
  {
  x="-6135-Y29";
  }
else if (z==29 && s<=7920)
  {
  x="-6140-29";
  }
else if (z==29 && s<=9980)
  {
  x="-6145-Y29";
  }
else if (z==29 && s<=14000)
  {
  x="-6160-Y29";
  }
else if (z==29 && s<=15200)
  {
  x="-6165-29";
  }
else if (z==29 && s<=19000)
  {
  x="-6170-Y29";
  }
else if (z==29 && s<=25000)
  {
  x="-6175-Y29";
  }
else if (z==35 && s<=981)
  {
  x="-6090-Y35";
  }
else if (z==35 && s<=1220)
  {
  x="-6095-Y35";
  }
else if (z==35 && s<=1560)
  {
  x="-6100-Y35";
  }
else if (z==35 && s<=1920)
  {
  x="-6105-Y35";
  }
else if (z==35 && s<=2410)
  {
  x="-6110-Y35";
  }
else if (z==35 && s<=2900)
  {
  x="-6115-Y35";
  }
else if (z==35 && s<=4010)
  {
  x="-6120-Y35";
  }
else if (z==35 && s<=5100)
  {
  x="-6125-Y35";
  }
else if (z==35 && s<=5950)
  {
  x="-6130-Y35";
  }
else if (z==35 && s<=6820)
  {
  x="-6135-Y35";
  }
else if (z==35 && s<=8360)
  {
  x="-6140-Y35";
  }
else if (z==35 && s<=12200)
  {
  x="-6145-Y35";
  }
else if (z==35 && s<=15500)
  {
  x="-6160-Y35";
  }
else if (z==35 && s<=18300)
  {
  x="-6165-Y35";
  }
else if (z==35 && s<=19300)
  {
  x="-6170-Y35";
  }
else if (z==35 && s<=24100)
  {
  x="-6175-Y35";
  }
else if (z==35 && s<=30200)
  {
  x="-6180-Y35";
  }
else if (z==43 && s<=858)
  {
  x="-6090-Y43";
  }
else if (z==43 && s<=1190)
  {
  x="-6095-Y43";
  }
else if (z==43 && s<=1540)
  {
  x="-6100-Y43";
  }
else if (z==43 && s<=2140)
  {
  x="-6105-Y43";
  }
else if (z==43 && s<=2570)
  {
  x="-6110-Y43";
  }
else if (z==43 && s<=2990)
  {
  x="-6115-Y43";
  }
else if (z==43 && s<=3780)
  {
  x="-6120-Y43";
  }
else if (z==43 && s<=4700)
  {
  x="-6125-Y43";
  }
else if (z==43 && s<=5910)
  {
  x="-6130-Y43";
  }
else if (z==43 && s<=7430)
  {
  x="-6135-Y43";
  }
else if (z==43 && s<=7780)
  {
  x="-6140-Y43";
  }
else if (z==43 && s<=10600)
  {
  x="-6145-Y43";
  }
else if (z==43 && s<=14700)
  {
  x="-6160-Y43";
  }
else if (z==43 && s<=15500)
  {
  x="-6165-Y43";
  }
else if (z==43 && s<=19200)
  {
  x="-6170-Y43";
  }
else if (z==43 && s<=22300)
  {
  x="-6175-Y43";
  }
else if (z==43 && s<=29800)
  {
  x="-6180-Y43";
  }
else if (z==43 && s<=37200)
  {
  x="-6185-Y43";
  }
else if (z==59 && s<=1010)
  {
  x="-6095-Y59";
  }
else if (z==59 && s<=1400)
  {
  x="-6100-Y59";
  }
else if (z==59 && s<=1920)
  {
  x="-6105-Y59";
  }
else if (z==59 && s<=2330)
  {
  x="-6110-Y59";
  }
else if (z==59 && s<=2730)
  {
  x="-6115-Y59";
  }
else if (z==59 && s<=3530)
  {
  x="-6120-Y59";
  }
else if (z==59 && s<=4380)
  {
  x="-6125-Y59";
  }
else if (z==59 && s<=5920)
  {
  x="-6130-Y59";
  }
else if (z==59 && s<=6830)
  {
  x="-6135-Y59";
  }
else if (z==59 && s<=8010)
  {
  x="-6140-Y59";
  }
else if (z==59 && s<=9900)
  {
  x="-6145-Y59";
  }
else if (z==59 && s<=12000)
  {
  x="-6160-Y59";
  }
else if (z==59 && s<=15500)
  {
  x="-6165-Y59";
  }
else if (z==59 && s<=19400)
  {
  x="-6170-Y59";
  }
else if (z==59 && s<=25500)
  {
  x="-6175-Y59";
  }
else if (z==59 && s<=26400)
  {
  x="-6180-Y59";
  }
else if (z==59 && s<=32500)
  {
  x="-6185-Y59";
  }
else if (z==59 && s<=41300)
  {
  x="-6190-Y59";
  }
else if (z==59 && s<=51000)
  {
  x="-6195-Y59";
  }
else if (z==71 && s<=1410)
  {
  x="-6100-Y71";
  }
else if (z==71 && s<=1830)
  {
  x="-6105-Y71";
  }
else if (z==71 && s<=2180)
  {
  x="-6110-Y71";
  }
else if (z==71 && s<=2470)
  {
  x="-6115-Y71";
  }
else if (z==71 && s<=3120)
  {
  x="-6120-Y71";
  }
else if (z==71 && s<=3910)
  {
  x="-6125-Y71";
  }
else if (z==71 && s<=5960)
  {
  x="-6130-Y71";
  }
else if (z==71 && s<=7070)
  {
  x="-6135-Y71";
  }
else if (z==71 && s<=7920)
  {
  x="-6140-Y71";
  }
else if (z==71 && s<=9810)
  {
  x="-6145-Y71";
  }
else if (z==71 && s<=11300)
  {
  x="-6160-Y71";
  }
else if (z==71 && s<=18400)
  {
  x="-6165-Y71";
  }
else if (z==71 && s<=19300)
  {
  x="-6170-Y71";
  }
else if (z==71 && s<=23300)
  {
  x="-6175-Y71";
  }
else if (z==71 && s<=28600)
  {
  x="-6180-Y71";
  }
else if (z==71 && s<=31900)
  {
  x="-6185-Y71";
  }
else if (z==71 && s<=44100)
  {
  x="-6190-Y71";
  }
else if (z==71 && s<=50800)
  {
  x="-6195-Y71";
  }
else if (z==87 && s<=1730)
  {
  x="-6100-Y87";
  }
else if (z==87 && s<=2260)
  {
  x="-6105-Y87";
  }
else if (z==87 && s<=2640)
  {
  x="-6110-Y87";
  }
else if (z==87 && s<=3030)
  {
  x="-6115-Y87";
  }
else if (z==87 && s<=3770)
  {
  x="-6120-Y87";
  }
else if (z==87 && s<=4510)
  {
  x="-6125-Y87";
  }
else if (z==87 && s<=5660)
  {
  x="-6130-Y87";
  }
else if (z==87 && s<=7620)
  {
  x="-6135-Y87";
  }
else if (z==87 && s<=7900)
  {
  x="-6140-Y87";
  }
else if (z==87 && s<=9900)
  {
  x="-6145-Y87";
  }
else if (z==87 && s<=13900)
  {
  x="-6160-Y87";
  }
else if (z==87 && s<=15500)
  {
  x="-6165-Y87";
  }
else if (z==87 && s<=19200)
  {
  x="-6170-Y87";
  }
else if (z==87 && s<=22500)
  {
  x="-6175-Y87";
  }
else if (z==87 && s<=28500)
  {
  x="-6180-Y87";
  }
else if (z==87 && s<=34200)
  {
  x="-6185-Y87";
  }
else if (z==87 && s<=47000)
  {
  x="-6190-Y87";
  }
else if (z==87 && s<=54400)
  {
  x="-6195-Y87";
  }
else if (z==87 && s<=63500)
  {
  x="-6205-Y87";
  }
else if (z==87 && s<=85400)
  {
  x="-6215-Y87";
  }
else
  {
  x="- stop and contact Jay at 601.583.2005"
  }
document.getElementById("resulta").innerHTML= o + x + m;
document.getElementById('resultb').innerHTML = Math.round(r) + " RPM";
document.getElementById("resultc").innerHTML= s;
document.getElementById("resultd").innerHTML= n;

}
</script>
Use this application at your own risk. Results are calculated based on the Cyclo 6000 series catalog information.  The information provided is for reference ONLY!! I do not make any claims the information is correct, viable, usable, safe or marketable.  YOU are responsible for insuring YOU select the correct speed reducer based on the literature and guidance of Sumitomo Machinery Corporation of America (or Japan)!

</center>
<div>
</body>
</html>

这很好,除了我在这种方法上投入了 100 个小时,我需要再做 5-6 家制造商,这些制造商将比我刚刚做的更大。这只是一家制造商的一条生产线,我通过仅证明他们提供的 18 种可能比率中的 8 种将其截断以将工作量减半...

我想做的是为每个齿轮线创建一个 2 列表(如开头的示例),并让计算机查看第 1 列以在第 1 列中找到大于“ s" (Row #x, Column #1) 但在下一行 (Row #y, Column #1) 中小于 "s" 并打印 Row #y 列 #2 的数据。

似乎有一个简单的答案,但我找不到它 - grep、awk、sed、SOMETHING,我想念它......

【问题讨论】:

  • 您能否提供一个示例输入和输出。输入看起来如何,公式以及输出看起来应该如何?
  • 您的问题听起来很有趣,但是您的问题中没有足够的相关信息来帮助您解决它(例如,您的代码中的大多数数字都没有出现在您的输入中,所以是否有2之间的映射与否?)。不过,不要只是为您的问题增加一大堆复杂性 - 提出并发布一个真正代表您的问题的 minimal reproducible example(强调Minimal),以便我们可以帮助您。
  • 作为程序员必须学习的一件事:不要太执着于解决方案。不管你投入了多少小时,如果能找到更好的解决方案,就把它扔掉。
  • 基本上,必须有更简单的方法。只需在您喜欢的浏览器中运行脚本,看看我的困惑.....

标签: python mysql bash awk sed


【解决方案1】:

我真的无法从您的问题中看出什么是您要解决的问题的最佳方法,但编写您发布的一系列 if-else 的更好方法可能是(在 awk ):

split("298 393 579 765 1190 1610",nums)
for (i=1; i in nums; i++) {
    if (s < nums[i]) {
        x = "-" (6075 + i*5) "-Y" z
        break
    }
}

这只是为了让您了解一种可以更简短地编写代码的不同方式,但在您的问题中没有更多信息,即使这可能不必要地冗长,或者您可能需要使用 z 做其他事情,如果全部是 @987654325 @ 值确实具有相同的 s 比较或 x 输出。

【讨论】:

  • 这看起来很棒,但它远远超出了我的专业水平......我不反对使用我不理解的代码,但我必须能够“适应它”。我发布了我的整个代码......不知何故我认为它可以被简化......你的答案可能有效,但是,我不“明白”......
  • 此代码取决于第二列是完全规则的假设,并且可以从第一列计算。如果假设正确,这绝对是一种更好的方法。
  • @triplee,不,这是 awk。哦,我明白了,您的意思是 OP 代码。是的,看起来很奇怪,为什么没有标记。约翰尼 - 我怀疑是否有人会阅读你的整个代码来试图弄清楚。我当然不是。如果您在某个问题上需要帮助,您可以提出一个 minimal reproducible example 来演示您需要帮助的具体问题,而不是像大海捞针一样抛出 1000 行代码,让您的问题隐藏在其中。如果不清楚,请参阅How to Ask
  • 哦,我应该知道是谁在发布这个(-:......如果没有通常的 Awk 装饰,我怀疑 OP 可能会弄清楚这是哪种语言(我也不能!);也许澄清一下?
  • 完成。是的,在他发布他的大量代码示例之前,我认为他发布的内容已经是 awk,但我也认为我的代码将是临时的,直到他提供更多信息......哦,谢谢你的建议,你是对的当然。
【解决方案2】:

这在 awk 中很简单。传入您要比较的值(您可能会在 shell 变量中使用它,但在本例中,我硬编码 203)并从最后一行取回第二列,其中该值等于或大于第一列中的数字。

awk -F : -v value="203" 'NR==1 { next }  # skip the silly header line
    value >= $1 { m=$2; next }
    { exit }  # done; fall through to END
    END { print m }' file

这显然假设输入文件在第一列以单调递增的顺序排序,如您的示例所示。

-F : 设置列分隔符(Awk 中的默认值是任何空格),-v value=whatever 将 Awk 变量 value 设置为任何值。 (一个常见的新手误解是假设 Awk 可以使用 shell 变量——它们不是。Awk 基本上对调用程序一无所知,甚至不能假设它首先是从 shell 调用的。)

主要逻辑应该很容易理解——awk每次读取一行,只要值大于或等于第一列的数字,就将m设置为第二列,然后跳过脚本的其余部分并从内存中的下一个输入行重新开始。当条件不再成立时,我们退出;当脚本退出时,我们打印从上一行捕获的值。 (退出在这里是一个小的优化;显然不需要读取文件的其余部分。)作为几个极端情况,我们跳过第一行(因为它包含一个标题,而不是实际数据)并处理掉线通过从END 块打印而不是仅在我们实际遇到第一列实际上大于输入值的行时打印并退出文件的末尾。

如果您在 shell 脚本中需要这个,那么仅获取变量中的输出值的构造是

outputvalue=$(awk -F : -v value="$inputvalue" ....)

同样的逻辑显然在 Python 中也很容易实现。

import logging, sys

try:
    value = int(sys.argv[1])
except IndexError:
    logging.error('Syntax: {0} value'.format(sys.argv[0]))
    exit(123)

final = None
for line in sys.stdin:
    line = line.rstrip('\n')
    try:
        first, second = line.split(':')
    except ValueError:
        logging.warn('Invalid input {0}'.format(line))
        continue
    first = int(first)
    if value >= first:
        final = second
    else:
        break
print(final)

最后,这是您的 Javascript 代码的重构版本(我希望)它可以用更少的代码完成基本相同的事情。我并不是真正的 JavaScript 程序员,我也没有尝试过多地清理代码,但我猜这就是你实际上想要的。

function sumisize()
{
var y = (document.getElementById('vara').value);
var v = (document.getElementById('varb').value);
var u = (document.getElementById('varc').value);
var q = (document.getElementById('vard').value);
var w=(v*36);
var t=(w*u);
var s=(t*y);
var r=((1750/u)/y);
var x="";
var z=(y);
var p=(q);
var o="";
var n="";
var m="";

var zvalues = {
    11: { 298: 6080,   393: 6085,   579: 6090,   765: 6095,  1190: 6100,
	 1610: 6105,  1790: 6110,  1970: 6115,  2560: 6120,  2990: 6125,
	 4730: 6130,  5700: 6135,  6570: 6140,  7650: 6145,  9900: 6160 },
    17: { 408: 6080,   536: 6085,   788: 6090,  1040: 6095,  1620: 6100,
	 2190: 6105,  2440: 6110,  2680: 6115,  3490: 6120,  4070: 6125,
         5360: 6130,  6160: 6135,  8250: 6140,  9370: 6145, 10200: 6160,
	14700: 6165 },
    29: { 621: 6085,   832: 6090,  1040: 6095,  1610: 6100,  2120: 6105,
	 2530: 6110,  2950: 6115,  3980: 6120,  5010: 6125,  5960: 6130,
	 7500: 6135,  7920: 6140,  9980: 6145, 14000: 6160, 15200: 6165,
	19000: 6170, 25000: 6175 },
    35: { 981: 6090,  1220: 6095,  1560: 6100,  1920: 6105,  2410: 6110,
	 2900: 6115,  4010: 6120,  5100: 6125,  5950: 6130,  6820: 6135,
	 8360: 6140, 12200: 6145, 15500: 6160, 18300: 6165, 19300: 6170,
	24100: 6175, 30200: 6180 },
    43: { 858: 6090,  1190: 6095,  1540: 6100,  2140: 6105,  2570: 6110,
	 2990: 6115,  3780: 6120,  4700: 6125,	5910: 6130,  7430: 6135,
	 7780: 6140, 10600: 6145, 14700: 6160, 15500: 6165, 19200: 6170,
	22300: 6175, 29800: 6180, 37200: 6185 },
    59: {1010: 6095,  1400: 6100,  1920: 6105,  2330: 6110,  2730: 6115,
	 3530: 6120,  4380: 6125,  5920: 6130,  6830: 6135,  8010: 6140,
	 9900: 6145, 12000: 6160, 15500: 6165, 19400: 6170, 25500: 6175,
	26400: 6180, 32500: 6185, 41300: 6190, 51000: 6195 },
    71: {1410: 6100,  1830: 6105,  2180: 6110,	2470: 6115,  3120: 6120,
	 3910: 6125,  5960: 6130,  7070: 6135,  7920: 6140,  9810: 6145,
	11300: 6160, 18400: 6165, 19300: 6170, 23300: 6175, 28600: 6180,
	31900: 6185, 44100: 6190, 50800: 6195 },
    87: {1730: 6100,  2260: 6105,  2640: 6110,  3030: 6115,  3770: 6120,
	 4510: 6125,  5660: 6130,  7620: 6135,  7900: 6140,  9900: 6145,
	13900: 6160, 15500: 6165, 19200: 6170, 22500: 6175, 28500: 6180,
	34200: 6185, 47000: 6190, 54400: 6195, 63500: 6205, 85400: 6215 }
};

var mvalues = { 0.5:  -56,  1.0: -143,  1.5: -145,  2.0: -145,  3.0: -182,
		5.0: -184,  7.5: -213, 10.0: -215, 15.0: -254, 20.0: -256 };

if (p>0) {
    m=mvalues[v];
}

if (p==0)
  {
  o="CHH";
  }
else if (p==1)
  {
  o="CHHP";
  }
else if (p==2 && u==1)
  {
  o="CHHJ";
  }
else 
  {
  n=" Please Set 'Belt Drive Ratio' to 1 ";
  }
 
    var smax = -1;
    var diag = "diagnostics: "
    for (var k in zvalues[z]) {
	diag += "k(" + k + ")<=s(" + s + ")? "
	if (k<=s && k>smax) {
	    diag += "k>smax(" + smax + "); dv=" + zvalues[z][k] + ". "
	      smax = k;
	      dv = zvalues[z][k];
	  }
    }
    diag += " Final smax = " + smax
    if (smax > -1)
    {
	x="-" + dv + "-Y" + z;
    }
else
  {
  x="- stop and contact Jay at 601.583.2005" + diag
  }
document.getElementById("resulta").innerHTML= o + x + m;
document.getElementById('resultb').innerHTML = Math.round(r) + " RPM";
document.getElementById("resultc").innerHTML= s;
document.getElementById("resultd").innerHTML= n;

}
body {
    background-image: url("../media/sumi.jpeg");
    background-repeat: no-repeat;
    background-position: right top;
}
#main {
  max-width: 800px;
  margin: 20px auto; 
  border: solid;
  background: #87CEEB;
  padding: 50px;
  position: relative; 
}
/*
#answer {
  max-width: 200px;
  margin: 20px auto; 
  border: solid;
  background: #FFEFD5;
  padding: 50px;
  position: relative;
  padding: 10px;
  right: 300px; 
}*/
<!DOCTYPE html>
<html lang="en">
<body>
<head>
    <meta charset="utf-8">
    <title>Sumitomo Sizer</title><br>
</head>
<body>
<h6> here it is:
<h1><b>Sumitomo Cyclo sizer!!</b></h1>
<div id="main">
<P> I am only showing 8 of the 18 available ratios.  Sure, you might need       the others for some reason, but you can do most things with these 8.</p>

<p>  What output speed is closest AND OVER what you need:
  <select id="vara">
<option value="11">159 RPM (11:1)</option>
<option value="17">103 RPM (17:1)</option>
<option value="29">60 RPM (29:1)</option>
<option value="35">50 RPM (35:1)</option>
<option value="43">40 RPM (43:1)</option>
<option value="59">30 RPM (59:1</option>
<option value="71">25 RPM (71:1)</option>
<option value="87">20 RPM (87:1)</option>
</select>
</p>

<P>What is your motor Horsepower @1750:
   <select id="varb">
<option value="0.5">1/2</option>
<option value="1">1</option>
<option value="1.5">1-1/2</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="5">5</option>
<option value="7.5">7.5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
</select>
</p>
<p>belt drive ratio: 
<input id="varc" type="text" value="1"/>:1
</p>
<P>Input style:
   <select id="vard">
<option value="0">Standard</option>
<option value="1">Top motor mount</option>
<option value="2">C-face (w/coupling)</option>
</select>
</p>
<p>Click the button to get your Sumitomo size</p>

<button onclick="sumisize()">Find it</button>
</p>
<div id="answer">
Sumitomo part number: <h2><p id="resultd"></h2></p><p id="resulta"></p>
Actual output speed: <p id="resultb"> </p>
Torque in inch-lbs.:<p id="resultc"></p>
</div>

Use this application at your own risk. Results are calculated based on the Cyclo 6000 series catalog information.  The information provided is for reference ONLY!! I do not make any claims the information is correct, viable, usable, safe or marketable.  YOU are responsible for insuring YOU select the correct speed reducer based on the literature and guidance of Sumitomo Machinery Corporation of America (or Japan)!

</center>
<div>
</body>
</html>

【讨论】:

  • 查看python版本时,python如何知道我的“table”在哪里?抱歉,我对 Python 真的很弱,但是我已经用 Python 做了一些树莓派控件,所以,我愿意更深入地研究它。如果我不能在 JavaScript 中做到这一点,那将是我最好的选择。
  • 就像 Awk 脚本一样,这个 Python 脚本从标准输入 (sys.stdin) 读取表格。您可以像 python script 230 &lt;file 一样运行它以使用 file 中的表和 230 的值。
  • 现在更新了 Javascript 版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-08
  • 2022-11-01
  • 2021-10-11
  • 2015-11-30
  • 1970-01-01
  • 2019-09-12
  • 1970-01-01
相关资源
最近更新 更多