private void SaveCentralitySheet(int id, AnalyzeOptionInfo info, Object value) { Debug.Assert(value is List <Double>); List <Double> l = value as List <Double>; int s = l.Count(); Worksheet sheet = null; if (centralitySheetIndex == 0) { sheet = GetNextWorksheet(); centralitySheetIndex = sheet.Index; sheet.Name = "Centrality"; sheet.Columns[1].ColumnWidth = 10; sheet.Columns.HorizontalAlignment = XlHAlign.xlHAlignLeft; sheet.Cells[1, 1] = "Vertex"; sheet.Cells[1, 1].EntireRow.Font.Bold = true; for (int i = 2; i <= s + 1; ++i) { sheet.Cells[i, 1] = i - 2; } } else { sheet = (Worksheet)workbook.Sheets[centralitySheetIndex]; } sheet.Columns[centralitySheetLastColumn].ColumnWidth = 20; sheet.Cells[1, centralitySheetLastColumn] = info.FullName; for (int i = 2; i <= s + 1; ++i) { sheet.Cells[i, centralitySheetLastColumn] = l[i - 2].ToString(); } ++centralitySheetLastColumn; }
private void SaveDistributionSheet(int id, AnalyzeOptionInfo info, Object value) { int length = (info.FullName.Length > 31) ? 30 : info.FullName.Length; Worksheet sheet = GetNextWorksheet(); sheet.Name = info.FullName.Substring(0, length); sheet.Columns[1].ColumnWidth = 20; sheet.Columns[2].ColumnWidth = 20; sheet.Columns.HorizontalAlignment = XlHAlign.xlHAlignLeft; int lastRow = sheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Row; sheet.Cells[lastRow, 1] = info.XAxisName; sheet.Cells[lastRow, 1].EntireRow.Font.Bold = true; sheet.Cells[lastRow, 2] = info.YAxisName; sheet.Cells[lastRow, 2].EntireRow.Font.Bold = true; ++lastRow; Debug.Assert(value is SortedDictionary <Double, Double>); SortedDictionary <Double, Double> l = value as SortedDictionary <Double, Double>; foreach (KeyValuePair <Double, Double> d in l) { sheet.Cells[lastRow, 1] = d.Key; sheet.Cells[lastRow, 2] = d.Value; ++lastRow; } }
private void SaveToGlobalSheet(int id, AnalyzeOptionInfo info, Object value) { Worksheet sheet = null; if (globalSheetIndex == 0) { sheet = GetNextWorksheet(); globalSheetIndex = sheet.Index; } else { sheet = (Worksheet)workbook.Sheets[globalSheetIndex]; } sheet.Name = "Globals"; sheet.Columns[1].ColumnWidth = 30; sheet.Columns[2].ColumnWidth = 20; sheet.Columns.HorizontalAlignment = XlHAlign.xlHAlignLeft; if (globalsSheetLastRow == 0) { globalsSheetLastRow = sheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Row; } sheet.Cells[globalsSheetLastRow, 1] = info.FullName; sheet.Cells[globalsSheetLastRow, 2] = value.ToString(); ++globalsSheetLastRow; }
private void SaveTrajectorySheetAndFile(string researchName, int id, AnalyzeOptionInfo info, Object value) { string fileName = storageStr + researchName + "_ " + info.FullName + ".txt"; int length = (info.FullName.Length > 31) ? 30 : info.FullName.Length; Worksheet sheet = GetNextWorksheet(); sheet.Name = info.FullName.Substring(0, length); sheet.Columns[1].ColumnWidth = 100; sheet.Columns.HorizontalAlignment = XlHAlign.xlHAlignLeft; int lastRow = sheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Row; sheet.Cells[lastRow, 1] = fileName; sheet.Cells[lastRow, 1].EntireRow.Font.Bold = true; Debug.Assert(value is SortedDictionary <Double, Double>); SortedDictionary <Double, Double> l = value as SortedDictionary <Double, Double>; using (StreamWriter file = new StreamWriter(fileName)) { foreach (KeyValuePair <Double, Double> d in l) { file.WriteLine(d.Key + " " + d.Value); } } }
private void SaveEnsembleResult(string researchName, EnsembleResult e, int id) { foreach (AnalyzeOption opt in e.Result.Keys) { AnalyzeOptionInfo info = ((AnalyzeOptionInfo[])opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false))[0]; OptionType optionType = info.OptionType; switch (optionType) { case OptionType.Global: SaveToGlobalSheet(id, info, e.Result[opt]); break; case OptionType.ValueList: SaveValueListSheet(id, info, e.Result[opt]); break; case OptionType.Centrality: SaveCentralitySheet(id, info, e.Result[opt]); break; case OptionType.Distribution: SaveDistributionSheet(id, info, e.Result[opt]); break; case OptionType.Trajectory: SaveTrajectorySheetAndFile(researchName, id, info, e.Result[opt]); break; default: break; } } }
private void SaveToGlobalFile(string dirName, int id, AnalyzeOptionInfo info, Object value) { string fileName = dirName + Path.DirectorySeparatorChar + id.ToString() + "_globals"; using (StreamWriter w = new StreamWriter(fileName + ".txt", true)) { w.WriteLine(info.FullName + " " + value.ToString()); } }
private void SaveDistribution(AnalyzeOptionInfo info, Object value) { Debug.Assert(value is SortedDictionary <Double, Double>); SortedDictionary <Double, Double> l = value as SortedDictionary <Double, Double>; foreach (KeyValuePair <Double, Double> d in l) { writer.WriteStartElement("pair"); writer.WriteAttributeString(info.XAxisName, d.Key.ToString()); writer.WriteAttributeString(info.YAxisName, d.Value.ToString()); writer.WriteEndElement(); } }
private void SaveTrajectoryFile(string dirName, string researchName, int id, AnalyzeOptionInfo info, Object value) { string fileName = dirName + Path.DirectorySeparatorChar + id.ToString() + "_" + info.FullName; using (StreamWriter w = new StreamWriter(fileName + ".txt")) { Debug.Assert(value is SortedDictionary <Double, Double>); SortedDictionary <Double, Double> l = value as SortedDictionary <Double, Double>; foreach (KeyValuePair <Double, Double> d in l) { w.WriteLine(d.Key + " " + d.Value); } } }
private void SaveValueListFile(string dirName, int id, AnalyzeOptionInfo info, Object value) { string fileName = dirName + Path.DirectorySeparatorChar + id.ToString() + "_" + info.FullName; using (StreamWriter w = new StreamWriter(fileName + ".txt")) { Debug.Assert(value is List <Double>); List <Double> l = value as List <Double>; foreach (Double d in l) { w.WriteLine(d); } } }
private void LoadEnsembleResults(Workbook book, ResearchResult r) { EnsembleResult e = new EnsembleResult(r.Size); //e.NetworkSize = r.Size; e.EdgesCount = r.Edges; e.Result = new Dictionary <AnalyzeOption, Object>(); Array existingOptions = Enum.GetValues(typeof(AnalyzeOption)); foreach (AnalyzeOption opt in existingOptions) { AnalyzeOptionInfo optInfo = (AnalyzeOptionInfo)(opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false)[0]); switch (optInfo.OptionType) { case OptionType.Global: Double v = FindValueInGlobals(book, optInfo.FullName); if (v != -1) { e.Result.Add(opt, v); } break; case OptionType.ValueList: Object vl = LoadValueList(book, optInfo); if (vl != null) { e.Result.Add(opt, vl); } break; case OptionType.Distribution: case OptionType.Trajectory: Object vd = LoadDistribution(book, optInfo); if (vd != null) { e.Result.Add(opt, vd); } break; default: break; } } r.EnsembleResults.Add(e); }
private void SaveValueListSheet(int id, AnalyzeOptionInfo info, Object value) { int length = (info.FullName.Length > 31) ? 30 : info.FullName.Length; Worksheet sheet = GetNextWorksheet(); sheet.Name = info.FullName.Substring(0, length); sheet.Columns[1].ColumnWidth = 20; sheet.Columns.HorizontalAlignment = XlHAlign.xlHAlignLeft; int lastRow = sheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Row; Debug.Assert(value is List <Double>); List <Double> l = value as List <Double>; foreach (Double d in l) { sheet.Cells[lastRow, 1] = d; ++lastRow; } }
private void LoadEnsembleResults(ResearchResult r) { while (reader.Read()) { if (reader.Name == "Ensemble" && !reader.IsEmptyElement) { EnsembleResult e = new EnsembleResult(r.Size); //e.NetworkSize = r.Size; e.EdgesCount = r.Edges; e.Result = new Dictionary <AnalyzeOption, Object>(); reader.Read(); while (reader.NodeType != XmlNodeType.EndElement) { AnalyzeOption opt = (AnalyzeOption)Enum.Parse(typeof(AnalyzeOption), reader.Name); AnalyzeOptionInfo optInfo = (AnalyzeOptionInfo)(opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false)[0]); switch (optInfo.OptionType) { case OptionType.Global: e.Result.Add(opt, reader.ReadElementContentAsDouble()); break; case OptionType.ValueList: case OptionType.Centrality: e.Result.Add(opt, LoadValueList()); reader.Read(); break; case OptionType.Distribution: case OptionType.Trajectory: e.Result.Add(opt, LoadDistribution()); reader.Read(); break; default: break; } } r.EnsembleResults.Add(e); } } }
private Object LoadValueList(Workbook book, AnalyzeOptionInfo info) { int length = (info.FullName.Length > 31) ? 30 : info.FullName.Length; Worksheet sheet = FindSheetInBook(book, info.FullName.Substring(0, length)); if (sheet == null) { return(null); } List <Double> valueList = new List <Double>(); Range r = sheet.UsedRange; foreach (Range c in r) { valueList.Add(c.Value); } return(valueList); }
private void SaveEnsembleResult(string researchName, EnsembleResult e, int id) { writer.WriteStartElement("Ensemble"); writer.WriteAttributeString("id", id.ToString()); foreach (AnalyzeOption opt in e.Result.Keys) { AnalyzeOptionInfo info = ((AnalyzeOptionInfo[])opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false))[0]; OptionType optionType = info.OptionType; switch (optionType) { case OptionType.Global: writer.WriteElementString(opt.ToString(), e.Result[opt].ToString()); break; case OptionType.ValueList: case OptionType.Centrality: writer.WriteStartElement(opt.ToString()); SaveValueList(e.Result[opt]); writer.WriteEndElement(); break; case OptionType.Distribution: writer.WriteStartElement(opt.ToString()); SaveDistribution(info, e.Result[opt]); writer.WriteEndElement(); break; case OptionType.Trajectory: writer.WriteStartElement(opt.ToString()); SaveTrajectoryAndFile(researchName, info, e.Result[opt]); writer.WriteEndElement(); break; default: break; } } writer.WriteEndElement(); }
private Object LoadDistribution(Workbook book, AnalyzeOptionInfo info) { int length = (info.FullName.Length > 31) ? 30 : info.FullName.Length; Worksheet sheet = FindSheetInBook(book, info.FullName.Substring(0, length)); if (sheet == null) { return(null); } Range range = sheet.UsedRange; SortedDictionary <Double, Double> d = new SortedDictionary <Double, Double>(); for (int i = 2; i <= range.Rows.Count; ++i) { Range r = range.Rows[i]; d.Add(r.Cells[1].Value, r.Cells[2].Value); } return(d); }
private void SaveTrajectoryAndFile(string researchName, AnalyzeOptionInfo info, Object value) { string fileName = storageStr + researchName + "_" + info.FullName + ".txt"; writer.WriteElementString("FileName", fileName); /*writer.WriteStartElement(info.FullName); * writer.WriteAttributeString("FileName", fileName); * writer.WriteEndElement();*/ Debug.Assert(value is SortedDictionary <Double, Double>); SortedDictionary <Double, Double> l = value as SortedDictionary <Double, Double>; using (StreamWriter file = new StreamWriter(fileName)) { foreach (KeyValuePair <Double, Double> d in l) { file.WriteLine(d.Key.ToString() + " " + d.Value.ToString()); } } }
private void SaveCentralityFile(string dirName, int id, AnalyzeOptionInfo info, Object value) { throw new NotImplementedException(); }