Exemplo n.º 1
0
    /// <summary>
    ///   This method writes the data that is written in the lists during
    ///   recording to OGAMAs dataset.
    ///   If this could be successfully done the whole new data is
    ///   written to the database (SQL Database file).
    /// </summary>
    private void SaveRecordingIntoTablesAndDB()
    {
      try
      {
        // Set wait cursor until UI is reset
        Cursor.Current = Cursors.WaitCursor;

        string subject = this.currentTracker.Subject.SubjectName;

        if (subject == string.Empty)
        {
          var dialog = new AskForSubjectNameDialog(false);
          dialog.ShowDialog();
          subject = dialog.SubjectName;
        }

        this.bgwSaveSplash.RunWorkerAsync("Saving to database ...");

        // Creates an empty raw data table in the mdf database
        Queries.CreateRawDataTableInDB(subject);

        // Write RawDataTable into File with Bulk Statement
        Queries.WriteRawDataWithBulkStatement(subject, this.subjectRawDataTable);

        // Save subject information to dataset
        if (!Queries.WriteSubjectToDataSet(this.currentTracker.Subject))
        {
          throw new DataException("The new subject information could not be written into the dataset.");
        }

        // Save trial information to dataset
        if (!Queries.WriteTrialsDataListToDataSet(this.trialDataList))
        {
          throw new DataException("The new trials table could not be written into the dataset.");
        }

        // Save trial event information to dataset
        if (!Queries.WriteTrialEventsToDataSet(this.trialEventList))
        {
          throw new DataException("The new trials table could not be written into the dataset.");
        }

        Document.ActiveDocument.DocDataSet.EnforceConstraints = false;

        // Update subjects and trials table in the mdf database
        Document.ActiveDocument.DocDataSet.TrialEventsAdapter.Update(Document.ActiveDocument.DocDataSet.TrialEvents);
        Document.ActiveDocument.DocDataSet.TrialsAdapter.Update(Document.ActiveDocument.DocDataSet.Trials);
        Document.ActiveDocument.DocDataSet.SubjectsAdapter.Update(Document.ActiveDocument.DocDataSet.Subjects);

        Document.ActiveDocument.DocDataSet.AcceptChanges();
        Document.ActiveDocument.DocDataSet.CreateRawDataAdapters();

        Document.ActiveDocument.DocDataSet.EnforceConstraints = true;

        // Get trial data of current subject
        DataTable trialsTable = Document.ActiveDocument.DocDataSet.TrialsAdapter.GetDataBySubject(subject);

        // Hide splash
        this.bgwSaveSplash.CancelAsync();

        // Show new splash new info
        this.bgwCalcFixations.RunWorkerAsync("Calculating fixations ...");
        Application.DoEvents();

        // Calculate fixations
        var calculationObject = new FixationCalculation();
        calculationObject.CalcFixations(SampleType.Gaze, subject, trialsTable, null, null);
        calculationObject.CalcFixations(SampleType.Mouse, subject, trialsTable, null, null);

        this.bgwCalcFixations.CancelAsync();

        // Show the success information on the 
        // controllers screen
        var successDlg = new SavingSuccessDialog();
        Rectangle controllerBounds = PresentationScreen.GetControllerWorkingArea();
        successDlg.Location = new Point(
          controllerBounds.Width / 2 - successDlg.Width / 2,
          controllerBounds.Height / 2 - successDlg.Height / 2);
        successDlg.ShowDialog();
      }
      catch (Exception ex)
      {
        ExceptionMethods.HandleException(ex);

        // Hide saving splash.
        if (this.bgwSaveSplash.IsBusy)
        {
          this.bgwSaveSplash.CancelAsync();
        }

        // Hide fixation calculation splash.
        if (this.bgwCalcFixations.IsBusy)
        {
          this.bgwCalcFixations.CancelAsync();
        }

        // CleanUp
        // First reject changes (remove trial and subject table modifications)
        Document.ActiveDocument.DocDataSet.RejectChanges();

        Document.ActiveDocument.DocDataSet.EnforceConstraints = false;

        Document.ActiveDocument.DocDataSet.SubjectsAdapter.Update(Document.ActiveDocument.DocDataSet.Subjects);
        Document.ActiveDocument.DocDataSet.TrialsAdapter.Update(Document.ActiveDocument.DocDataSet.Trials);
        Document.ActiveDocument.DocDataSet.TrialEventsAdapter.Update(Document.ActiveDocument.DocDataSet.TrialEvents);

        // Remove eventually added raw data table in dataset
        if (Document.ActiveDocument.DocDataSet.Tables.Contains(this.currentTracker.Subject.SubjectName + "Rawdata"))
        {
          Document.ActiveDocument.DocDataSet.Tables.Remove(this.currentTracker.Subject.SubjectName + "Rawdata");
        }

        Document.ActiveDocument.DocDataSet.EnforceConstraints = true;

        // Remove raw data table in database file (.mdf)
        Queries.DeleteRawDataTableInDB(this.currentTracker.Subject.SubjectName);

        string filename = Path.Combine(
          Document.ActiveDocument.ExperimentSettings.ThumbsPath,
          this.currentTracker.Subject.SubjectName + ".avi");
        if (File.Exists(filename))
        {
          File.Delete(filename);
        }
      }
      finally
      {
        // Free resources
        this.trialEventList.Clear();
        this.trialDataList.Clear();
        this.subjectRawDataTable.Dispose();
      }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Starts fixation calculation for every subject in list. 
    /// </summary>
    /// <param name="worker">background worker</param>
    /// <param name="e">do work event arguments</param>
    private void CalculateFixForAllSubjects(BackgroundWorker worker, DoWorkEventArgs e)
    {
      DataTable subjectsTable = Document.ActiveDocument.DocDataSet.SubjectsAdapter.GetData();
      foreach (DataRow subjectRow in subjectsTable.Rows)
      {
        string strSubject = (string)subjectRow["SubjectName"];
        try
        {
          ((MainForm)this.MdiParent).StatusLabel.Text = "Calculation Subject: " + strSubject;
        }
        catch (InvalidOperationException ex)
        {
          ExceptionMethods.HandleExceptionSilent(ex);
        }

        // Get trial data of current subject
        DataTable trialsTable = Document.ActiveDocument.DocDataSet.TrialsAdapter.GetDataBySubject(strSubject);

        FixationCalculation calculationObject = new FixationCalculation();
        calculationObject.CalcFixations(SampleType.Gaze, strSubject, trialsTable, worker, e);
        calculationObject.CalcFixations(SampleType.Mouse, strSubject, trialsTable, worker, e);

        if (e.Cancel)
        {
          break;
        }
      }
    }
Exemplo n.º 3
0
    /// <summary>
    /// The <see cref="Control.Click"/> event handler for the
    /// <see cref="Button"/> <see cref="btnCalculateFix"/>.
    /// User pressed calculate button. Starts fixation calculation 
    /// referring to parameter selections in a background worker thread.
    /// </summary>
    /// <param name="sender">Source of the event.</param>
    /// <param name="e">An empty <see cref="EventArgs"/></param>
    private void btnCalculateFix_Click(object sender, EventArgs e)
    {
      // Disable the Start button.
      this.btnCalculateFix.Enabled = false;

      this.Cursor = Cursors.WaitCursor;

      // unbind datagridview because it should not be updated while background worker is busy,
      // that would give a cross thread error. Is reset in backgroundWorker_RunWorkerCompleted 
      this.dgvGazeFixations.DataSource = null;
      this.dgvMouseFixations.DataSource = null;

      if (this.btnSelectedSubject.Checked)
      {
        string subject = this.cbbSubject.Text;
        ((MainForm)this.MdiParent).StatusLabel.Text = "Calculating subject: " + subject;

        int deleted = Document.ActiveDocument.DocDataSet.GazeFixationsAdapter.DeleteBySubject(subject);
        deleted = Document.ActiveDocument.DocDataSet.MouseFixationsAdapter.DeleteBySubject(subject);

        Document.ActiveDocument.DocDataSet.GazeFixationsAdapter.Fill(Document.ActiveDocument.DocDataSet.GazeFixations);
        Document.ActiveDocument.DocDataSet.MouseFixationsAdapter.Fill(Document.ActiveDocument.DocDataSet.MouseFixations);

        FixationCalculation calculationObject = new FixationCalculation();
        calculationObject.Worker.ProgressChanged += new ProgressChangedEventHandler(this.bgwCalcFixations_ProgressChanged);
        calculationObject.Worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.bgwCalcFixations_RunWorkerCompleted);
        calculationObject.CalculateSubjectsFixations(subject);
      }
      else if (this.btnAllSubjects.Checked)
      {
        int affectedRows = Document.ActiveDocument.DocDataSet.GazeFixationsAdapter.DeleteAll();
        affectedRows = Document.ActiveDocument.DocDataSet.MouseFixationsAdapter.DeleteAll();

        Document.ActiveDocument.DocDataSet.GazeFixationsAdapter.Fill(Document.ActiveDocument.DocDataSet.GazeFixations);
        Document.ActiveDocument.DocDataSet.MouseFixationsAdapter.Fill(Document.ActiveDocument.DocDataSet.MouseFixations);

        this.bgwCalcFixationsForAllSubjects.RunWorkerAsync();
      }

      this.Cursor = Cursors.Default;
    }
Exemplo n.º 4
0
    /// <summary>
    /// This method calculates the fixations for the subjects
    ///   that are currently imported.
    /// </summary>
    /// <param name="mainWindow">
    /// The <see cref="MainForm"/> to get access to the status label.
    /// </param>
    private static void CalculateFixations(MainForm mainWindow)
    {
      mainWindow.StatusLabel.Text = "Calculating Fixations ...";

      foreach (SubjectsData subject in SubjectList)
      {
        // Get trial data of current subject
        DataTable trialsTable = Document.ActiveDocument.DocDataSet.TrialsAdapter.GetDataBySubject(subject.SubjectName);

        // Calculate fixations
        var calculationObject = new FixationCalculation();
        calculationObject.CalcFixations(SampleType.Gaze, subject.SubjectName, trialsTable, null, null);
        calculationObject.CalcFixations(SampleType.Mouse, subject.SubjectName, trialsTable, null, null);
      }

      mainWindow.StatusLabel.Text = "Fixation calculation done ...";
    }