public MainInterface()
        {
            InitializeComponent();
            database = new DatabaseControl();
            bw.WorkerSupportsCancellation = true;
            bw.WorkerReportsProgress = true;

            blankList = new List<bool>();

            //studies = database.Load();
            currentStudy = new Study();
            studyDisplay.DataSource = database.GetStudies();

            currentSubject = new Subject();
            //subjectDisplay.DataSource = currentStudy.subjects;

            currentSession = new Session();
            //sessionDisplay.DataSource = currentSubject.sessions;

            currentTrial = new Trial();
            //trialDisplay.DataSource = currentSession.trials;

            radiusSettings.SelectedIndex = 1;

            this.Refresh();
        }
        public SensorReading(Study study, Subject subject, Session session, Trial trial, long recordnum, TrackerInterface.Record rec)
        {
            this.study = study;
            this.subject = subject;
            this.session = session;
            this.trial = trial;
            this.time = rec.time[0];

            sensors = new Sensor[32];

            for (int i = 0; i < sensors.Length; i++)
            {
                sensors[i] = new Sensor();
                sensors[i].active = rec.active[i];
                sensors[i].x = rec.x[i];
                sensors[i].y = rec.y[i];
                sensors[i].z = rec.z[i];
                sensors[i].pitch = rec.pitch[i];
                sensors[i].yaw = rec.yaw[i];
                sensors[i].roll = rec.roll[i];
                sensors[i].time = rec.time[i];
                if (this.time == 0)
                {
                    time = rec.time[i];
                }
                sensors[i].quality = rec.quality[i];
                sensors[i].button = rec.button[i];
            }
        }
 public Subject_PreMongo(string id, string bdate, string gender, Study study)
 {
     this.study = study;
     this.id = id;
     this.bdate = bdate;
     this.gender = gender;
     this.sessions = new ObservableCollection<Session>();
 }
 public Trial_PreMongo(string name, string time, Study study, Subject subject, Session session)
 {
     this.study = study;
     this.subject = subject;
     this.session = session;
     this.name = name;
     this.data = new ConcurrentQueue<SensorReading>();
 }
 public Session_PreMongo(string name, string tdate, Study study, Subject subject)
 {
     this.study = study;
     this.subject = subject;
     this.name = name;
     this.tdate = tdate;
     this.trials = new ObservableCollection<Trial>();
 }
