コード例 #1
0
        private void UpdateCache(Telegram telegram, decimal current)
        {
            var entry = new GasFlowCacheEntry {
                Timestamp         = telegram.GasTimestamp,
                Value             = telegram.GasConsumption,
                LastGasFlowResult = current
            };

            this.m_telegrams.AddOrUpdate(telegram.SerialNumberGasMeter, entry, (serial, oldValue) => entry);
        }
コード例 #2
0
        public decimal ComputeFlow(Telegram telegram)
        {
            var result = 0M;

            if (this.m_telegrams.TryGetValue(telegram.SerialNumberGasMeter, out var old))
            {
                result = this.ComputePerMinute(old, telegram);
            }

            this.UpdateCache(telegram, result);
            return(result);
        }
コード例 #3
0
        private decimal ComputePerMinute(GasFlowCacheEntry old, Telegram @new)
        {
            if (@new.GasTimestamp == old.Timestamp)
            {
                return(old.LastGasFlowResult);
            }

            var diff  = @new.GasTimestamp.Subtract(old.Timestamp);
            var usage = @new.GasConsumption - old.Value;

            if (usage < 0)
            {
                this.m_logger.Warn("New gas m3 lower than previously received. Are telegrams being received out of order?");
                return(0M);
            }

            return(usage / Convert.ToDecimal(diff.TotalMinutes));
        }