列車のリアルタイムの位置を表示するプログラムを作りたい。

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
福ちゃん3

列車のリアルタイムの位置を表示するプログラムを作りたい。

#1

投稿記事 by 福ちゃん3 » 1年前

jsで列車の運行状況、今の時間で、どの列車が、どこの駅とどこの駅の間を走っているかをリアルタイムで、表示するサイトを作っています。
一度、dayjugeのところを値を変えたりしたのですが、
一つわかったことは、曜日で分けると、
例えば、1月1日をAダイヤ、2日、3日をBダイヤ、それ以外の日をCダイヤといった、
不規則なダイヤ設定に対応できないことがわかりました。
その不規則なダイヤ設定をするためには、日付毎にダイヤを割り振りしなければならない、
つまり、1日ごとにAダイヤ、Bダイヤ、Cダイヤといった分け方をしなければならないのですが、
その方法がわからないのです。
参考にしたサイトは、こちらです。

http://r113.web.fc2.com/p/viewer/oc-port/index.html
以下はjavascriptの文章です。
<code>
var timeTable = new Array();

//列車データの配列のキーの集合
var timeTableArrayKey = new Array();

//設定時刻
var setSecondSum = 0;

//自動リアルタイム更新設定
var realtimeUpdate = true;

var directionNameAry = ["下り", "上り"];

//日付変更の基準
var dayChangeTime = 3 * 3600 + 0 * 60;

//始発・終着駅での停留時間
var turningSecond = 1 * 30;