Beispiel #6
0
        public void ExportStudyToMultipleFiles(DatabaseControl db, Study study, string directory)
        {
            string header = "StudyName,SubjectID,SessionName,SessionDate,TrialName,SessionSync1.Onset,SessionSync1.Offset,SessionSync2.Onset,SessionSync2.Offset,";

            for (int i = 0; i < 15; i++)
            {
                header += string.Format("Sensor{0}.ID,Sensor{0}.Time,Sensor{0}.Switch,Sensor{0}.X,Sensor{0}.Y,Sensor{0}.Z,Sensor{0}.Pitch,Sensor{0}.Roll,Sensor{0}.Yaw,Sensor{0}.quality,", i);
            }

            foreach (Subject sub in db.GetSubjects(study))
            {
                foreach (Session sess in db.GetSessions(sub))
                {
                    foreach (Trial trial in db.GetTrials(sess))
                    {
                        Console.WriteLine("Dumping trial : " + trial.name);
                        string filename = directory + "\\" + study.name + "-" + sub.id + "-" + sess.name + "-" + trial.name + ".csv";
                        status = string.Format("{0} - {1} - {2} - {3}", study.name, sub.id, sess.name, trial.name);

                        using (System.IO.StreamWriter file = new System.IO.StreamWriter(@filename))
                        {
                            file.Write(header + "\n");

                            int total = db.GetSensorReadings(trial).Count();
                            int count = 0;
                            foreach (SensorReading pt in db.GetSensorReadings(trial))
                            {
                                count++;
                                percent = Convert.ToInt32(Math.Ceiling((float)count / (float)total * 100.0));
                                Sensor[] sensors = pt.sensors;

                                // Append study/sub/sess/trial data
                                file.Write(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", study.name, sub.id, sess.name, sess.tdate, trial.name, sess.sync1_on, sess.sync1_off, sess.sync2_on, sess.sync2_off));
                                for (int i = 0; i < sensors.Length; i++)
                                {
                                    if (sensors[i].active == 1)
                                    {
                                        // Append sensor data whether sensor is active or not
                                        file.Write(string.Format(",{0},{9},{1},{2:0.00},{3:0.00},{4:0.00},{5:0.00},{6:0.00},{7:0.00},{8}",
                                            i, sensors[i].button, sensors[i].x, sensors[i].y, sensors[i].z, sensors[i].pitch, sensors[i].roll, sensors[i].yaw, sensors[i].quality, sensors[i].time));
                                    }
                                    else
                                    {
                                        // If the sensor wasn't active then append a blank filler
                                        file.Write(",,,,,,,,,,");
                                    }
                                }
                                file.Write("\n");
                            }
                        }
                        percent = 0;
                    }
                }
            }
        }
Beispiel #7
0
 public Session(string name, string tdate, Study study, Subject subject)
 {
     this.study = study;
     this.subject = subject;
     this.name = name;
     this.tdate = tdate;
     this.sync1_on = -1;
     this.sync1_off = -1;
     this.sync2_on = -1;
     this.sync2_off = -1;
     //this.trials = new ObservableCollection<Trial>();
 }
        private void addNewStudy_Click(object sender, EventArgs e)
        {
            string       value  = "";
            DialogResult result = MainInterface.InputBox("New Study", "New study name:", ref value);

            if (result == DialogResult.OK && value != "")
            {
                currentStudy = new Study(value);
                database.AddStudy(currentStudy);

                studyDisplay.DataSource = null;
                studyDisplay.DataSource = database.GetStudies();
                studyDisplay.ClearSelected();
                Console.WriteLine(database.GetStudies());
                studyDisplay.SetSelected(database.GetStudyIndex(currentStudy), true);
            }
            else if (result == DialogResult.OK)
            {
                MessageBox.Show("Invalid study name.");
            }
        }
 public ObservableCollection<Subject> GetSubjects(Study study)
 {
     ObservableCollection<Subject> subjects = new ObservableCollection<Subject>();
     var query = Query.EQ("study._id", study._Id);
     foreach (Subject subject in subject_collection.Find(query))
     {
         subjects.Add(subject);
     }
     ObservableCollection<Subject> subjectsSort = new ObservableCollection<Subject>(
         subjects.OrderBy(subject => subject.id)
         );
     return subjectsSort;
 }
Beispiel #10
0
        // This function will return a list of all of the times that the sync key was hit
        public List<int> FindSyncTimes(DatabaseControl db, Study study, Subject sub, Session sess)
        {
            List<int> times = new List<int>();

            return times;
        }
 public Exporter runExportSubjectByTrial(DatabaseControl database, Study currentStudy, Subject currentSubject, String directory)
 {
     Thread.Sleep(100);
     exporter.ExportSubjectToMultipleFiles(database, currentStudy, currentSubject, directory);
     return(exporter);
 }
 public Exporter runExportSubject(DatabaseControl database, Study currentStudy, Subject currentSubject, String filename)
 {
     Thread.Sleep(100);
     exporter.ExportSubjectToCSVOneFile(database, currentStudy, currentSubject, filename);
     return(exporter);
 }
 public void SetTrial(Trial trial)
 {
     this.trial = trial;
     this.session = trial.session;
     this.subject = session.subject;
     this.study = session.study;
 }
        private void addNewStudy_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogResult result = MainInterface.InputBox("New Study", "New study name:", ref value);
            if (result == DialogResult.OK && value != "")
            {
                currentStudy = new Study(value);
                database.AddStudy(currentStudy);

                studyDisplay.DataSource = null;
                studyDisplay.DataSource = database.GetStudies();
                studyDisplay.ClearSelected();
                Console.WriteLine(database.GetStudies());
                studyDisplay.SetSelected(database.GetStudyIndex(currentStudy), true);
            }
            else if (result == DialogResult.OK)
            {
                MessageBox.Show("Invalid study name.");
            }
        }
 public Exporter runExportSubjectByTrial(DatabaseControl database, Study currentStudy, Subject currentSubject, String directory)
 {
     Thread.Sleep(100);
     exporter.ExportSubjectToMultipleFiles(database, currentStudy, currentSubject, directory);
     return exporter;
 }
