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); }
internal void InternalExport(string location, ExportType exportType, bool showMessage) { string AmountLabel = null; TerminologyUnit TermUnit = 0; DataSheet dsterm = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); ExportColumnCollection columns = this.CreateColumnCollection(); TerminologyUtilities.GetAmountLabelTerminology(dsterm, ref AmountLabel, ref TermUnit); string WorksheetName = string.Format(CultureInfo.InvariantCulture, "{0} by Transition and State", AmountLabel); if (exportType == ExportType.ExcelFile) { this.ExcelExport(location, columns, this.CreateReportQuery(false), WorksheetName); } else { columns.Remove("ScenarioName"); this.CSVExport(location, columns, this.CreateReportQuery(true)); if (showMessage) { FormsUtilities.InformationMessageBox("Data saved to '{0}'.", location); } } }
private static void AddChartTransitionVariables(SyncroSimLayoutItemCollection items, Project project) { string AmountLabel = null; string UnitsLabel = null; TerminologyUnit TermUnit = 0; DataSheet dsterm = project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetAmountLabelTerminology(dsterm, ref AmountLabel, ref TermUnit); UnitsLabel = TerminologyUtilities.TerminologyUnitToString(TermUnit); string disp = string.Format(CultureInfo.InvariantCulture, "{0} ({1})", AmountLabel, UnitsLabel); SyncroSimLayoutItem Normal = new SyncroSimLayoutItem(Strings.TRANSITION_AMOUNT_VARIABLE_NAME, disp, false); SyncroSimLayoutItem Proportion = new SyncroSimLayoutItem(Strings.TRANSITION_PROPORTION_VARIABLE_NAME, "Proportion", false); Normal.Properties.Add(new MetaDataProperty("dataSheet", "stsim_OutputStratumTransition")); Proportion.Properties.Add(new MetaDataProperty("dataSheet", "stsim_OutputStratumTransition")); Normal.Properties.Add(new MetaDataProperty("column", "Amount")); Proportion.Properties.Add(new MetaDataProperty("column", "Amount")); Normal.Properties.Add(new MetaDataProperty("skipTimestepZero", "True")); Proportion.Properties.Add(new MetaDataProperty("skipTimestepZero", "True")); Normal.Properties.Add(new MetaDataProperty("defaultValue", "0.0")); Proportion.Properties.Add(new MetaDataProperty("defaultValue", "0.0")); items.Add(Normal); items.Add(Proportion); }
private void RefreshCalculatedValues() { DataRow drProp = this.DataFeed.GetDataSheet(Strings.DATASHEET_SPPIC_NAME).GetDataRow(); if (drProp == null) { return; } //Num Cells int NumCells = DataTableUtilities.GetDataInt(drProp[Strings.DATASHEET_SPPIC_NUM_CELLS_COLUMN_NAME]); this.TextBoxNumCells.Text = NumCells.ToString(CultureInfo.InvariantCulture); //Get the units and refresh the units labels - the default Raster Cell Units is Metres^2 string srcSizeUnits = DataTableUtilities.GetDataStr(drProp[Strings.DATASHEET_SPPIC_CELL_SIZE_UNITS_COLUMN_NAME]); string srcAreaUnits = srcSizeUnits + "^2"; string amountlabel = null; TerminologyUnit destUnitsVal = 0; TerminologyUtilities.GetAmountLabelTerminology( this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME), ref amountlabel, ref destUnitsVal); string destAreaLbl = TerminologyUtilities.TerminologyUnitToString(destUnitsVal); srcAreaUnits = srcAreaUnits.ToLower(CultureInfo.InvariantCulture); amountlabel = amountlabel.ToLower(CultureInfo.InvariantCulture); destAreaLbl = destAreaLbl.ToLower(CultureInfo.InvariantCulture); this.LabelRasterCellArea.Text = string.Format(CultureInfo.InvariantCulture, "Cell size ({0}):", srcAreaUnits); this.LabelCalcCellArea.Text = string.Format(CultureInfo.InvariantCulture, "Cell size ({0}):", destAreaLbl); this.LabelCalcTtlAmount.Text = string.Format(CultureInfo.InvariantCulture, "Total {0} ({1}):", amountlabel, destAreaLbl); // Calculate Cell Area in raster's native units float cellSize = DataTableUtilities.GetDataSingle(drProp[Strings.DATASHEET_SPPIC_CELL_SIZE_COLUMN_NAME]); double cellArea = Math.Pow(cellSize, 2); this.TextBoxCellArea.Text = cellArea.ToString("N4", CultureInfo.InvariantCulture); // Calc Cell Area in terminology units double cellAreaTU = 0; if (!CheckBoxCellSizeOverride.Checked) { cellAreaTU = InitialConditionsSpatialDataSheet.CalcCellArea(cellArea, srcSizeUnits, destUnitsVal); this.TextBoxCellAreaCalc.Text = cellAreaTU.ToString("N4", CultureInfo.InvariantCulture); drProp[Strings.DATASHEET_SPPIC_CELL_AREA_COLUMN_NAME] = cellAreaTU; TextBoxCellAreaCalc.ReadOnly = true; } else { cellAreaTU = DataTableUtilities.GetDataDbl(drProp[Strings.DATASHEET_SPPIC_CELL_AREA_COLUMN_NAME]); TextBoxCellAreaCalc.ReadOnly = false; } // Now calculate total area in the specified terminology units var ttlArea = cellAreaTU * NumCells; this.TextBoxTotalArea.Text = ttlArea.ToString("N4", CultureInfo.InvariantCulture); }
private void CreateExcelReport(string fileName) { string AmountLabel = null; TerminologyUnit AmountLabelUnits = 0; string ReportQuery = CreateReportQuery(false); DataTable ReportData = this.GetDataTableForReport(ReportQuery); DataSheet dsterm = this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME); TerminologyUtilities.GetAmountLabelTerminology(dsterm, ref AmountLabel, ref AmountLabelUnits); string WorksheetName = string.Format(CultureInfo.InvariantCulture, "{0} by State Class", AmountLabel); ExportTransformer.ExcelExport(fileName, this.CreateColumnCollection(), ReportData, WorksheetName); }
protected override void OnDataSheetChanged(DataSheetMonitorEventArgs e) { base.OnDataSheetChanged(e); string AmountLabel = null; TerminologyUnit AmountUnits = TerminologyUnit.None; TerminologyUtilities.GetAmountLabelTerminology(e.DataSheet, ref AmountLabel, ref AmountUnits); this.Columns[Strings.DATASHEET_TRANSITION_SIZE_DISTRIBUTION_MAXIMUM_AREA_COLUMN_NAME].DisplayName = (string.Format(CultureInfo.InvariantCulture, "Maximum {0} ({1})", AmountLabel, TerminologyUtilities.TerminologyUnitToString(AmountUnits))); }
protected override void OnDataSheetChanged(DataSheetMonitorEventArgs e) { base.OnDataSheetChanged(e); string amountlabel = null; TerminologyUnit units = 0; string unitsLbl = null; TerminologyUtilities.GetAmountLabelTerminology(e.DataSheet, ref amountlabel, ref units); unitsLbl = TerminologyUtilities.TerminologyUnitToString(units).ToLower(CultureInfo.InvariantCulture); this.LabelTotalAmount.Text = string.Format(CultureInfo.InvariantCulture, "Total ({0}):", unitsLbl); this.LabelCellSize.Text = string.Format(CultureInfo.InvariantCulture, "Cell size ({0}):", unitsLbl); this.TextBoxNumCells.Enabled = (this.ShouldEnableView() && (!this.CheckBoxCalcFromDist.Checked)); }
protected override void OnDataSheetChanged(DataSheetMonitorEventArgs e) { base.OnDataSheetChanged(e); string AmountLabel = null; TerminologyUnit AmountUnits = TerminologyUnit.None; TerminologyUtilities.GetAmountLabelTerminology(e.DataSheet, ref AmountLabel, ref AmountUnits); this.Columns[Strings.DATASHEET_AMOUNT_COLUMN_NAME].DisplayName = (string.Format(CultureInfo.InvariantCulture, "Target {0} ({1})", AmountLabel, TerminologyUtilities.TerminologyUnitToString(AmountUnits))); this.Columns[Strings.DATASHEET_DISTRIBUTIONTYPE_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} Distribution", AmountLabel); this.Columns[Strings.DATASHEET_DISTRIBUTION_FREQUENCY_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} Sampling Frequency", AmountLabel); this.Columns[Strings.DATASHEET_DISTRIBUTIONSD_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} SD", AmountLabel); this.Columns[Strings.DATASHEET_DISTRIBUTIONMIN_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} Min", AmountLabel); this.Columns[Strings.DATASHEET_DISTRIBUTIONMAX_COLUMN_NAME].DisplayName = string.Format(CultureInfo.InvariantCulture, "Target {0} Max", AmountLabel); }
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(); }
protected override void OnRowsAdded(object sender, DataSheetRowEventArgs e) { base.OnRowsAdded(sender, e); var ThisData = this.GetData(); DataSheet dsProp = this.GetDataSheet(Strings.DATASHEET_SPPIC_NAME); DataRow drProp = dsProp.GetDataRow(); if (drProp == null && ThisData.DefaultView.Count > 0) { dsProp.BeginAddRows(); drProp = dsProp.GetData().NewRow(); DataRow FirstRow = ThisData.DefaultView[0].Row; StochasticTimeRaster FirstRast = this.LoadRaster(FirstRow, Strings.DATASHEET_SPIC_STRATUM_FILE_COLUMN_NAME); if (FirstRast.IntCells == null) { FirstRast.LoadData(); } drProp[Strings.DATASHEET_SPPIC_NUM_ROWS_COLUMN_NAME] = FirstRast.Height; drProp[Strings.DATASHEET_SPPIC_NUM_COLUMNS_COLUMN_NAME] = FirstRast.Width; drProp[Strings.DATASHEET_SPPIC_NUM_CELLS_COLUMN_NAME] = FirstRast.GetNumberValidCells(); drProp[Strings.DATASHEET_SPPIC_XLLCORNER_COLUMN_NAME] = FirstRast.XllCorner; drProp[Strings.DATASHEET_SPPIC_YLLCORNER_COLUMN_NAME] = FirstRast.YllCorner; drProp[Strings.DATASHEET_SPPIC_CELL_SIZE_COLUMN_NAME] = FirstRast.CellSize; drProp[Strings.DATASHEET_SPPIC_CELL_SIZE_UNITS_COLUMN_NAME] = FirstRast.CellSizeUnits; drProp[Strings.DATASHEET_SPPIC_SRS_COLUMN_NAME] = FirstRast.Projection; drProp[Strings.DATASHEET_SPPIC_CELL_AREA_OVERRIDE_COLUMN_NAME] = false; string amountlabel = null; TerminologyUnit destUnitsVal = 0; double cellArea = System.Math.Pow((double)FirstRast.CellSize, 2); TerminologyUtilities.GetAmountLabelTerminology(this.Project.GetDataSheet(Strings.DATASHEET_TERMINOLOGY_NAME), ref amountlabel, ref destUnitsVal); drProp[Strings.DATASHEET_SPPIC_CELL_AREA_COLUMN_NAME] = CalcCellArea(cellArea, FirstRast.CellSizeUnits, destUnitsVal); dsProp.Changes.Add(new ChangeRecord(this, "Added raster metadata")); dsProp.GetData().Rows.Add(drProp); dsProp.EndAddRows(); } }
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)); } }