我有一个主表,其中包含一分钟分辨率的 2021 年时间戳(“Timestamp-1min”)。 需要根据一年中每一天的一对条件(日出、日落:黄昏开始和结束),用一天分辨率(“开始-结束-TS1”)的第二个表中的数据填充主表,同时匹配日、月和[条件中的时间(小时:分钟)]。
我已在 2021 年 6 月 14 日完成此操作,该日期位于“Timestamp-1min-Result”表中。
我添加了一列 -“S Start-S End”- 即日出-开始,日出-结束在每天的匹配时间的同一列中,另一列是暮光(开始和结束)。 我还想填充日长、中日时间、黄昏时间和代码列 (DT/TT) - 白天/黄昏时间,这将有助于使用我稍后加入的另一个表执行统计。 我如何才能使用公式来填充总日时间和黄昏时间(在结果表中),而不是从第二个表中获取值。 如何单独创建白天(作为 DT)和黄昏时间(作为 TT)的代码?
如何以交互方式进行? 或者 JSL 是唯一的方法吗?
纳尔逊,
惊人的! 多谢!!!
需要知道从哪里开始练习脚本编写。 是否有我们可以遵循和 DIY 的基本脚本示例?
完成您想要的操作的唯一有效方法是使用 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]
);
);