public void GetDiscreteTime()
        {
            LinkableTimeSeriesGroup linkableTimeSeriesGroup = new LinkableTimeSeriesGroup();

            linkableTimeSeriesGroup.Initialize(arguments);

            //testing timespan series (exchange item 1), first record
            ITimeSpan time = (ITimeSpan)linkableTimeSeriesGroup.GetDiscreteTime(linkableTimeSeriesGroup.GetOutputExchangeItem(0).Quantity, linkableTimeSeriesGroup.GetOutputExchangeItem(0).ElementSet, 0);

            System.DateTime startTime = new TimeStamp(new TimeSpan(time).Start).ToDateTime();
            System.DateTime endTime   = new TimeStamp(new TimeSpan(time).End).ToDateTime();
            Assert.AreEqual(new System.DateTime(2010, 1, 1), startTime);
            Assert.AreEqual(new System.DateTime(2010, 1, 3), endTime);

            //testing timespan series (exchange item 1), last record
            time      = (ITimeSpan)linkableTimeSeriesGroup.GetDiscreteTime(linkableTimeSeriesGroup.GetOutputExchangeItem(0).Quantity, linkableTimeSeriesGroup.GetOutputExchangeItem(0).ElementSet, 9);
            startTime = new TimeStamp(new TimeSpan(time).Start).ToDateTime();
            endTime   = new TimeStamp(new TimeSpan(time).End).ToDateTime();
            Assert.AreEqual(new System.DateTime(2010, 1, 19), startTime);
            Assert.AreEqual(new System.DateTime(2010, 1, 21), endTime);

            //testing timestamp series (exchange item 1), first record
            ITimeStamp timestamp = (ITimeStamp)linkableTimeSeriesGroup.GetDiscreteTime(linkableTimeSeriesGroup.GetOutputExchangeItem(1).Quantity, linkableTimeSeriesGroup.GetOutputExchangeItem(1).ElementSet, 0);

            Assert.AreEqual(new System.DateTime(2010, 1, 1), new TimeStamp(timestamp).ToDateTime());

            //testing timestamp series (exchange item 1), last record
            timestamp = (ITimeStamp)linkableTimeSeriesGroup.GetDiscreteTime(linkableTimeSeriesGroup.GetOutputExchangeItem(1).Quantity, linkableTimeSeriesGroup.GetOutputExchangeItem(1).ElementSet, 5);
            Assert.AreEqual(new System.DateTime(2010, 1, 11), new TimeStamp(timestamp).ToDateTime());
        }
示例#2
0
        public IEnumerable <ReceivedAnswers> GetResult(ITimeStamp timestamp)
        {
            var startTime = new BsonDateTime(timestamp.StartTime);
            var endTime   = new BsonDateTime(timestamp.EndTime);

            return(_repository.GetSingle(a => a.SubmitDateTime > startTime && a.SubmitDateTime < endTime));
        }
示例#3
0
 /// <summary>
 /// Adds the given element to the collection
 /// </summary>
 /// <param name="item">The item to add</param>
 public override void Add(IModelElement item)
 {
     if ((this._parent.Q == null))
     {
         IQuality qCasted = item.As <IQuality>();
         if ((qCasted != null))
         {
             this._parent.Q = qCasted;
             return;
         }
     }
     if ((this._parent.T == null))
     {
         ITimeStamp tCasted = item.As <ITimeStamp>();
         if ((tCasted != null))
         {
             this._parent.T = tCasted;
             return;
         }
     }
     if ((this._parent.PulseConfig == null))
     {
         IPulseConfig pulseConfigCasted = item.As <IPulseConfig>();
         if ((pulseConfigCasted != null))
         {
             this._parent.PulseConfig = pulseConfigCasted;
             return;
         }
     }
 }
示例#4
0
        public int FetchCorrectAnswerCount(ITimeStamp timestamp)
        {
            var startTime     = new BsonDateTime(timestamp.StartTime);
            var endTime       = new BsonDateTime(timestamp.EndTime);
            var correctAnswer = _repository.GetSingle(a => a.Correct == 1 && a.SubmitDateTime > startTime && a.SubmitDateTime < endTime);

            return(correctAnswer.Count());
        }
示例#5
0
 /// <summary>
 /// 静态构造函数
 /// </summary>
 static ValidateFactory()
 {
     CallFrequencyInstance = new DefaultCallFrequency();
     IPAddressInstance     = new DefaultIPAddress();
     RegisterInstance      = new DefaultRegister();
     SecurityInstance      = new DefaultSecurity();
     TimeStampInstance     = new DefaultTimeStamp();
 }
