<commit_before>﻿using System;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using log4net;
using RoboticsTxt.Lib.Contracts;

namespace RoboticsTxt.Lib.Components.Communicator
{
    internal class MotorDistanceInfo
    {
        private readonly ILog logger = LogManager.GetLogger(typeof(MotorDistanceInfo));
        private readonly Subject<short> commandIdChangesSubject;
        private readonly Subject<int> distanceDifferencesSubject;

        private short currentCommandId;
        private short currentDistanceValue;

        public MotorDistanceInfo(Motor motor)
        {
            this.Motor = motor;
            this.IsTracking = true;

            distanceDifferencesSubject = new Subject<int>();
            commandIdChangesSubject = new Subject<short>();
        }

        public Motor Motor { get; }

        public bool IsTracking { get; set; }

        // TODO think about rename
        public IObservable<int> DistanceDifferences => distanceDifferencesSubject.AsObservable();

        public IObservable<short> CommandIdChanges => commandIdChangesSubject.AsObservable();

        public void SetCurrentDistanceValue(short distanceValue, short commandId)
        {
            if (!this.IsTracking)
            {
                this.currentDistanceValue = distanceValue;
                return;
            }

            if ((distanceValue < currentDistanceValue))
            {
                currentDistanceValue = 0;
                logger.Info("reset currentDistance");
            }

            if (currentDistanceValue == distanceValue)
            {
                return;
            }

            var difference = distanceValue - currentDistanceValue;

            logger.Info($"d={distanceValue:000} - diff={difference:000} - c={commandId:000}");

            currentDistanceValue = distanceValue;
            this.distanceDifferencesSubject.OnNext(difference);

            currentCommandId = commandId;
            commandIdChangesSubject.OnNext(commandId);<commit_msg>fixed logging level...<commit_after>﻿using System;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using log4net;
using RoboticsTxt.Lib.Contracts;

namespace RoboticsTxt.Lib.Components.Communicator
{
    internal class MotorDistanceInfo
    {
        private readonly ILog logger = LogManager.GetLogger(typeof(MotorDistanceInfo));
        private readonly Subject<short> commandIdChangesSubject;
        private readonly Subject<int> distanceDifferencesSubject;

        private short currentCommandId;
        private short currentDistanceValue;

        public MotorDistanceInfo(Motor motor)
        {
            this.Motor = motor;
            this.IsTracking = true;

            distanceDifferencesSubject = new Subject<int>();
            commandIdChangesSubject = new Subject<short>();
        }

        public Motor Motor { get; }

        public bool IsTracking { get; set; }

        // TODO think about rename
        public IObservable<int> DistanceDifferences => distanceDifferencesSubject.AsObservable();

        public IObservable<short> CommandIdChanges => commandIdChangesSubject.AsObservable();

        public void SetCurrentDistanceValue(short distanceValue, short commandId)
        {
            if (!this.IsTracking)
            {
                this.currentDistanceValue = distanceValue;
                return;
            }

            if ((distanceValue < currentDistanceValue))
            {
                currentDistanceValue = 0;
                logger.Info("reset currentDistance");
            }

            if (currentDistanceValue == distanceValue)
            {
                return;
            }

            var difference = distanceValue - currentDistanceValue;

            logger.Debug($"d={distanceValue:000} - diff={difference:000} - c={commandId:000}");

            currentDistanceValue = distanceValue;
            this.distanceDifferencesSubject.OnNext(difference);

            currentCommandId = commandId;
            commandIdChangesSubject.OnNext(commandId);
{'fraction_non_alphanumeric': 0.0772076961026147, 'fraction_numerical': 0.005426739023186976, 'mean_word_length': 2.296747967479675, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6742127', 'n_tokens_mistral': 1016, 'n_tokens_neox': 935, 'n_words': 207}