我有一個主表,其中包含一分鐘分辨率的 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]
);
);