示例#6
0
        public void Run(ITimeStamp time)
        {
            //IScalarSet scalarSet = new ScalarSet();

            ScalarSet scalarSet = new ScalarSet((IScalarSet)_link.SourceComponent.GetValues(time, _link.ID));

            _earliestInputTime.ModifiedJulianDay = time.ModifiedJulianDay;
            _resultsBuffer.AddValues(time, scalarSet);
        }
示例#7
0
 /// <summary>
 /// Adds the given element to the collection
 /// </summary>
 /// <param name="item">The item to add</param>
 public override void Add(IModelElement item)
 {
     if ((this._parent.T == null))
     {
         ITimeStamp tCasted = item.As <ITimeStamp>();
         if ((tCasted != null))
         {
             this._parent.T = tCasted;
             return;
         }
     }
 }
示例#8
0
 /// <summary>
 /// Adds the given element to the collection
 /// </summary>
 /// <param name="item">The item to add</param>
 public override void Add(IModelElement item)
 {
     if ((this._parent.Q == null))
     {
         IQuality qCasted = item.As <IQuality>();
         if ((qCasted != null))
         {
             this._parent.Q = qCasted;
             return;
         }
     }
     if ((this._parent.OperTm == null))
     {
         ITimeStamp operTmCasted = item.As <ITimeStamp>();
         if ((operTmCasted != null))
         {
             this._parent.OperTm = operTmCasted;
             return;
         }
     }
 }
示例#9
0
 /// <summary>
 /// Adds the given element to the collection
 /// </summary>
 /// <param name="item">The item to add</param>
 public override void Add(IModelElement item)
 {
     if ((this._parent.ValWTr == null))
     {
         IValWithTrans valWTrCasted = item.As <IValWithTrans>();
         if ((valWTrCasted != null))
         {
             this._parent.ValWTr = valWTrCasted;
             return;
         }
     }
     if ((this._parent.T == null))
     {
         ITimeStamp tCasted = item.As <ITimeStamp>();
         if ((tCasted != null))
         {
             this._parent.T = tCasted;
             return;
         }
     }
     if ((this._parent.Q == null))
     {
         IQuality qCasted = item.As <IQuality>();
         if ((qCasted != null))
         {
             this._parent.Q = qCasted;
             return;
         }
     }
     if ((this._parent.SubVal == null))
     {
         IValWithTrans subValCasted = item.As <IValWithTrans>();
         if ((subValCasted != null))
         {
             this._parent.SubVal = subValCasted;
             return;
         }
     }
 }
示例#10
0
        private ListViewItem GetItem(IEvent Event)
        {
            string[] subItems = new string[5];
            subItems[0] = (_eventsCount++).ToString();
            subItems[1] = Event.Type.ToString();
            subItems[2] = Event.Description;

            ILinkableComponent sender = Event.Sender;

            if (sender != null)
            {
                subItems[3] = sender.ModelID;
            }

            ITimeStamp simTime = Event.SimulationTime;

            if (simTime != null)
            {
                subItems[4] = CalendarConverter.ModifiedJulian2Gregorian(simTime.ModifiedJulianDay).ToString();
            }

            return(new ListViewItem(subItems));
        }
示例#11
0
 public NoScanner(ITimeStamp timeStamp)
 {
     this.timeStamp = timeStamp;
 }
