列車走行位置プログラムにおいて、特別ダイヤにおいても、特別ダイヤ期間中が平日の場合は平日、土休日であれば土休日のダイヤを返したいです。
Q&A
Closed
解決したいこと
列車走行位置プログラムを作っています。
全日ダイヤと特別ダイヤの実装方法については成功しましたが、
特定日の運転の際に、平日ダイヤや土休日ダイヤで設定したダイヤが消えてしまいます。
具体的には特定日が平日のダイヤの場合には平日ダイヤを、
土休日ダイヤの場合には土休日ダイヤを返したいのですが、どのようにしたらいいのでしょうか。
解決方法をご提示ください。
if (value === "10月12日・11月3/24日" && diaDay === DiaType.SPECIAL) return true;で、10月12日・11月3・24日に運転する特別ダイヤを設定すると、
if (value === "全日") return true;で、全日(毎日)運転としたダイヤは動く一方で、
if (value === "平日" && diaDay === DiaType.WEEKDAY) return true;→平日運転、
if (value === "土・休日" && diaDay === DiaType.HOLIDAY) return true;→土休日運転は消えてしまいます。
該当するソースコード
function getStationTimetable(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(!judgeTrainRunningDay(timeTable[arrayKey]["運転日"]))
continue;
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++;
}
}
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;
}
}
}
}
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;
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);
}
}
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 "";
}
}
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);
}
自分で試したこと
チャットgptで調べましたが、利用制限オーバーとなりました。
現時点で分かっているのは、
// 各列車が本日運転する列車なのかそうでないのかを判定する
// 引数はその列車の運転日情報 例:平日 全日 土・休日
function judgeTrainRunningDay(value) {
if (value === "全日") return true;
if (value === "平日" && diaDay === DiaType.WEEKDAY) return true;
if (value === "土曜・休日運休" && diaDay === DiaType.WEEKDAY) return true;
if (value === "毎日運転" && diaDay === DiaType.WEEKDAY) return true;
if (value === "休日" && diaDay === DiaType.HOLIDAY) return true;
if (value === "土休日" && diaDay === DiaType.HOLIDAY) return true;
if (value === "土・休日" && diaDay === DiaType.HOLIDAY) return true;
if (value === "土曜・休日運転" && diaDay === DiaType.HOLIDAY) return true;
if (value === "毎日運転" && diaDay === DiaType.HOLIDAY) return true;
if (value === "10月9/12/31日・11月3/21/24日" && ((diaDay === DiaType.SPECIAL)||(diaDay === DiaType.SPECIAL2))) return true;
if (value === "10月12日・11月3/24日" && diaDay === DiaType.SPECIAL) return true;
return false;
}
により、全日運転はすべての日に表示。逆に平日であれば、平日と入力されたものをここで返して、表示する。土休日も然りということと、
// 平日ダイヤと土・休日ダイヤと特殊ダイヤの入れ替え
function changeDiaType() {
switch (diaDay) {
case DiaType.WEEKDAY:
diaDay = DiaType.HOLIDAY;
break;
case DiaType.HOLIDAY:
diaDay = DiaType.SPECIAL;
break;
case DiaType.SPECIAL:
diaDay = DiaType.SPECIAL2;
break;
case DiaType.SPECIAL2:
diaDay = DiaType.WEEKDAY;
break;
default:
break;
}
で、平日の場合と土休日の場合とその他特別ダイヤなどの日をそれぞれ表示のきりかえができることです。
どうかご助言をご提示お願いします。
尚その際、javascript文は省略せずにお願い申し上げます。
また、参考にしているのは、こちらのHPになります。
http://r113.web.fc2.com/p/viewer/jrw-hokuriku-20150314/index.html