Esempio n. 1
0
        protected override void PerformTimestep(ICollection <EngineOutputItem> requiredOutputItems)
        {
            //--- perform calculation ---

            //Status = LinkableComponentStatus.Updating;

            if (_Inpath != null)
            {
                ESRI.ArcGIS.SpatialAnalystTools.Fill fill = new ESRI.ArcGIS.SpatialAnalystTools.Fill();
                fill.in_surface_raster = _Inpath;


                _Outpath = _outpath;

                if (_Outpath == null)
                {
                    //determine outpath
                    string[] inpath = _Inpath.Split('\\');
                    int      l      = inpath[inpath.Length - 1].Length;
                    _Outpath = _Inpath.Remove(_Inpath.Length - l);

                    string name = _OutputItem.ElementSet.Caption;
                    name = name.Replace(" ", "");
                    if (name.Length >= 9)
                    {
                        name = name.Remove(9);
                    }

                    _Outpath += name + "_fil";
                }

                fill.out_surface_raster = _Outpath;


                GP.Execute(fill, null);
                if (GP.MaxSeverity == 2)
                {
                    object sev = 2;
                    throw new Exception("Unable to perform raster Fill operationESRI ERROR: " + GP.GetMessages(ref sev));
                }



                numProcessed++;
                _currentTime.AddSeconds(_timeStepLengthInSeconds);
                this._outputExchangeItems[0].SetSingleTime(this.GetCurrentTime(true));
                this._inputExchangeItems[0].SetSingleTime(this.GetCurrentTime(true));

                //Status = LinkableComponentStatus.Updated;

                //clear inputs
                this._Inpath = null;

                //if (numProcessed >= requiredOutputItems.Count)
                //{
                //    //_currentTime = _simulationEnd;
                //    Status = LinkableComponentStatus.Done;
                //}
            }
        }
Esempio n. 2
0
        public void AddSecondsTest()
        {
            var t1 = new Time(0, 0, 0, 0);

            t1.AddSeconds(30);
            var t2 = new Time(0, 0, 30, 0);

            Assert.AreEqual(t2, t1);

            t1 = new Time(23, 59, 30, 0);
            t1.AddSeconds(30);
            t2 = new Time(0, 0, 0, 0);
            Assert.AreEqual(t2, t1);

            t1 = new Time(0, 0, 0, 0);
            t1.AddSeconds(60);
            t2 = new Time(0, 1, 0, 0);
            Assert.AreEqual(t2, t1);

            t1 = new Time(0, 0, 15, 0);
            t1.AddSeconds(-15);
            t2 = new Time(0, 0, 0, 0);
            Assert.AreEqual(t2, t1);

            t1 = new Time(0, 1, 0, 0);
            t1.AddSeconds(-60);
            t2 = new Time(0, 0, 0, 0);
            Assert.AreEqual(t2, t1);

            t1 = new Time(0, 0, 15, 0);
            t1.AddSeconds(-30);
            t2 = new Time(23, 59, 45, 0);
            Assert.AreEqual(t2, t1);
        }
Esempio n. 3
0
 public TimeStampRecord(string rec, DateTime flightdate)
     : base(rec)
 {
     Time = flightdate.Date;
     Time = Time.AddHours(Convert.ToInt32(rec.Substring(1, 2)));
     Time = Time.AddMinutes(Convert.ToInt32(rec.Substring(3, 2)));
     Time = Time.AddSeconds(Convert.ToInt32(rec.Substring(5, 2)));
 }
Esempio n. 4
0
 public async void run()
 {
     while (true)
     {
         Time = Time.AddSeconds(_offset);
         await Task.Delay(1000);
     }
 }
Esempio n. 5
0
        public bool IsNearby(DateTime TargetTime)
        {
            if (Time == null)
            {
                return(false);
            }

            return(Time.AddSeconds(-5) > TargetTime && TargetTime < Time.AddSeconds(5));
        }