示例#12
0
    /// <summary>
    /// A ValueSet corresponding to a TimeStamp is calculated using interpolation or
    /// extrapolation in corresponding lists of ValueSets and TimeStamps.
    /// </summary>
		/// <param name="requestedTimeStamp">TimeStamp for which the values are requested</param>
    /// <returns>ValueSet that corresponds to the requested time stamp</returns>
		private IValueSet MapFromTimeStampsToTimeStamp(ITimeStamp requestedTimeStamp)
		{
      try
      {
        int	     m  = ((IValueSet)_values[0]).Count;
        double[][] xr = new double[m][];                             // Values to return
        double   tr = requestedTimeStamp.ModifiedJulianDay;		     // Requested TimeStamp

        int nk; // number of components (scalars has only 1 and vectors has 3 (3 axis))

        if (_values[0] is IVectorSet)
        {
          nk = 3;
        }
        else
        {
          nk = 1;
        }

        for (int i = 0; i < m; i++)
        {
          xr[i] = new double[nk];
        }

        //---------------------------------------------------------------------------
        //  Buffered TimesStamps: |          >tb0<   >tb1<   >tb2<  >tbN<
        //  Requested TimeStamp:  |    >tr<
        //                         -----------------------------------------> t
        // --------------------------------------------------------------------------
        if (tr <= ((ITimeStamp)_times[0]).ModifiedJulianDay )
        {
          double tb0 = ((ITimeStamp) _times[0]).ModifiedJulianDay;
          double tb1 = ((ITimeStamp) _times[1]).ModifiedJulianDay;

          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m ; i++) //For each Vector in buffered VectorSet [0]
            {
              double sbi0 = Support.GetVal((IValueSet)_values[0], i, k);
              double sbi1       = Support.GetVal((IValueSet)_values[1], i, k);
              xr[i][k-1] = ((sbi0 - sbi1)/(tb0 - tb1))*(tr - tb0) * (1 - _relaxationFactor) + sbi0;
            }
          }
        }

          //---------------------------------------------------------------------------
          //  Buffered TimesStamps: |    >tb0<   >tb1<   >tb2<  >tbN_2<  >tbN_1<
          //  Requested TimeStamp:  |                                             >tr<
          //                         ---------------------------------------------------> t
          // --------------------------------------------------------------------------
        else if (tr > ((ITimeStamp) _times[_times.Count - 1]).ModifiedJulianDay)
        {
          double tbN_2 = ((ITimeStamp) _times[_times.Count - 2]).ModifiedJulianDay;
          double tbN_1 = ((ITimeStamp) _times[_times.Count - 1]).ModifiedJulianDay;

          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m; i++) //For each Vector in buffered VectorSet [N-1]
            {
              double sbiN_2     = Support.GetVal((IValueSet)_values[_times.Count-2], i, k);
              double sbiN_1     = Support.GetVal((IValueSet)_values[_times.Count-1], i, k);

              xr[i][k-1] = ((sbiN_1 - sbiN_2)/(tbN_1 - tbN_2))*(tr - tbN_1)*(1 - _relaxationFactor) + sbiN_1;
            }
          }
        }

          //---------------------------------------------------------------------------
          //  Availeble TimesStamps: |    >tb0<   >tb1<  >tbna<       >tnb<   >tbN_1<  >tbN_2<
          //  Requested TimeStamp:   |                          >tr<
          //                         -------------------------------------------------> t
          // --------------------------------------------------------------------------
        else
        {
          for (int n = _times.Count - 2; n >= 0 ; n--)
          {
            double tbn1 = ((ITimeStamp) _times[n]).ModifiedJulianDay;
            double tbn2 = ((ITimeStamp) _times[n+1]).ModifiedJulianDay;

            if ( tbn1 <= tr && tr <= tbn2)
            {
              for (int k = 1; k <= nk; k++)
              {
                for (int i = 0; i < m; i++) //For each Vector in buffered VectorSet [n]
                {
					IValueSet valueSet_n = (IValueSet)_values[n];
					double sbin1 = Support.GetVal(valueSet_n, i, k);

					IValueSet valueSet_nPlus1 = (IValueSet)_values[n+1];
                	double sbin2 = Support.GetVal(valueSet_nPlus1, i, k);;

					if ( valueSet_n.IsValid(i) && valueSet_nPlus1.IsValid(i))
					{
						xr[i][k-1]     = ((sbin2 - sbin1)/(tbn2 - tbn1)) * (tr - tbn1) + sbin1;
					}
					else if ( valueSet_n.IsValid(i) ) 
					{
						xr[i][k-1] = sbin1;
					}
					else if ( valueSet_nPlus1.IsValid(i) ) 
					{
						xr[i][k-1] = sbin2;
					}
					else
					{
						// both invalid, set to one of the (==invalid) values
						xr[i][k-1] = sbin1;
					}
                }
              }
              break;
            }
          }
        }
        //----------------------------------------------------------------------------------------------
        if (_values[0] is IVectorSet)
        {
          Vector [] vectors = new Vector[m]; 

          for (int i = 0; i < m; i++)
          {
            vectors[i] = new Vector(xr[i][0],xr[i][1],xr[i][2]);
          }

          VectorSet vectorSet = new VectorSet(vectors);

          return vectorSet;
        }
        else
        {
          double[] xx = new double[m];

          for (int i = 0; i < m; i++)
          {
            xx[i] = xr[i][0];
          }
				
          ScalarSet scalarSet = new ScalarSet(xx);

          return scalarSet;
        }
      }
      catch (Exception e)
      {
        throw new Exception("MapFromTimeStampsToTimeStamp Failed",e);
      }
		}
