/// <summary> /// get compare table for given scenario and model type /// </summary> /// <param name="scenario"></param> /// <param name="modelType"></param> /// <returns></returns> private SWATUnitColumnYearResult getCompareResult(Scenario scenario, SWATModelType modelType) { //get scenario result ScenarioResult compareResult = scenario.getModelResult(modelType, _result.Interval); if (compareResult == null) { throw new Exception("Can't find model " + modelType.ToString() + " in scenario " + scenario.Name); } if (compareResult.Status == ScenarioResultStatus.UNKNOWN) { throw new Exception("The status of model " + modelType.ToString() + " in scenario " + scenario.Name + " is unknown."); } if (compareResult.Status == ScenarioResultStatus.UNSUCCESS) { throw new Exception("The simulation of " + modelType.ToString() + " in scenario " + scenario.Name + " is not successful. Please check the model first."); } if (compareResult.Status == ScenarioResultStatus.NO_EXIST) { throw new Exception("The simulation result of " + modelType.ToString() + " in scenario " + scenario.Name + " doesn't exist. Please run the model first."); } //get unit SWATUnit unit = compareResult.getSWATUnit(_result.Unit.Type, _result.Unit.ID); if (unit == null) { throw new Exception("Can't find " + _result.Unit.Type + " " + _result.Unit.ID.ToString() + " in scenario " + scenario.Name + ",model " + modelType.ToString()); } SWATUnitResult unitResult = unit.getResult(_result.Name); if (unitResult == null) { throw new Exception("Can't find result " + _result.Name + " for " + _result.Unit.Type + " " + _result.Unit.ID.ToString() + " in scenario " + scenario.Name + ",model " + modelType.ToString()); } if (unitResult.Interval != _result.Interval) { throw new Exception("The interval for " + _result.Name + " for " + _result.Unit.Type + " " + _result.Unit.ID.ToString() + " in scenario " + scenario.Name + ",model " + modelType.ToString() + " is different from current result."); } return(unitResult.getResult(_col, _year)); }
private void updateTableAndChart() { _statistics = "No Statistics Data Available"; if (onDataStatisticsChanged != null) { onDataStatisticsChanged(this, new EventArgs()); } if (_resultType == null || _col == null) { return; } if (!this._scenario.Watershed.Results.ContainsKey(_resultType)) { return; } ArcSWAT.SWATUnitResult result = this._scenario.Watershed.Results[_resultType]; if (!result.Columns.Contains(_col)) { return; } int year = -1; if ((result.Interval == ArcSWAT.SWATResultIntervalType.DAILY || result.Interval == ArcSWAT.SWATResultIntervalType.MONTHLY) && yearCtrl1.DisplayByYear) { year = yearCtrl1.Year; } if (_compareResult == null) //don't compare { ArcSWAT.SWATUnitColumnYearResult oneResult = result.getResult(_col, year); this.tableView1.Result = oneResult; this.outputDisplayChart1.Result = oneResult; _statistics = oneResult.Statistics.ToString(); if (onDataStatisticsChanged != null) { onDataStatisticsChanged(this, new EventArgs()); } } else //compare { try { ArcSWAT.SWATUnitColumnYearCompareResult compare = result.getResult(_col, year).Compare(_compareResult); this.tableView1.CompareResult = compare; this.outputDisplayChart1.CompareResult = compare; _statistics = compare.Statistics.ToString(); if (onDataStatisticsChanged != null) { onDataStatisticsChanged(this, new EventArgs()); } } catch (System.Exception e) { SWAT_SQLite.showInformationWindow(e.ToString()); } } }
public SWATUnitColumnYearResult(string col, int year, SWATUnitResult result) : base(col, year) { _result = result; _colCompare = string.Format("{0}_{1}", _col, _result.Unit.Scenario.ID); }
/// <summary> /// update corresponding layer /// </summary> /// <param name="type"></param> public void drawLayer(string resultType, string col, DateTime date, ArcSWAT.ResultSummaryType summaryType) { if (_type != ArcSWAT.SWATUnitType.SUB && _type != ArcSWAT.SWATUnitType.RCH) { return; } if (_workingLayer == null) { return; } if (_unitList == null && _scenario != null) { if (_type == ArcSWAT.SWATUnitType.SUB) { _unitList = _scenario.Subbasins; } if (_type == ArcSWAT.SWATUnitType.RCH) { _unitList = _scenario.Reaches; } } if (_unitList == null) { return; } _resultColumn = col; _summaryType = summaryType; _resultDate = date; Debug.WriteLine("Draw Layer, " + _workingLayer.LegendText); Debug.WriteLine("Getting results..."); DateTime d = DateTime.Now; DataTable dt = _workingLayer.DataSet.DataTable; int resultIndex = dt.Columns.IndexOf(RESULT_COLUMN); int idIndex = dt.Columns.IndexOf(ID_COLUMN_NAME); if (summaryType == ArcSWAT.ResultSummaryType.AVERAGE_ANNUAL || summaryType == ArcSWAT.ResultSummaryType.ANNUAL) { int year = -1; if (summaryType == ArcSWAT.ResultSummaryType.ANNUAL) { year = date.Year; } Dictionary <int, double> ave_annual = _scenario.getAverageAnnualResults(_type, col, year); foreach (DataRow r in dt.Rows) { r[resultIndex] = ArcSWAT.ScenarioResultStructure.EMPTY_VALUE; int id = int.Parse(r[idIndex].ToString()); r[resultIndex] = ave_annual[id]; } } else { foreach (DataRow r in dt.Rows) { r[resultIndex] = ArcSWAT.ScenarioResultStructure.EMPTY_VALUE; int id = int.Parse(r[idIndex].ToString()); if (!_unitList.ContainsKey(id)) { continue; } ArcSWAT.SWATUnit unit = _unitList[id]; if (!unit.Results.ContainsKey(resultType)) { continue; } ArcSWAT.SWATUnitResult result = unit.Results[resultType]; if (!result.Columns.Contains(col)) { continue; } if (summaryType == ArcSWAT.ResultSummaryType.TIMESTEP) { r[resultIndex] = result.getData(col, date); } else if (summaryType == ArcSWAT.ResultSummaryType.ANNUAL) //annual { r[resultIndex] = result.getData(col, date.Year); } } } Debug.WriteLine(DateTime.Now.Subtract(d).TotalMilliseconds); Debug.WriteLine("setLayerSchema"); d = DateTime.Now; //update symbol setLayerSchema(_workingLayer); Debug.WriteLine(DateTime.Now.Subtract(d).TotalMilliseconds); ////update chart //onLayerSelectionChanged(type); if (onMapUpdated != null) { onMapUpdated(this, new EventArgs()); } }
/// <summary> /// update corresponding layer /// </summary> /// <param name="type"></param> public void drawLayer(string resultType, string col, DateTime date) { if (_type != ArcSWAT.SWATUnitType.SUB && _type != ArcSWAT.SWATUnitType.RCH) { return; } if (_workingLayer == null) { return; } if (_unitList == null && _scenario != null) { if (_type == ArcSWAT.SWATUnitType.SUB) { _unitList = _scenario.Subbasins; } if (_type == ArcSWAT.SWATUnitType.RCH) { _unitList = _scenario.Reaches; } } if (_unitList == null) { return; } Debug.WriteLine("Draw Layer, " + _workingLayer.LegendText); Debug.WriteLine("Getting results..."); DateTime d = DateTime.Now; DataTable dt = _workingLayer.DataSet.DataTable; int resultIndex = dt.Columns.IndexOf(RESULT_COLUMN); int idIndex = dt.Columns.IndexOf(ID_COLUMN_NAME); foreach (DataRow r in dt.Rows) { r[resultIndex] = ArcSWAT.ScenarioResultStructure.EMPTY_VALUE; int id = int.Parse(r[idIndex].ToString()); if (!_unitList.ContainsKey(id)) { continue; } ArcSWAT.SWATUnit unit = _unitList[id]; if (!unit.Results.ContainsKey(resultType)) { continue; } ArcSWAT.SWATUnitResult result = unit.Results[resultType]; if (!result.Columns.Contains(col)) { continue; } r[resultIndex] = result.getData(col, date); } Debug.WriteLine(DateTime.Now.Subtract(d).TotalMilliseconds); Debug.WriteLine("setLayerSchema"); d = DateTime.Now; //update symbol setLayerSchema(_workingLayer); Debug.WriteLine(DateTime.Now.Subtract(d).TotalMilliseconds); ////update chart //onLayerSelectionChanged(type); }
private void updateTableAndChart() { tableView1.DataTable = null; outputDisplayChart1.clear(); _statistics = "No Statistics Data Available"; if (onDataStatisticsChanged != null) { onDataStatisticsChanged(this, new EventArgs()); } if (_resultType == null || _col == null || _unit == null) { return; } if (!_unit.Results.ContainsKey(_resultType)) { return; } ArcSWAT.SWATUnitResult result = _unit.Results[_resultType]; if (!result.Columns.Contains(_col)) { return; } //consider year selection int year = -1; if ((result.Interval == ArcSWAT.SWATResultIntervalType.DAILY || result.Interval == ArcSWAT.SWATResultIntervalType.MONTHLY) && yearCtrl1.DisplayByYear) { year = yearCtrl1.Year; } //current working result ArcSWAT.SWATUnitColumnYearResult oneResult = result.getResult(_col, year); //set compare control //compareCtrl1.HasObervedData = (oneResult.ObservedData != null); //do the update if (compareCtrl1.CompareResult == null) //don't compare { if (oneResult.Table.Rows.Count == 0 && _type == ArcSWAT.SWATUnitType.HRU) { MessageBox.Show("No results for HRU " + _unit.ID.ToString() + ". For more results, please modify file.cio."); } this.tableView1.Result = oneResult; this.outputDisplayChart1.Result = oneResult; this._statistics = oneResult.SeasonStatistics(seasonCtrl1.Season).ToString(); if (oneResult.ObservedData != null) { this._statistics += " || Compare to Observed: " + oneResult.CompareWithObserved.SeasonStatistics(seasonCtrl1.Season).ToString() + ")"; } if (onDataStatisticsChanged != null) { onDataStatisticsChanged(this, new EventArgs()); } } else //compare { try { ArcSWAT.SWATUnitColumnYearCompareResult compare = null; if (compareCtrl1.CompareResult != null) { compare = oneResult.Compare(compareCtrl1.CompareResult); //compare to scenario this._statistics = string.Format("{0} vs {1}: {2}", result.Unit.Scenario.ModelType, compareCtrl1.CompareResult.ModelType, compare.SeasonStatistics(seasonCtrl1.Season)); if (oneResult.ObservedData != null) { //compare to observed this._statistics += " || "; this._statistics += string.Format("{0} vs Observed: {1}", result.Unit.Scenario.ModelType, oneResult.CompareWithObserved.SeasonStatistics(seasonCtrl1.Season)); ArcSWAT.SWATUnitColumnYearResult comparedData = compare.ComparedData as ArcSWAT.SWATUnitColumnYearResult; this._statistics += " || "; this._statistics += string.Format("{0} vs Observed: {1}", compareCtrl1.CompareResult.ModelType, comparedData.CompareWithObserved.SeasonStatistics(seasonCtrl1.Season)); } } else { compare = oneResult.CompareWithObserved; this._statistics = compare.SeasonStatistics(seasonCtrl1.Season).ToString(); } this.tableView1.CompareResult = compare; this.outputDisplayChart1.CompareResult = compare; if (onDataStatisticsChanged != null) { onDataStatisticsChanged(this, new EventArgs()); } } catch (System.Exception e) { SWAT_SQLite.showInformationWindow(e.ToString()); } } }
private void TableResultsCtrl_Load(object sender, EventArgs e) { cmbIDs.SelectedIndexChanged += (s, ee) => { _unit = _units[Convert.ToInt32(cmbIDs.SelectedItem.ToString())]; if (_unit == null) { return; } lblInfo.Text = _unit.ToStringBasicInfo(); if (cmbResultTypes.Items.Count > 0) { _result = _unit.Results[cmbResultTypes.SelectedItem.ToString()]; updateResult(); return; } cmbResultTypes.Items.Clear(); foreach (string type in _unit.Results.Keys) { cmbResultTypes.Items.Add(type); } if (cmbResultTypes.Items.Count > 0) { cmbResultTypes.SelectedIndex = 0; } }; cmbResultTypes.SelectedIndexChanged += (s, ee) => { if (_unit == null) { return; } _result = _unit.Results[cmbResultTypes.SelectedItem.ToString()]; if (_result == null) { return; } cmbColumns.Items.Clear(); foreach (string col in _result.Columns) { cmbColumns.Items.Add(col); } if (cmbColumns.Items.Count > 0) { cmbColumns.SelectedIndex = 0; } updateResult(); }; cmbColumns.SelectedIndexChanged += (s, ee) => { //to-do change the char while columns changes if (_result == null) { return; } updateResult(); }; }