private ExportColumnCollection CreateColumnCollection() { ExportColumnCollection c = new ExportColumnCollection(); string PrimaryStratumLabel = null; string SecondaryStratumLabel = null; string TertiaryStratumLabel = null; DataSheet dsterm = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); string TimestepLabel = TerminologyUtilities.GetTimestepUnits(this.Project); TerminologyUtilities.GetStratumLabelTerminology( dsterm, ref PrimaryStratumLabel, ref SecondaryStratumLabel, ref TertiaryStratumLabel); c.Add(new ExportColumn("ScenarioID", "Scenario ID")); c.Add(new ExportColumn("ScenarioName", "Scenario")); c.Add(new ExportColumn("Iteration", "Iteration")); c.Add(new ExportColumn("Timestep", TimestepLabel)); c.Add(new ExportColumn("Stratum", PrimaryStratumLabel)); c.Add(new ExportColumn("SecondaryStratum", SecondaryStratumLabel)); c.Add(new ExportColumn("TertiaryStratum", TertiaryStratumLabel)); c.Add(new ExportColumn("AttributeType", "Attribute")); c.Add(new ExportColumn("AgeMin", "Age Min")); c.Add(new ExportColumn("AgeMax", "Age Max")); c.Add(new ExportColumn("Amount", "Total Value")); c["Amount"].DecimalPlaces = 2; c["Amount"].Alignment = ColumnAlignment.Right; return(c); }
private ExportColumnCollection CreateColumnCollection() { ExportColumnCollection c = new ExportColumnCollection(); string AmountLabel = null; string UnitsLabel = null; TerminologyUnit TermUnit = 0; string PrimaryStratumLabel = null; string SecondaryStratumLabel = null; string TertiaryStratumLabel = null; DataSheet dsterm = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); string TimestepLabel = TerminologyUtilities.GetTimestepUnits(this.Project); TerminologyUtilities.GetAmountLabelTerminology(dsterm, ref AmountLabel, ref TermUnit); TerminologyUtilities.GetStratumLabelTerminology(dsterm, ref PrimaryStratumLabel, ref SecondaryStratumLabel, ref TertiaryStratumLabel); UnitsLabel = TerminologyUtilities.TerminologyUnitToString(TermUnit); string AmountTitle = string.Format(CultureInfo.InvariantCulture, "{0} ({1})", AmountLabel, UnitsLabel); c.Add(new ExportColumn("ScenarioID", "Scenario ID")); c.Add(new ExportColumn("ScenarioName", "Scenario")); c.Add(new ExportColumn("Iteration", "Iteration")); c.Add(new ExportColumn("Timestep", TimestepLabel)); c.Add(new ExportColumn("Stratum", PrimaryStratumLabel)); c.Add(new ExportColumn("SecondaryStratum", SecondaryStratumLabel)); c.Add(new ExportColumn("TertiaryStratum", TertiaryStratumLabel)); c.Add(new ExportColumn("StateClass", "State Class")); c.Add(new ExportColumn("AgeMin", "Age Min")); c.Add(new ExportColumn("AgeMax", "Age Max")); c.Add(new ExportColumn("Amount", AmountTitle)); c["Amount"].DecimalPlaces = 2; c["Amount"].Alignment = ColumnAlignment.Right; return(c); }
protected override void ModifyLayout(SyncroSimLayout layout) { if (this.Library == null) { Debug.Assert(false); return; } if (this.Library.Session.ActiveProject == null) { Debug.Assert(false); return; } SyncroSimLayoutItem PrimaryStrataGroup = layout.Items.FindItem("stsim_PrimaryStrata", true); if (PrimaryStrataGroup == null) { Debug.Assert(false); return; } string psl = null; string ssl = null; string tsl = null; DataSheet dsterm = this.Library.Session.ActiveProject.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetStratumLabelTerminology(dsterm, ref psl, ref ssl, ref tsl); PrimaryStrataGroup.DisplayName = psl; }
private List <int> GetApplicableSecondaryStrata() { List <int> l = new List <int>(); string psl = null; string ssl = null; string tsl = null; TerminologyUtilities.GetStratumLabelTerminology(this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME), ref psl, ref ssl, ref tsl); DataSheet ds = this.ResultScenario.GetDataSheet(Strings.DATASHEET_NSIC_DISTRIBUTION_NAME); foreach (DataRow dr in ds.GetData().Rows) { if (dr[Strings.DATASHEET_SECONDARY_STRATUM_ID_COLUMN_NAME] == DBNull.Value) { ExceptionUtils.ThrowInvalidOperationException( "Cannot split by '{0}' because '{1}' is not specified for all records in Initial Conditions Distribution.", ssl, ssl); } int id = Convert.ToInt32(dr[Strings.DATASHEET_SECONDARY_STRATUM_ID_COLUMN_NAME], CultureInfo.InvariantCulture); if (!l.Contains(id)) { l.Add(id); } } Debug.Assert(l.Count > 0); return(l); }
private void RefreshTitleBar(Project project) { string primary = null; string secondary = null; string tertiary = null; DataSheet ds = project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetStratumLabelTerminology(ds, ref primary, ref secondary, ref tertiary); this.Text = "Select " + primary; }
protected STSimMapBase(Scenario scenario) { this.m_Scenario = scenario; DataSheet ds = scenario.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetStratumLabelTerminology( ds, ref this.m_PrimaryStratumLabel, ref this.m_SecondaryStratumLabel, ref this.m_TertiaryStratumLabel); }
protected override void OnDataSheetChanged(DataSheetMonitorEventArgs e) { base.OnDataSheetChanged(e); string Primary = null; string Secondary = null; string Tertiary = null; TerminologyUtilities.GetStratumLabelTerminology(e.DataSheet, ref Primary, ref Secondary, ref Tertiary); this.Columns[Strings.DATASHEET_PT_STRATUMIDSOURCE_COLUMN_NAME].DisplayName = Primary; this.Columns[Strings.DATASHEET_PT_STRATUMIDDEST_COLUMN_NAME].DisplayName = "To " + Primary; }
private void OnTerminologyChanged(DataSheetMonitorEventArgs e) { string Primary = null; string Secondary = null; string Tertiary = null; string AmountLabel = null; TerminologyUnit AmountUnits = TerminologyUnit.None; TerminologyUtilities.GetStratumLabelTerminology(e.DataSheet, ref Primary, ref Secondary, ref Tertiary); TerminologyUtilities.GetAmountLabelTerminology(e.DataSheet, ref AmountLabel, ref AmountUnits); this.m_FilesDataGrid.Columns[PRIMARY_STRATUM_FILE_NAME_COLUMN_INDEX].HeaderText = BuildLowerCaseLabel(Primary); this.m_FilesDataGrid.Columns[SECONDARY_STRATUM_FILE_NAME_COLUMN_INDEX].HeaderText = BuildLowerCaseLabel(Secondary); this.m_FilesDataGrid.Columns[TERTIARY_STRATUM_FILE_NAME_COLUMN_INDEX].HeaderText = BuildLowerCaseLabel(Tertiary); this.RefreshCalculatedValues(); }
private void ValidateNormalSplit() { string psl = null; string ssl = null; string tsl = null; string aml = null; TerminologyUnit amu = 0; DataSheet tds = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetStratumLabelTerminology(tds, ref psl, ref ssl, ref tsl); TerminologyUtilities.GetAmountLabelTerminology(tds, ref aml, ref amu); //We don't support splits by secondary strata for spatial runs as this time if (this.IsSpatial) { ExceptionUtils.ThrowInvalidOperationException("Cannot split by '{0}' for a spatial model run.", ssl); } //If there are less than 2 secondary strata records referenced by //Initial Conditions Distribution we cannot do a split by secondary strata List <int> l = this.GetApplicableSecondaryStrata(); if (l.Count < 2) { ExceptionUtils.ThrowInvalidOperationException("Cannot split by '{0}' because there are fewer than two references to '{1}' in Initial Conditions Distribution.", ssl, ssl); } //If there are Transition Targets with NULL secondary stata then add a warning if (NullValueExists(this.ResultScenario.GetDataSheet(Strings.DATASHEET_TRANSITION_TARGET_NAME).GetData(), Strings.DATASHEET_SECONDARY_STRATUM_ID_COLUMN_NAME)) { this.RecordStatus(StatusType.Warning, string.Format(CultureInfo.InvariantCulture, "Run is splitting by '{0}' but Transition Targets are not specified by '{1}'. Allocating targets in proportion to '{2}'.", ssl, ssl, aml)); } //If there are Transition Attribute Targets with NULL secondary stata then add a warning if (NullValueExists(this.ResultScenario.GetDataSheet(Strings.DATASHEET_TRANSITION_ATTRIBUTE_TARGET_NAME).GetData(), Strings.DATASHEET_SECONDARY_STRATUM_ID_COLUMN_NAME)) { this.RecordStatus(StatusType.Warning, string.Format(CultureInfo.InvariantCulture, "Run is splitting by '{0}' but Transition Attribute Targets are not specified by '{1}'. Allocating targets in proportion to '{2}'.", ssl, ssl, aml)); } }
public void ThrowDataException(int stateClassId, bool isDestination) { string psl = null; string ssl = null; string tsl = null; string StateClassName = "NULL"; DataSheet StateClassDataSheet = this.m_Project.GetDataSheet(Strings.DATASHEET_STATECLASS_NAME); string Location = "From"; if (isDestination) { Location = "To"; } TerminologyUtilities.GetStratumLabelTerminology(this.m_Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME), ref psl, ref ssl, ref tsl); StateClassName = Convert.ToString(DataTableUtilities.GetTableValue(StateClassDataSheet.GetData(), StateClassDataSheet.ValueMember, stateClassId, Strings.DATASHEET_NAME_COLUMN_NAME), CultureInfo.InvariantCulture); string msg = string.Format(CultureInfo.InvariantCulture, "The state class '{0}' could not be located in '{1} {2}'.", StateClassName, Location, psl); throw new DataException(msg); }
private void ValidateRaster(StochasticTimeRaster rast, int rows, int columns, string columnName) { string PrimaryStratumLabel = null; string SecondaryStratumLabel = null; string TertiaryStratumLabel = null; string ColumnDisplayName = this.Columns[columnName].DisplayName; DataSheet TerminologySheet = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetStratumLabelTerminology( TerminologySheet, ref PrimaryStratumLabel, ref SecondaryStratumLabel, ref TertiaryStratumLabel); if (columnName == Strings.DATASHEET_SPIC_STRATUM_FILE_COLUMN_NAME) { ColumnDisplayName = PrimaryStratumLabel; } else if (columnName == Strings.DATASHEET_SPIC_SECONDARY_STRATUM_FILE_COLUMN_NAME) { ColumnDisplayName = SecondaryStratumLabel; } if (rast.Height != rows) { string msg = null; if (columnName == Strings.DATASHEET_SPIC_STRATUM_FILE_COLUMN_NAME) { msg = string.Format(CultureInfo.InvariantCulture, "The number of rows for the '{0}' raster does not match that of the other '{1}' rasters.", PrimaryStratumLabel, PrimaryStratumLabel); } else { msg = string.Format(CultureInfo.InvariantCulture, "The number of rows for the '{0}' raster does not match that of the '{1}' raster.", ColumnDisplayName, PrimaryStratumLabel); } throw new DataException(msg); } else if (rast.Width != columns) { string msg = null; if (columnName == Strings.DATASHEET_SPIC_STRATUM_FILE_COLUMN_NAME) { msg = string.Format(CultureInfo.InvariantCulture, "The number of columns for the '{0}' raster does not match that of the other '{1}' rasters.", PrimaryStratumLabel, PrimaryStratumLabel); } else { msg = string.Format(CultureInfo.InvariantCulture, "The number of columns for the '{0}' raster does not match that of the '{1}' raster.", ColumnDisplayName, PrimaryStratumLabel); } throw new DataException(msg); } }
private void CreatePartialLibraries(DataTable splitData, bool isSpatialSplit) { string psl = null; string ssl = null; string tsl = null; TerminologyUtilities.GetStratumLabelTerminology( this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME), ref psl, ref ssl, ref tsl); //Save the library because we may have added status data to the scenario if (this.Library.HasChanges()) { this.Library.Save(); } this.BeginProgress(splitData.Rows.Count + 1); this.SetStatusMessage(string.Format(CultureInfo.InvariantCulture, "Preparing Data For Parallel Processing (Split by '{0}')", ssl)); //We have numJobs + 1 because we want the progress indicator to include //the time it takes to create the partial library. this.CreatePartialLibrary(); this.StepProgress(); //Then make a copy of the partial library for each job. Note, however, that for the final //job we move the partial library instead of copying it. List <string> Files = new List <string>(); DataView dv = new DataView(splitData, null, "ID", DataViewRowState.CurrentRows); int JobId = 1; foreach (DataRowView drv in dv) { string JobFileName = string.Format(CultureInfo.InvariantCulture, "Job-{0}.ssim", JobId); string FullFileName = Path.Combine(this.JobFolderName, JobFileName); drv.Row["FileName"] = FullFileName; if (JobId == splitData.Rows.Count) { File.Move(this.PartialLibraryName, FullFileName); } else { File.Copy(this.PartialLibraryName, FullFileName); } this.ConfigureDatabase(drv.Row, isSpatialSplit); Debug.Assert(!Files.Contains(FullFileName)); Files.Add(FullFileName); this.StepProgress(); JobId += 1; } this.CompleteProgress(); //If it is a spatial split, configure the external files if (isSpatialSplit) { this.ConfigureExternalFiles(splitData); } //Create the configuration file this.CreateSplitConfigurationFile(Files, splitData.Rows.Count); //The partial file and input folder should now be gone Debug.Assert(!File.Exists(this.PartialLibraryName)); Debug.Assert(!Directory.Exists(Path.Combine(this.JobFolderName, "Partial.ssim.input"))); this.SetStatusMessage(null); }