public Hyperparameters Copy(Hyperparameters individ, string source, string destination) { Hyperparameters H = individ.Clone(); var algorithmBranches = H.getNodesByparentID(H.getNodeByName("committee")[0].ID); List <Hyperparameters> hs = new List <Hyperparameters>(); for (int j = 0; j < algorithmBranches.Count; j++) { var h = new Hyperparameters(H.toJSON(algorithmBranches[j].ID), form1); var new_save_folder = destination + "\\" + h.getValueByName("model_name") + "\\"; //новые пути прописываются в h.json автоматически, если передать объект Hyperparameters по ссылке, а не по значению Algorithm.CopyFiles(h, h.getValueByName("save_folder"), new_save_folder); hs.Add(h); } //удаление старых записей for (int i = 0; i < algorithmBranches.Count; i++) { H.deleteBranch(algorithmBranches[i].ID); } //приращение новых записей к узлу "committee" for (int i = 0; i < algorithmBranches.Count; i++) { H.addBranch(hs[i], hs[i].nodes[0].name(), H.getNodeByName("committee")[0].ID); } H.setValueByName("report_path", destination); H = H.Clone(); File.WriteAllText(destination + "\\h.json", H.toJSON(0), System.Text.Encoding.Default); return(H); }
public static void CopyFiles(Hyperparameters h, string source, string destination) { if (destination[destination.Length - 1] != '\\') { destination += destination + '\\'; } Directory.CreateDirectory(destination); if (source.Replace("\\\\", "\\") != destination.Replace("\\\\", "\\")) { foreach (string file in Directory.GetFiles(source)) { if (Path.GetFileName(file) != "h.json") { File.Copy(file, destination + Path.GetFileName(file), true); } } } //указание пути сохранения в параметрах h.setValueByName("save_folder", destination); string jsonFilePath = destination + "h.json"; h.setValueByName("json_file_path", jsonFilePath); string predictionsFilePath = destination + "predictions.txt"; h.setValueByName("predictions_file_path", predictionsFilePath); File.WriteAllText(jsonFilePath, h.toJSON(0), System.Text.Encoding.Default); }
public static void MoveFiles(Hyperparameters h, string source, string destination) { if (destination[destination.Length - 1] != '\\') { destination += '\\'; } Directory.CreateDirectory(destination); if (source != destination) { foreach (string file in Directory.GetFiles(destination)) { File.Delete(file); } foreach (string file in Directory.GetFiles(source)) { repeat1: try { if (Path.GetFileName(file) != "h.json") { File.Copy(file, destination + Path.GetFileName(file)); } else { File.Delete(file); } } catch { throw; goto repeat1; } } } else { } //указание пути сохранения в параметрах h.setValueByName("save_folder", destination); string jsonFilePath = destination + "h.json"; h.setValueByName("json_file_path", jsonFilePath); string predictionsFilePath = destination + "predictions.txt"; h.setValueByName("predictions_file_path", predictionsFilePath); File.WriteAllText(jsonFilePath, h.toJSON(0), System.Text.Encoding.Default); }