예제 #1
0
        public void InsertValue(int pointId, DateTime timestamp, double value)
        {
            TSPoint point     = fDB.Get <TSPoint>(pointId);
            string  tableName = point.GetDataTableName();

            InsertValue(tableName, timestamp, value);
        }
예제 #2
0
        public void DeleteValue(int pointId, DateTime timestamp)
        {
            TSPoint point     = fDB.Get <TSPoint>(pointId);
            string  tableName = point.GetDataTableName();

            string tsx = ALCore.FmtSQLiteDate(timestamp);

            fDB.Execute(string.Format("delete from {0} where Timestamp = '{1}'", tableName, tsx));
        }
예제 #3
0
        public void UpdateValue(int pointId, DateTime timestamp, double value)
        {
            TSPoint point     = fDB.Get <TSPoint>(pointId);
            string  tableName = point.GetDataTableName();

            string tsx   = ALCore.FmtSQLiteDate(timestamp);
            string vx    = ALCore.FmtSQLiteFloat(value);
            string query = string.Format("update {0} set Value = '{1}' where Timestamp = '{2}'", tableName, vx, tsx);

            fDB.Execute(query);
        }
예제 #4
0
        public IList <TSValue> QueryValues(int pointId, DateTime begTime, DateTime endTime)
        {
            TSPoint point     = fDB.Get <TSPoint>(pointId);
            string  tableName = point.GetDataTableName();

            string tsBeg = ALCore.FmtSQLiteDate(begTime);
            string tsEnd = ALCore.FmtSQLiteDate(endTime);
            string query = string.Format("select * from {0} where Timestamp between '{1}' and '{2}'", tableName, tsBeg, tsEnd);

            return(fDB.Query <TSValue>(query));
        }
예제 #5
0
        public void DeletePoint(TSPoint point)
        {
            string tableName = point.GetDataTableName();

            string idxExpr = string.Format("drop index \"{0}_Timestamp\"", tableName);

            fDB.Execute(idxExpr);

            string tblExpr = string.Format("drop table {0}", tableName);

            fDB.Execute(tblExpr);

            fDB.Delete(point);
        }
예제 #6
0
        public void AddPoint(TSPoint point)
        {
            fDB.Insert(point);

            string tableName = point.GetDataTableName();

            string tblExpr = string.Format("create table {0}(\"Timestamp\" datetime, \"Value\" float)", tableName);

            fDB.Execute(tblExpr);

            string idxExpr = string.Format("create unique index \"{0}_Timestamp\" on \"{1}\"(\"Timestamp\")", tableName, tableName);

            fDB.Execute(idxExpr);
        }
예제 #7
0
        public void ReceivePointValue(int pointId, DateTime timestamp, double value)
        {
            TSPoint point = fDB.Get <TSPoint>(pointId);

            SDCompression compression;

            if (!fCompressionCache.TryGetValue(pointId, out compression))
            {
                compression = new SDCompression(point.Deviation, 60 * 10); // default: 60sec * 10min
                fCompressionCache.Add(pointId, compression);
            }

            if (compression.ReceivePoint(ref timestamp, ref value))
            {
                string tableName = point.GetDataTableName();
                InsertValue(tableName, timestamp, value);
            }
        }
예제 #8
0
        public double GetCurrentValue(int pointId)
        {
            TSPoint point = fDB.Get <TSPoint>(pointId);

            SDCompression compression;

            if (!fCompressionCache.TryGetValue(pointId, out compression))
            {
                compression = new SDCompression(point.Deviation, 60 * 10); // default: 60sec * 10min
                fCompressionCache.Add(pointId, compression);
            }

            if (compression != null)
            {
                return(compression.CurrentPoint.Value);
            }

            return(double.NaN);
        }
예제 #9
0
        public void Test_Common()
        {
            var instance = new TSDatabase();

            Assert.IsNotNull(instance);

            TSPoint point = new TSPoint();

            point.Name = "temperature test";
            point.Type = MeasurementType.Temperature;
            Assert.AreEqual("temperature test", point.ToString());
            instance.AddPoint(point);

            point.Name = "temperature test 2";
            instance.UpdatePoint(point);

            point = instance.GetPoint(point.Id);
            Assert.IsNotNull(point);
            instance.DeletePoint(point);
        }
예제 #10
0
 public void UpdatePoint(TSPoint point)
 {
     fDB.Update(point);
 }