Ejemplo n.º 1
0
        private static BMRecordCurrent GetAverageValue(List <BMRecordCurrent> records, int start, int bucketSize)
        {
            if (start >= records.Count || bucketSize <= 0)
            {
                return(new BMRecordCurrent());
            }

            BMRecordCurrent rec = new BMRecordCurrent(records[start]);

            if (bucketSize == 1)
            {
                return(rec);
            }

            int count = 1;

            for (int i = start + 1; i < records.Count && i < (start + bucketSize); i++, count++)
            {
                rec += records[i];
            }
            rec /= count;

            TimeSpan interval     = records[start + count - 1].Date - records[start].Date;
            TimeSpan halfInterval = TimeSpan.FromMilliseconds(interval.TotalMilliseconds / 2);

            rec.Date = records[start].Date + halfInterval;

            if (interval.TotalSeconds < 1.0)
            {
                Log.d("Interval is too small: idx: {0} count: {1} time: {2}", start, bucketSize, interval);
            }

            return(rec);
        }
Ejemplo n.º 2
0
        public static BMRecordCurrent operator /(BMRecordCurrent r1, double factor)
        {
            BMRecordCurrent rec = new BMRecordCurrent(r1);

            rec.Temperature /= factor;
            rec.AirHumidity /= factor;
            rec.AirPressure /= factor;
            return(rec);
        }
Ejemplo n.º 3
0
        public static BMRecordCurrent operator +(BMRecordCurrent r1, BMRecordCurrent r2)
        {
            BMRecordCurrent rec = new BMRecordCurrent(r2); //later one for time, battery level etc.

            rec.Temperature += r1.Temperature;
            rec.AirHumidity += r1.AirHumidity;
            rec.AirPressure += r1.AirPressure;
            return(rec);
        }
Ejemplo n.º 4
0
        //empty record for average, min, max
        public BMRecordCurrent(BMRecordCurrent r = null) : base(r)
        {
            if (r == null)
            {
                return;
            }

            BatteryLevel    = r.BatteryLevel;
            LoggingInterval = r.LoggingInterval;
            numBreach       = r.numBreach;
            _mode           = r._mode;
        }
Ejemplo n.º 5
0
        public BMRecordCurrent AddRecord(BluetoothDevice device, short rssi, DateTime recordDate, byte[] data)
        {
            BMRecordCurrent record = new BMRecordCurrent(device, rssi, recordDate, data);

            lock (Records)
            {
                BMRecordCurrent last = Records.LastOrDefault();
                if (last != null && last == record) //not changed - update
                {
                    Records[Records.Count - 1] = record;
                }
                else //new record
                {
                    if (last == null)
                    {
                        last = record;
                    }

                    Records.Add(record);
                }
            }

            return(record);
        }
Ejemplo n.º 6
0
        //assuming all DB are sorted by date
        public static List <BMRecordCurrent> MergeLinear(List <BMRecordCurrent> r1, List <BMRecordCurrent> r2)
        {
            if ((r1 == null || r1.Count == 0) && (r2 == null || r2.Count == 0))
            {
                return(new List <BMRecordCurrent>());
            }
            if (r1 == null || r1.Count == 0)
            {
                return(new List <BMRecordCurrent>(r2));
            }
            if (r2 == null || r2.Count == 0)
            {
                return(new List <BMRecordCurrent>(r1));
            }

            List <BMRecordCurrent> records = new List <BMRecordCurrent>(r1.Count);
            BMRecordCurrent        current = null, last = null;

            int i1 = 0, i2 = 0;

            while (i1 < r1.Count || i2 < r2.Count)
            {
                if (i1 < r1.Count && i2 < r2.Count)
                {
                    if (r1[i1].Date == r2[i2].Date)
                    {
                        current = r1[i1];
                        i1++;
                        i2++;
                    }
                    else if (r1[i1].Date < r2[i2].Date)
                    {
                        current = r1[i1];
                        i1++;
                    }
                    else
                    {
                        current = r2[i2];
                        i2++;
                    }
                }
                else if (i1 < r1.Count)
                {
                    current = r1[i1];
                    i1++;
                }
                else if (i2 < r2.Count)
                {
                    current = r2[i2];
                    i2++;
                }


                if (last == null || current.Date != last.Date)
                {
                    records.Add(current);
                    last = current;
                }
            }

            return(records);
        }