我正在制作此脚本,以在工作表文档中填充约10000点的唯一数据,以供神经网络使用。问题是我在检查时间是否在四分之一小时时以某种方式在脚本中间返回0。这仅在函数的第4次循环中发生,并且开始让我感到沮丧。代码在这里:
function checkTimes(sT,eT,rT){
sT = sT.toString();
eT = eT.toString();
startTime = sT;
endTime = eT;
if(sT[2] >= "6"){
startTime = sT[0] + (Number(sT[1]) + 1).toString() + "00";
}
if(sT[0] >= "2" && sT[1] >= "5"){
startTime = "1030";
newDay = 1;
}
endTime = Number(startTime) + rT;
if(eT[2] >= "6"){
endTime = eT[0] + (Number(eT[1]) + 1).toString() + "00";
}
return [startTime, endTime];
}
// use .indexOf() function
function roundQuarter(sT,rT){
sT = sT.toString();
var quarterTimes = ['00','15','30','45'];
var tempTimes = checkTimes(sT,rT);
addUp = Number(tempTimes[0][2] + tempTimes[0][3]);
subDown = Number(tempTimes[0][2] + tempTimes[0][3]);
Logger.log("The current number is " + addUp);
if(quarterTimes.indexOf(sT[2]+sT[3]) == -1){
for(var i = 0; i <= 8; i++){
addUp = addUp +1;
Logger.log('Adding up... ' + addUp);
subDown = subDown -1;
Logger.log('Subtracting down... ' + subDown);
if(quarterTimes.indexOf(addUp.toString()) != -1){
return sT[0] + sT[1] + Number(addUp + 15);
}
if(quarterTimes.indexOf(subDown.toString()) != -1){
return sT[0] + sT[1] + Number(subDown + 30);
}
}
}else{
return (Number(sT) + 15);
}
}
// Check Previous Endtime
// run roundQuarter to find nearest quarter hour
function incTimes(sT,eT,rT){
Logger.log('Incrementing Times...');
var timeTemp = checkTimes(sT,eT,rT);
startTime = timeTemp[0];
endTime = timeTemp[1];
startTime = roundQuarter((sT + rT).toString(),rT);
endTime = roundQuarter((eT + rT).toString(),rT);
return [startTime, endTime];
}
function incTheatre(T){
if(T == '9'){
return '1'
}else{
return (Number(T) + 1).toString();
}
}
function calRandNum(isMajor,wsr){
if(isMajor){
mult = 100
}else{
mult = 50
}
multi = mult * (1 - (wsr/25));
return Math.floor(Math.random() * multi)+1;
}
function mainFunc() {
var startTime = "1030";
var runTime = 200;
var incremTimes = [1,2];
var endTime = Number(startTime) + runTime;
Logger.log(endTime + " Is the current end time.");
var wsr = 0;
var expectPop = '100';
var actualPop = '110';
var theatre = '1';
var essenTheatres = ['1','4','5','9'];
var nonEssenTheatres = ['2','3','6','7','8'];
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var currDay = days[0];
var ss = SpreadsheetApp.openById('1Rvv9tVn12JZpnn4lWfVHdgeOA_6wRlGt6JqdFY7sKCE');
var data = ss.getDataRange().getValues();
var appendedRow = ['Name','Publisher','Genre','Weeks Since Release','Day of Showing','Theatre','Start Time','End Time','Run Time','Presales','Actual Attendance'];
var movieNames = [['Black Panther','Marvel','Action',wsr,currDay,theatre,startTime,endTime,215,expectPop,actualPop],['Infinity War','Marvel','Action',wsr,currDay,theatre,startTime,endTime,240,expectPop,actualPop],
['Incredibles 2','Disney','Action',wsr,currDay,theatre,startTime,endTime,205,expectPop, actualPop],['Peter Rabbit','Sony','Fantasy',wsr,currDay,theatre,startTime,endTime,135,expectPop,actualPop],
['Deathwish', 'MGM','Action',wsr,currDay,theatre,startTime,endTime,147,expectPop,actualPop],['A Quiet Place','Paramount','Thriller',wsr,currDay,theatre,startTime,endTime,131,expectPop,actualPop],
['Ready Player One','Warner Bros','Action',wsr,currDay,theatre,startTime,endTime,219,expectPop,actualPop],['Pacific Rim: Uprising','Universal','Action',wsr,currDay,theatre,startTime,endTime,151,expectPop,actualPop]];
var essenMovies = [movieNames[0],movieNames[1],movieNames[2],movieNames[6]];
var nonEssenMovies = [movieNames[3],movieNames[4],movieNames[5],movieNames[7]];
var timeArray = checkTimes(startTime,endTime,200);
startTime = timeArray[0];
endTime = timeArray[1];
var quarter = roundQuarter('0020',runTime);
Logger.log(quarter)
Logger.log(startTime)
Logger.log(endTime)
var testTime = incTimes(1030, 1230, 200);
Logger.log(testTime[0]);
Logger.log(testTime[1]);
var daysPassed = 0;
var dayNum = 0;
/*TODO:
Check to see if day is reset **DONE**
Increment week after 7 days
Check for all theatres to be assigned
Use movieNames array for end time
*/
for(var i = 0;i < 1; i++){
if(dayNum == days.length -1){
wsr = wsr + 1;
dayNum = 0
}
currDay = days[dayNum];
if(essenTheatres.indexOf(theatre) != -1){
for(var i = 0; i < essenMovies.length; i++){
if(i == 2){
startTime = startTime + 15;
}
timeArray = checkTimes(startTime, endTime, essenMovies[i][8]);
startTime = timeArray[0];
endTime = timeArray[1];
incremTimes = incTimes(startTime, endTime, essenMovies[i][8]);
ss.appendRow(essenMovies[i]);
theatre = incTheatre(theatre);
startTime = incremTimes[0];
endTime = incremTimes[1];
}
}
if(nonEssenMovies.indexOf(theatre) != -1){
for(var i = 0; i < nonEssenMovies.length; i++){
if(i == 2 || i == 4){
startTime = startTime + 15;
}
timeArray = checkTimes(startTime, endTime, nonEssenMovies[i][8]);
startTime = timeArray[0];
endTime = timeArray[1];
incremTimes = incTimes(startTime, endTime, nonEssenMovies[i][8]);
ss.appendRow(nonEssenMovies[i]);
if(theatre == '9'){
runTime = nonEssenMovies[i][8];
}
startTime = incremTimes[0];
endTime = incremTimes[1];
theatre = incTheatre(theatre);
}
}
var newTimes = incTimes(startTime, endTime, runTime);
}
}
登录此处:
[18-07-24 01:16:40:598 EDT] 1230 Is the current end time.
[18-07-24 01:16:40:852 EDT] The current number is 20
[18-07-24 01:16:40:852 EDT] Adding up... 21
[18-07-24 01:16:40:853 EDT] Subtracting down... 19
[18-07-24 01:16:40:853 EDT] Adding up... 22
[18-07-24 01:16:40:854 EDT] Subtracting down... 18
[18-07-24 01:16:40:854 EDT] Adding up... 23
[18-07-24 01:16:40:855 EDT] Subtracting down... 17
[18-07-24 01:16:40:855 EDT] Adding up... 24
[18-07-24 01:16:40:855 EDT] Subtracting down... 16
[18-07-24 01:16:40:856 EDT] Adding up... 25
[18-07-24 01:16:40:856 EDT] Subtracting down... 15
[18-07-24 01:16:40:857 EDT] 0045
[18-07-24 01:16:40:857 EDT] 1030
[18-07-24 01:16:40:858 EDT] 1230.0
[18-07-24 01:16:40:858 EDT] Incrementing Times...
[18-07-24 01:16:40:859 EDT] The current number is 30
[18-07-24 01:16:40:860 EDT] The current number is 30
[18-07-24 01:16:40:860 EDT] 1430
[18-07-24 01:16:40:861 EDT] 1445.0
[18-07-24 01:16:40:861 EDT] Incrementing Times...
[18-07-24 01:16:40:862 EDT] The current number is 30
[18-07-24 01:16:40:863 EDT] The current number is 0
[18-07-24 01:16:40:863 EDT] Adding up... 1
[18-07-24 01:16:40:864 EDT] Subtracting down... -1
[18-07-24 01:16:40:864 EDT] Adding up... 2
[18-07-24 01:16:40:865 EDT] Subtracting down... -2
[18-07-24 01:16:40:865 EDT] Adding up... 3
[18-07-24 01:16:40:866 EDT] Subtracting down... -3
[18-07-24 01:16:40:866 EDT] Adding up... 4
[18-07-24 01:16:40:867 EDT] Subtracting down... -4
[18-07-24 01:16:40:867 EDT] Adding up... 5
[18-07-24 01:16:40:867 EDT] Subtracting down... -5
[18-07-24 01:16:40:868 EDT] Adding up... 6
[18-07-24 01:16:40:868 EDT] Subtracting down... -6
[18-07-24 01:16:40:869 EDT] Adding up... 7
[18-07-24 01:16:40:869 EDT] Subtracting down... -7
[18-07-24 01:16:40:870 EDT] Adding up... 8
[18-07-24 01:16:40:870 EDT] Subtracting down... -8
[18-07-24 01:16:40:871 EDT] Adding up... 9
[18-07-24 01:16:40:871 EDT] Subtracting down... -9
这是说错误发生在第3行,其中eT是未定义的。有人有什么想法吗?