Esempio n. 6
0
        protected override void PerformTimestep(ICollection <EngineOutputItem> requiredOutputItems)
        {
            // Compute a "steady state" solution for this timestep. All water added to storage
            // are either leaked or flows out of the model

            // Let it rain/runoff equally on each node, store the amount of water in storage
            for (int i = 0; i < _numberOfNodes; i++)
            {
                _inflowStorage[i] += _runoff * _timeStepLengthInSeconds;
            }

            // From up-river and down (when ground water level is -10):
            // half of the storage flows to the next node (added to its storage)
            // and half of it leaks. All storages are emptied in the process.
            // Leakage decays as ground water levels increases. At -5 m the leakage
            // is zero. At 0 and above, the leakage is negative (inflow into river)
            for (int i = 0; i < _numberOfNodes - 1; i++)
            {
                double leakFac = -_groundWaterLevel[i] * 0.1 - 0.5;
                leakFac = Math.Min(Math.Max(leakFac, -0.5), 0.5);
                double totalFlow = _inflowStorage[i] / _timeStepLengthInSeconds;
                _flow[i]               = (1 - leakFac) * totalFlow;
                _leakage[i]            = leakFac * totalFlow;
                _inflowStorage[i + 1] += _inflowStorage[i] - _leakage[i] * _timeStepLengthInSeconds;
            }

            // Calculate outflow from last node (for mass conservation checking)
            _lastNodeOutflow = _inflowStorage[_numberOfNodes - 1] / _timeStepLengthInSeconds;

            for (int i = 0; i < _numberOfNodes; i++)
            {
                _inflowStorage[i] = 0;
            }

            // Increase engine's current time
            // Update the exchange items time info

            _currentTime.AddSeconds(_timeStepLengthInSeconds);

            //foreach (EngineOutputItem engineOutputItem in Outputs)
            //{
            //    if (flowItemsAsSpan)
            //    {
            //        engineOutputItem.SetSingleTimeSpan(currentTime.StampAsModifiedJulianDay - timeStepLengthInDays,
            //                                           timeStepLengthInDays);
            //    }
            //    else
            //    {
            //        engineOutputItem.SetSingleTime(currentTime.StampAsModifiedJulianDay);
            //    }
            //    if (engineOutputItem.StoreValuesInExchangeItem)
            //    {
            //        engineOutputItem.Values = GetOutputValuesFromComputationalCore(engineOutputItem);
            //    }
            //}
        }
Esempio n. 7
0
 public void UpdateReminderTime()
 {
     if (IsRepeating)
     {
         while (Time <= DateTime.UtcNow)
         {
             Time = Time.AddSeconds(Frequency);
         }
     }
 }
Esempio n. 8
0
 protected override void PerformTimestep(ICollection <EngineOutputItem> requiredOutputItems)
 {
     // Increase engine's current time, update the exchange items accordingly
     _currentTime.AddSeconds(_timeStepLengthInSeconds);
     this.TimeExtent.Times[0] = _currentTime;
     foreach (EngineOutputItem engineOutputItem in requiredOutputItems)
     {
         engineOutputItem.TimeSet.SetSingleTime(_currentTime);
     }
 }
Esempio n. 9
0
        public override ITime GetInputTime(bool asStamp)
        {
            if (!asStamp)
            {
                throw new NotSupportedException();
            }
            Time targetTime = new Time(_currentTime);

            targetTime.AddSeconds(_timeStepLengthInSeconds);
            return(targetTime);
        }
Esempio n. 10
0
        public void AddSeconds_ZeroSecondsArgument_ShouldReturnCorrectTime()
        {
            // Arrange
            Time time = new Time();

            // Act
            time.AddSeconds(0);
            // Assert
            time.Hours.Should().Be(0);
            time.Minutes.Should().Be(0);
            time.Seconds.Should().Be(0);
        }
Esempio n. 11
0
        public void AddSeconds_NegativeNumberArgument_ShouldReturnCorrectTime()
        {
            // Arrange
            Time time = new Time();

            // Act
            time.AddSeconds(-3661);
            // Assert
            time.Hours.Should().Be(-1);
            time.Minutes.Should().Be(-1);
            time.Seconds.Should().Be(-1);
        }
Esempio n. 12
0
        public void ShouldAddSeconds()
        {
            // Given
            const double value = 123.456;
            var          time  = new Time(12345);

            // When
            var result = time.AddSeconds(value);

            // Then
            Assert.AreEqual(time.TotalSeconds + value, result.TotalSeconds, TimeInaccuracy);
        }
Esempio n. 13
0
        public void AddSecondTest()
        {
            int hour    = 8;
            int mins    = 0;
            int second  = 1;
            var target  = new Time(hour, mins, second);
            int second1 = 1;

            target = target.AddSeconds(second1);

            var expect = new TimeSpan(hour, mins, second1 + second);

            Assert.AreEqual(expect.Ticks, target.Ticks);
        }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        if (!Away)
        {
            FastForward = Input.GetButton(FastForwardButton);
        }

        DateTime previousTime = Time;

        Time = Time.AddSeconds((double)(UnityEngine.Time.deltaTime * gameTimeScale));

        if (previousTime.Day != Time.Day)
        {
            NewDay();
        }
    }
        static void WriteDailyTicks(TeaFile <Tick> tf, Time day, bool isGoodDay)
        {
            Time t   = day.AddHours(9);    // start trading session at 09:00
            Time end = day.AddHours(17.5); // end trading session at 17:30

            while (t < end)
            {
                //  on a good day, we write many ticks, on a bad day however only 1 percent as much
                if (isGoodDay || DrawRandom(1))
                {
                    double p = r.NextDouble() * 100000.0;
                    tf.Write(new Tick {
                        Time = t, Price = p, Volume = 10
                    });
                }
                t = t.AddSeconds(15 + r.Next(0, 20));
            }
        }
