平日ダイヤと土休日ダイヤが表示されない事案が発生しております。
目標は、diatype.specialの期間中に平日があれば、diatype.weekdayと、併記。
土休日であれば、diatype.holidayと同時に併記したいです。
chatGPTでは、実装がエラーになったりし、
他の質問サイトでは、質問が不十分なところを指摘され、直しても何日も何の音さたがないので、もう、誰も答えないものだと思い、諦めてここに来ました。
元ネタは、こちらです。
コード: 全て選択
http://r113.web.fc2.com/p/viewer/jrw-hokuriku-20150314/index.html
//駅から発車する列車の時刻を取得する
function getStationTimetable(currentStaNum)
{
//alert(currentStaNum);
stationTimetableArrayKey = new Array();
stationTimetableArrayKey[currentStaNum] = new Array();
stationTimetableArrayKey[currentStaNum]["下り"] = new Array();
stationTimetableArrayKey[currentStaNum]["上り"] = new Array();
var i=0;
var trainCount = new Array;
trainCount["下り"] = 0;
trainCount["上り"] = 0;
for(i=0 ; i<trainBasicData.length ; i++)
{
arrayKey = timeTableArrayKey[i];
//運転日が一致する場合のみ続ける
//if(timeTable[arrayKey]["運転日"] != "平日" && timeTable[arrayKey]["運転日"] != "全日")
if(!judgeTrainRunningDay(timeTable[arrayKey]["運転日"]))
continue;
//駅の時刻がちゃんと入力されていて
//、かつ終着駅=大阪駅でない場合 && timeTable[arrayKey]["行先"] != stationList[currentStaNum]
if(timeTable[arrayKey]["駅時刻"][currentStaNum]["着"] >= 0 )
{
var direction = timeTable[arrayKey]["方向"];
//列車番号+運転日を記録
stationTimetableArrayKey[currentStaNum][direction][trainCount[direction]] = arrayKey;
//カウント
trainCount[direction]++;
//alert(arrayKey + " は " + stationList[currentStaNum] + "駅で " + timeTable[arrayKey]["駅時刻"][stationList[currentStaNum]]["着"] + "〜" + timeTable[arrayKey]["駅時刻"][stationList[currentStaNum]]["発"]);
//stationTimetableArrayKey[19][trainCount]
//trainCount++;
}
}
//alert(stationList[currentStaNum])
//alert(stationTimetableArrayKey[currentStaNum]["下り"].length +"本を入れ替えよう");
////////発車時刻の順にクイックソートで並び替える
var i, j, k;
for(i = 0 ; i<directionNameAry.length ; i++)
{
var currentDirection = directionNameAry[i];
var buff = ""; //データを一時的に避難させておくところ
for(j=stationTimetableArrayKey[currentStaNum][currentDirection].length-1 ; j>=0 ; j--)
{
for(k=0 ; k<j ; k++)
{
//時刻の大小関係が逆だったら、入れ替える
//クイックソート
//入れ替える対象は
var arrayKeyA = stationTimetableArrayKey[currentStaNum][currentDirection][k];
var arrayKeyB = stationTimetableArrayKey[currentStaNum][currentDirection][k+1];
//alert(arrayKeyA);
//alert(arrayKeyB);
if(timeTable[arrayKeyA]["駅時刻"][currentStaNum]["発"] > timeTable[arrayKeyB]["駅時刻"][currentStaNum]["発"])
{
//入れ替える
stationTimetableArrayKey[currentStaNum][currentDirection][k] = arrayKeyB;
stationTimetableArrayKey[currentStaNum][currentDirection][k+1] = arrayKeyA;
}
}
}
}
//alert(stationTimetableArrayKey[currentStaNum]["下り"]);
//alert(stationTimetableArrayKey[currentStaNum]["下り"].length +"本あるよ");
//////結果をDIVに出力
for(i = 0 ; i<directionNameAry.length ; i++)
{
var currentDirection = directionNameAry[i];
var output = "";
output += "";
output += "";
//output += "<table border='0'>";
output += "<div>";
output += "";
output += "";
output += "";
nextTrainHeight = ""; //次発の列車の縦位置を記録する変数
divTop = 0; //1行ごとに20ずつ増やしていく
for(j=0 ; j < stationTimetableArrayKey[currentStaNum][currentDirection].length ; j++)
{
var currentArrayKey = stationTimetableArrayKey[currentStaNum][currentDirection][j];
//alert(currentArrayKey);
//document.getElementById("staTimetableTimeDiv").innerHTML += i+"本目 "+currentArrayKey+"<br />";
//output += "<tr style='white-space:nowrap; height:25px; '>";
var bgColor = getTypeColor(timeTable[currentArrayKey]["種別"], 0);
var color = getTypeColor(timeTable[currentArrayKey]["種別"], 1);
output += "<div style='position:absolute; top:"+divTop+"px; left:0px; width:60px; text-align:center;'><span style='color:"+color+"; background-color:"+bgColor+"'>" + timeTable[currentArrayKey]["列車番号"] + "</span></div>";
output += "<div style='position:absolute; top:"+divTop+"px; left:40px; width:120px; text-align:center;'><span style='color:"+color+"; background-color:"+bgColor+"'>" + timeTable[currentArrayKey]["種別"] + "</span></div>";
//着時刻と発時刻が異なる場合、つまりその駅に停車する場合
if(timeTable[currentArrayKey]["駅時刻"][currentStaNum]["着"] != timeTable[currentArrayKey]["駅時刻"][currentStaNum]["発"])
{
//着時刻
var timeOutput = "";
var secondSum = timeTable[currentArrayKey]["駅時刻"][currentStaNum]["着"];
timeOutput += digitAdjuster(secondToHour(secondSum), " ");
timeOutput += ":";
timeOutput += digitAdjuster(secondToMinute(secondSum), "0");
//timeOutput += "<span style='font-size:70%;'> ";
//timeOutput += digitAdjuster(secondToSecond(secondSum), "0");
//timeOutput += "</span>";
timeOutput += "";
output += "<div style='position:absolute; top:"+divTop+"px; left:150px; width:70px; text-align:right;'>" + timeOutput + " <span style='font-size:80%; '>着</span></div>";
//発時刻
var timeOutput = "";
var secondSum = timeTable[currentArrayKey]["駅時刻"][currentStaNum]["発"];
timeOutput += digitAdjuster(secondToHour(secondSum), " ");
timeOutput += ":";
timeOutput += digitAdjuster(secondToMinute(secondSum), "0");
//timeOutput += "<span style='font-size:70%;'> ";
//timeOutput += digitAdjuster(secondToSecond(secondSum), "0");
//timeOutput += "</span>";
timeOutput += "";
output += "<div style='position:absolute; top:"+divTop+"px; left:230px; width:70px; text-align:right;'>" + timeOutput + " <span style='font-size:80%; '>発 </span></div>";
}
else
{
//その駅を通過する列車の場合
var timeOutput = "";
var secondSum = timeTable[currentArrayKey]["駅時刻"][currentStaNum]["発"];
timeOutput += digitAdjuster(secondToHour(secondSum), " ");
timeOutput += ":";
timeOutput += digitAdjuster(secondToMinute(secondSum), "0");
//timeOutput += "<span style='font-size:70%;'> ";
//timeOutput += digitAdjuster(secondToSecond(secondSum), "0");
//timeOutput += "</span>";
timeOutput += "";
//output += "<td colspan='2' style='text-align:center;'>" + timeOutput + " 通過</td>";
output += "<div style='position:absolute; top:"+divTop+"px; left:230px; width:70px; text-align:center; color:#aaa; '>" + timeOutput + " <span style='font-size:80%; '>通過</span></div>";
}
//次発の列車の縦位置を特定する
var secondSum = timeTable[currentArrayKey]["駅時刻"][currentStaNum]["発"];
if(setSecondSum < secondSum && nextTrainHeight == "")
nextTrainHeight = divTop - 20;
if(timeTable[currentArrayKey]["行先"] != stationList[currentStaNum])
{
output += "<div style='position:absolute; top:"+divTop+"px; left:310px; width:150px; '>" + timeTable[currentArrayKey]["行先"] + "<span style='font-size:80%;'> 行</span></div>";
}
else
{
output += "<div style='position:absolute; top:"+divTop+"px; left:310px; width:80px; '>当駅止まり</div>";
}
if(timeTable[currentArrayKey]["駅時刻"][currentStaNum]["のりば"] >= 0)
output += "<div style='position:absolute; top:"+divTop+"px; left:390px; width:80px; text-align:right;'>" + timeTable[currentArrayKey]["駅時刻"][currentStaNum]["のりば"] + "<span style='font-size:80%;'> 番線</span></div>";
else
output += "<td></td>";
output += "</tr>\n";
divTop+= 20;
}
//output += "</table>";
output += "</div>";
var idName = "staTimetableTime"+i+"Div";
if(document.getElementById(idName) != null)
document.getElementById(idName).innerHTML = output;
//現在時刻へスクロールする
if(document.getElementById(idName) != null)
document.getElementById(idName).scrollTop = nextTrainHeight;
var idName = "staTimetableTimeTitle"+i+"Div";
if(document.getElementById(idName) != null)
document.getElementById(idName).innerHTML = stationList[currentStaNum]+"駅 "+currentDirection+" 時刻表";
output += "";
output += "";
output += "";
}
}
// 曜日を表す列挙型
const DayOfWeek = {
SUNDAY: 0,
MONDAY: 1,
TUESDAY: 2,
WEDNESDAY: 3,
THURSDAY: 4,
FRIDAY: 5,
SATURDAY: 6
};
// ダイヤタイプを表す列挙型
const DiaType = {
WEEKDAY: 0,
HOLIDAY: 1,
SPECIAL: 2, // 特殊ダイヤを追加
SPECIAL2: 3, // 特殊ダイヤを追加
};
let displayDiaType = DiaType.WEEKDAY; // 画面表示のダイヤタイプ
let trainDiaType = DiaType.WEEKDAY; // 列車のダイヤタイプ
// 特定日かどうかを判定する関数
function isSpecialDay(month, date) {
if ((month === 10 && date === 12) || (month === 11 && date === 3) || (month === 11 && date === 24)) {
return DiaType.SPECIAL;
} else if ((month === 10 && date === 9) || (month === 10 && date === 31) || (month === 11 && date === 21)) {
return DiaType.SPECIAL2;
}
return null;
}
// 平日か土休日かを判定する関数
function getDiaTypeByDayOfWeek(dayOfWeek) {
if (dayOfWeek === DayOfWeek.SUNDAY || dayOfWeek === DayOfWeek.SATURDAY) {
return DiaType.HOLIDAY;
}
return DiaType.WEEKDAY;
}
// 平日ダイヤか土休日ダイヤかを判定する
function judgeDiaDay() {
let setYear = nowYear; // 年
let setMonth = nowMonth; // 月
let setDate = nowDate; // 日
let setDay = nowDay; // 曜日
// 特定日を判定
let specialDiaType = isSpecialDay(setMonth, setDate);
if (specialDiaType !== null) {
displayDiaType = specialDiaType;
trainDiaType = specialDiaType;
} else {
// 平日・土休日を判定
let dayDiaType = getDiaTypeByDayOfWeek(setDay);
displayDiaType = dayDiaType;
trainDiaType = dayDiaType;
}
// 表示更新
updateDisplayDiaDay();
return trainDiaType === DiaType.WEEKDAY;
}
// 表示更新
function updateDisplayDiaDay() {
const todayDiaDaySpan = document.getElementById("todayDiaDaySpan");
if (todayDiaDaySpan) {
todayDiaDaySpan.innerHTML = getDiaTypeString(displayDiaType);
todayDiaDaySpan.style.backgroundColor = getDiaTypeColor(displayDiaType);
}
}
// DiaTypeに対応する文字列を取得する関数
function getDiaTypeString(diaType) {
switch (diaType) {
case DiaType.WEEKDAY:
return " 平日ダイヤ ";
case DiaType.HOLIDAY:
return "土・休日ダイヤ";
case DiaType.SPECIAL:
return " 10月9/12/31日・11月3/21/24日ダイヤ ";
case DiaType.SPECIAL2:
return " 10月12日・11月3/24日ダイヤ ";
default:
return "";
}
}
// DiaTypeに対応する背景色を取得する関数
function getDiaTypeColor(diaType) {
switch (diaType) {
case DiaType.WEEKDAY:
return "#9ff"; // 平日ダイヤの背景色
case DiaType.HOLIDAY:
return "#fcf"; // 土・休日ダイヤの背景色
case DiaType.SPECIAL:
case DiaType.SPECIAL2:
return "#ff9"; // 特殊ダイヤの背景色
default:
return "";
}
}
// 各列車が本日運転する列車なのかそうでないのかを判定する
// 引数はその列車の運転日情報 例:平日 全日 土・休日
function judgeTrainRunningDay(value) {
if (value === "全日") return true;
if ((value === "平日" || value === "毎日運転") && (trainDiaType === DiaType.WEEKDAY || trainDiaType === DiaType.SPECIAL || trainDiaType === DiaType.SPECIAL2)) return true;
if ((value === "土休日" || value === "毎日運転") && (trainDiaType === DiaType.HOLIDAY || trainDiaType === DiaType.SPECIAL || trainDiaType === DiaType.SPECIAL2)) return true;
if (value === "土曜・休日運休" && trainDiaType === DiaType.WEEKDAY) return true;
if (value === "土曜・休日運転" && (trainDiaType === DiaType.HOLIDAY || trainDiaType === DiaType.SPECIAL || trainDiaType === DiaType.SPECIAL2)) return true;
if (value === "10月9/12/31日・11月3/21/24日" && trainDiaType === DiaType.SPECIAL) return true;
if (value === "10月12日・11月3/24日" && trainDiaType === DiaType.SPECIAL2) return true;
return false;
}
// 画面表示のダイヤタイプの入れ替え
function changeDisplayDiaType() {
switch (displayDiaType) {
case DiaType.WEEKDAY:
displayDiaType = DiaType.HOLIDAY;
break;
case DiaType.HOLIDAY:
displayDiaType = DiaType.SPECIAL;
break;
case DiaType.SPECIAL:
displayDiaType = DiaType.SPECIAL2;
break;
case DiaType.SPECIAL2:
displayDiaType = DiaType.WEEKDAY;
break;
default:
break;
}
// 列車のダイヤタイプも合わせて変更
trainDiaType = displayDiaType;
// 表示更新
updateDisplayDiaDay();
// 時刻表データ再読み込み
getTimeTable();
// 再表示
setNewTime(setSecondSum);
// 路線図に列車を配置していく
drawTrain();
// 時刻表スペースをリセット
resetTimetableSpace();
}
// 時刻表を表示する関数
function getTrainTimetableInfo(key) {
alert(key);
}