//+------------------------------------------------------------------+ //| Saver.mqh | //| Copyright 2025, Niquel Mendoza. | //| https://www.mql5.com/es/users/nique_372 | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Niquel Mendoza." #property link "https://www.mql5.com/es/users/nique_372" #property strict #ifndef AIDATATASKRUNNER_BACKEND_BASES_SAVER_MQH #define AIDATATASKRUNNER_BACKEND_BASES_SAVER_MQH //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "Defines.mqh" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CTaskSaver : public CLoggerBase { public: CTaskSaver(void) {} ~CTaskSaver(void) {} //--- bool LoadC(const string& file_name, int fc, string& msg, string& progress, string& file_name_json, string& mainfolder, string& exp_path); bool SaveC(const string& file_name, int fc, string& msg, const string& progress, const string& file_name_json, const string& mainfolder, const string& exp_path); //--- bool Load(const string& file_name, TaskTester& arr[], int& size, int file_common, string& msg); bool Save(const string& file_name, TaskTester& arr[], int size, int file_common, bool filter, string& msg); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTaskSaver::LoadC(const string &file_name, int fc, string &msg, string &progress, string &file_name_json, string &mainfolder, string &exp_path) { //--- ::ResetLastError(); const int fh = FileOpen(file_name, FILE_READ | FILE_TXT | fc); if(fh == INVALID_HANDLE) { msg = (StringFormat("Fallo al abrir el archivo = %s, ultimo error = %d", file_name, ::GetLastError())); return false; } //--- progress = FileReadString(fh); mainfolder = FileReadString(fh); exp_path = FileReadString(fh); file_name_json = FileReadString(fh); //--- FileClose(fh); //--- return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTaskSaver::SaveC(const string &file_name, int fc, string &msg, const string &progress, const string& file_name_json, const string &mainfolder, const string &exp_path) { //--- ::ResetLastError(); const int fh = FileOpen(file_name, FILE_WRITE | FILE_TXT | fc); if(fh == INVALID_HANDLE) { msg = (StringFormat("Fallo al abrir el archivo = %s, ultimo error = %d", file_name, ::GetLastError())); return false; } //--- FileWrite(fh, progress); FileWrite(fh, mainfolder); FileWrite(fh, exp_path); FileWrite(fh, file_name_json); //--- FileClose(fh); //--- return true; } //+------------------------------------------------------------------+ //| Tareas | //+------------------------------------------------------------------+ // Se usa | para las separciones dado que no se puede tener nombres de arhcivos con ese char bool CTaskSaver::Save(const string &file_name, TaskTester &arr[], int size, int file_common, bool filter, string& msg) { //--- ::ResetLastError(); const int fh = FileOpen(file_name, FILE_WRITE | FILE_CSV | file_common); if(fh == INVALID_HANDLE) { msg = (StringFormat("Fallo al abrir el archivo = %s, ultimo error = %d", file_name, ::GetLastError())); return false; } //--- FileWrite(fh, "Timeframe|Symbol|SetFile|StartDate|EndDate|SymbolFolder|Label|LabelId"); //--- for(int i = 0; i < size; i++) { if(!filter || (arr[i].state == AIEXECUTOR_TASK_STATE_IN_PROCESS || arr[i].state == AIEXECUTOR_TASK_STATE_IN_QUEQE || arr[i].state == AIEXECUTOR_TASK_STATE_PENDIENTE)) FileWrite(fh, arr[i].ToStringFile()); } //--- FileClose(fh); return true; } //+------------------------------------------------------------------+ bool CTaskSaver::Load(const string &file_name, TaskTester& arr[], int& size, int file_common, string& msg) { //--- if(FileIsExist(file_name, file_common)) { //--- ::ResetLastError(); const int fh = FileOpen(file_name, FILE_READ | FILE_CSV | file_common); if(fh == INVALID_HANDLE) { msg = (StringFormat("Fallo al abrir el archivo = %s, ultimo error = %d", file_name, ::GetLastError())); return false; } //--- FileReadString(fh); // Cabezera //--- size = ArrayResize(arr, 0); //--- string arr_str[8]; while(!FileIsEnding(fh)) { if(StringSplit(FileReadString(fh), '|', arr_str) != 8) { LogWarning("Linea invalida omitida", FUNCION_ACTUAL); continue; } //--- static TaskTester task; task.Assing(arr_str); //--- // Quizas no hague falta?¿ //if(task.state == AIEXECUTOR_TASK_STATE_FINISHED || task.state == AIEXECUTOR_TASK_STATE_FAILED) // continue; //--- arr[ArrayResize(arr, (++size)) - 1] = task; } //--- FileClose(fh); } else { LogWarning("No se enocnrro un archivo del cual cargar", FUNCION_ACTUAL); } //--- return true; } //+------------------------------------------------------------------+ /* ExpertPath=ICTRaptor.ex5 MainFolder=ICTKiller\\ TemporalFIleName=none MoveFilesName=pred.csv,sl.csv,tp.csv,scaler_tp.csv,scaler_sl.csv,scaler_pred.csv */ /* Timeframe,Symbol,SetFile,SymbolFolderName,Label,LabelId,StartDate,EndDate 1,XAUUSD,ICTKiller\\XAUUSD\\M1\\Best\\data.set,XAUUSD,Best,0,2025.01.01 10:10:10,2026.01.01 */ //+------------------------------------------------------------------+ #endif // AIDATATASKRUNNER_BACKEND_BASES_SAVER_MQH