プログラム垂れ流し -4ページ目

[Javascript]放射線量常駐監視

javascriptでけっこうなんでもできちゃうと思ってる私です。

先々週くらいに放射線量きになるけど、サイトまで見に行くのがめんどくさいので常駐御知らせHTMLをつくりました。

コピペでHTMLで保存すれば使えるかと思います。
諸事情でIE6でしかつかってないので、多少修正が必要かもしれませんのであしからず。
以下ソース
<!doctype html>
<html>
<head>
<title>東京都放射線量</title>
<script type="text/javascript">
<!--
//////////////定数//////////////
//観測データ公開URL
//monitorhtml='http://ftp.jaist.ac.jp/pub/emergency/monitoring.tokyo-eiken.go.jp/report/report_table.do.html';
monitorhtml='http://113.35.73.180/report/report_table.do';
//繰り返し時間
intervaltime=1*5*1000;

//放射線量情報格納用
DAY='day';
TIME='time';
MAX='max';
MIN='min';
AVE='average';
info=new Array();
info[DAY]='';
info[TIME]='';
info[MAX]=0;
info[MIN]=0;
info[AVE]=0;

//////////////関数//////////////
httpRequest = false;
if(window.XMLHttpRequest) {
    // Firefox, Opera など
    httpRequest = new XMLHttpRequest();
    httpRequest.overrideMimeType('text/xml');
} else if(window.ActiveXObject) {
    // IE
    try {
        httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e) {
        httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
    }
}

function request()
{
    httpRequest.open('GET', monitorhtml, true);
    httpRequest.onreadystatechange = function() {
        if(httpRequest.readyState == 4) {
            if(httpRequest.status == 200) {
                analyzeBody(httpRequest.responseText);
            }
        }
    }
    httpRequest.send(null);
}

function analyzeBody(body){
//    document.getElementById("hoge").innerHTML = '<html><head><title>東京都放射線量</title></head><body>';
    body = body.slice(body.indexOf('<td>平均値<br />(average)'));
    body = body.slice(body.indexOf('</td>')+5);
    var ary = new Array();
    var day;
//    while(1){
        //getDay
        day = body.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}/);
        if(!day){
            return;
        }
        
        //gettime
        time = body.match(/[0-9]{2}:[0-9]{2}~[0-9]{2}:[0-9]{2}/);
        body = body.slice(body.indexOf('</td>')+5);
        
        //前回取得と同じならスキップ
        if(info[DAY]+info[TIME] == day+time){
            return;
        }
        
        //getMax
        max = body.match(/[0-9.]{1,}/);
        body = body.slice(body.indexOf('</td>')+5);
        
        //getMin
        min = body.match(/[0-9.]{1,}/);
        body = body.slice(body.indexOf('</td>')+5);
        
        //getAverage
        ave = body.match(/[0-9.]{1,}/);
        body = body.slice(body.indexOf('</td>')+5);
        
        //初回情報記録
        if(!info[MAX]){info[MAX]=max;}
        if(!info[MIN]){info[MIN]=min;}
        if(!info[AVE]){info[AVE]=ave;}
        
        //前回との差分確認
        difmax=roundScale((max-info[MAX]),3);
        difmin=roundScale((min-info[MIN]),3);
        difave=roundScale((ave-info[AVE]),3);
        signmax=getSign(difmax);
        signmin=getSign(difmin);
        signave=getSign(difave);
        
        str = '';
        str += '東京都新宿区百人町'+'\n';
        str += day+'\n';
        str += time+'\n\n';
        str += '最大値:'+max+'('+ signmax +')\n';
        str += '最小値:'+min+'('+ signmin +')\n';
        str += '平均値:'+ave+'('+ signave +')';
        alert(str);
        
        //放射線量をメモリに保持
        info[DAY]=day;
        info[TIME]=time;
        info[MAX]=max;
        info[MIN]=min;
        info[AVE]=ave;
//    }
//    document.getElementById("hoge").innerHTML += '</body></html>';
}
////////////補佐関数////////////
function roundScale(num,scale){
    scale = scale>0 ? scale : 0;
    return (Math.round(num*(Math.pow(10,scale))))/Math.pow(10,scale);
}

function getSign(num){
    if(num < 0){return num.toString();}
    if(num > 0){return '+'+num.toString();}
    return '+-0';
}

//////////////処理//////////////
window.resizeTo(0, 0);

//初回処理
request();

//繰り返し処理
setInterval(request,intervaltime);

// -->
</script>
</head>
<body/>
</html>

[ORACLE 10g]テーブルコメント(論理名)を取得するSQL

エビデンス作る時とかに作ったので、メモ
パラメータにテーブル名入れると、コメントをタブ区切りで取得します。
エクセルに貼ると幸せになります。

=========================================================
select
replace(wmsys.wm_concat(COMMENTS),',',chr(9)) AS 論理名
from
(select
C.COMMENTS
from
USER_TAB_COLUMNS A
,USER_TABLES B
,USER_COL_COMMENTS C
where
A.TABLE_NAME = :table_name
and A.TABLE_NAME = B.TABLE_NAME
and A.TABLE_NAME = C.TABLE_NAME
and A.COLUMN_NAME = C.COLUMN_NAME
order by A.TABLE_NAME ,A.COLUMN_ID)

=========================================================

wmsys.wm_concat
これは取得結果を並べて表示してくれる裏関数っぽいです。

[Javascript]小数点を任意の桁まで四捨五入する。

処理はタイトルの通り。
ちょっと使うのに作ったからメモ

function roundScale(num,scale){
   &nbspscale = scale>0 ? scale : 0;
   &nbspreturn (Math.round(num*(Math.pow(10,scale))))/Math.pow(10,scale);
}

■例
roundScale(12.3456);
roundScale(12.3456,0);
roundScale(12.3456,1);
roundScale(12.3456,2);
roundScale(12.3456,3);

■結果
12
12
12.3
12.35
12.346