【发布时间】: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),以便我们可以帮助您。
-
作为程序员必须学习的一件事:不要太执着于解决方案。不管你投入了多少小时,如果能找到更好的解决方案,就把它扔掉。
-
基本上,必须有更简单的方法。只需在您喜欢的浏览器中运行脚本,看看我的困惑.....