public void Cardinality(string casesFilesDir, int maxNumOfDiag) { CSVExport myExport = new CSVExport(); List <PhysioCaseInstance> physioCases = new List <PhysioCaseInstance>(); List <string> files = Directory.GetFiles(casesFilesDir).ToList(); foreach (string file in files) { PhysioCaseInstance physioCase = caseParser.ParseCase(file); if (physioCase != null) { physioCases.Add(physioCase); } } foreach (PhysioCaseInstance physioCase in physioCases) { if (physioCase.Diagnoses.Count < 2 || (maxNumOfDiag > 0 && physioCase.Diagnoses.Count > maxNumOfDiag)) { continue; } myExport.AddRow(); myExport["Observation"] = physioCase.Id; myExport["RealDiagCard"] = physioCase.RealDiagCardinality; myExport["MaxCard"] = physioCase.MaxCardinality; myExport["MinCard"] = physioCase.MinCardinality; } myExport.ExportToFile("Physiotherapy_Cardinality.csv"); }
/// <summary> /// 保存文件到path,可能是源文件也可能是其他文件 /// </summary> /// <param name="path"></param> /// <returns保存是否成功></returns> public bool SaveFile(string path) { SaveLayout(); DataGridViewConsoleForm.Level verifyLevel = VerifySelfAndShowConsole("保存文件"); bool canSave = false; if (verifyLevel == DataGridViewConsoleForm.Level.Info) { canSave = true; } else if (verifyLevel == DataGridViewConsoleForm.Level.Warning) { if (MessageBox.Show("您现在有Warning,确定存储吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { canSave = true; } } if (canSave) { // 保存文件 CSVExport myExport = new CSVExport(",", false); try { for (int rowIdx = 0; rowIdx < m_DataTable.Rows.Count; rowIdx++) { myExport.AddRow(); DataRow dataRow = m_DataTable.Rows[rowIdx]; for (int colIdx = 0; colIdx < m_DataTable.Columns.Count; colIdx++) { string value = (string)dataRow[colIdx]; myExport[colIdx.ToString()] = value; } } myExport.ExportToFile(path); } catch (Exception ex) { DebugUtility.ShowExceptionMessageBox(string.Format("保存文件({0})失败", path), ex); return(false); } return(true); } else { MessageBox.Show(string.Format("保存文件({0})失败", path), "提示"); return(false); } }
public void RealWC(string casesFilesDir, int maxNumOfDiag, BatchCostEstimator bce) { CSVExport myExport = new CSVExport(); List <PhysioCaseInstance> physioCases = new List <PhysioCaseInstance>(); string bceType = bce.Type(); string overhead = bce.Overhead + ""; List <string> files = Directory.GetFiles(casesFilesDir).ToList(); foreach (string file in files) { PhysioCaseInstance physioCase = caseParser.ParseCase(file); if (physioCase != null) { physioCases.Add(physioCase); } } foreach (PhysioCaseInstance physioCase in physioCases) { if (physioCase.Diagnoses.Count < 2 || (maxNumOfDiag > 0 && physioCase.Diagnoses.Count > maxNumOfDiag)) { continue; } SystemState currSystemState = new SystemState(physioCase.Diagnoses.Components); currSystemState.Diagnoses = physioCase.Diagnoses; //!! check for bug double wc = bce.WastedCostUtility(new RepairAction(physioCase.RealDiagnosis.Diag), currSystemState); myExport.AddRow(); myExport["Objective Function"] = bceType; myExport["Overhead"] = overhead; myExport["Observation"] = physioCase.Id; myExport["RealDiag"] = physioCase.RealDiagnosis; myExport["RealWC"] = wc; } string fileName = "Physiotherapy_RealWC"; if (maxNumOfDiag > 0) { fileName += "_maxDiag=" + maxNumOfDiag; } fileName += "_" + bceType + "_o=" + overhead; myExport.ExportToFile(fileName + ".csv"); }
public void BatchRepair(string casesFilesDir, BatchPlanner planner, double overhead, int maxNumOfDiag) { Console.WriteLine(planner.Type() + " o=" + overhead); Stopwatch stopwatch = new Stopwatch(); CSVExport myExport = new CSVExport(); List <PhysioCaseInstance> physioCases = new List <PhysioCaseInstance>(); List <string> files = Directory.GetFiles(casesFilesDir).ToList(); foreach (string file in files) { PhysioCaseInstance physioCase = caseParser.ParseCase(file); if (physioCase != null) { physioCases.Add(physioCase); } } foreach (PhysioCaseInstance physioCase in physioCases) { if (physioCase.Diagnoses.Count < 2 || (physioCase.Diagnoses.Count > maxNumOfDiag && maxNumOfDiag > 0))//!! { continue; } // Console.WriteLine(physioCase.Id); //!! int iterationCounter = 0; double totalCost = 0; int numberOfFixed = 0; int expanded = 0; bool foundOpt = true; bool finished = false; List <Comp> toRepair = new List <Comp>(physioCase.RealDiagnosis.Diag); SystemState currSystemState = new SystemState(physioCase.Diagnoses.Components); currSystemState.Diagnoses = physioCase.Diagnoses; //!! check for bug stopwatch.Start(); while (!finished) { RepairAction action = planner.Plan(currSystemState); if (action == null) { break; //!! } iterationCounter++; totalCost += overhead; numberOfFixed += action.Count; foreach (Comp comp in action.R) { totalCost += comp.Cost; if (toRepair.Contains(comp)) { toRepair.Remove(comp); } } if (toRepair.Count > 0) { currSystemState.SetNextState(action); } else { finished = true; } if (iterationCounter == 1) { expanded = planner.IterationDetails.NumOfExpanded; foundOpt = planner.IterationDetails.FoundOpt; } planner.ExportIterationDetails("1", physioCase.Id, iterationCounter, finished); } if (!finished)//!! { continue; } stopwatch.Stop(); int time = stopwatch.Elapsed.Milliseconds; stopwatch.Reset(); myExport.AddRow(); //myExport["System"] = model.Id; myExport["Algorithm"] = planner.Algorithm(); if (planner.Bounded) { myExport["Bound"] = planner.Bound; } else { myExport["Bound"] = "No Bound"; } myExport["Objective Function"] = planner.ObjectiveFunction(); myExport["Overhead"] = overhead; myExport["Observation"] = physioCase.Id; myExport["# Diagnoses"] = physioCase.Diagnoses.Count; myExport["Runtime(ms)"] = time; myExport["# Iterations"] = iterationCounter; myExport["Cost"] = totalCost; myExport["# Fixed Components"] = numberOfFixed; myExport["# Expanded In First Iteration"] = expanded; myExport["Found Opt"] = foundOpt; } string fileName = "Physiotherapy " + planner.Type() + "_o=" + overhead; if (maxNumOfDiag > 0) { fileName += "_MaxDiag" + maxNumOfDiag; } myExport.ExportToFile(fileName + ".csv"); planner.CreateIterationDetailsFile(fileName + "_IterationDetails"); }
private void P4_lblExport_Click(object sender, EventArgs e) { try { string saveFileName = ""; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "CSV文件(逗号分割)|*.csv|文本文件|*.txt"; saveFileDialog1.Title = "查询日志导出文件"; saveFileDialog1.ShowDialog(); if (String.IsNullOrEmpty(saveFileDialog1.FileName)) { return; } else { saveFileName = saveFileDialog1.FileName; } List<ClientIPViewModel> exportList = new List<ClientIPViewModel>(); int index = 1; if (p4_chk_onlyNotMatched.Checked) { foreach (var item in _clientIPLogsNotMatched) { ClientIPViewModel ipView = new ClientIPViewModel(item); ipView.SeqNo = index; exportList.Add(ipView); index++; } } else { foreach (var item in _clientIPLogs) { ClientIPViewModel ipView = new ClientIPViewModel(item); ipView.SeqNo = index; exportList.Add(ipView); index++; } } var csvExport = new CSVExport<ClientIPViewModel>(exportList); Dictionary<string, string> headerNames = new Dictionary<string, string>(); //{ "No.", "查询时间", "录入人", "待验证运营商", "详细地址", "IP", "查询结果", "判断结果" } headerNames.Add("SeqNo", "No."); headerNames.Add("QueryDate", "查询时间"); headerNames.Add("Recordor", "录入人"); headerNames.Add("ExpectedISP", "待验证运营商"); headerNames.Add("Address", "详细地址"); headerNames.Add("IP", "IP"); headerNames.Add("RealISP", "查询结果"); headerNames.Add("StatusDisplay", "判断结果"); csvExport.ExportToFile(saveFileName, headerNames); MessageBox.Show("查询日志已成功导出到 " + saveFileName + "。", "导出成功"); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误"); } }