示例#13
0
        private void AddToBuffer(ILink link)
        {
            // ----------------------------------------------------------------------------------------------------
            // The method adds values associated with the link.source to a SmartBuffer.
            // ----------------------------------------------------------------------------------------------------

            //dictionary of values indexed by their date\time
            SortedDictionary <DateTime, ArrayList> dict = new SortedDictionary <DateTime, ArrayList>();

            //create a buffer instance to temporarily store data
            SmartBuffer _smartBuffer = new SmartBuffer();

            //set the relaxation factor, if specifed in *.omi file.
            if (_relaxationFactor > 0)
            {
                _smartBuffer.RelaxationFactor = _relaxationFactor;
            }

            //get link.source quantity and elementset
            IQuantity   sourceQuantity   = link.SourceQuantity;
            IElementSet sourceElementSet = link.SourceElementSet;

            string sql = "SELECT DISTINCT ds.SeriesID " +
                         "FROM DataValues dv " +
                         "INNER JOIN DataSeries ds ON dv.SeriesID = ds.SeriesID " +
                         "INNER JOIN DataThemes dt ON dv.SeriesID = dt.SeriesID " +
                         "INNER JOIN Sites s ON ds.SiteID = s.SiteID " +
                         "INNER JOIN DataThemeDescriptions dtd On dt.ThemeID = dtd.ThemeID " +
                         "WHERE dtd.ThemeName = '" + sourceElementSet.ID.ToString() + "' " +
                         "ORDER BY s.SiteName ASC";

            DataTable tbl = _db.LoadTable("values", sql);

            //get the number of series' in this theme
            Dictionary <string, int> sites = new Dictionary <string, int>();

            //get the number of sites in this series
            int k = 0;

            foreach (DataRow row in tbl.Rows)
            {
                if (!sites.ContainsKey(Convert.ToString(row["SeriesID"])))
                {
                    sites.Add(Convert.ToString(row["SeriesID"]), k);
                    k++;
                }
            }


            //query the db for values associated with source quantity and elementset
            //TODO: LOOKUP BY THEMENAME, NOT THEMEID
            sql = "SELECT ds.SeriesID, dv.LocalDateTime, dv.DataValue " +
                  "FROM DataValues dv " +
                  "INNER JOIN DataSeries ds ON dv.SeriesID = ds.SeriesID " +
                  "INNER JOIN DataThemes dt ON dv.SeriesID = dt.SeriesID " +
                  "INNER JOIN DataThemeDescriptions dtd On dt.ThemeID = dtd.ThemeID " +
                  "WHERE dtd.ThemeName = '" + sourceElementSet.ID.ToString() + "' " +
                  "ORDER BY dv.LocalDateTime ASC";
            //"ORDER BY dv.DataValue ASC";

            tbl = _db.LoadTable("values", sql);

            //get the number of series' in this theme
            List <DateTime> t = new List <DateTime>();
            Dictionary <DateTime, double[]> Times = new Dictionary <DateTime, double[]>();

            //get the number of sites in this series
            //int k = 0;
            //foreach (DataRow row in tbl.Rows)
            //{
            //    if (!sites.ContainsKey(Convert.ToString(row["SeriesID"])))
            //    {
            //        sites.Add(Convert.ToString(row["SeriesID"]), k);
            //        k++;
            //    }

            //    if(!t.Contains(Convert.ToDateTime(row["LocalDateTime"])))
            //        t.Add(Convert.ToDateTime(row["LocalDateTime"]));
            //}
            //initialize a dictionary to hold the times and values
            foreach (DataRow row in tbl.Rows)
            {
                if (!Times.ContainsKey(Convert.ToDateTime(row["LocalDateTime"])))
                {
                    Times.Add(Convert.ToDateTime(row["LocalDateTime"]), new double[sites.Count]);
                }
            }
            //Times.OrderBy<pair,
            Times.OrderBy(pair => pair.Value);
            foreach (DataRow row in tbl.Rows)
            {
                double   v  = Convert.ToDouble(row["DataValue"]);
                string   id = Convert.ToString(row["SeriesID"]);
                DateTime dt = Convert.ToDateTime(row["LocalDateTime"]);
                Times[dt][sites[id]] = v;
            }


            for (int i = 0; i <= t.Count - 1; i++)
            {
                double[] vals = new double[sites.Count];
                DateTime dt   = t[i];
                foreach (DataRow row in tbl.Rows)
                {
                    double v  = Convert.ToDouble(row["DataValue"]);
                    string id = Convert.ToString(row["SeriesID"]);

                    //add v to vals in the location defined by its site id
                    vals[sites[id]] = v;
                }

                ArrayList a = new ArrayList();
                a.Add(vals);
                dict.Add(t[i], a);
            }
            ////check to see if time/value combination has been already added
            //if (dict.ContainsKey(dt))
            //{
            //    //if yes, add value to existing dictionary
            //    ArrayList a = dict[dt];
            //    a.Add(v);
            //}
            //else
            //{
            //    //if not, add value to new dictionary
            //    ArrayList a = new ArrayList();
            //    a.Add(v);
            //    dict.Add(dt, a);
            //}

            //double[] valueset = null;
            //ITimeStamp time_stmp = null;
            ////add dictionary to the smart buffer
            //foreach (KeyValuePair<DateTime, ArrayList> kvp in dict)
            //{
            //    time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(kvp.Key));
            //    valueset = (double[])kvp.Value.ToArray(typeof(double));
            //    _smartBuffer.AddValues(time_stmp, new ScalarSet(valueset));
            //}


            // //sort the dictionary
            //var sortDict = from keys in Times.Keys
            //           orderby Times[keys] ascending
            //           select keys;

            ////Times = (Dictionary<DateTime, double[]>)sortDict;

            //foreach (KeyValuePair<DateTime, double[]> kvp in Times.OrderBy(key => key.Value))
            //{

            //    time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(kvp.Key));
            //    valueset = kvp.Value;
            //    _smartBuffer.AddValues(time_stmp, new ScalarSet(valueset));
            //}

            //add dictionary to the smart buffer
            double[]   valueset  = null;
            ITimeStamp time_stmp = null;

            foreach (KeyValuePair <DateTime, double[]> kvp in Times)
            {
                time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(kvp.Key));
                valueset  = kvp.Value;
                _smartBuffer.AddValues(time_stmp, new ScalarSet(valueset));
            }

            //if ExactMatch is requested, then save the times for using in the GetValues method
            try
            {
                if (_exactMatch)
                {
                    List <double> times = new List <double>();
                    foreach (KeyValuePair <DateTime, double[]> kvp in Times)
                    {
                        time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(kvp.Key));
                        times.Add(time_stmp.ModifiedJulianDay);
                    }
                    _times.Add(link.ID, times);
                }
            }
            catch (Exception) { }

            ////if ExactMatch is requested, then save the times for using in the GetValues method
            //try
            //{
            //    if (_exactMatch)
            //    {
            //        List<double> times = new List<double>();
            //        foreach (KeyValuePair<DateTime, ArrayList> kvp in dict)
            //        {

            //            time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(kvp.Key));
            //            times.Add(time_stmp.ModifiedJulianDay);
            //        }
            //        _times.Add(link.ID, times);
            //    }
            //}
            //catch (Exception) { }

            //store the number of elements for this link
            _elementCount.Add(link.ID, valueset.Length);

            //store the lastest known time for this link
            _endTimes.Add(link.ID, (TimeStamp)time_stmp);
            //store the smart buffer based on linkID
            _buffer.Add(link.ID, _smartBuffer);

            //initialize the last index variable
            _lastIndex.Add(link.ID, 0);

            //adjust start time based on target component
            if (link.TargetComponent.TimeHorizon.Start.ModifiedJulianDay > this.EarliestInputTime.ModifiedJulianDay)
            {
                this._earliestInputTime = link.TargetComponent.TimeHorizon.Start.ModifiedJulianDay;
            }


            #region Initialize Element Mapper

            try
            {
                //get the first (stored) data operation
                IDataOperation dataOp = link.GetDataOperation(0);
                //get dataOperation description
                string dataOpDesc = dataOp.GetArgument(1).Value;
                //add a element mapper instance to the mapper dictionary
                mapper.Add(link.ID, new ElementMapper());
                //initialize the element mapper and create a mapping matrix
                mapper[link.ID].Initialise(dataOpDesc, link.SourceElementSet, link.TargetElementSet);
            }
            catch (Exception e) { }

            #endregion
        }
