Tengo una tabla principal con marca de tiempo para 2021 en una resolución de un minuto ("Marca de tiempo-1min"). Es necesario llenar la tabla principal con datos de la segunda tabla con resolución de un día ("Inicio-Fin-TS1") dependiendo de un par de condiciones para cada día de un año (Amanecer, Atardecer: Inicio y fin del crepúsculo) mientras se hace coincidir la día, mes y [hora(Hr:min) en las condiciones].
Lo hice para la fecha 14/06/2021, que se encuentra en la tabla "Marca de tiempo-1min-Resultado".
Agregué una columna - "S Inicio-S Fin" - que es Amanecer-Inicio, Amanecer-Fin en la misma columna en los horarios coincidentes para cada día y otra columna para Crepúsculo (Inicio y Fin) de la misma manera. También quiero completar la duración del día, la hora media, la hora del crepúsculo y una columna de código (DT/TT): hora diurna/crepuscular, lo que ayudará a realizar estadísticas con otra tabla a la que me uniría más adelante. ¿Cómo puedo usar fórmulas para completar el tiempo total del día y el tiempo del crepúsculo (en la tabla de resultados) en lugar de tomar valores de la segunda tabla? ¿Cómo puedo crear el código solo para el horario diurno (como DT) y el horario crepuscular (como TT)?
¿Cómo hacerlo de forma interactiva? O ¿JSL es la única forma?
Aquí hay algunas sugerencias:
nelson,
¡Asombroso! ¡¡¡Muchas gracias!!!
Necesito saber por dónde empezar a practicar el scripting. ¿Existen ejemplos básicos de secuencias de comandos que podamos seguir y hacerlo usted mismo?
La única forma eficaz de hacer lo que quieres es utilizar una parte de JSL.Hacerlo usando múltiples columnas de fórmula obligaría a leer medio millón de registros varias veces.El JSL siguiente lee la tabla principal solo una vez.
Además, podría hacer todo esto en una tabla, pero luego tendría que fingir que está usando Excel y mover todos los datos de la tabla de datos de búsqueda a la tabla principal y luego ocultar las columnas.No sería bonito.Aquí está el script que creo que debería ayudarle en gran medida a resolver su problema.Con medio millón de registros, se necesitan unos minutos para realizar todas las comparaciones necesarias.Tenga en cuenta que el script busca 2 tablas de datos con nombres específicos.
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]
);
);