Esempio n. 16
0
        private void OnTick(object sender, EventArgs e)
        {
            if (_pause)
            {
                return;
            }

            int seconds = (int)Math.Pow(60.0, GameSpeed);

            if (GameSpeed > 2)
            {
                seconds = (int)TimeSpan.FromDays(1).TotalSeconds;
            }

            for (int i = 0; i < seconds; i++)
            {
                if (Time.Second == 0)
                {
                    for (int j = _gameObjects.Count - 1; j >= 0; j--)
                    {
                        _gameObjects[j].OnMinute();
                    }
                }

                if (Time.Hour == 0 && Time.Minute == 0 && Time.Second == 0)
                {
                    for (int j = _gameObjects.Count - 1; j >= 0; j--)
                    {
                        _gameObjects[j].OnDayBegin();
                    }
                    OnDayBegin();
                }

                Time = Time.AddSeconds(1);
            }

            Tick?.Invoke();
        }
Esempio n. 17
0
        private void SimulateTime(float deltaTime)
        {
            if (TimePassage == TimePassage.Paused)
            {
                return;
            }

            var speed = NormalSpeedPerSeconds;

            if (TimePassage == TimePassage.FastSpeed)
            {
                speed *= FastSpeedMultiplier;
            }
            else if (TimePassage == TimePassage.SuperSpeed)
            {
                speed *= SuperSpeedMultiplier;
            }
            else if (TimePassage == TimePassage.CustomSpeed)
            {
                speed = CustomSpeed;
            }

            Time = Time.AddSeconds(speed * deltaTime);
        }
Esempio n. 18
0
 void timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     Time = Time.AddSeconds(1);
 }
Esempio n. 19
0
        public void AddSeconds()
        {
            Time t = new Time(2010, 2, 3);
            Time t2 = t.AddSeconds(5);

            (t2.NetTime - t.NetTime).TotalSeconds.Should().Be(5);
        }
Esempio n. 20
0
        protected override void PerformTimestep(ICollection <EngineOutputItem> requiredOutputItems)
        {
            //--- perform calculation ---

            //this.Status = LinkableComponentStatus.Updating;

            if (_Inpath != null)
            {
                ESRI.ArcGIS.SpatialAnalystTools.Spline spline = new ESRI.ArcGIS.SpatialAnalystTools.Spline();
                spline.in_point_features = _Inpath;
                spline.z_field           = "Z";
                spline.number_points     = 12;
                spline.weight            = 0.1;
                spline.spline_type       = "REGULARIZED";
                spline.cell_size         = 10;

                _Outpath = _outpath;

                if (_Outpath == null)
                {
                    //determine outpath
                    string[] inpath = _Inpath.Split('\\');
                    int      l      = inpath[inpath.Length - 1].Length;
                    _Outpath = _Inpath.Remove(_Inpath.Length - l);

                    string name = _OutputItem.ElementSet.Caption;
                    name = name.Replace(" ", "");
                    if (name.Length >= 9)
                    {
                        name = name.Remove(9);
                    }

                    _Outpath += name + "_spl";
                }
                spline.out_raster = _Outpath;

                //check to see if this file has already been created
                if (!_outputFiles.ContainsKey(_Outpath))
                {
                    _outputFiles.Add(_Outpath, true);

                    GP.Execute(spline, null);
                    if (GP.MaxSeverity == 2)
                    {
                        object sev = 2;
                        throw new Exception("Spline Interpolation Failed. Input file path = " + _Inpath + "  ESRI ERROR: " + GP.GetMessages(ref sev));
                    }
                }

                //clear inputs
                //this._Inpath = null;
            }


            numProcessed++;


            _currentTime.AddSeconds(_timeStepLengthInSeconds);
            this._outputExchangeItems[0].SetSingleTime(this.GetCurrentTime(true));
            this._inputExchangeItems[0].SetSingleTime(this.GetCurrentTime(true));

            //if (numProcessed >= requiredOutputItems.Count)
            //{
            //    _currentTime = _simulationEnd;
            //}
            //else
            //    this.Status = LinkableComponentStatus.Updated;
        }
Esempio n. 21
0
        public void AddSecondTest()
        {
            int hour = 8;
            int mins = 0;
            int second = 1;
            var target = new Time(hour, mins, second);
            int second1 = 1;
            target = target.AddSeconds(second1);

            var expect = new TimeSpan(hour, mins, second1 + second);
            Assert.AreEqual(expect.Ticks, target.Ticks);
        }