示例#14
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">The time stamp to copy</param>
 public TimeStamp(ITimeStamp source)
 {
     ModifiedJulianDay = source.ModifiedJulianDay;
 }
示例#15
0
    /// <summary>
    /// A ValueSet corresponding to a TimeSpan is calculated using interpolation or
    /// extrapolation in corresponding lists of ValueSets and TimeSpans.
    /// </summary>
    /// <param name="requestedTimeStamp">Time for which the ValueSet is requested</param>
    /// <returns>ValueSet that corresponds to requestedTime</returns>
		private IValueSet MapFromTimeSpansToTimeStamp(ITimeStamp requestedTimeStamp)
		{
      try
      {
        int	     m  = ((IValueSet)_values[0]).Count;
        double[][] xr = new double[m][];                             // Values to return
        double   tr = requestedTimeStamp.ModifiedJulianDay; 	     // Requested TimeStamp

        int nk; // number of components (scalars has only 1 and vectors has 3 (3 axis))

        if (_values[0] is IVectorSet)
        {
          nk = 3;
        }
        else
        {
          nk = 1;
        }

        for (int i = 0; i < m; i++)
        {
          xr[i] = new double[nk];
        }

        //---------------------------------------------------------------------------
        //  Buffered TimesSpans:  |          >tbb0<  ..........  >tbbN<
        //  Requested TimeStamp:  |    >tr<
        //                         -----------------------------------------> t
        // --------------------------------------------------------------------------
        if (tr <= ((ITimeSpan)_times[0]).Start.ModifiedJulianDay )
        {
          double tbb0 = ((ITimeSpan) _times[0]).Start.ModifiedJulianDay;
          double tbb1 = ((ITimeSpan) _times[1]).Start.ModifiedJulianDay;
				
          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m ; i++) //For each Vector in buffered VectorSet [0]
            {
              double sbi0       = Support.GetVal((IValueSet)_values[0], i, k);
              double sbi1       = Support.GetVal((IValueSet)_values[1], i, k);
              xr[i][k-1] = ((sbi0 - sbi1)/(tbb0 - tbb1))*(tr - tbb0) * (1 - _relaxationFactor) + sbi0;
            }
          }
        }

          //---------------------------------------------------------------------------
          //  Buffered TimesSpans:  |    >tbb0<   .................  >tbbN_1<
          //  Requested TimeStamp:  |                                             >tr<
          //                         ---------------------------------------------------> t
          // --------------------------------------------------------------------------
        else if (tr >= ((ITimeSpan) _times[_times.Count - 1]).End.ModifiedJulianDay)
        {
          double tbeN_2 = ((ITimeSpan) _times[_times.Count - 2]).End.ModifiedJulianDay;
          double tbeN_1 = ((ITimeSpan) _times[_times.Count - 1]).End.ModifiedJulianDay;

          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m; i++) //For each Vector in buffered VectorSet [N-1]
            {
              double sbiN_2 = Support.GetVal((IValueSet)_values[_times.Count-2], i, k);
              double sbiN_1 = Support.GetVal((IValueSet)_values[_times.Count-1], i, k);

              xr[i][k-1] = ((sbiN_1 - sbiN_2)/(tbeN_1 - tbeN_2))*(tr - tbeN_1)*(1 - _relaxationFactor) + sbiN_1;
            }
          }
        }

          //---------------------------------------------------------------------------
          //  Availeble TimesSpans:  |    >tbb0<   ......................  >tbbN_1<
          //  Requested TimeStamp:   |                          >tr<
          //                         -------------------------------------------------> t
          // --------------------------------------------------------------------------
        else
        {
          for (int n = _times.Count - 1; n >= 0 ; n--)
          {
            double tbbn = ((ITimeSpan) _times[n]).Start.ModifiedJulianDay;
            double tben = ((ITimeSpan) _times[n]).End.ModifiedJulianDay;

            if ( tbbn <= tr && tr < tben)
            {
              for (int k = 1; k <= nk; k++)
              {
                for (int i = 0; i < m; i++) //For each Vector in buffered VectorSet [n]
                {
                  xr[i][k-1]     = Support.GetVal((IValueSet)_values[n], i, k);
                }
              }
              break;
            }
          }
        }

        //----------------------------------------------------------------------------------------------
	
		
        if (_values[0] is IVectorSet)
        {
          Vector [] vectors = new Vector[m]; 

          for (int i = 0; i < m; i++)
          {
            vectors[i] = new Vector(xr[i][0],xr[i][1],xr[i][2]);
          }

          VectorSet vectorSet = new VectorSet(vectors);

          return vectorSet;
        }
        else
        {
          double[] xx = new double[m];

          for (int i = 0; i < m; i++)
          {
            xx[i] = xr[i][0];
          }
				
          ScalarSet scalarSet = new ScalarSet(xx);

          return scalarSet;
        }
      }
      catch (Exception e)
      {
        throw new Exception("MapFromTimeSpansToTimeStamp Failed",e);
      }
		}
