示例#1
0
        private static int getMatchingDatasourceIndex(RrdDb rrd1, int dsIndex, RrdDb rrd2)
        {
            String dsName = rrd1.getDatasource(dsIndex).DsName;

            try
            {
                return(rrd2.getDsIndex(dsName));
            }
            catch (ArgumentException e)
            {
                return(-1);
            }
        }
示例#2
0
        public void setDsType(Common.DsType newDsType)
        {
            dsType = newDsType;
            dsTypeName.set(dsType.Name);

            // set datasource type
            // reset datasource status
            lastValue.set(Double.NaN);
            accumValue.set(0.0);
            // reset archive status
            int dsIndex = parentDb.getDsIndex(dsName.get());

            Archive[] archives = parentDb.getArchives();
            foreach (Archive archive in archives)
            {
                archive.getArcState(dsIndex).setAccumValue(Double.NaN);
            }
        }
示例#3
0
文件: Archive.cs 项目: mujing/rrd4net
 private static int getMatchingDatasourceIndex(RrdDb rrd1, int dsIndex, RrdDb rrd2)
 {
    String dsName = rrd1.getDatasource(dsIndex).DsName;
    try
    {
       return rrd2.getDsIndex(dsName);
    }
    catch (ArgumentException e)
    {
       return -1;
    }
 }
示例#4
0
文件: Model.cs 项目: mujing/rrd4net
      public FetchData GetArchiveData(DatabaseData databaseData, string dataSourceName, ArcDef archiveDefinition)
      {
         RrdDb database = null;
         try
         {
            database = new RrdDb(databaseData.Definition.getPath(), true);
            int datasourceIndex = database.getDsIndex(dataSourceName);
            Archive archive = database.getArchive(new ConsolFun(archiveDefinition.getConsolFun().Name), archiveDefinition.Steps);
            Robin robin = archive.getRobin(datasourceIndex);
            double[] values = robin.getValues();
            DateTime archiveStartTime = archive.getStartDateTime();
            TimeSpan tick = new TimeSpan(archive.getArcStep() * TimeSpan.TicksPerSecond);

            FetchData fetchedData = new FetchData(archive.getArcStep(), archive.getEndTime(), new string[] { dataSourceName });
            long[] timestamps = new long[archive.getRows()];
            long offset = archive.getStartTime();
            for (var i = 0; i < archive.getRows(); i++)
            {
               timestamps[i] = offset;
               offset += archive.getArcStep();
            }
            fetchedData.setTimestamps(timestamps);
            double[][] value = new double[1][];
            value[0] = values;
            fetchedData.setValues(value);
            return fetchedData;

         }
         finally
         {
            if (database != null)
               database.close();
         }
      }
示例#5
0
      public void ImportData(string dataPath, DatabaseData databaseData, TimeSpan expectedTick )
      {
         if (model.ReadOnly)
            throw new ApplicationException("Can't import data. Database readonly");


         List<string> columns = new List<string>();
         List<FetchedData> unifiedData = ReadAndUnifyData(dataPath, out columns);

         string databasePath = databaseData.Definition.Path;
         RrdDb database = new RrdDb(databasePath, false);

         int[] dsIndexes = new int[columns.Count];
         for (int i = 0; i < columns.Count; i++)
         {
            dsIndexes[i] = database.getDsIndex(columns[i]);
         }


         string[] dsNames = database.getDsNames();
         rrd4n.DataAccess.Data.Sample sample = new rrd4n.DataAccess.Data.Sample(databasePath, dsNames, 0);
         
         foreach (var data in unifiedData)
         {
            sample.setDateTime(data.TimeStamp);
            for (int i = 0; i < data.Values.Count; i++ )
            {
               sample.setValue(dsIndexes[i], data.Values[i]); 
            }

            try
            {
               // When using file access abstraction
               //dbAccess.StoreData(sample);

               //Without abstraction
               database.store(sample);
               sample.clearValues();
            }
            catch (ArgumentException)
            {
            }
            model.DatabaseDirty = true;
         }
         database.close();
         OpenDatabase(databasePath);
      }
示例#6
0
        public FetchData fetchData(FetchRequest request)
        {
            long arcStep    = getArcStep();
            long fetchStart = Util.normalize(request.FetchStart, arcStep);
            long fetchEnd   = Util.normalize(request.FetchEnd, arcStep);

            if (fetchEnd < request.FetchEnd)
            {
                fetchEnd += arcStep;
            }
            long startTime = getStartTime();
            long endTime   = getEndTime();

            String[] dsToFetch = request.getFilter();
            if (dsToFetch == null)
            {
                dsToFetch = parentDb.getDsNames();
            }
            int dsCount  = dsToFetch.Length;
            int ptsCount = (int)((fetchEnd - fetchStart) / arcStep + 1);

            long[]     timestamps = new long[ptsCount];
            double[][] values     = new double[dsCount][];
            for (int i = 0; i < dsCount; i++)
            {
                values[i] = new double[ptsCount];
            }


            long matchStartTime = Math.Max(fetchStart, startTime);
            long matchEndTime   = Math.Min(fetchEnd, endTime);

            double[][] robinValues = null;
            if (matchStartTime <= matchEndTime)
            {
                // preload robin values
                int matchCount      = (int)((matchEndTime - matchStartTime) / arcStep + 1);
                int matchStartIndex = (int)((matchStartTime - startTime) / arcStep);
                robinValues = new double[dsCount][];
                for (int i = 0; i < dsCount; i++)
                {
                    int dsIndex = parentDb.getDsIndex(dsToFetch[i]);
                    robinValues[i] = robins[dsIndex].getValues(matchStartIndex, matchCount);
                }
            }
            for (int ptIndex = 0; ptIndex < ptsCount; ptIndex++)
            {
                long time = fetchStart + ptIndex * arcStep;
                timestamps[ptIndex] = time;
                for (int i = 0; i < dsCount; i++)
                {
                    double value = Double.NaN;
                    if (time >= matchStartTime && time <= matchEndTime)
                    {
                        // inbound time
                        int robinValueIndex = (int)((time - matchStartTime) / arcStep);
                        Debug.Assert(robinValues != null);
                        value = robinValues[i][robinValueIndex];
                    }
                    values[i][ptIndex] = value;
                }
            }
            FetchData fetchData = new FetchData(steps.get(), endTime, parentDb.getDsNames());

            fetchData.setTimestamps(timestamps);
            fetchData.setValues(values);
            return(fetchData);
        }