public List <Word> testList(User requested) { //database.Refresh(refresh_mode, requested); StudiesUser current = studiesUserFromUser(requested); List <Word> list = getWordList(current.WordListID, current.WordSublistID, current.Mix); return(list); }
//public bool advanceUserInStudy(DataClasses1DataContext database, int SID, int UID) public bool advanceUserInStudy(int SID, int UID) { DataClasses1DataContext database = new DataClasses1DataContext(); StudiesUser u = (from user in database.StudiesUsers where user.StudyID == SID && user.UserID == UID select user).Single(); //database.Refresh(refresh_mode, new Object[] {u, database.WordSublists, database.TrialTypes}); StudyUserGroup g = u.StudyUserGroup; //database.Refresh(refresh_mode, g); var subkeys = (from s in database.WordSublists select s.ID); var typekeys = (from s in database.TrialTypes select s.ID); int firstSublist = subkeys.Min(); int lastSublist = subkeys.Max(); int firstType = typekeys.Min(); int lastType = typekeys.Max(); if ((u.WordSublistID < lastSublist) && u.Mix) { u.WordSublistID++; u.Mix = false; } else if (!u.Mix) { if (u.WordSublistID == firstSublist) //nothing to mix at the beginning { u.WordSublistID++; } else { u.Mix = true; } } else if (u.TrialTypeID < lastType) { u.WordSublistID = firstSublist; u.TrialTypeID++; u.Mix = false; } else if (u.WordListID == g.FirstListID) { u.WordListID = g.SecondListID; u.WordSublistID = firstSublist; u.TrialTypeID = firstType; } else { u.Complete = true; } database.SubmitChanges(); return(u.Complete); }
public bool?allowTrial(User current) { //database.Refresh(refresh_mode, current); StudiesUser currentStudy = studiesUserFromUser(current); if (currentStudy.TrialType.Name == "Completed") { return(null); } DateTime today = DateTime.Now.Date; List <TrialBlock> blocks = userBlocks(current); TrialBlock last = null; if (blocks.Count > 0) { last = blocks[0]; } List <TrialBlock> todaysBlocks = new List <TrialBlock>(); foreach (TrialBlock t in blocks) { if (today == t.StartTime.Date) { todaysBlocks.Add(t); } if (DateTime.Compare(t.StartTime, last.StartTime) > 0) { last = t; } } //none performed yet if (last == null) { return(true); } //none today, and less than min wait since the last if ((DateTime.Compare(today, last.StartTime.Date) > 0) && ((DateTime.Now - last.StartTime) > currentStudy.Study.getWaitTime())) { return(true); } //fewer than 2 today if (todaysBlocks.Count < 2) { return(true); } //otherwise two have been performed today or not enough time since previous day return(false); }
public bool receiveSoundFeedback(User current) { //database.Refresh(refresh_mode, current); StudiesUser su = studiesUserFromUser(current); bool startControl = su.StudyUserGroup.StartControl; if (su.StudyUserGroup.FirstListID == su.WordListID) { return(startControl); } else { return(!startControl); } }
public bool recordTrialBlock(TrialBlockData results) { DataClasses1DataContext database = new DataClasses1DataContext(); StudiesUser x = (from su in database.StudiesUsers where su.StudyID == results.studyID && su.UserID == results.userID select su).Single(); TrialBlock newBlock = new TrialBlock(); newBlock.StudyID = results.studyID; newBlock.StartTime = results.taken; newBlock.UserID = results.userID; newBlock.TrialTypeID = results.typeID; newBlock.WordListID = x.WordListID; newBlock.WordSublistID = x.WordSublistID; database.TrialBlocks.InsertOnSubmit(newBlock); database.SubmitChanges(); int trialcount = results.clickID1s.Length; for (int i = 0; i < trialcount; i++) { Trial newTrial = new Trial(); newTrial.TrialBlockID = newBlock.ID; newTrial.WordID = results.words[i]; newTrial.TimeFirstIDpresented = results.showID1s[i]; newTrial.TimeFirstIDclicked = results.clickID1s[i]; newTrial.TimeSecondIDpresented = results.showID2s[i]; newTrial.TimeSecondIDclicked = results.clickID2s[i]; newTrial.TimeOptionsPresented = results.optionsShown[i]; newTrial.Option1ID = results.optionIDs[i][0]; newTrial.Option2ID = results.optionIDs[i][1]; newTrial.Option3ID = results.optionIDs[i][2]; newTrial.TimeOptionClicked = results.clickOptionTimes[i]; newTrial.OptionIDClicked = results.optionIDsClicked[i]; database.Trials.InsertOnSubmit(newTrial); database.SubmitChanges(); } return(evalPerformance(database, newBlock.ID, newBlock.Study.TargetWordsPerMinute, results.studyID, results.userID)); }
public string userUpdate(int userID, bool userActive, string userPassword, int studyID, int studyUserGroupID) { DataAccessor database = new DataAccessor(); User u = database.getUserByID(userID); User uu = database.login(u.Username, userPassword); StudiesUser su = database.studiesUserFromUser(u); bool movable = database.userEligibileToMove(userID); if (database.studyIDFromUser(u) != studyID || su.UserGroupID != studyUserGroupID) { if (!movable) { return("Error: Cannot move user."); } database.updateStudiesUser(userID, studyID, studyUserGroupID); } if (uu == null || (u.Active != userActive)) { database.updateUser(userID, userActive, userPassword); } return("Update successful."); }
public StudiesUser createStudiesUsers(int userID, int studyID, int studyUserGroupID) { DataClasses1DataContext database = new DataClasses1DataContext(); StudiesUser su = new StudiesUser(); su.StudyID = studyID; su.Complete = false; su.Mix = false; su.UserGroupID = studyUserGroupID; su.UserID = userID; su.WordSublistID = 1; /* * Ugly, but I designed the database wrong on this point. * StudyUserGroups.StartControl is a bool but should be a FK to TrialType * For now, use "True" as meaning "See Select" (1) and "False" as "Hear Select" (2) */ su.WordListID = StudyUserGroupStartListKey(studyUserGroupID); su.TrialTypeID = 1; database.StudiesUsers.InsertOnSubmit(su); database.SubmitChanges(); return(su); }
public void updateStudiesUser(int userID, int studyID, int studyUserGroupID) { DataClasses1DataContext database = new DataClasses1DataContext(); StudiesUser current_su = studiesUserFromUser(getUserByID(userID)); if (current_su != null) { database.StudiesUsers.DeleteOnSubmit(current_su); database.SubmitChanges(); } StudiesUser nsu = new StudiesUser(); nsu.UserID = userID; nsu.StudyID = studyID; nsu.UserGroupID = studyUserGroupID; nsu.Complete = false; nsu.Mix = false; nsu.TrialTypeID = 1; nsu.WordListID = 1; nsu.WordSublistID = 1; database.StudiesUsers.InsertOnSubmit(nsu); database.SubmitChanges(); }
public StudiesUser createStudiesUsers(int userID, int studyID, int studyUserGroupID) { DataClasses1DataContext database = new DataClasses1DataContext(); StudiesUser su = new StudiesUser(); su.StudyID = studyID; su.Complete = false; su.Mix = false; su.UserGroupID = studyUserGroupID; su.UserID = userID; su.WordSublistID = 1; /* * Ugly, but I designed the database wrong on this point. * StudyUserGroups.StartControl is a bool but should be a FK to TrialType * For now, use "True" as meaning "See Select" (1) and "False" as "Hear Select" (2) */ su.WordListID = StudyUserGroupStartListKey(studyUserGroupID); su.TrialTypeID = 1; database.StudiesUsers.InsertOnSubmit(su); database.SubmitChanges(); return su; }