Exemplo n.º 1
0
        internal async Task DisableAsync()
        {
            Cts.Cancel();
            await Task;

            Task.Dispose();

            var stillDisabledEvent = new StillDisabledEvent(Id);

            Kafka.ProduceEventAsJson(nameof(StillDisabledEvent), stillDisabledEvent);
        }
Exemplo n.º 2
0
        internal void Run()
        {
            Cts = new CancellationTokenSource();

            var stillStartedEvent = new StillStartedEvent(Id);

            Kafka.ProduceEventAsJson(nameof(StillStartedEvent), stillStartedEvent);

            Task = Task.Run <Task>(
                function: ProduceRandomSensorData,
                cancellationToken: Cts.Token);
        }
Exemplo n.º 3
0
        private static void DetectPolice()
        {
            Task.Run(async() =>
            {
                var r = new Random();
                while (true)
                {
                    var randomNumber = r.Next();

                    if (randomNumber % 10 == 0)
                    {
                        Kafka.ProduceEventAsJson(nameof(PoliceDetectedEvent), new PoliceDetectedEvent(Guid.NewGuid()));
                    }

                    await Task.Delay(500);
                }
            });
        }
Exemplo n.º 4
0
        private async Task ProduceRandomSensorData()
        {
            int iterationsToRefill = 10;

            while (!Cts.Token.IsCancellationRequested)
            {
                if (!GasTankIsEmpty)
                {
                    gasCapacity -= 1;
                }

                Kafka.ProduceEventAsJson(nameof(StillPingEvent), new StillPingEvent(Id));

                var r = new Random();

                var randomMashTemperature       = Temperatures.TemperaturesValues[r.Next(0, Temperatures.TemperaturesValues.Length)];
                var randomDistillateTemperature = Temperatures.TemperaturesValues[r.Next(0, Temperatures.TemperaturesValues.Length)];



                Kafka.ProduceEventAsJson(topicName: nameof(StillSensorReadEvent),
                                         ev: new StillSensorReadEvent(Id, randomMashTemperature, randomDistillateTemperature, gasCapacity));

                await Task.Delay(1000);

                if (GasTankIsEmpty)
                {
                    iterationsToRefill -= 1;

                    if (iterationsToRefill <= 0)
                    {
                        gasCapacity        = 100;
                        iterationsToRefill = 10;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private static void ReadSensorData()
        {
            Console.WriteLine($"----------BIMBROWNIA AI----------{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}");
            Console.WriteLine("Sensor readings:");

            if (sensorDataDictionary.IsEmpty)
            {
                Console.WriteLine("No stills running");
            }
            else
            {
                foreach (var sensorData in sensorDataDictionary.Values.Where(v => !v.Disabled))
                {
                    Console.WriteLine($"Still with id: {sensorData.StillId}. Avg. mash temp: {sensorData.AverageMashTemperatureReading} C°. Avg. distillate temp: {sensorData.AverageDistillateTemperatureReading} C°. Gas cpty.: {sensorData.LastGasCapacityPercentage}%");
                    Console.WriteLine("----------");

                    if (sensorData.HasRealiableReadings)
                    {
                        if (sensorData.AverageDistillateTemperatureReading > 95)
                        {
                            Kafka.ProduceEventAsJson(topicName: nameof(DangerousDistillateAvgTemperatureEvent),
                                                     ev: new DangerousDistillateAvgTemperatureEvent(sensorData.StillId, sensorData.AverageDistillateTemperatureReading));
                        }
                        if (sensorData.AverageMashTemperatureReading > 95)
                        {
                            Kafka.ProduceEventAsJson(topicName: nameof(DangerousMashAvgTemperatureEvent),
                                                     ev: new DangerousMashAvgTemperatureEvent(sensorData.StillId, sensorData.AverageMashTemperatureReading));
                        }
                        if (sensorData.LastGasCapacityPercentage <= 0)
                        {
                            Kafka.ProduceEventAsJson(topicName: nameof(GasTankIsEmptyEvent),
                                                     ev: new GasTankIsEmptyEvent(sensorData.StillId));
                        }
                    }
                }
            }
        }