示例#16
0
 public static DateTime GetTimeStamp(this ITimeStamp iTimeStamp)
 {
     return(DateTimeOffset.FromUnixTimeMilliseconds((long)iTimeStamp.timestamp).ToLocalTime().DateTime);
 }
        public void ExpectedExceptions()
        {
            string str = "";
            LinkableTimeSeriesGroup linkableTimeSeriesGroup = new LinkableTimeSeriesGroup();

            try
            {
                string modelID = linkableTimeSeriesGroup.ModelID;
            }
            catch (System.Exception exception)
            {
                str = string.Copy(exception.Message);
            }

            Assert.AreEqual("property \"ModelID\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked", str);

            try
            {
                ITimeSpan timeHorizon = linkableTimeSeriesGroup.TimeHorizon;
            }
            catch (System.Exception exception)
            {
                str = string.Copy(exception.Message);
            }

            Assert.AreEqual("property \"TimeHorizon\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked", str);

            try
            {
                ITimeStamp earlistNeededTime = linkableTimeSeriesGroup.EarliestInputTime;
            }
            catch (System.Exception exception)
            {
                str = string.Copy(exception.Message);
            }

            Assert.AreEqual("property \"EarliestInputTime\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked", str);

            try
            {
                IValueSet valueSet = linkableTimeSeriesGroup.GetValues(new TimeStamp(new System.DateTime(2010, 1, 1)), "LinkID");
            }
            catch (System.Exception exception)
            {
                str = string.Copy(exception.Message);
            }

            Assert.AreEqual("Method \"GetValues\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked", str);

            try
            {
                int discreteTimeCount = linkableTimeSeriesGroup.GetDiscreteTimesCount(new Quantity(), new ElementSet());
            }
            catch (System.Exception exception)
            {
                str = string.Copy(exception.Message);
            }

            Assert.AreEqual("Method \"GetDiscreteTimesCount\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked", str);

            try
            {
                ITime discreteTime = linkableTimeSeriesGroup.GetDiscreteTime(new Quantity(), new ElementSet(), 2);
            }
            catch (System.Exception exception)
            {
                str = string.Copy(exception.Message);
            }

            Assert.AreEqual("Method \"GetDiscreteTime\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked", str);
        }
