Problemi con l'incremento di ciascuna data in una colonnaCiao,
Sto importando dati con timestamp da un file SQLite, ecco un timestamp come esempio: 2024-04-12T18:55:42.464558Z. Poiché JMP non supporta i microsecondi, taglio gli ultimi 8 caratteri e converto la colonna in un formato ora. Tutto sembra funzionare fino a questo punto. Tuttavia, quando tento di incrementare ciascun timestamp di 6 ore (differenze di fuso orario), tutti i timestamp vengono semplicemente eliminati.
dt = Current Data Table(); // Gets the currently active data table
// Check if the "timestamp" column exists
If( Contains( dt << Get Column Names("String"), "timestamp"),
// Get the column reference
col = Column(dt, "timestamp");
// Truncate the last 8 characters from each value in the "timestamp" column
col << Set Each Value( Substr( Char( col ), 1, Length( Char( col ) ) - 8 ) );
// Convert the truncated timestamps to numeric datetime values
col << data type(numeric) << modeling type(continuous) << format("yyyy-mm-ddThh:mm:ss");
// Subtract 6 hours from each datetime value using Date Increment
For( i = 1, i <= N Rows(dt), i++,
If( !Is Missing( col[i] ),
col[i] = Date Increment( col[i], "Hour", -6 );
);
);
Show("Timestamps have been truncated and decremented by 6 hours.");
,
// Error handling if column does not exist
Show("Error: 'timestamp' column does not exist in the current data table.")
);Quale sarebbe il modo corretto per convertire sostanzialmente i timestamp in un formato accettabile per JMP e incrementare ciascun valore di -6? Grazie!
Automazione e scriptingRi: Problemi nell'incremento di ciascuna data in una colonnaSe non vuoi avere millisecondi, penso che potresti provare a modificare la tua query SQL e rimuoverli lì.
Per la tua soluzione, hai provato che il tuo script faccia quello che ti aspetti che faccia fino alla parte di sottrazione? Le colonne sono cambiate in numeriche, continue, formattate correttamente E JMP le riconosce come date (cambia il formato in Migliore e ottieni il formato datenum di JMP).
Ri: Problemi nell'incremento di ciascuna data in una colonnaGrazie per il tuo contributo Ho capito. La funzione di incremento della data richiede un valore numerico, quindi il timestamp doveva essere convertito nel tipo di dati corretto prima dell'elaborazione. Ho anche dovuto cambiare "Ora" in "Secondo". Ecco il codice funzionante se qualcuno si imbatte in questo in futuro.
dt = Current Data Table(); // Gets the currently active data table
// Check if the "timestamp" column exists
If( Contains( dt << Get Column Names("String"), "timestamp"),
// Get the column reference
col = Column(dt, "timestamp");
// Process each row and remove the last 8 characters from the timestamp string
col << Set Each Value( Substr( :timestamp, 1, Length( :timestamp ) - 8 ) );
Show("Timestamps have been truncated.");
col << data type(numeric) << modeling type(continuous) << format("yyyy-mm-ddThh:mm:ss");
// Loop through each row in the column
For( i = 1, i <= N Rows(dt), i++,
// Read the value in the "timestamp" column for row i
timestamp_value = col[i];
numeric_datetime = Num( timestamp_value, Informat( "yyyy-mm-ddThh:mm:ss" ) );
numeric_datetime_adjusted = Date Increment(numeric_datetime, "second", -21600);
col[i] = numeric_datetime_adjusted;
);
,
// Error handling if column does not exist
Show("Error: 'timestamp' column does not exist in the current data table.")
);