/// <summary> /// Removes a student from a class /// </summary> /// <param name="classId">The id of the class to remove the student from</param> /// <param name="studentId">The id of the student to unenroll</param> /// <returns>The deleted enrollment</returns> public Enrollment UnEnrollStudent(int classId, int studentId) { var enrollment = _db.Enrollments .Include(e => e.Class) .FirstOrDefault(e => e.Class.Id == classId && e.Student.Id == studentId); if (enrollment == null) { throw new InvalidOperationException("Error unenrolling student"); } // Delete the Person object from the PersonGroup var faceClient = RecognitionService.GetFaceClient(); Task.Run(() => faceClient.DeletePersonAsync(classId.ToString(), enrollment.PersonId)); // Remove all attendance and enrollment information var attendance = _db.Attendance.Where(a => a.Student.Id == studentId); _db.Attendance.RemoveRange(attendance); enrollment.Class.TrainingStatus = TrainingStatus.UnTrained; // Update training status for class _db.Enrollments.Remove(enrollment); _db.SaveChanges(); return(enrollment); }
/// <summary> /// Deletes a class with the given id and all other related information /// </summary> /// <param name="classId">Id of the class to delete</param> public Class DeleteClass(int classId) { var @class = _db.Classes.Find(classId); if (@class == null) { throw new InvalidOperationException("Error deleting class."); } // Delete all lectures var lectureManager = new LectureManager(_db); var lectures = new List <Lecture>(@class.Lectures); foreach (var lecture in lectures) { lectureManager.Delete(lecture.Id); } // Delete all enrollments _db.Enrollments.RemoveRange(@class.Enrollment); // Delete cognitive data var faceClient = RecognitionService.GetFaceClient(); Task.Run(() => faceClient.DeletePersonGroupAsync(@class.Id.ToString())).Wait(); _db.Classes.Remove(@class); _db.SaveChanges(); return(@class); }
public async Task TelegramRecordedAudioTest() { using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var cancellationToken = cancellationTokenSource.Token; await using var moduleService = new StaticModuleService( TestModules.CreateDefaultRecorder(), TestModules.CreateTelegramRunner() ); await using var runnerService = new RunnerService(moduleService); await using var recognitionService = new RecognitionService(moduleService); using var exceptions = new IServiceBase[] { moduleService, runnerService }.EnableLogging(cancellationTokenSource); var bytes = await recognitionService.StartRecordMp3_5Second_Stop_Async(cancellationToken); await runnerService.RunAsync( new Command("telegram audio", new Value(string.Empty, nameof(TelegramRecordedAudioTest)) { Data = bytes, }), cancellationToken); }
public async Task SendTelegramVoiceMessageTest() { using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var cancellationToken = cancellationTokenSource.Token; await using var hookService = new HookService { new (new Command("send-telegram-voice-message"), new Keys(Key.L, Key.RAlt), true), }; await using var moduleService = new StaticModuleService( TestModules.CreateDefaultRecorder(), TestModules.CreateDefaultRecognizer(), TestModules.CreateTelegramRunner() ); await using var recognitionService = new RecognitionService(moduleService); await using var runnerService = new RunnerService( moduleService, moduleService, hookService ); using var exceptions = new IServiceBase[] { moduleService, runnerService, hookService }.EnableLogging(cancellationTokenSource); await hookService.InitializeAsync(cancellationToken); moduleService.Add(new RecognitionServiceRunner(recognitionService)); await Task.Delay(TimeSpan.FromSeconds(15), cancellationToken); }
public async Task <IActionResult> ProcessFinalStringAsync(string userRequestMessage) { RecognitionService service = new RecognitionService(); string userResponse = await service.ProcessText(userRequestMessage); return(Content(userResponse)); }
public async Task Process_ReturnsEmptyRecognitionResult_WhenIntentScoreIsLessThanRequired() { var query = "I'm testing you"; var luisResultModel = CreateTestLuisResultModel(); var recognitionResult = new RecognitionResult { Message = string.Empty }; var settingsMock = new Mock <ISettings>(); settingsMock.Setup(x => x.IntentThreshold).Returns(0.9); var intentServiceMock = new Mock <IIntentService>(); intentServiceMock.Setup(x => x.Execute(string.Empty, null)) .Returns(Task.FromResult(recognitionResult)) .Verifiable(); var luisServiceMock = CreateLuisServiceMock(luisResultModel, query); var loggerMock = new Mock <ILogger <RecognitionService> >(); var recognitionService = new RecognitionService(settingsMock.Object, intentServiceMock.Object, luisServiceMock.Object, loggerMock.Object); var result = await recognitionService.Process(query); luisServiceMock.Verify(); intentServiceMock.Verify(); Assert.IsNotNull(result); Assert.AreEqual(result, recognitionResult); }
public async Task SendTelegramVoiceMessageTest() { using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var cancellationToken = cancellationTokenSource.Token; await using var moduleService = new StaticModuleService( TestModules.CreateDefaultRecorder(), TestModules.CreateDefaultRecognizer(), TestModules.CreateTelegramRunner() ); await using var recognitionService = new RecognitionService(moduleService); await using var runnerService = new RunnerService(moduleService, moduleService, recognitionService); using var exceptions = new IServiceBase[] { moduleService, recognitionService, runnerService }.EnableLogging(cancellationTokenSource); moduleService.Add(new RecognitionServiceRunner(recognitionService)); var process = runnerService.Start(new Command("send-telegram-voice-message"), cancellationToken); await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); var value = await process.StopAsync(cancellationToken); Assert.AreNotEqual(0, value.Output.Data.Length); }
/// <summary> /// Clears all data in the identified item /// </summary> /// <param name="item">The asset whose data contents are to be deleted</param> public ActionResult Clear(string item) { item = item.ToLowerInvariant(); switch (item) { case "db": _dataAccess.DbContext.Database.Delete(); break; case "cognitive": RecognitionService.ClearAll(); break; case "storage": new StorageService().ClearAll(); break; case "all": RecognitionService.ClearAll(); new StorageService().ClearAll(); _dataAccess.DbContext.Database.Delete(); break; default: return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.Message = "Deletion Successful"; return(View("Index")); }
public static async Task Start_Wait5Seconds_Stop_TestAsync( this RecognitionService service, CancellationToken cancellationToken = default) { using var recognition = await service.StartAsync(cancellationToken); await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); await recognition.StopAsync(cancellationToken); }
public static async Task <byte[]> StartRecordMp3_5Second_Stop_Async( this RecognitionService service, CancellationToken cancellationToken = default) { var recording = await service.StartRecordAsync(new AudioSettings(AudioFormat.Mp3), cancellationToken); await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); await recording.StopAsync(cancellationToken); return(recording.Data); }
public UserStoriesViewModel( IVstsService vstsService, NavigationServiceEx navigationService, IDialogServiceEx dialogService, RecognitionService recognitionService, SpeechService speechService) : base(vstsService, navigationService, dialogService, recognitionService, speechService) { }
/// <summary> /// /// </summary> /// <param name="recognitionService"></param> public PreviewViewModel(RecognitionService recognitionService) { RecognitionService = recognitionService ?? throw new ArgumentNullException(nameof(recognitionService)); Observable.FromEventPattern( RecognitionService, nameof(RecognitionService.Started)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => { IsStartedAgain = IsActive; Text = "Waiting command..."; IsActive = true; }); Observable.FromEventPattern <ICommand>( RecognitionService, nameof(RecognitionService.PreviewCommandReceived)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(pattern => { Text = $"{pattern.EventArgs}"; }); Observable.FromEventPattern <ICommand>( RecognitionService, nameof(RecognitionService.CommandReceived)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(pattern => { Text = pattern.EventArgs.IsEmpty ? "Didn't get that." : $"{pattern.EventArgs}"; }); Observable.FromEventPattern <ICommand>( RecognitionService, nameof(RecognitionService.CommandReceived)) .Delay(TimeSpan.FromSeconds(3)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => { IsActive = IsStartedAgain; Text = IsStartedAgain ? Text : string.Empty; IsStartedAgain = false; }); Close = ReactiveCommand.CreateFromTask(async cancellationToken => { IsActive = false; await RecognitionService.StopAsync(cancellationToken).ConfigureAwait(false); }).WithDefaultCatch(this); }
public static async Task Start5SecondsStart5SecondsStopTestAsync( this RecognitionService service, CancellationToken cancellationToken = default) { await service.StartAsync(cancellationToken); await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); await service.StartAsync(cancellationToken); await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); await service.StopAsync(cancellationToken); }
/// <summary> /// Enrolls a student into a class /// </summary> /// <param name="classId">The id of the class to enroll the student into</param> /// <param name="studentId">The id of the student to enroll</param> /// <returns>The enrollment created</returns> public Enrollment EnrollStudent(int classId, int studentId) { var existing = _db.Enrollments .FirstOrDefault(e => e.Class.Id == classId && e.Student.Id == studentId); var @class = _db.Classes.Find(classId); var student = _db.Students.Find(studentId); // Already enrolled if (existing != null) { throw new InvalidOperationException("Error enrolling student"); } var enrollment = new Enrollment { Class = @class, EnrollDate = DateTime.Now, Student = student }; _db.Enrollments.Add(enrollment); // Add the faces if (!student.Profile.Images.Any()) { throw new InvalidOperationException("Profile must be added before enrollment."); } // Create the Person for this student var faceClient = RecognitionService.GetFaceClient(); var person = Task.Run(() => faceClient.CreatePersonAsync(classId.ToString(), student.FirstName)).Result; foreach (var image in student.Profile.Images) { Task.Run(() => faceClient.AddPersonFaceAsync(@class.Id.ToString(), person.PersonId, image.Url)).Wait(); } // Update training status for class enrollment.PersonId = person.PersonId; enrollment.Class.TrainingStatus = TrainingStatus.UnTrained; _db.SaveChanges(); return(enrollment); }
public async Task SimpleTest() { using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var cancellationToken = cancellationTokenSource.Token; await using var moduleService = new StaticModuleService( TestModules.CreateDefaultRecorder(), TestModules.CreateDefaultRecognizer() ); await using var recognitionService = new RecognitionService(moduleService); using var exceptions = new IServiceBase[] { moduleService, recognitionService }.EnableLogging(cancellationTokenSource); await recognitionService.Start_Wait5Seconds_Stop_TestAsync(cancellationToken); }
public WashingMachineViewModel() { _washingProgramModel = new WashingProgramModel(); MainGridVisibility = Visibility.Visible; WashingProgramGridVisibility = Visibility.Hidden; WashingTimeGridVisibility = Visibility.Hidden; WashingTemperatureGridVisibility = Visibility.Hidden; WashingSummaryGridVisibility = Visibility.Hidden; OrderHistoryGridVisibility = Visibility.Hidden; WashingMachineProgramInfoVisibility = Visibility.Hidden; _eventAggregator = new EventAggregator(); _eventAggregator.Subscribe(this); _recognitionService = new RecognitionService(_eventAggregator); _synthesizerService = new SynthesizerService(); _databaseService = new DatabaseService(); _recognitionFromSentence = new RecognitionFromSentenceService(); }
/// <summary> /// Creates a new class /// </summary> /// <param name="name">The name/title of the class</param> /// <param name="number">The course number</param> /// <param name="section">The section</param> /// <param name="semester">The semester e.g. Fall 2016</param> /// <param name="teacher">The teacher for this class</param> /// <returns>The created class</returns> /// <remarks>Throws InvalidOperationException if class already exists with the given details</remarks> public Class CreateClass(string name, int number, string section, Semester semester, int year, int teacherId) { var existing = _db.Classes .Count(c => c.Name == name && c.Number == number && c.Section == section && c.Semester == semester && c.Teacher.Id == teacherId); var teacher = _db.Teachers.Find(teacherId); if (existing > 0 || teacher == null) { throw new InvalidOperationException("Error creating class"); } var newClass = new Class { Name = name, Number = number, Section = section, Semester = semester, Year = year, TrainingStatus = TrainingStatus.UnTrained, Teacher = teacher }; var added = _db.Classes.Add(newClass); _db.SaveChanges(); // Create the PersonGroup for this class var faceClient = RecognitionService.GetFaceClient(); Task.Run(() => faceClient.CreatePersonGroupAsync(added.Id.ToString(), added.Name)).Wait(); return(added); }
public async Task Process_ReturnsNonEmptyRecognitionResult_WhenIntentHasRequiredScore() { var query = "I'm testing you"; var luisResultModel = CreateTestLuisResultModel(); var recognitionResult = new RecognitionResult { Message = "I will pass your test" }; var settingsMock = new Mock <ISettings>(); settingsMock.Setup(x => x.IntentThreshold).Returns(0.75); var intentServiceMock = new Mock <IIntentService>(); var intentWithHighestScore = luisResultModel.Intents.OrderByDescending(x => x.Score).FirstOrDefault(); intentServiceMock.Setup(x => x.Execute(intentWithHighestScore.Name, luisResultModel.Entities)) .Returns(Task.FromResult(recognitionResult)) .Verifiable(); var luisServiceMock = CreateLuisServiceMock(luisResultModel, query); var loggerMock = new Mock <ILogger <RecognitionService> >(); var recognitionService = new RecognitionService(settingsMock.Object, intentServiceMock.Object, luisServiceMock.Object, loggerMock.Object); var result = await recognitionService.Process(query); luisServiceMock.Verify(); intentServiceMock.Verify(); Assert.IsNotNull(result); Assert.AreEqual(result, recognitionResult); }
/// <summary> /// Train the recognizer for the given class /// </summary> /// <param name="classId">The id of the class</param> public void TrainRecognizer(int classId) { var @class = GetById(classId); if (@class == null) { throw new InvalidOperationException("Error training recognizer"); } if (@class.TrainingStatus != TrainingStatus.UnTrained) { return; } @class.TrainingStatus = TrainingStatus.Training; _db.SaveChanges(); var recognitionService = new RecognitionService(); Task.Run(() => recognitionService.TrainRecognizer(classId.ToString())).Wait(); @class.TrainingStatus = TrainingStatus.Trained; _db.SaveChanges(); }
public RecognitionController(RecognitionService service) { this.service = service; }
/// <summary> /// Record a new lecture for the given class using the given images /// </summary> /// <param name="classId">The id of the class</param> /// <param name="images">The images to detect students from</param> public Lecture RecordLecture(int classId, IEnumerable <Stream> images) { var @class = _db.Classes.Find(classId); if (@class == null) { throw new InvalidOperationException("Error training recognizer"); } else if (@class.TrainingStatus != TrainingStatus.Trained) { throw new InvalidOperationException("Cannot record using untrained recognizer"); } var lecture = new Lecture() { Class = @class, RecordDate = DateTime.Now }; // Save the images in Azure Storage var storageManager = new StorageService(); var uploadedImages = storageManager.SaveImages(images); foreach (var image in uploadedImages) { lecture.Images.Add(image); } // Detect the faces in the images var recognitionService = new RecognitionService(); var personIds = recognitionService.DetectStudents(classId.ToString(), uploadedImages); // Create StudentAttendance for each student in class var enrollments = _db.Enrollments.Where(e => e.Class.Id == classId) .Include(e => e.Student); Dictionary <Guid, StudentAttendance> attendanceMap = new Dictionary <Guid, StudentAttendance>(); foreach (var enrollment in enrollments) { var attendance = new StudentAttendance { Lecture = lecture, Student = enrollment.Student, Present = false }; lecture.Attendance.Add(attendance); attendanceMap.Add(enrollment.PersonId, attendance); } // Mark detected students as present foreach (var personId in personIds) { attendanceMap[personId].Present = true; } _db.Lectures.Add(lecture); _db.SaveChanges(); // Alert absent students var absent = lecture.Attendance.Where(a => !a.Present) .Select(a => a.Student); AlertAbsentStudents(absent, @class); return(lecture); }