示例#18
0
 public NoPrinter(ITimeStamp timeStamp)
 {
     this.timeStamp = timeStamp;
 }
示例#19
0
 public VideoController(AppContext context, ITimeStamp timestamp)
 {
     _context   = context;
     _timestamp = timestamp;
 }
 public TimeSpan(ITimeStamp start, ITimeStamp end)
 {
     _start = new TimeStamp(start.ModifiedJulianDay);
     _end = new TimeStamp(end.ModifiedJulianDay);
 }
 public DummyComponent1Base(ITimeSpan timeHorizon)
 {
     _timeHorizon = timeHorizon;
     _earliestInputTime = _timeHorizon.Start;
 }
 public TimeSpan(ITime2 timeHorizon)
 {
     _start = new TimeStamp(timeHorizon.StampAsModifiedJulianDay);
     _end = new TimeStamp(timeHorizon.StampAsModifiedJulianDay + timeHorizon.DurationInDays);
 }
示例#23
0
 public static void SetTimeStamp(this ITimeStamp iTimeStamp, DateTime timeStamp)
 {
     iTimeStamp.timestamp = (ulong)(new DateTimeOffset(timeStamp).ToUnixTimeMilliseconds());
 }
示例#24
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">The time stamp to copy</param>
 public TimeStamp(ITimeStamp source)
 {
     ModifiedJulianDay = source.ModifiedJulianDay;
 }
示例#25
0
 public int FetchAnswerCount(ITimeStamp timestamp)
 {
     return(_timeStampResult.GetResult(timestamp).Count());
 }
