コード例 #1
0
ファイル: Project.cs プロジェクト: PolyHydrat/swat-eclipse
        public Project(string prj) : base(prj)
        {
            Debug.WriteLine("Information: Intialize ArcSWAT project using " + prj);

            if (!IsValid)
            {
                return;
            }

            _spatial = new Spatial(Folder + DEFAULT_WATERSHED_FOLDER);
            if (!_spatial.IsValid)
            {
                _isValid = false; _error = _spatial.Error; return;
            }

            _scenarios = Scenario.FromProjectFolder(Folder + DEFAULT_SCENARIOS_FOLDER, this);
            if (_scenarios.Count == 0)
            {
                _isValid = false; _error = "No Scenarios found!"; return;
            }

            _observation_daily   = new ObservationData(Folder + DEFAULT_OBSERVATION_DATA_FILE_DAILY);
            _observation_monthly = new ObservationData(Folder + DEFAULT_OBSERVATION_DATA_FILE_MONTHLY);
            _observation_yearly  = new ObservationData(Folder + DEFAULT_OBSERVATION_DATA_FILE_YEARLY);
        }
コード例 #2
0
        public SWATUnitObservationData(SWATUnitColumnYearResult result, ObservationData parent)
        {
            _parentData = parent;

            _id = result.UnitResult.Unit.ID;
            _unitType = result.UnitResult.Unit.Type;
            _col = result.Column;
            _startYear = result.UnitResult.Unit.Scenario.StartYear;
            _endYear = result.UnitResult.Unit.Scenario.EndYear;
        }
コード例 #3
0
        public SWATUnitObservationData(SWATUnitColumnYearResult result, ObservationData parent)
        {
            _parentData = parent;

            _id        = result.UnitResult.Unit.ID;
            _unitType  = result.UnitResult.Unit.Type;
            _col       = result.Column;
            _startYear = result.UnitResult.Unit.Scenario.StartYear;
            _endYear   = result.UnitResult.Unit.Scenario.EndYear;
        }
コード例 #4
0
 public SWATUnitObservationData(int id, SWATUnitType unitType, 
     string dataType,
     int startYear, int endYear,
     ObservationData parent)
 {
     _parentData = parent;
     _id = id;
     _unitType = unitType;
     _col = dataType;
     _startYear = startYear;
     _endYear = endYear;
 }
コード例 #5
0
 public SWATUnitObservationData(int id, SWATUnitType unitType,
                                string dataType,
                                int startYear, int endYear,
                                ObservationData parent)
 {
     _parentData = parent;
     _id         = id;
     _unitType   = unitType;
     _col        = dataType;
     _startYear  = startYear;
     _endYear    = endYear;
 }
コード例 #6
0
ファイル: Project.cs プロジェクト: ajarbancina/swat-eclipse
        public Project(string prj)
            : base(prj)
        {
            Debug.WriteLine("Information: Intialize ArcSWAT project using " + prj);

            if (!IsValid) return;

            _spatial = new Spatial(Folder + DEFAULT_WATERSHED_FOLDER);
            if (!_spatial.IsValid) { _isValid = false; _error = _spatial.Error; return; }

            _scenarios = Scenario.FromProjectFolder(Folder + DEFAULT_SCENARIOS_FOLDER,this);
            if (_scenarios.Count == 0) { _isValid = false; _error = "No Scenarios found!"; return; }

            _observation_daily = new ObservationData(Folder + DEFAULT_OBSERVATION_DATA_FILE_DAILY);
            _observation_monthly = new ObservationData(Folder + DEFAULT_OBSERVATION_DATA_FILE_MONTHLY);
            _observation_yearly = new ObservationData(Folder + DEFAULT_OBSERVATION_DATA_FILE_YEARLY);
        }