function main()
{
//現在時刻を1秒ごとに更新して表示する
nowTimeDisplay();
judgeDiaDay(); //今日が平日ダイヤか休日ダイヤか
setInterval("nowTimeDisplay()",1000);

//時刻表データを取得、整える
getTimeTable();

//現在日時の取得
</code>
中略
<code>

```ここに言語を入力
//駅での停車時間プラスマイナス何秒は停車と見なされるのか
var stationStopSpareTime = 0;



//各列車の在線位置を割り出す
function getTrainPosition()
{
//配列の中身をリセット
trainExistData = new Array();
trainExistCount = 0;

var i=0;
for(i=0 ; i<trainBasicData.length ; i++)
{
arrayKey = timeTableArrayKey;

//運転日が一致する場合のみ続ける
//if(timeTable[arrayKey]["運転日"] != "平日" && timeTable[arrayKey]["運転日"] != "全日")
if(!judgeTrainRunningDay(timeTable[arrayKey]["運転日"]))
continue;

/*
//始発駅発車時刻と終着駅到着時刻の間以外の場合は処理をスキップするようにする
if(timeTable[arrayKey]["始発駅発車時刻"] > setSecondSum || setSecondSum > timeTable[arrayKey]["終着駅発車時刻"])
{
//alert("とばす 現在時刻"+setSecondSum+" "+timeTable[arrayKey]["始発駅発車時刻"]+"?"+timeTable[arrayKey]["終着駅発車時刻"])
continue;
}
*/


//下りの場合は米原から姫路へ
//上りの場合は姫路から米原へ
//初期値
if(timeTable[arrayKey]["方向"] == "下り")
j = 0;
else
j = stationList.length - 1;

while(true)
{
//if(arrayKey == "2119G_全日")
//alert(arrayKey+"列車 "+timeTable[arrayKey]["方向"]+" "+stationList[j]+"駅 "+trainTimeData[j][0]+" "+trainTimeData[j][1]+" "+trainTimeData[j][2]);

//対象外の駅の場合は以下の処理はスキップするようにする
if(trainTimeData[j][0] != -1 || trainTimeData[j][1] != -1)
{
//今見ている駅
var nowStationNum = j;

//次に進む駅
if(timeTable[arrayKey]["方向"] == "下り")
nextStationNum = j + 1;
else
nextStationNum = j - 1;

//if(arrayKey == "2119G_全日")
//alert("now: "+setSecondSum+" "+arrayKey+"列車 "+stationList[nowStationNum]+" "+timeTable[arrayKey]["駅時刻"][stationList[nowStationNum]]["着"]+"/"+timeTable[arrayKey]["駅時刻"][stationList[nowStationNum]]["発"])

//駅に停車中の列車が見つかったら
if(timeTable[arrayKey]["駅時刻"][nowStationNum]["着"] - stationStopSpareTime <= setSecondSum && timeTable[arrayKey]["駅時刻"][nowStationNum]["発"] + stationStopSpareTime > setSecondSum)
{
//列車の在線状況を記録
recordTrainExistData(arrayKey, nowStationNum, -1);

//if(arrayKey == "2127G_全日")
//alert(timeTable[arrayKey]["列車番号"] +" "+stationList[j]+"駅 "+secondToHHMMSS(timeTable[arrayKey]["駅時刻"][stationList[j]]["着"])+"~"+secondToHHMMSS(timeTable[arrayKey]["駅時刻"][stationList[j]]["発"])+" 停車中");
}

//駅間走行中の判定は次の駅の分まで見るので、配列外を参照してしまわないようにここで止める
if(nextStationNum < 0 || nextStationNum > stationList.length - 1 )
break;

//駅間走行中の列車が見つかったら
//alert(stationList[j]);

//if(arrayKey == "2127G_全日")
//alert(stationList[nowStationNum]+" "+timeTable[arrayKey]["駅時刻"][stationList[nowStationNum]]["発"] +"+"+ stationStopSpareTime +"<="+ setSecondSum +"&&"+ timeTable[arrayKey]["駅時刻"][stationList[nextStationNum]]["着"] +"-"+ stationStopSpareTime +">"+ setSecondSum)

if(timeTable[arrayKey]["駅時刻"][nowStationNum]["発"] + stationStopSpareTime <= setSecondSum && timeTable[arrayKey]["駅時刻"][nextStationNum]["着"] - stationStopSpareTime > setSecondSum)
{
//駅発車?次駅までにかかる時間
var t1 = timeTable[arrayKey]["駅時刻"][nextStationNum]["着"] - timeTable[arrayKey]["駅時刻"][nowStationNum]["発"];
//駅発車?今現在までの時間
var t2 = setSecondSum - timeTable[arrayKey]["駅時刻"][nowStationNum]["発"];
var advance = t2 / t1;

//列車の在線状況を記録
if(timeTable[arrayKey]["方向"] == "下り")
recordTrainExistData(arrayKey, nowStationNum, advance);
else
recordTrainExistData(arrayKey, nextStationNum, advance);

//if(arrayKey == "2127G_全日")
//alert(timeTable[arrayKey]["列車番号"] +" "+stationList[j]+"駅 "+secondToHHMMSS(timeTable[arrayKey]["駅時刻"][stationList[j]]["発"])+"~"+stationList[j+1]+"駅 "+secondToHHMMSS(timeTable[arrayKey]["駅時刻"][stationList[j+1]]["着"])+" 走行中 "+ advance+"");
}

}


//ループを繰り返すたびに実行する処理
if(timeTable[arrayKey]["方向"] == "下り")
j++;
else
j--;

//ループを抜ける条件
if(timeTable[arrayKey]["方向"] == "下り" && j > stationList.length - 1 )
break;
else if(timeTable[arrayKey]["方向"] == "上り" && j < 0 )
break;

}


}

}
</code>
中略
<code>



//今日が平日ダイヤか休日ダイヤか
function judgeDiaDay()
{

setYear = nowYear; //年
setMonth = nowMonth; //月
setDate = nowDate; //日
setDay = nowDay; //曜日

//3時より前なら前日扱いにする
if(HHMMSSToSecond(nowHour, nowMinute, nowSecond) < dayChangeTime)
{
nowDateSet.setDate(nowDateSet.getDate()-1);

setYear = nowDateSet.getYear(); //年
setMonth = nowDateSet.getMonth() + 1; //月
setDate = nowDateSet.getDate(); //日
setDay = nowDateSet.getDay(); //曜日

}

if(setYear < 2000) setYear += 1900; //年の補正、1900プラスしとかないといけない場合があるため

//平日ダイヤか祝日ダイヤの判定
if(dayJudge(setYear, setMonth, setDate, setDay))
{
//表示させる欄が存在すれば、表示させる
if(document.getElementById("todayDiaDaySpan") != null)
{
document.getElementById("todayDiaDaySpan").innerHTML = " 平日ダイヤ ";
document.getElementById("todayDiaDaySpan").style.backgroundColor = "#fcf";
}
DiaDay = 1;
}
else if((document.getElementById("todayDiaDaySpan") != null))
{
//表示させる欄が存在すれば、表示させる
if(document.getElementById("todayDiaDaySpan") != null)
{
document.getElementById("todayDiaDaySpan").innerHTML = "土・休日ダイヤ";
document.getElementById("todayDiaDaySpan").style.backgroundColor = "#9ff";
}
DiaDay = 2;
}
else if((document.getElementById("todayDiaDaySpan") != null))
{
//表示させる欄が存在すれば、表示させる
if(document.getElementById("todayDiaDaySpan") != null)
{
document.getElementById("todayDiaDaySpan").innerHTML = "10月9・12・31日・11月3・21・24日ダイヤ";
document.getElementById("todayDiaDaySpan").style.backgroundColor = "#ff0";
}
DiaDay = 3;
}
else ((document.getElementById("todayDiaDaySpan") != null))
{
//表示させる欄が存在すれば、表示させる
if(document.getElementById("todayDiaDaySpan") != null)
{
document.getElementById("todayDiaDaySpan").innerHTML = "10月12日・11月3・24日ダイヤ";
document.getElementById("todayDiaDaySpan").style.backgroundColor = "#0f0";
}
DiaDay = 4;
}
}



//各列車が本日運転する列車なのかそうでないのかを判定する
//引数はその列車の運転日情報 例:平日 全日 土・休日
function judgeTrainRunningDay(value)
{
if(value == "全日")
return true;

//平日ダイヤ
else if(value == "平日" && DiaDay == 1)
return true;
else if(value == "土曜・休日運休" && DiaDay == 1)
return true;
else if(value == "毎日運転" && DiaDay == 1)
return true;

//土・休日ダイヤ
else if(value == "休日" && DiaDay == 2)
return true;
else if(value == "土休日" && DiaDay == 2)
return true;
else if(value == "土・休日" && DiaDay == 2)
return true;
else if(value == "土曜・休日運転" && DiaDay == 2)
return true;
else if(value == "毎日運転" && DiaDay == 2)
return true;

//10月9・12・31日・11月3・21・24日ダイヤ
else if(value == "10月9・12・31日・11月3・21・24日運転" && DiaDay == 3)
return true;
else if(value == "10月12日・11月3・24日運転" && DiaDay == 3)
return true;

//10月12日・11月3・24日ダイヤ
else if(value == "10月12日・11月3・24日運転" && DiaDay == 4)
return true;

else
return false;

}


//平日ダイヤと土・休日ダイヤの入れ替え
function changeDiaType()
{
if(DiaDay == 4)
{
document.getElementById("todayDiaDaySpan").innerHTML = "10月12日・11月3・24日ダイヤ";
document.getElementById("todayDiaDaySpan").style.backgroundColor = "#0f0";
DiaDay = 4;
}
else if(DiaDay == 3)
{
document.getElementById("todayDiaDaySpan").innerHTML = "10月9・12・31日・11月3・21・24日ダイヤ";
document.getElementById("todayDiaDaySpan").style.backgroundColor = "#ff0";
DiaDay = 3;
}
else if(DiaDay == 2)
{
document.getElementById("todayDiaDaySpan").innerHTML = "土休日ダイヤ";
document.getElementById("todayDiaDaySpan").style.backgroundColor = "#fcf";
DiaDay = 2;
}
else
{
document.getElementById("todayDiaDaySpan").innerHTML = " 平日ダイヤ ";
document.getElementById("todayDiaDaySpan").style.backgroundColor = "#9ff";
DiaDay = 1;
}

//時刻表データ再読み込み
getTimeTable();

//再表示
setNewTime(setSecondSum);

//路線図に列車を配置していく
drawTrain();

//時刻表スペースをリセット
var idName = "staTimetableTime0Div";
document.getElementById(idName).innerHTML = "駅名をクリックすると、時刻表が表示されます。";
var idName = "staTimetableTime1Div";
document.getElementById(idName).innerHTML = "";
var idName = "staTimetableTimeTitle0Div";
document.getElementById(idName).innerHTML = "";
var idName = "staTimetableTimeTitle1Div";
document.getElementById(idName).innerHTML = "";

//インタフェース再セット
//timeButtonInterfaceUpdate(true);

}
</code>

アバター
あたっしゅ
記事: 664
登録日時: 13年前
住所: 東京23区
連絡を取る:

Re: 列車のリアルタイムの位置を表示するプログラムを作りたい。

#2

投稿記事 by あたっしゅ » 1年前

東上☆海美「
<code>
</code>
不等号では、ありません。[]みみ。

で、これらって、『他人の書いたプログラムを、俺の思うとおりに変えてくれ』という事なんですか ?
VTuber:
東上☆海美☆(とうじょう・うみみ)
http://atassyu.php.xdomain.jp/vtuber/index.html
レスがついていないものを優先して、レスするみみ。時々、見当外れなレスしみみ。

中の人:
手提鞄あたッしュ、[MrAtassyu] 手提鞄屋魚有店
http://ameblo.jp/mratassyu/
Pixiv: 666303
Windows, Mac, Linux, Haiku, Raspbery Pi, Jetson Nano, 電子ブロック 持ち。

返信

“C言語何でも質問掲示板” へ戻る