我有一个主表,其时间戳为 2021 年,分辨率为一分钟(“Timestamp-1min”)。 在匹配日、月和 [条件中的时间(小时:分钟)]。
我已经在“Timestamp-1min-Result”表中的日期 6/14/2021 完成了它。
我添加了一列 - “S Start-S End” - 这是日出开始、日出结束和暮光之城(开始和结束)的另一列。我还想填充日长、T 中、暮光时间和代码列 (DT/TT) - 白天/黄昏时间,这将有助于对我稍后加入的另一个表执行统计信息。 我怎样才能使用公式来填充总白天时间和暮光时间(在结果表中),而不是从第二个表中获取值。 如何单独为白天(作为 DT)和暮光时间(作为 TT)创建代码?
如何以交互方式进行? 或者 JSL 是唯一的方法吗?
做你想做的事的唯一有效方法是使用一段 JSL。使用多个公式列会强制多次读取 50 万条记录。下面的 JSL 只读取一次主表。
此外,您可以在一张表中完成所有这些操作,但是您必须假装您正在使用 Excel 并将所有数据从查找数据表移动到主表中,然后隐藏列。不会很漂亮。这是我认为应该让您解决问题的脚本。对于 50 万条记录,完成所有必需的比较需要几分钟。请注意,该脚本正在寻找 2 个具有特定名称的数据表。
Names Default To Here( 1 );
dtMain = Data Table( "Timestamp-1min" );
dtLookUP = Data Table( "Start-End-TS1" );
// Add the required new colummns
dtMain << New Column( "S Start-S End", format("h:m:s"));
dtMain << New Column( "T Start-T End", format("h:m:s"));
dtMain << New Column( "Day Length", format("h:m:s"));
dtMain << New Column( "Mid T", format("h:m:s"));
dtMain << New Column( "Twilight time", format("h:m:s"));
dtMain << New Column( "DT/TT", character);
// Loop through Main table and set values
DT = "";
dl = twTime = .;
For( i = 1, i <= N Rows( dtMain ), i++,
If( i == 1 | Day( dtMain:Timestamp[i] ) != Day( dtMain:Timestamp[i - 1] ),
theRow = Try(
(dtLookUp << get rows where(
dtLookUp:Month 2 == Month( dtMain:Timestamp[i] ) & dtLookUp:Date == Day( dtMain:Timestamp[i] )
))[1],
.
)
);
// Get the time for the current row
theTime = Date MDY( 12, 31, 1899 ) + 3600 * Hour( dtMain:Timestamp[i] ) + 60 * Minute( dtMain:Timestamp[i] )
+Second( dtMain:Timestamp[i] );
theNextTime = Date MDY( 12, 31, 1899 ) + 3600 * Hour( dtMain:Timestamp[i + 1] ) + 60 *
Minute( dtMain:Timestamp[i + 1] ) + Second( dtMain:Timestamp[i + 1] );
// If this is a Twilight Start, record the time, and set the value for Twilight time
If( dtLookUp:Twilight start[theRow] >= theTime & dtLookUp:TwilightStart[theRow] <= theNextTime,
dtMain:"T Start-T End"n[i] = dtLookUp:Twilight start[theRow];
DT = "TT";
twTime = dtLookUp:Twilight Length[theRow];
);
// If this is Sunrise, recorde the time and set the value for Day Length
If( dtLookUp:Sunrise[theRow] >= theTime & dtLookUp:Sunrise[theRow] <= theNextTime,
dtMain:"S Start-S End"n[i] = dtLookUp:Sunrise[theRow];
DT = "DT";
dl = dtLookUp:Day Length[theRow];
);
// If sunset has ended record the value and blank out the day length time
If( dtLookUp:Sunset[theRow] >= theTime & dtLookUp:Sunset[theRow] <= theNextTime,
dtMain:"S Start-S End"n[i] = dtLookUp:Sunset[theRow];
DT = "TT";
dl = .;
);
// If twighlight has ended record the value and blank out the Twilight time
If( dtLookUp:Twilight End[theRow] >= theTime & dtLookUp:Twilight End[theRow] <= theNextTime,
dtMain:"T Start-T End"n[i] = dtLookUp:Twilight End[theRow];
DT = "";
twTime = .;
);
// If this is the Mid T time, record the value
If( dtLookUp:Mid T[theRow] >= theTime & dtLookUp:Mid T[theRow] <= theNextTime,
dtMain:Mid T[i] = dtLookUp:Mid T[theRow]
);
// Write the repeating values
dtMain:"DT/TT"n[i] = DT;
dtMain:Twilight time[i] = twTime;
dtMain:Day Length[i] = dl;
// Do some cleanup on ending records
If( Is Missing( dtMain:"S Start-S End"n[i] ) == 0 & Is Missing( dtMain:Day Length[i - 1] ) == 0,
dtMain:Day Length[i] = dtMain:Day Length[i - 1]
);
If( Is Missing( dtMain:"T Start-T End"n[i] ) == 0 & Is Missing( dtMain:Twilight time[i - 1] ) == 0,
dtMain:Twilight time[i] = dtMain:Twilight time[i - 1]
);
If( Is Missing( dtMain:Twilight time[i] ) == 0 & dtMain:"DT/TT"n[i] == "",
dtMain:"DT/TT"n[i] = dtMain:"DT/TT"n[i - 1]
);
);
纳尔逊,
惊人! 非常感谢!!!
需要知道从哪里开始练习脚本。 是否有我们可以遵循和 DIY 的基本脚本示例?