コード例 #7
0
        protected override void read()
        {
            if (_table != null)
            {
                return;
            }
            if (_parentData == null)
            {
                return;
            }
            if (_parentData.Observation == null)
            {
                return;
            }

            //get table name
            //each observed data for one corresponding table in the database
            string tableName =
                ObservationData.getTableName(_parentData.UnitType, _parentData.ID, _col);

            //get filter based on given year
            string filter = "";

            if (_year > 0)                                                                                                                       //specific year
            {
                filter += string.Format("{0} >= '{1}-01-01' and {0} <= '{2}-12-31'", ObservationData.OBSERVATION_COLUMN_DATE, _year - 1, _year); //read two years of data to consider hydrological year
            }
            else //all years in between start and end year
            {
                if (_parentData.StartYear > 0)
                {
                    filter += string.Format("{0} >= '{1}-01-01'", ObservationData.OBSERVATION_COLUMN_DATE, _parentData.StartYear);
                }
                if (_parentData.EndYear > 0)
                {
                    if (filter.Length > 0)
                    {
                        filter += " and ";
                    }
                    filter += string.Format("{0} <= '{1}-01-01'", ObservationData.OBSERVATION_COLUMN_DATE, _parentData.EndYear);
                }
            }
            if (filter.Length > 0)
            {
                filter = " where " + filter;
            }

            DataTable dt = _parentData.Observation.GetDataTable(
                string.Format("select * from [{0}] {1}", tableName, filter));

            if (dt.Columns.Count == 2)
            {
                //add a date time column and convert time from text to date
                dt.Columns.Add(SWATUnitResult.COLUMN_NAME_DATE, typeof(DateTime));
                DateTime d = DateTime.Now;
                foreach (DataRow r in dt.Rows)
                {
                    RowItem item = new RowItem(r);
                    if (DateTime.TryParse(item.getColumnValue_String(0), out d))
                    {
                        r[2] = d;
                    }
                }

                dt.Columns[1].ColumnName = _col;
                _table = dt;
            }
        }
コード例 #8
0
        private void getPerformanceTableForType(int splitYear, bool withSplitYear, DataTable dt, SWATUnitType type, StatisticCompareType statisticType)
        {
            Dictionary <int, SWATUnit> units = null;

            if (type == SWATUnitType.RCH)
            {
                units = _reaches;
            }
            else if (type == SWATUnitType.RES)
            {
                units = _reservoirs;
            }
            if (units == null)
            {
                return;
            }

            StringCollection ids = new StringCollection();

            foreach (SWATUnit oneUnit in units.Values)
            {
                foreach (SWATUnitResult unitResult in oneUnit.Results.Values)
                {
                    foreach (string col in unitResult.Columns)
                    {
                        SWATUnitColumnYearResult oneResult = unitResult.getResult(col, -1);
                        if (oneResult.CompareWithObserved == null)
                        {
                            continue;
                        }

                        //avoid repeat records, like TSS
                        string id = string.Format("{0}_{1}_{2}", unitResult.Unit.Type, unitResult.Unit.ID, col);
                        if (ids.Contains(id))
                        {
                            continue;
                        }
                        ids.Add(id);

                        //create a new row
                        DataRow r = dt.NewRow();
                        r[0] = unitResult.Unit.Type.ToString();
                        r[1] = unitResult.Unit.ID;
                        r[2] = ObservationData.getObservationColumnFromSWAT(col);

                        double total = oneResult.CompareWithObserved.Statistics.Statistic("", statisticType);
                        r[3] = Math.Round(total, 4);
                        if (withSplitYear)
                        {
                            double before = ScenarioResultStructure.EMPTY_VALUE;
                            double after  = ScenarioResultStructure.EMPTY_VALUE;
                            oneResult.CompareWithObserved.Statistics.Statistic(splitYear, statisticType, out before, out after);

                            r[4] = Math.Round(before, 4);
                            r[5] = Math.Round(after, 4);
                        }
                        dt.Rows.Add(r);
                    }
                }
            }
        }