/// <summary> /// Creator: Chase Schulte /// Created: 2020/03/01 /// Approver: /// /// Deactivate a Training Video /// </summary> /// /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="video"></param> /// <returns></returns> public int DeactivateTrainingVideo(TrainingVideo video) { int videoID = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_deactivate_training_video", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@TrainingVideoID", video.TrainingVideoID); try { conn.Open(); videoID = Convert.ToInt32(cmd.ExecuteNonQuery()); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(videoID); }
private void TrainingVideoContextMenu_Opened(object sender, RoutedEventArgs e) //dynamically change the context menu options for each video depending on the training stage { TrainingVideo selectedVideo = (TrainingVideo)TrainingListBox.SelectedItem; ContextMenu contextMenu = (ContextMenu)sender; if (selectedVideo != null) { MenuItem labelItem = (MenuItem)contextMenu.Items[1]; MenuItem framesItem = (MenuItem)contextMenu.Items[2]; if (!selectedVideo.FramesExtracted) { framesItem.Header = "Extract & Label Frames"; labelItem.Visibility = Visibility.Collapsed; } else { framesItem.Header = "Extract More Frames"; labelItem.Visibility = Visibility.Visible; } if (!selectedVideo.FramesLabeled) { labelItem.Header = "Label Frames"; } else { labelItem.Header = "Edit Labels"; } } }
/// <summary> /// Creator: Alex Diers /// Created: 2/6/2020 /// Approver: Lane Sandburg /// /// Implementation of the InsertTrainingVideo method to add a TrainingVideo /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> /// <param name="video"></param> /// <returns></returns> public int InsertTrainingVideo(TrainingVideo video) { int videoID = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_insert_training_video", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@TrainingVideoID", video.TrainingVideoID); cmd.Parameters.AddWithValue("@RunTimeMinutes", video.RunTimeMinutes); cmd.Parameters.AddWithValue("@RunTimeSeconds", video.RunTimeSeconds); cmd.Parameters.AddWithValue("@Description", video.Description); try { conn.Open(); videoID = Convert.ToInt32(cmd.ExecuteNonQuery()); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(videoID); }
public ActionResult TrainingVideoList() { TrainingVideo d = new TrainingVideo(); DataTable dt = d.selectall(); return(View(dt)); }
/// <summary> /// Creator: Alex Diers /// Created: 2/6/2020 /// Approver: Lane Sandburg /// /// Method to activate video /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> /// <param name="videoID"></param> /// <returns>int</returns> public int ActivateTrainingVideo(TrainingVideo videoID) { TrainingVideo trainingVideo = null; //Fail immediately if null if (videoID == null) { throw new Exception(); } //Check that video is in list, if so assign it, else fail foreach (var v in trainingVideos) { if (videoID.TrainingVideoID == v.TrainingVideoID) { trainingVideo = v; } } //Throw exception if video isn't in list if (trainingVideo == null || videoID.TrainingVideoID != trainingVideo.TrainingVideoID) { throw new Exception(); } //Activate it trainingVideo.Active = true; if (trainingVideo.Active == true) { return(1); } return(0); }
public ActionResult TrainingVideoDelete(int ID) { TrainingVideo d = new TrainingVideo(); d.TrainingVideoID = ID; d.delete(); return(RedirectToAction("TrainingVideoList")); }
private void ExtractFrames(TrainingVideo video) //extract frames from a particular training video { FramesToExtractDialog dialog = new FramesToExtractDialog(); //first ask the user how many frames to extract if (dialog.ShowDialog() == true) { CurrentProject.FramesToExtract = dialog.FramesToExtractTextBox.Text; UpdateFramesToExtract(); FileSystemUtils.WaitForFile(CurrentProject.ConfigPath); string filePath = EnvDirectory + "\\vdlc_extract_frames.py"; FileSystemUtils.MurderPython(); FileSystemUtils.RenewScript(filePath, AllScripts.ExtractFrames); //run DLC's extract_frames function using a script FileSystemUtils.ReplaceStringInFile(filePath, "config_path_identifier", CurrentProject.ConfigPath); //set function parameters FileSystemUtils.ReplaceStringInFile(filePath, "video_path_identifier", video.Path); Process p = new Process(); //prepare a cmd process to run the script ProcessStartInfo info = new ProcessStartInfo(); info.FileName = "cmd.exe"; info.RedirectStandardInput = true; info.UseShellExecute = false; info.Verb = "runas"; info.CreateNoWindow = !ReadShowDebugConsole(); //if show debug console = true, then create no window has to be false p.EnableRaisingEvents = true; p.Exited += (sender1, e1) => //once done, continue to labeling the video automatically { LabelFrames(video); }; p.StartInfo = info; p.Start(); using (StreamWriter sw = p.StandardInput) { //run the script using the command line if (sw.BaseStream.CanWrite) { sw.WriteLine(Drive); sw.WriteLine("cd " + EnvDirectory); sw.WriteLine(FileSystemUtils.CONDA_ACTIVATE_PATH); sw.WriteLine("conda activate " + EnvName); sw.WriteLine("ipython vdlc_extract_frames.py"); if (info.CreateNoWindow == false) //for debug purposes { sw.WriteLine("ECHO WHEN YOU'RE DONE, CLOSE THIS WINDOW"); p.WaitForExit(); sw.WriteLine("Done, exiting."); } } } } else { EnableInteraction(); } }
// MARK: Extraction Methods private void EditFramesClicked(object sender, RoutedEventArgs e) { TrainingVideo vid = (TrainingVideo)TrainingListBox.SelectedItem; if (vid != null) //check if the video has extracted frames, if not inform the user { BarInteraction(); ExtractFrames(vid); } else { MessageBox.Show("This video's project data seems to be corrupted. Try adding it again under a different name.", "Video Data Corrupted", MessageBoxButton.OK); } }
public async Task <VideoAnalysisDto> GetVideoAnalysisForEdit(VideoAnalysisDto input) { var users = await _context.Role.Where(x => x.Id == input.Id).FirstOrDefaultAsync(); if (users != null) { TrainingVideo trainingVideoDto = MappingProfile.MappingConfigurationSetups().Map <TrainingVideo>(input); _context.TrainingVideo.Update(trainingVideoDto); await _context.SaveChangesAsync(); return(MappingProfile.MappingConfigurationSetups().Map <VideoAnalysisDto>(trainingVideoDto)); } return(new VideoAnalysisDto()); }
/// <summary> /// Creator: Alex Diers /// Created: 2/6/2020 /// Approver: Jordan Lindo /// /// Implementation of the InsertTrainingVideo method from the ITrainingVideoManager /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> /// <param name="video"></param> /// <returns></returns> public bool InsertTrainingVideo(TrainingVideo video) { bool result = true; try { result = _trainingVideoAccessor.InsertTrainingVideo(video) > 0; } catch (Exception ex) { throw new ApplicationException("Video not added", ex); } return(result); }
/// <summary> /// Creator: Alex Diers /// Created: 2/13/2020 /// Approver: Lane Sandburg /// /// Implementation of the RetrieveTrainingVideoManager method from the ITrainingVideoManager interface /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> /// <returns></returns> public bool EditTrainingVideo(TrainingVideo oldVideo, TrainingVideo newVideo) { bool result = false; try { result = _trainingVideoAccessor.UpdateTrainingVideo(oldVideo, newVideo) > 0; } catch (Exception ex) { throw new ApplicationException("Update failed", ex); } return(result); }
private void DeleteClicked(object sender, RoutedEventArgs e) //delete training video clicked { FileSystemUtils.MurderPython(); BarInteraction(); if (CurrentProject.TrainingVideos.Count < 2) { MessageBox.Show("There needs to be at least one video.", "Invalid Action", MessageBoxButton.OK, MessageBoxImage.Warning); //there's a bug if the user adds videos and then decides to delete all of them, this prevents it from happening EnableInteraction(); } else { if (MessageBox.Show("Are you sure?", "Delete Video", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { EnableInteraction(); } else { TrainingVideo selectedVideo = (TrainingVideo)TrainingListBox.SelectedItem; //delete the training video int selectedIndex = TrainingListBox.SelectedIndex; CurrentProject.TrainingVideos.RemoveAt(selectedIndex); TrainingListBox.ItemsSource = CurrentProject.TrainingVideos; TrainingListBox.UpdateLayout(); File.Delete(selectedVideo.Path); //File.Delete(selectedVideo.ThumbnailPath); thumbnail is being used by the program so there's a lock on it and we can't delete it - //TODO string dir = CurrentProject.ConfigPath.Substring(0, CurrentProject.ConfigPath.LastIndexOf("\\")) + "\\labeled-data\\" + selectedVideo.Name; //delete the associated labeled data if it exists if (Directory.Exists(dir)) { foreach (var file in Directory.GetFiles(dir)) { File.Delete(file); } } DeleteVidFromConfig(CurrentProject.ConfigPath, selectedVideo.Path); if (CurrentProject.TrainedWith.Contains(selectedVideo.Path)) { CurrentProject.TrainedWith.Remove(selectedVideo.Path); UpdateVGLConfig(); } if (Directory.Exists(dir)) { Directory.Delete(dir); } SyncUI(); EnableInteraction(); } } }
/// <summary> /// Creator: Chase Schulte /// Created: 03/01/2020 /// Approver: Jordan Lindo /// /// Method tests viewing TrainingVideo objects by Employee /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> public int UpdateTrainingVideo(TrainingVideo oldVideo, TrainingVideo newVideo) { bool videoTrue = false; //Fail immediatly if null if (oldVideo == null) { throw new Exception(); } //Check that eRole is in list, if so assign it, else fail foreach (var trainingVideo in trainingVideos) { if (oldVideo.TrainingVideoID == trainingVideo.TrainingVideoID && oldVideo.RunTimeSeconds == trainingVideo.RunTimeSeconds && oldVideo.RunTimeMinutes == trainingVideo.RunTimeMinutes && oldVideo.Description == trainingVideo.Description && trainingVideo != null) { videoTrue = true; } } //Throw exception if eRole isn't in list if (videoTrue == false) { throw new Exception(); } //Make sure PK remains the same if (oldVideo.TrainingVideoID != newVideo.TrainingVideoID) { throw new Exception(); } //Make sure description isn't too long if (newVideo.Description != null && newVideo.Description.Length > 1000) { throw new Exception(); } //Update old ERole to newVideo oldVideo = newVideo; //Make sure old eRole is updated if (oldVideo == newVideo) { return(1); } return(0); }
public ActionResult TrainingVideoInsert(FormCollection collection) { TrainingVideo d = new TrainingVideo(); d.UploadTime = Convert.ToDateTime(DateTime.Now.ToString()); //Convert.ToDateTime(DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss")); d.VideoTitle = collection["VideoTitle"]; d.VideoURL = collection["VideoURL"]; d.StaffID = Convert.ToInt32(collection["StaffID"]); d.VideoCategoryID = Convert.ToInt32(collection["VideoCategoryID"]); d.HelpfulCount = Convert.ToInt32(collection["HelpfulCount"]); d.TotalCount = Convert.ToInt32(collection["TotalCount"]); d.insert(); return(RedirectToAction("TrainingVideoDetail")); }
private void LabelFrames(TrainingVideo video) //start DLC's labeling toolbox for a particular video { string filePath = EnvDirectory + "\\vdlc_label_frames.py"; FileSystemUtils.MurderPython(); FileSystemUtils.RenewScript(filePath, AllScripts.LabelFrames); //prepare to call DeepLabCut's labeling function FileSystemUtils.ReplaceStringInFile(filePath, "config_path_identifier", CurrentProject.ConfigPath); //set params FileSystemUtils.ReplaceStringInFile(filePath, "video_path_identifier", CurrentProject.ConfigPath.Substring(0, CurrentProject.ConfigPath.LastIndexOf("\\")) + "\\labeled-data\\" + video.Name); Process p = new Process(); //prepare the cmd backgroung process ProcessStartInfo info = new ProcessStartInfo(); info.FileName = "cmd.exe"; info.RedirectStandardInput = true; info.UseShellExecute = false; info.Verb = "runas"; info.CreateNoWindow = !ReadShowDebugConsole(); //if show debug console = true, then create no window has to be false p.EnableRaisingEvents = true; p.Exited += (sender1, e1) => { SyncUI(); EnableInteraction(); }; p.StartInfo = info; p.Start(); using (StreamWriter sw = p.StandardInput) //run the labeling script { if (sw.BaseStream.CanWrite) { sw.WriteLine(Drive); sw.WriteLine("cd " + EnvDirectory); sw.WriteLine(FileSystemUtils.CONDA_ACTIVATE_PATH); sw.WriteLine("conda activate " + EnvName); sw.WriteLine("ipython vdlc_label_frames.py"); if (info.CreateNoWindow == false) //for debug purposes { sw.WriteLine("ECHO WHEN YOU'RE DONE, CLOSE THIS WINDOW"); p.WaitForExit(); sw.WriteLine("Done, exiting."); } } } }
public ActionResult TrainingVideoEdit(int id) { TrainingVideo c = new TrainingVideo(); c.TrainingVideoID = id; c.SelectByID(); Staff s = new Models.Staff(); ViewBag.dts = s.selectall(); VideoCategory vc = new Models.VideoCategory(); ViewBag.dtvc = vc.selectall(); return(View(c)); }
/// <summary> /// Creator: Alex Diers /// Created: 2/6/2020 /// Approver: Lane Sandburg /// /// Method to test the insertion of a TrainingVideo object /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> /// <param name="video"></param> /// <returns></returns> public int InsertTrainingVideo(TrainingVideo video) { TrainingVideo newVideo = new TrainingVideo(); newVideo = video; try { trainingVideos.Add(newVideo); return(1); } catch (Exception ex) { return(0); throw ex; } }
public ActionResult TrainingVideoUpdate(FormCollection collection) { TrainingVideo d = new TrainingVideo(); d.TrainingVideoID = Convert.ToInt32(collection["TrainingVideoID"]); d.SelectByID(); d.UploadTime = Convert.ToDateTime(DateTime.Now.ToString()); d.VideoTitle = collection["VideoTitle"]; d.VideoURL = collection["VideoURL"]; d.StaffID = Convert.ToInt32(collection["StaffID"]); d.VideoCategoryID = Convert.ToInt32(collection["VideoCategoryID"]); d.HelpfulCount = Convert.ToInt32(collection["HelpfulCount"]); d.TotalCount = Convert.ToInt32(collection["TotalCount"]); d.update(); return(RedirectToAction("TrainingVideoList")); }
// MARK: Labeling Methods private void EditLabelsClicked(object sender, RoutedEventArgs e) { TrainingVideo vid = (TrainingVideo)TrainingListBox.SelectedItem; if (vid != null) //check if the video has extracted frames, if not inform the user { if (vid.FramesExtracted) { BarInteraction(); LabelFrames(vid); } else { MessageBox.Show("You haven't extracted any frames for this video. Choose the \"Edit Frames\" option instead.", "Frames Not Extracted", MessageBoxButton.OK); } } else { MessageBox.Show("This video's project data is corrupted. Try adding the video under a different name.", "Video Data Corrupted", MessageBoxButton.OK); } }
/// <summary> /// Creator: Alex Diers /// Created: 2/13/2020 /// Approver: Lane Sandburg /// /// Implementation of the SelectTrainingVideosByEmployee method used to show /// a list of training videos the employee needs to watch /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> public int UpdateTrainingVideo(TrainingVideo oldVideo, TrainingVideo newVideo) { int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_update_trainer_video", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@NewRunTimeMinutes", newVideo.RunTimeMinutes); cmd.Parameters.AddWithValue("@NewRunTimeSeconds", newVideo.RunTimeSeconds); cmd.Parameters.AddWithValue("@NewDescription", newVideo.Description); cmd.Parameters.AddWithValue("@OldTrainingVideoID", oldVideo.TrainingVideoID); cmd.Parameters.AddWithValue("@OldRunTimeMinutes", oldVideo.RunTimeMinutes); cmd.Parameters.AddWithValue("@OldRunTimeSeconds", oldVideo.RunTimeSeconds); cmd.Parameters.AddWithValue("@OldDescription", oldVideo.Description); try { conn.Open(); rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }