2021 年のタイムスタンプを 1 分の解像度 (「Timestamp-1min」) で含むメイン テーブルがあります。 1 年の各日の条件のペア (日の出、日没: 黄昏の開始と終了) に応じて、1 日の解像度 (「開始-終了-TS1」) で 2 番目のテーブルのデータをメイン テーブルに入力する必要があります。日、月、[条件内の時間(時:分)]。
「Timestamp-1min-Result」テーブルにある日付 6/14/2021 に対してこれを実行しました。
毎日の一致する時刻で同じ列に日の出-開始、日の出-終了を表す「S Start-S End」という列を追加し、同様に黄昏(開始と終了)の列を追加しました。 また、後で結合する別のテーブルで統計を実行するのに役立つ、日の長さ、T 半ば、夕暮れ時間、およびコード列 (DT/TT) 日中/夕暮れ時間を設定したいと考えています。 2 番目のテーブルから値を取得するのではなく、数式を使用して合計日中時間と夕暮れ時間 (結果テーブル内) を入力するにはどうすればよいですか。 日中のみ (DT として) およびトワイライトタイムのみ (TT として) のコードを作成するにはどうすればよいですか?
インタラクティブに行うにはどうすればよいでしょうか? それとも JSL が唯一の方法ですか?
ネルソン
すばらしい! どうもありがとう!!!
スクリプトの練習をどこから始めればよいかを知る必要があります。 真似してDIYできる基本的なスクリプトの例はありますか?
必要なことを効率的に行う唯一の方法は、JSL の一部を使用することです。複数の数式列を使用してこれを実行すると、50 万件のレコードを複数回読み取る必要があります。以下の JSL はメインテーブルを 1 回だけ読み取ります。
また、これをすべて 1 つのテーブルで実行することもできますが、その場合は 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]
);
);