Beispiel #1
0
        public async Task <IActionResult> GenerateTriggerLogs()
        {
            var amount = 1000;
            var tlList = new List <TriggerLog>();

            for (int i = 0; i < amount; i++)
            {
                Random rng = new Random();

                var timestamp = DateTime.Now;
                var room      = await _context.Room.OrderBy(o => Guid.NewGuid()).FirstAsync();

                var tl = new TriggerLog
                {
                    Timestamp = timestamp.AddMinutes(1),
                    RoomID    = room.RoomID,
                    Command   = "W1",
                    Sensor    = SensorType.Temperature
                };
                tlList.Add(tl);
            }
            _context.TriggerLog.BulkInsert(tlList);

            TempData["Success"] = "Triggers Generated";
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> GenerateSensorData()
        {
            var dataList = new List <SensorData>();
            var amount   = 1000;

            var rng = new Random();

            var temp = DateTime.Now;
            var span = TimeSpan.FromDays(1).TotalMinutes / 1000;

            for (int i = 0; i < amount; i++)
            {
                var room = await _context.Room.OrderBy(o => Guid.NewGuid()).FirstAsync();

                var data = new SensorData();
                data.Timestamp   = temp;
                data.Humidity    = 50 - (rng.Next(-3, 3));
                data.CO2         = (int)(Math.Sin(i / 300f) * 100) + 300;
                data.Temperature = (int)(Math.Sin(i / 300f) * 20) + 15;
                data.RoomID      = room.RoomID;

                temp = temp.AddMinutes(span);
                dataList.Add(data);
                var triggers = await _context.Trigger.Where(t => t.RoomID == room.RoomID).ToListAsync();

                var triggerList = new List <TriggerLog>();
                foreach (var trigger in triggers)
                {
                    if ((trigger.GreaterThan && data.Temperature > trigger.Value) || (trigger.GreaterThan == false && data.Temperature < trigger.Value))
                    {
                        var tl = new TriggerLog
                        {
                            Timestamp = data.Timestamp,
                            RoomID    = data.RoomID,
                            Command   = trigger.Command,
                            Sensor    = trigger.Sensor
                        };
                        triggerList.Add(tl);
                    }
                }
                _context.TriggerLog.BulkInsert(triggerList);
            }


            _context.SensorData.AddRange(dataList);
            await _context.BulkSaveChangesAsync();

            TempData["Success"] = "Data Generated";
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
 private void LogEvent(string eventMessage)
 {
     Debug.WriteLine(eventMessage);
     TriggerLog?.Invoke(eventMessage);
 }