6.09.2012

Network Speed Calculator with HTA

HTA版ネットワーク速度計算機

ネットワークの伝送時間を概算で得たい場合、以下の計算式をよく利用する。

bandwidth: 帯域幅(bps)
efficiency: 伝送効率(%)
datasize: データ量(バイト)
timetaken: 所要時間(秒)

image

この計算を簡単に行えるようにHTAのスクリプトを作成した。

・NetSpeed.hta

<html><!--
'*****************************************************************************
'*
'* NAME           : Network Speed Calculator
'*
'* DESCRIPTION    : Calculate bandwidth, data size or time taken.
'*
'* VERSION HISTORY:
'* 1.0  2012-06-09  Initial release by mogproject
'*
'*****************************************************************************
--><head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>&nbsp;</title>

<script language="JavaScript"><!--
resizeWindow(350, 170);

function resizeWindow(width, height) {
  width = Math.min(width, screen.width);
  height = Math.min(height, screen.height);
  window.resizeTo(width, height);
  window.moveTo ((screen.width - width) / 2, (screen.height - height) / 2);
}
--></script>
 
<HTA:APPLICATION
 ID             ="hta"
 APPLICATIONNAME="Network Speed Calculator"
 VERSION        ="1.0"
 ICON           =""
 BORDER         ="normal"
 BORDERSTYLE    ="normal"
 CAPTION        ="yes"
 INNERBORDER    ="yes"
 MAXIMIZEBUTTON ="yes"
 MINIMIZEBUTTON ="yes"
 SHOWINTASKBAR  ="yes"
 SINGLEINSTANCE ="yes"
 SYSMENU        ="yes"
 WINDOWSTATE    ="normal"
 SCROLL         ="no"
 SCROLLFLAT     ="yes"
 SELECTION      ="no"
 CONTEXTMENU    ="yes"
 NAVIGABLE      ="no" />

<script language="JavaScript"><!--
function onLoad() {
  document.title= hta.applicationName + " v" + hta.version;

  txtBandwidth.value = 100;
  txtEfficiency.value = 80;
  txtDataSize.value = "";
  txtTimeTaken.value = "";
  checkAvailability();
}
function onKeyPress(evt) {
  window.event.returnValue
      = (evt.keyCode >= 48 && event.keyCode <= 57) || event.keyCode == 46;
}
function onKeyUp() {
  checkAvailability();
}
function checkAvailability() {
  var elems = [txtBandwidth, txtDataSize, txtTimeTaken];
  for (var i in elems) {
    elems[i].style.backgroundColor = "white";
  }
  btnCalcBandwidth.disabled = ! (txtEfficiency.value.length
      && txtDataSize.value.length && txtTimeTaken.value.length);
  btnCalcDataSize.disabled = ! (txtEfficiency.value.length
      && txtBandwidth.value.length && txtTimeTaken.value.length);
  btnCalcTimeTaken.disabled = ! (txtEfficiency.value.length
      && txtBandwidth.value.length && txtDataSize.value.length);
}
function updateValue(elem, val) {
  elem.value = Math.round(val * 100) / 100;
  checkAvailability();
  elem.style.backgroundColor = "yellow";
}
function calcBandwidth() {
  updateValue(txtBandwidth,
      800 * txtDataSize.value * lstUnitDataSize.value
      / (txtTimeTaken.value * lstUnitTimeTaken.value * txtEfficiency.value)
      / lstUnitBandwidth.value);
}
function calcDataSize() {
  updateValue(txtDataSize,
      txtBandwidth.value * lstUnitBandwidth.value * txtEfficiency.value
      * txtTimeTaken.value * lstUnitTimeTaken.value / 800
      / lstUnitDataSize.value);
}
function calcTimeTaken() {
  updateValue(txtTimeTaken,
      800 * txtDataSize.value * lstUnitDataSize.value
      / (txtBandwidth.value * lstUnitBandwidth.value * txtEfficiency.value)
      / lstUnitTimeTaken.value);
}
--></script>

