Beispiel #1
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);
        }
Beispiel #2
0
        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();
                }
            }
        }