Пример #1
0
        public string getResultStatus(SWATModelType modelType)
        {
            StringBuilder status = new StringBuilder();

            for (int j = Convert.ToInt32(SWATResultIntervalType.MONTHLY); j <= Convert.ToInt32(SWATResultIntervalType.YEARLY); j++)
            {
                SWATResultIntervalType interval = (SWATResultIntervalType)j;
                ScenarioResult         result   = getModelResult(modelType, interval);
                if (result == null)
                {
                    continue;
                }

                if (status.Length > 0)
                {
                    status.Append(";");
                }
                status.Append(interval);
                status.Append(":");
                if (result.Status != ScenarioResultStatus.NORMAL)
                {
                    status.Append(result.Status);
                }
                else
                {
                    status.Append(string.Format("{0:yyyy-MM-dd hh:mm:ss}", result.SimulationTime));
                }
            }
            return(status.ToString());
        }
Пример #2
0
 public ScenarioResult(string databasePath,Scenario scen, SWATModelType modelType, SWATResultIntervalType interval)
 {
     _databasePath = databasePath;
     _parentScenario = scen;
     _modelType = modelType;
     checkStatus();
     if (Status == ScenarioResultStatus.NORMAL)
          loadModelStructure();
 }
Пример #3
0
        public static string getSWATExecutableName(SWATModelType modelType)
        {
            int index = Convert.ToInt32(modelType);

            if (index >= 0 && index < EXE_NAMES.Length)
            {
                return(EXE_NAMES[index]);
            }
            return("");
        }
Пример #4
0
        public ScenarioResult getModelResult(SWATModelType modelType, SWATResultIntervalType interval)
        {
            string id = getResultID(modelType, interval);

            if (_results.ContainsKey(id))
            {
                return(_results[id]);
            }
            return(null);
        }
Пример #5
0
        public static string getDatabaseName(SWATModelType modelType, SWATResultIntervalType interval)
        {
            int index = Convert.ToInt32(modelType);

            if (index >= 0 && index < DATABASE_NAMES.Length)
            {
                return(DATABASE_NAMES[index] + "_" + interval.ToString().ToLower() + DATABASE_NAME_EXT);
            }

            return("");
        }
Пример #6
0
 public ScenarioResult(string databasePath, Scenario scen, SWATModelType modelType, SWATResultIntervalType interval)
 {
     _databasePath   = databasePath;
     _parentScenario = scen;
     _modelType      = modelType;
     checkStatus();
     if (Status == ScenarioResultStatus.NORMAL)
     {
         loadModelStructure();
     }
 }
Пример #7
0
        /// <summary>
        /// Re-read results when it's simulated again.
        /// </summary>
        /// <param name="modelType"></param>
        public void reReadResults(SWATModelType modelType, SWATResultIntervalType interval)
        {
            ScenarioResult result = getModelResult(modelType, interval);

            if (result != null)
            {
                _results[getResultID(modelType, interval)] =
                    new ScenarioResult(
                        _modelfolder + @"\" + ScenarioResultStructure.getDatabaseName(modelType, interval), this, modelType, interval);
            }
        }
Пример #8
0
        private SWATUnitColumnYearCompareResult Compare(Scenario scenario, SWATModelType modelType)
        {
            string tableID = string.Format("{0}_{1}", scenario.Name, modelType);

            if (!_compares.ContainsKey(tableID))
            {
                _compares.Add(tableID,
                              new SWATUnitColumnYearCompareResult(this, this.getCompareResult(scenario, modelType)));
            }

            return(_compares[tableID]);
        }
Пример #9
0
        public SWATUnitColumnYearCompareResult Compare(SWATModelType modelType)
        {
            if (modelType == SWATModelType.UNKNOWN)
            {
                throw new Exception("Unknown model type!");
            }
            if (_result.Unit.Scenario.ModelType == modelType)
            {
                throw new Exception("Compared model type is same with current scenario.");
            }

            return(Compare(_result.Unit.Scenario.Scenario, modelType));
        }
Пример #10
0
        /// <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));
        }
Пример #11
0
        public Scenario(string f, Project prj)
            : base(f)
        {
            if (IsValid)
            {
                _prj         = prj;
                _modelfolder = Folder + DEFAULT_TXTINOUT_NAME;
                if (!Directory.Exists(_modelfolder))
                {
                    _modelfolder = null;
                    _isValid     = false;
                    _error       = _modelfolder + " doesn't exist!";
                    return;
                }
                _name = (new DirectoryInfo(Folder)).Name;

                //Regular SWAT and CanSWAT could run one a same model
                _hasResults = false;
                for (int i = Convert.ToInt32(ArcSWAT.SWATModelType.SWAT_488); i <= Convert.ToInt32(ArcSWAT.SWATModelType.CanSWAT); i++)
                {
                    SWATModelType modelType = (SWATModelType)i;
                    for (int j = Convert.ToInt32(SWATResultIntervalType.MONTHLY); j <= Convert.ToInt32(SWATResultIntervalType.YEARLY); j++)
                    {
                        SWATResultIntervalType interval = (SWATResultIntervalType)j;
                        ScenarioResult         result   = new ScenarioResult(
                            _modelfolder + @"\" + ScenarioResultStructure.getDatabaseName(modelType, interval),
                            this, modelType, interval);
                        if (result.Status == ScenarioResultStatus.NORMAL)
                        {
                            _hasResults = true;
                        }
                        _results.Add(getResultID(modelType, interval), result);
                    }
                }
            }
        }
        /// <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 SWATUnitColumnYearCompareResult Compare(Scenario scenario, SWATModelType modelType)
        {
            string tableID = string.Format("{0}_{1}", scenario.Name, modelType);
            if (!_compares.ContainsKey(tableID))
                  _compares.Add(tableID,
                      new SWATUnitColumnYearCompareResult(this, this.getCompareResult(scenario,modelType)));

            return _compares[tableID];
        }
        public SWATUnitColumnYearCompareResult Compare(SWATModelType modelType)
        {
            if (modelType == SWATModelType.UNKNOWN) throw new Exception("Unknown model type!");
            if (_result.Unit.Scenario.ModelType == modelType)
                throw new Exception("Compared model type is same with current scenario.");

            return Compare(_result.Unit.Scenario.Scenario, modelType);
        }
Пример #15
0
 private string getResultID(SWATModelType modelType, SWATResultIntervalType interval)
 {
     return(modelType.ToString() + "_" + interval.ToString());
 }