private void resetLearningBtn_Click(object sender, EventArgs e)
 {
     if (allUsersLstView.FocusedItem != null)
     {
         int userID = int.Parse(allUsersLstView.FocusedItem.SubItems[1].Text);
         UserDBDataSetWorkerTableAdapters.WordDataTableAdapter wordAdapter   = new UserDBDataSetWorkerTableAdapters.WordDataTableAdapter();
         UserDBDataSetWorkerTableAdapters.TimingTableAdapter   timingAdapter = new UserDBDataSetWorkerTableAdapters.TimingTableAdapter();
         timingAdapter.DeleteByUserID(userID);
         wordAdapter.DeleteByUserID(userID);
         Populate();
     }
 }
Beispiel #2
0
        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);
        }
        public bool SaveData(UserClient client, List <KeyData.KeyEntry> data)
        {
            WordInsert        Data = new WordInsert();
            List <WordInsert> words = new List <WordInsert>();
            String            PKBT, CKBT;//Previous and current keyboard type

            PKBT = data[0].keyboardType;
            List <UserDBDataSetWorker.TimingRow> timingEntries = new List <UserDBDataSetWorker.TimingRow>();
            int Ptime = Ptime = 0, Ctime = 0;

            Data.word = "";
            foreach (KeyData.KeyEntry entry in data)//extract data from parameter data
            {
                UserDBDataSetWorker.TimingRow timingEntry = dataSet.Timing.NewTimingRow();
                Ctime = entry.time;
                timingEntry.Timing = Ctime - Ptime;
                CKBT = entry.keyboardType;
                if (entry.keyValue == ':' || entry.keyValue == ',' || entry.keyValue == ' ')
                {
                    if (Data.word != "")
                    {
                        Data.KeyboardType = keyToInt(CKBT);
                        Data.UserID       = GetUserClientID(client.GetName(), client.GetPass());
                        words.Add(Data);
                    }
                    Data      = new WordInsert();
                    Data.word = "";
                    Ctime     = 0;
                }
                else if (CKBT != PKBT)
                {
                    if (Data.word != "")
                    {
                        Data.KeyboardType = keyToInt(CKBT);
                        Data.UserID       = GetUserClientID(client.GetName(), client.GetPass());
                        words.Add(Data);
                    }
                    Data       = new WordInsert();
                    Data.word  = "";
                    Ctime      = 0;
                    Data.word += entry.keyValue.ToString();
                }
                else
                {
                    Data.word += (char)entry.keyValue;
                    if (timingEntry.Timing != Ctime)
                    {
                        timingEntries.Add(timingEntry);
                    }
                }
                Ptime = Ctime;
                PKBT  = CKBT;
            }
            //Get straggling data.
            Data.KeyboardType = keyToInt(data[data.Count - 1].keyboardType);
            Data.UserID       = GetUserClientID(client.GetName(), client.GetPass());
            words.Add(Data);

            foreach (WordInsert word in words)//enter words
            {
                UserDBDataSetWorkerTableAdapters.WordDataTableAdapter adapter = new UserDBDataSetWorkerTableAdapters.WordDataTableAdapter();
                int test1 = GetUserClientID(client.GetName(), client.GetPass());
                adapter.WordInsert(test1, word.word, word.KeyboardType);
                int test = GetLatestWordID();
                for (int i = 1; i < word.word.Length; i++)//enter timing for words
                {
                    UserDBDataSetWorkerTableAdapters.TimingTableAdapter timeAdapter = new UserDBDataSetWorkerTableAdapters.TimingTableAdapter();
                    timeAdapter.TimingInsert(GetLatestWordID(), timingEntries[i].Timing, i);
                }
            }
            return(true);
        }