public int GetLatestWordID() { int answer = 0; UserDBDataSetWorkerTableAdapters.WordDataTableAdapter adapter = new UserDBDataSetWorkerTableAdapters.WordDataTableAdapter(); UserDBDataSetWorker.UserClientDataTable table = new UserDBDataSetWorker.UserClientDataTable(); answer = adapter.MaxWordID().Value; return(answer); }
public bool CheckCredentials(String UserName, String Password) { UserDBDataSetWorkerTableAdapters.UserClientTableAdapter checkAdapter = new UserDBDataSetWorkerTableAdapters.UserClientTableAdapter(); UserDBDataSetWorker.UserClientDataTable table = new UserDBDataSetWorker.UserClientDataTable(); checkAdapter.CheckCredentials(table, UserName, Password); if (table.Count == 1) { return(true); } return(false); }
private int GetUserClientID(String UserName, String Password) { UserDBDataSetWorkerTableAdapters.UserClientTableAdapter checkAdapter = new UserDBDataSetWorkerTableAdapters.UserClientTableAdapter(); UserDBDataSetWorker.UserClientDataTable table = new UserDBDataSetWorker.UserClientDataTable(); checkAdapter.CheckCredentials(table, UserName, Password); if (table.Count == 1) { return(table[0].UserID); } return(-1); }
/// <summary> /// Add users on database to screen. /// </summary> public void Populate() { UserDBDataSetWorkerTableAdapters.UserClientTableAdapter adapter = new UserDBDataSetWorkerTableAdapters.UserClientTableAdapter(); UserDBDataSetWorker.UserClientDataTable userTable = adapter.GetUserWordCount(); allUsersLstView.Items.Clear(); foreach (UserDBDataSetWorker.UserClientRow row in userTable) { string[] subItems = new string[3]; subItems[0] = row.UserName; subItems[1] = row.UserID.ToString(); subItems[2] = row.ItemArray[3].ToString(); allUsersLstView.Items.Add(new ListViewItem(subItems)); } }
private void submitBtn_Click(object sender, EventArgs e) { bool passed = false; if (parent.proctor.CheckCredentials(usernameRTxt.Text, passwordRTxt.Text)) { UserDBDataSetWorkerTableAdapters.UserClientTableAdapter adapter = new UserDBDataSetWorkerTableAdapters.UserClientTableAdapter(); UserDBDataSetWorker.UserClientDataTable userTable = adapter.GetCheckCredentials(usernameRTxt.Text, passwordRTxt.Text); parent.proctor.GetConnection().SetLearning(target, userTable[0].UserName, userTable[0].Pass, userTable[0].UserID); Hide(); parent.Populate(); } else { //ask for resubmission with new username } }
/// <summary> /// Updates the activeClientListView predictions for predicting mode clients. /// </summary> /// <param name="data"> /// The prediction data from proctor. /// </param> public void UpdatePredictions(List <KeyValuePair <UserClient, KeyValuePair <int, double> > > data) { if (activeClientsLstView.InvokeRequired) { SetPredictionTextCallback d = new SetPredictionTextCallback(UpdatePredictions); this.Invoke(d, data); } else { if (activeClientsLstView.Items.Count > 0 && data.Count > 0) { foreach (KeyValuePair <UserClient, KeyValuePair <int, double> > prediction in data) { UserDBDataSetWorkerTableAdapters.UserClientTableAdapter adapter = new UserDBDataSetWorkerTableAdapters.UserClientTableAdapter(); UserDBDataSetWorker.UserClientDataTable userClientTable = adapter.GetDataByUserID(prediction.Value.Key); ListViewItem item = activeClientsLstView.Items[prediction.Key.GetName()]; ListViewItem test = activeClientsLstView.Items[0]; item.SubItems[2].Text = userClientTable[0].UserName; item.SubItems[3].Text = userClientTable[0].UserID.ToString(); item.SubItems[4].Text = (prediction.Value.Value * 100).ToString(); } } } }
private KeyValuePair <int, double> predict(UserClient client) { KeyValuePair <int, double> answer; List <KeyValuePair <int, double> > answerlist = new List <KeyValuePair <int, double> >(), meanAnswerList = new List <KeyValuePair <int, double> >(), medianAnswerList = new List <KeyValuePair <int, double> >(); double likeness = 0, meanLikeness = 0, medianLikeness = 0; List <WordData> predictionData = ToWords(client.GetPredictionData()); if (predictionData.Count > 0) { UserDBDataSetWorkerTableAdapters.UserClientTableAdapter userAdapt = new UserDBDataSetWorkerTableAdapters.UserClientTableAdapter(); UserDBDataSetWorker.UserClientDataTable userTable = userAdapt.GetUserClientData(); foreach (UserDBDataSetWorker.UserClientRow userRow in userTable) { int count = 0; foreach (WordData word in predictionData) { UserDBDataSetWorkerTableAdapters.WordDataTableAdapter wordAdapt = new UserDBDataSetWorkerTableAdapters.WordDataTableAdapter(); UserDBDataSetWorker.WordDataDataTable wordTable = wordAdapt.GetDataByUserIDandWord(userRow.UserID, word.GetWord()); if (wordTable.Count > 0) { List <WordData> wordList = new List <WordData>(); foreach (UserDBDataSetWorker.WordDataRow wordRow in wordTable) { UserDBDataSetWorkerTableAdapters.TimingTableAdapter timeAdapt = new UserDBDataSetWorkerTableAdapters.TimingTableAdapter(); UserDBDataSetWorker.TimingDataTable timeTable = timeAdapt.GetDataByWordID(wordRow.WordID); if (timeTable.Count > 0) { int[] timing = new int[timeTable.Count]; for (int i = 0; i < timeTable.Count; i++) { timing[i] = timeTable[i].Timing; } WordData learnedWord = new WordData(wordRow.Word, timing, userRow.UserID); double comp = Compare(word, learnedWord); if (comp > 0) { likeness += Compare(word, learnedWord); count++; } wordList.Add(learnedWord); } } if (word.GetTiming().Length > 0) { meanLikeness = MeanCompare(word, wordList); medianLikeness = MedianCompare(word, wordList); } //meanaverage } } likeness /= count; answerlist.Add(new KeyValuePair <int, double>(userRow.UserID, likeness)); meanAnswerList.Add(new KeyValuePair <int, double>(userRow.UserID, meanLikeness)); medianAnswerList.Add(new KeyValuePair <int, double>(userRow.UserID, medianLikeness)); meanAList = meanAnswerList; medianAList = medianAnswerList; bool problem; if (likeness > 1) { problem = true; } likeness = 0; count = 0; } } if (answerlist.Count > 1) { switch (predictionMode) { case 0: //compare answer = MaxValue(answerlist); //most probable prediction break; case 1: //mean answer = MaxValue(meanAnswerList); //most probable prediction break; default: case 2: //median answer = MaxValue(medianAnswerList); //most probable prediction break; } } else { answer = new KeyValuePair <int, double>(0, 0); } return(answer); }