private void DoneButton_Click(object sender, RoutedEventArgs e) { if (!this.SelectedVertices.Any()) { MessageBox.Show("Select at least 1 node.", "Error!", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } this.InputSheet.Cells.Clear(); this.InputSheet.Cells.NumberFormat = "@"; var sheetModel = new SheetModel { SheetHeaders = new Dictionary <string, object> { { "Network File", this.fileName }, { "Start Year", this.StartYear }, { "End Year", this.EndYear } }, ColumnHeaders = new List <string> { "Section Key", "Latitude", "Longitude" }, StartYear = this.StartYear, EndYear = this.EndYear, Vertices = this.SelectedVertices }; sheetModel.LineValue["One"] = new Dict <int, string, double[]>(); sheetModel.Write(this.InputSheet); }
private void ModelRunButton_Click(object sender, RibbonControlEventArgs e) { this.VertexListBox.OutputSheet.Cells.Clear(); var sheetModel = SheetModel.Read(this.VertexListBox.InputSheet); sheetModel.Run(); sheetModel.Write(this.VertexListBox.OutputSheet); this.VertexListBox.OutputSheet.Activate(); }
public static SheetModel Read(Worksheet worksheet) { var sheetModel = new SheetModel(); var row = 1; var col = 1; var key = worksheet.ReadText(row, col); var value = worksheet.Read(row, col + 1); while (key != null) { sheetModel.SheetHeaders[key] = value; row++; key = worksheet.ReadText(row, col); value = worksheet.Read(row, col + 1); } // Go to next row row++; // This row should contain the column headers. var columnHeader = worksheet.ReadText(row, col); while (columnHeader != null) { sheetModel.ColumnHeaders.Add(columnHeader); col++; columnHeader = worksheet.ReadText(row, col); } sheetModel.StartYear = Convert.ToInt32(sheetModel.SheetHeaders["Start Year"]); sheetModel.EndYear = Convert.ToInt32(sheetModel.SheetHeaders["End Year"]); var fileName = sheetModel.SheetHeaders["Network File"].ToString(); sheetModel.Network = Network.Read(fileName); sheetModel.Graph = Graph.Read(sheetModel.Network); // For the vertex blocks we work with find. Range firstFind = null; var currentFind = worksheet.Cells.Find("Belief"); while (currentFind != null) { if (firstFind == null) { firstFind = currentFind; } else if (currentFind.Address == firstFind.Address) { break; } row = currentFind.Row; col = currentFind.Column; // Get sectionId var sectionId = worksheet.ReadText(row, 1); if (!sheetModel.LineEvidence.ContainsKey(sectionId)) { sheetModel.LineEvidence[sectionId] = new Dict <int, string, VertexEvidence>(); } // Get vertexKey var vertexKey = worksheet.ReadText(sheetModel.SheetHeaders.Count + 2, col); var vertex = sheetModel.Graph.Vertices[vertexKey]; col++; for (var year = sheetModel.StartYear; year <= sheetModel.EndYear; year++) { value = worksheet.Read(row, col); if (value != null) { var evidence = vertex.States.ParseEvidenceString(value.ToString()); sheetModel.LineEvidence[sectionId][year][vertexKey] = evidence; } else { var vertexEvidence = new VertexEvidence { Value = new double[vertex.States.Count] }; var isEvidenceNull = true; foreach (var state in vertex.States) { var i = vertex.States.IndexOf(state); var stateValue = worksheet.Read(row + i + 1, col); if (stateValue == null) { vertexEvidence.Value[i] = 0; } else { isEvidenceNull = false; vertexEvidence.Value[i] = Convert.ToDouble(stateValue); } } if (!isEvidenceNull) { sheetModel.LineEvidence[sectionId][year][vertexKey] = vertexEvidence; } } col++; } currentFind = worksheet.Cells.FindNext(currentFind); } return(sheetModel); }