示例#26
0
 /// <summary>
 /// Adds the given element to the collection
 /// </summary>
 /// <param name="item">The item to add</param>
 public override void Add(IModelElement item)
 {
     if ((this._parent.InstMag == null))
     {
         IAnalogueValue instMagCasted = item.As <IAnalogueValue>();
         if ((instMagCasted != null))
         {
             this._parent.InstMag = instMagCasted;
             return;
         }
     }
     if ((this._parent.Q == null))
     {
         IQuality qCasted = item.As <IQuality>();
         if ((qCasted != null))
         {
             this._parent.Q = qCasted;
             return;
         }
     }
     if ((this._parent.T == null))
     {
         ITimeStamp tCasted = item.As <ITimeStamp>();
         if ((tCasted != null))
         {
             this._parent.T = tCasted;
             return;
         }
     }
     if ((this._parent.Units == null))
     {
         IUnits unitsCasted = item.As <IUnits>();
         if ((unitsCasted != null))
         {
             this._parent.Units = unitsCasted;
             return;
         }
     }
     if ((this._parent.SVC == null))
     {
         IScaledValueConfig sVCCasted = item.As <IScaledValueConfig>();
         if ((sVCCasted != null))
         {
             this._parent.SVC = sVCCasted;
             return;
         }
     }
     if ((this._parent.Min == null))
     {
         IAnalogueValue minCasted = item.As <IAnalogueValue>();
         if ((minCasted != null))
         {
             this._parent.Min = minCasted;
             return;
         }
     }
     if ((this._parent.Max == null))
     {
         IAnalogueValue maxCasted = item.As <IAnalogueValue>();
         if ((maxCasted != null))
         {
             this._parent.Max = maxCasted;
             return;
         }
     }
 }
示例#27
0
 public string FetchSubject(ITimeStamp timestamp)
 {
     return(_resultStamp.GetResult(timestamp).FirstOrDefault().Subject);
 }
        private double CalculateTimePercentage(ITimeStamp start, ITimeStamp current, ITimeStamp stop)
        {
            var startD = start.ModifiedJulianDay;
            var stopD = stop.ModifiedJulianDay;
            var currentD = current.ModifiedJulianDay;

            if (currentD > stopD)
                return 100.0;

            stopD -= startD;
            currentD -= startD;

            return (currentD/stopD)*100.0;
        }
示例#29
0
		public void Run(ITimeStamp time)
		{
			//IScalarSet scalarSet = new ScalarSet();
			
			ScalarSet scalarSet = new ScalarSet((IScalarSet) _link.SourceComponent.GetValues(time,_link.ID));
			_earliestInputTime.ModifiedJulianDay = time.ModifiedJulianDay;
			_resultsBuffer.AddValues(time,scalarSet);
		}
示例#30
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="Start">Start time</param>
		/// <param name="End">End time</param>
		public TimeSpan(ITimeStamp Start, ITimeStamp End)
		{
			_start = Start;
			_end = End;
		}
示例#31
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Start">Start time</param>
 /// <param name="End">End time</param>
 public TimeSpan(ITimeStamp Start, ITimeStamp End)
 {
     _start = Start;
     _end   = End;
 }
示例#32
0
		/// <summary>
		/// Clear all records in the buffer assocaited to time that is earlier that the
		/// time specified in the argument list. However, one record associated to time 
		/// before the time in the argument list is left in the buffer.
		/// The criteria when comparing TimeSpans is that they may not overlap in order
		/// to be regarded as before each other.
		/// (see also Oatc.OpenMI.Sdk.Buffer.Support.IsBefore(ITime ta, ITime tb)
		/// </summary>
		/// <param name="time">time before which the records are removed</param>
		public void ClearBefore(ITimeStamp time)
		{
			int numberOfRecordsToRemove = 0;

			foreach (ITime t in _times)
			{
				if (Support.IsBefore(t, time))
				{
					numberOfRecordsToRemove ++;
				}
			}

			numberOfRecordsToRemove--; // decrease index to ensure that one record before time is left back


			if (numberOfRecordsToRemove > 0)
			{
				_times.RemoveRange(0,numberOfRecordsToRemove);
				_values.RemoveRange(0,numberOfRecordsToRemove);
			}
		}
示例#33
0
 public TimeResponseFormater(ITimeStamp timeStamp)
 {
     this.timeStamp = timeStamp;
 }
示例#34
0
 public int FetchProgress(ITimeStamp timestamp)
 {
     return(_timeStampResult.GetResult(timestamp).Sum(b => b.Progress));
 }