¿Cómo concateno dinámicamente n tablas de datos en JSL?Estoy creando un script para automatizar el flujo de trabajo de un compañero de trabajo que es un usuario novato de JMP. La primera operación del script es combinar todas las iteraciones de datos de las ejecuciones del modelo. Esto se logra por,
- Se solicita al usuario que seleccione el directorio de las tablas de datos individuales que representan norte iteraciones de una ejecución del modelo.
- El script abre todas las tablas de datos de iteración que tienen un nombre predefinido seguido del número de iteración: “SGR Scenaio Iteration i”.
- A medida que se abre la tabla de datos de cada iteración, se agrega una columna de iteración y se rellena previamente con el número de iteración.
- Una vez abiertas todas las tablas de datos, las tablas de datos 2 a 10 se concatenan con la primera tabla de datos para crear una nueva tabla de datos combinados denominada "Iteraciones combinadas del escenario SGR".
- Las iteraciones originales luego se cierran sin guardarse; esto es intencional para preservar las tablas de datos originales.
Aquí está el código para la primera parte de la secuencia de comandos que realiza las tareas enumeradas anteriormente:
Names Default to Here(1);
Delete Symbols();
//----------------------------------------------------------------------------------------------
// Select file path, then import and combine all iteration data tables into a single data table
// of replicates of sorties completed across iterations.
//----------------------------------------------------------------------------------------------
path = Pick Directory("Select the directory containing the iteration files.");
iterationFile = path || "SGR Scenario Iteration 1.jmp";
dtIterationTables = Open(iterationFile, "Invisible");
// add Iteration column
dtIterationTables << New Column(
"Iteration",
Ordinal,
Set Each Value(1)
);
dtIterationTables << Move Selected Columns(
{"Iteration"},
After(:Time of Day)
);
// get remaining iteration tables
i = 2;
iterationFile = path || "SGR Scenario Iteration 2.jmp";
While(File Exists(iterationFile),
nTables = i;
dtIterationFile = Open(iterationFile, "Invisible");
// add Iteration column
dtIterationFile << New Column(
"Iteration",
Ordinal,
Set Each Value(i)
);
dtIterationFile << Move Selected Columns(
{"Iteration"},
After(:Time of Day)
);
//look for next iteration table
i++;
iterationFile = path || "SGR Scenario Iteration " || Char(i) || ".jmp";
);
// concatenate current interation table to first iteration table
// NOTE: AWAITING RESPONSE ON HOW TO MAKE THIS PROCESS DYNAMIC
Data Table("SGR Scenario Iteration 1") << Concatenate(
Data Table("SGR Scenario Iteration 2"),
Data Table("SGR Scenario Iteration 3"),
Data Table("SGR Scenario Iteration 4"),
Data Table("SGR Scenario Iteration 5"),
Data Table("SGR Scenario Iteration 6"),
Data Table("SGR Scenario Iteration 7"),
Data Table("SGR Scenario Iteration 8"),
Data Table("SGR Scenario Iteration 9"),
Data Table("SGR Scenario Iteration 10"),
Output Table("SGR Scenario Combined Iterations")
);
// close original iteration tables
i = 1;
While(i <= nTables,
dtIterationTable = Data Table("SGR Scenario Iteration " || Char(i));
Close(dtIterationTable);
Clear Symbols(dtIterationTable);
i++;
);<BR />El problema que tengo es con el paso 4. El script actual está codificado para concatenar 10 tablas de datos, pero necesito poder concatenar norte tablas de datos para que mi compañero de trabajo no se limite a procesar solo 10 iteraciones, o peor aún, tener que intentar editar el código JSL cada vez que cambia el tamaño del conjunto de datos (léase: viene a mí para cambiar el script). Puedes ver en el código que tengo una variable, nTablas , ese es el recuento de la cantidad de tablas de datos que se abrieron, ya que todos los demás bloques de código están configurados para manejar norte tablas de datos
Cualquier ayuda en este asunto sería muy apreciada.
Fusión y limpieza de datosRe: ¿Cómo concateno dinámicamente n tablas de datos en JSL?Tuve que hacer un poco de limpieza en la solución sugerida, pero básicamente funcionó. Aquí está el código actualizado para el front-end de mi script:
Names Default to Here(1);
Delete Symbols();
//----------------------------------------------------------------------------------------------
// Select file path, then import and combine all iteration data tables into a single data table
// of replicates of sorties completed by te hour across iterations.
//----------------------------------------------------------------------------------------------
path = Pick Directory("Select the directory containing the iteration files.");
iterationFile = path || "SGR Scenario Iteration 1.jmp";
dtIterationTables = Open(iterationFile, "Invisible");
dtIterationTables << Set Name("SGR Scenario Combined Iterations");
// add Iteration column
dtIterationTables << New Column(
"Iteration",
Ordinal,
Set Each Value(1)
);
dtIterationTables << Move Selected Columns(
{"Iteration"},
After(:Time of Day)
);
// get remaining iteration tables
i = 2;
iterationFile = path || "SGR Scenario Iteration " || Char(i) || ".jmp";
While(File Exists(iterationFile),
dtIterationFile = Open(iterationFile, "Invisible");
// add Iteration column
dtIterationFile << New Column(
"Iteration",
Ordinal,
Set Each Value(i)
);
// append current iteration table to combined table
dtIterationTables = dtIterationTables << Concatenate(
dtIterationFile,
Append to first table(1)
);
Close(dtIterationFile, NoSave);
//look for next iteration data table
i++;
iterationFile = path || "SGR Scenario Iteration " || Char(i) || ".jmp";
);
//----------------------------------------------------------------------------------------------
// Add Replicate column and then create data table with simplified statistical model.
//----------------------------------------------------------------------------------------------
dtIterationTables << New Column(
"Replicate",
Ordinal,
Formula(Num(Right(:Time of Day, Length(:Time of Day) - Contains(:Time of Day, " "))))
);
dtIterationTables << Move Selected Columns(
{"Replicate"},
After(:Iteration)
);
// make data set more flexible by stacking the hour columns to simplify the statistical model
dtIterationTables << Stack(
columns(
:Name("1200"),
:Name("1300"),
:Name("1400"),
:Name("1500"),
:Name("1600"),
:Name("1700"),
:Name("1800"),
:Name("1900"),
:Name("2000"),
:Name("2100"),
:Name("2200")
),
Source Label Column("Hour"),
Stacked Data Column("Sorties Completed"),
Copy formula(0),
Name("Non-stacked columns")(Keep(:Iteration, :Replicate)),
Output Table("Combined SGR Scenario Iterations")
);
dtAllIterations = Data Table("Combined SGR Scenario Iterations");
Close(dtIterationTables, NoSave);
dtAllIterations:Hour << Set Modeling Type("Ordinal");
dtAllIterations << Save As(path || "Combined SGR Scenario Iterations.jmp");¡Gracias por la ayuda!
Re: ¿Cómo concateno dinámicamente n tablas de datos en JSL?Echa un vistazo al siguiente código.Debería conseguir lo que quieres.Realmente no pude probar el código, pero creo que es bastante preciso.Adopta el enfoque de no tener que realizar un seguimiento de cuántas tablas de datos se han leído, ya que realiza la concatenación después de ingresar cada archivo.
Names Default to Here(1);
Delete Symbols();
//----------------------------------------------------------------------------------------------
// Select file path, then import and combine all iteration data tables into a single data table
// of replicates of sorties completed across iterations.
//----------------------------------------------------------------------------------------------
path = Pick Directory("Select the directory containing the iteration files.");
iterationFile = path || "SGR Scenario Iteration 1.jmp";
dtBaseIterationTables = Open(iterationFile, "Invisible");
dtBaseIterationTable << set name( "SGR Scenario Combined Iterations" );
// add Iteration column
dtBaseIterationTables << New Column(
"Iteration",
Ordinal,
Set Each Value(1)
);
dtBaseIterationTables << Move Selected Columns(
{"Iteration"},
After(:Time of Day)
);
// get remaining iteration tables
i = 2;
//iterationFile = path || "SGR Scenario Iteration 2.jmp";
While(File Exists(path || "SGR Scenario Iteration " || char( i ) || ".jmp";),
//nTables = i;
dtIterationFile = Open(path || "SGR Scenario Iteration " || char( i ) || ".jmp", "Invisible");
// add Iteration column
dtIterationFile << New Column(
"Iteration",
Ordinal,
Set Each Value(i)
);
/* // Not required since the columns from this table will align with the base table
dtIterationFile << Move Selected Columns(
{"Iteration"},
After(:Time of Day)
)*/;
//look for next iteration table
i++;
// iterationFile = path || "SGR Scenario Iteration " || Char(i) || ".jmp";
dtBaseIterationTables = dtBaseIterationTables << Concatenate( dtIterationFile, append to first table( 1 ) );
close( dtIterationFile, nosave );
);<BR /><BR />dtBaseIterationTables << Show Window( 1 );
/*// concatenate current interation table to first iteration table
// NOTE: AWAITING RESPONSE ON HOW TO MAKE THIS PROCESS DYNAMIC
Data Table("SGR Scenario Iteration 1") << Concatenate(
Data Table("SGR Scenario Iteration 2"),
Data Table("SGR Scenario Iteration 3"),
Data Table("SGR Scenario Iteration 4"),
Data Table("SGR Scenario Iteration 5"),
Data Table("SGR Scenario Iteration 6"),
Data Table("SGR Scenario Iteration 7"),
Data Table("SGR Scenario Iteration 8"),
Data Table("SGR Scenario Iteration 9"),
Data Table("SGR Scenario Iteration 10"),
Output Table("SGR Scenario Combined Iterations")
);
// close original iteration tables
i = 1;
While(i <= nTables,
dtIterationTable = Data Table("SGR Scenario Iteration " || Char(i));
Close(dtIterationTable);
Clear Symbols(dtIterationTable);
i++;
);*/