Beispiel #16
0
        // This function will return a list of all of the times that the sync key was hit
        public List <int> FindSyncTimes(DatabaseControl db, Study study, Subject sub, Session sess)
        {
            List <int> times = new List <int>();

            return(times);
        }
        private void removeStudy_Click(object sender, EventArgs e)
        {
            if (studyDisplay.SelectedIndex > -1)
            {
                DialogResult result = MessageBox.Show("Are you sure you want to delete this study?", "Remove Study", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    currentStudy = database.GetStudies()[studyDisplay.SelectedIndex];
                    database.RemoveStudy(currentStudy);
                    currentStudy = null;

                    studyDisplay.DataSource = null;
                    studyDisplay.DataSource = database.GetStudies();
                }
            }
        }
 public int GetStudyIndex(Study study)
 {
     ObservableCollection<Study> studies = GetStudies();
     for (int i = 0; i < studies.Count; i++)
     {
         Study s = studies[i];
         if (study._Id == s._Id)
         {
             return i;
         }
     }
     return -1;
 }
 public void AddStudy(Study s)
 {
     studies_collection.Insert(s);
     Console.WriteLine("Study added.");
 }
        private void studyDisplay_SelectedIndexChanged(object sender, EventArgs e)
        {
            Console.WriteLine(studyDisplay.SelectedIndex);
            if (studyDisplay.SelectedIndex == -1)
            {
                studyDisplay.ClearSelected();
            }
            else
            {
                currentStudy = database.GetStudies()[studyDisplay.SelectedIndex];
                Console.WriteLine(currentStudy.ToString());

                // Refresh the data windows
                subjectDisplay.DataSource = database.GetSubjects(currentStudy);
                ((CurrencyManager)subjectDisplay.BindingContext[subjectDisplay.DataSource]).Refresh();
                subjectDisplay.ClearSelected();

                sessionDisplay.DataSource = blankList;
                ((CurrencyManager)sessionDisplay.BindingContext[sessionDisplay.DataSource]).Refresh();
                //sessionDisplay.DataSource = null;
                //sessionDisplay.DataSource = currentSubject.sessions;
                //sessionDisplay.ClearSelected();

                trialDisplay.DataSource = blankList;
                ((CurrencyManager)trialDisplay.BindingContext[trialDisplay.DataSource]).Refresh();
                //trialDisplay.DataSource = null;
                //trialDisplay.DataSource = currentSession.trials;
                //trialDisplay.ClearSelected();
            }
        }
 public void AddStudy(Study s)
 {
     studies_collection.Insert(s);
     Console.WriteLine("Study added.");
 }
 public void RemoveStudy(Study s)
 {
     var query = Query.Or(
         Query.EQ("_id", s._Id),
         Query.EQ("study._id", s._Id)
         );
     studies_collection.Remove(query);
     session_collection.Remove(query);
     subject_collection.Remove(query);
     trial_collection.Remove(query);
     sensor_readings_collection.Remove(query);
 }
 public Exporter runExportSubject(DatabaseControl database, Study currentStudy, Subject currentSubject, String filename)
 {
     Thread.Sleep(100);
     exporter.ExportSubjectToCSVOneFile(database, currentStudy, currentSubject, filename);
     return exporter;
 }