<style type="text/css"><!--
body {
  font-family     : Verdana, Arial, Helvetica, Sans-serif;
  font-size       : 9px;
  font-weight     : normal;
  background-color: #a9a9a9;
  color           : #000000;
  margin          : 0px 0px 0px 0px;
}
table {
  border-collapse : collapse;
  border-spacing  : 0px;
  border-width    : 0px;
  border-style    : solid;
}
table.main {
  width           : 320px;
  height          : 120px;
  font-size       : 12px;
}
input {
  font-family     : Verdana, Arial, Helvetica, Sans-serif;
  font-weight     : normal;
}
input.text {
  font-size       : 14px;
  text-align      : right;
  width           : 6em;
}
input.button {
  width           : 4em;
}
select {
  font-family     : Verdana, Arial, Helvetica, Sans-serif;
  font-size       : 12px;
  font-weight     : normal;
}
--></style>
</head>

<body onload="onLoad()">
<table width="100%" height="100%"><tr><td align="center">
<table class="main">
<tr>
 <td align="right">bandwidth</td>
 <td align="right">
   <input name="txtBandwidth" type="text" class="text"
    onkeypress="window.event.returnValue = onKeyPress(window.event)"
    onkeyup="onKeyUp()" onchange="onKeyUp()" />
 </td>
 <td align="left">
  <select name="lstUnitBandwidth">
   <option value="1">bps</option>
   <option value="1024">Kbps</option>
   <option value="1048576" selected="selected">Mbps</option>
   <option value="1073741824">Gbps</option>
  </select>
 </td>
 <td align="left">
  <input name="btnCalcBandwidth" type="button" class="button" value="calc"
   onclick="calcBandwidth()" />
 </td>
</tr>
<tr>
 <td align="right">efficiency</td>
 <td align="right">
   <input name="txtEfficiency" type="text" class="text"
    onkeypress="onKeyPress(window.event)"
    onkeyup="onKeyUp()" onchange="onKeyUp()" />
 </td>
 <td align="left">%</td>
 <td align="left"></td>
</tr>
<tr>
 <td align="right">data size</td>
 <td align="right">
   <input name="txtDataSize" type="text" class="text"
    onkeypress="onKeyPress(window.event)"
    onkeyup="onKeyUp()" onchange="onKeyUp()" />
 </td>
 <td align="left">
  <select name="lstUnitDataSize">
   <option value="1">Byte</option>
   <option value="1024">KB</option>
   <option value="1048576" selected="selected">MB</option>
   <option value="1073741824">GB</option>
   <option value="1099511627776">TB</option>
  </select>
 </td>
 <td align="left">
  <input name="btnCalcDataSize" type="button" class="button" value="calc""
   onclick="calcDataSize()" />
 </td>
</tr>
<tr>
 <td align="right">time taken</td>
 <td align="right">
   <input name="txtTimeTaken" type="text" class="text"
    onkeypress="onKeyPress(window.event)"
    onkeyup="onKeyUp()" onchange="onKeyUp()" />
 </td>
 <td align="left">
  <select name="lstUnitTimeTaken">
   <option value="1">seconds</option>
   <option value="60" selected="selected">minutes</option>
   <option value="3600">hours</option>
   <option value="86400">days</option>
  </select>
 </td>
 <td align="left">
  <input name="btnCalcTimeTaken" type="button" class="button" value="calc"
   onclick="calcTimeTaken()" />
  </td>
</tr>
</table>
</body>
</td></tr></table>
</html>

・画面

image

・使用方法

(1) 必要な帯域幅を算出したい場合
bandwidthの単位, efficiency, data size, time taken を設定し、bandwidth 横の「calc」ボタンを押下。

(2) 時間内に伝送可能なデータ量を算出したい場合
bandwidth, efficiency, data sizeの単位, time taken を設定し、data size 横の「calc」ボタンを押下。

(3) 所要時間を算出したい場合
bandwidth, efficiency, data size, time takenの単位 を設定し、time taken 横の「calc」ボタンを押下。

0 件のコメント:

コメントを投稿