Ho una tabella principale con timestamp per il 2021 con risoluzione di un minuto ("Timestamp-1min"). È necessario riempire la tabella principale con i dati della seconda tabella con risoluzione di un giorno ("Start-End-TS1") a seconda di una coppia di condizioni per ogni giorno dell'anno (alba, tramonto: inizio e fine crepuscolo) abbinando il giorno, mese e [ora(Hr:min) nelle condizioni].
L'ho fatto per la data 14/06/2021, che si trova nella tabella "Timestamp-1min-Result".
Ho aggiunto una colonna -"S Start-S End"- che è Sunrise-Start, Sunrise-End e un'altra colonna per Twilight (Start and End). Voglio anche popolare la durata del giorno, la metà T, l'ora del crepuscolo e un codice colonna (DT/TT)- Ora diurna/crepuscolare che aiuterà a eseguire le statistiche con un'altra tabella a cui unirei in seguito. Come posso semplicemente usare le formule per popolare l'ora del giorno totale e l'ora del crepuscolo (nella tabella dei risultati) invece di prendere valori dalla seconda tabella. Come posso creare il codice solo per Daytime (come DT) e solo per Twilight (come TT)?
Come farlo in modo interattivo? O JSL è l'unico modo?
L'unico modo efficiente per fare quello che vuoi è usare un pezzo di JSL.Farlo utilizzando più colonne di formula forzerebbe la lettura di mezzo milione di record più volte.Il JSL di seguito legge la tabella principale solo una volta.
Inoltre, potresti farlo tutto in una tabella, ma poi dovresti fingere di utilizzare Excel e spostare tutti i dati dalla tabella dei dati di ricerca nella tabella principale e quindi nascondere le colonne.Non sarebbe carino.Ecco la sceneggiatura che penso dovrebbe farti fare molta strada nella risoluzione del tuo problema.Con mezzo milione di record ci vogliono pochi minuti per fare tutti i confronti richiesti.Si noti che lo script sta cercando 2 tabelle di dati con nomi specifici.
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]
);
);
Nelson,
Sorprendente! Molte grazie!!!
Necessità di sapere da dove iniziare per esercitarsi con lo scripting. Ci sono esempi di scripting di base che potremmo seguire e fai-da-te?