Ejemplo n.º 1
0
        /// <summary>
        /// Creates the learn log entry.
        /// </summary>
        /// <param name="learnLogStruct">The learn log struct.</param>
        /// <param name="parent">The parent.</param>
        /// <remarks>Documented by Dev08, 2008-09-05</remarks>
        public static void CreateLearnLogEntry(LearnLogStruct learnLogStruct, ParentClass parent)
        {
            if (lastSessionId < 0)             //Only write if there is a valid userSession
            {
                return;
            }

            if (parent.CurrentUser.ConnectionString.Typ == DatabaseType.Xml)
            {
                return;
            }
            else
            {
                try
                {
                    lock (logQueue)
                    {
                        logQueue.Enqueue(learnLogStruct);
                        Monitor.Pulse(logQueue);
                    }
                }
                catch (Exception ex) { Trace.WriteLine("Error writing log: " + ex.Message); }
            }
        }
        /// <summary>
        /// Creates the learn log entry.
        /// </summary>
        /// <param name="learnLog">The learn log.</param>
        /// <remarks>Documented by Dev10, 2009-01-11</remarks>
        public void CreateLearnLogEntry(LearnLogStruct learnLog)
        {
            bool answeredCardCorrect = false;

            if (learnLog.MoveType != MoveType.Manual)
            {
                if (learnLog.NewBox > 1)
                {
                    answeredCardCorrect = true;
                }
            }

            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                cmd.CommandText  = "INSERT INTO LearnLog (session_id, user_id, lm_id, cards_id, old_box, new_box, timestamp, duration, learn_mode, move_type, answer, direction, case_sensitive, correct_on_the_fly, percentage_known, percentage_required) ";
                cmd.CommandText += "VALUES(@sid, @uid, @lmid, @cid, @obox, @nbox, @ts, @dur, @lmode, @mtype, @answ, @dir, @csen, @cotf, @pknown, @preq); ";
                if (learnLog.MoveType != MoveType.Manual && answeredCardCorrect)
                {
                    cmd.CommandText += "UPDATE LearningSessions SET sum_right=sum_right + 1 WHERE id=@sid AND user_id=@uid AND lm_id=@lmid; ";
                }
                else if (learnLog.MoveType != MoveType.Manual && !answeredCardCorrect)
                {
                    cmd.CommandText += "UPDATE LearningSessions SET sum_wrong=sum_wrong + 1 WHERE id=@sid AND user_id=@uid AND lm_id=@lmid; ";
                }

                string newBoxContent = string.Empty;
                string oldBoxContent = string.Empty;
                if (learnLog.NewBox.Value > 0)
                {
                    newBoxContent = "box" + learnLog.NewBox.Value.ToString() + "_content";
                }
                else
                {
                    newBoxContent = "pool_content";
                }

                if (learnLog.OldBox.Value > 0)
                {
                    oldBoxContent = "box" + learnLog.OldBox.Value.ToString() + "_content";
                }
                else
                {
                    oldBoxContent = "pool_content";
                }

                if (learnLog.NewBox.Value != learnLog.OldBox.Value)
                {
                    cmd.CommandText += "UPDATE LearningSessions SET " + newBoxContent + "=" + newBoxContent + " + 1, " + oldBoxContent + "=" + oldBoxContent + " - 1 WHERE id=@sid AND user_id=@uid AND lm_id=@lmid; ";
                }

                cmd.Parameters.Add("@sid", learnLog.SessionID.Value);
                cmd.Parameters.Add("@uid", Parent.CurrentUser.Id);
                cmd.Parameters.Add("@lmid", Parent.CurrentUser.ConnectionString.LmId);
                cmd.Parameters.Add("@cid", learnLog.CardsID.Value);
                cmd.Parameters.Add("@obox", learnLog.OldBox.Value);
                cmd.Parameters.Add("@nbox", learnLog.NewBox.Value);
                cmd.Parameters.Add("@ts", learnLog.TimeStamp.Value);
                cmd.Parameters.Add("@dur", learnLog.Duration.Value);
                cmd.Parameters.Add("@lmode", learnLog.LearnMode.Value.ToString());
                cmd.Parameters.Add("@mtype", learnLog.MoveType.Value.ToString());
                cmd.Parameters.Add("@answ", learnLog.Answer);
                cmd.Parameters.Add("@dir", learnLog.Direction.Value.ToString());
                cmd.Parameters.Add("@csen", learnLog.CaseSensitive);
                cmd.Parameters.Add("@cotf", learnLog.CorrectOnTheFly);
                cmd.Parameters.Add("@pknown", learnLog.PercentageKnown);
                cmd.Parameters.Add("@preq", learnLog.PercentageRequired);

                MSSQLCEConn.ExecuteNonQuery(cmd);
            }

            //delete caches
            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.StatisticWrongCards, learnLog.SessionID.Value));
            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.StatisticCorrectCards, learnLog.SessionID.Value));
            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.StatisticContentOfBoxes, learnLog.SessionID.Value));
        }
Ejemplo n.º 3
0
        public void IStatisticsLogAndSessionTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary target = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))      //Learning
                {
                    if (target.Parent.CurrentUser.ConnectionString.Typ == DatabaseType.Xml)
                    {
                        return;
                    }

                    ICardsTests.FillDummyDic(target);
                    Log.OpenUserSession(target.Id, target.Parent);

                    for (int i = 0; i < 10; i++)
                    {
                        LearnLogStruct lls = new LearnLogStruct();
                        lls.SessionID       = Log.LastSessionID;
                        lls.CardsID         = target.Cards.Cards[i].Id;
                        lls.Answer          = "testAnswer " + i;
                        lls.CaseSensitive   = i % 2 == 0 ? true : false;
                        lls.CorrectOnTheFly = i % 2 == 0 ? true : false;
                        lls.Direction       = EQueryDirection.Mixed;
                        lls.Duration        = new TimeSpan(0, 0, 50).Ticks;
                        lls.LearnMode       = EQueryType.Word;
                        lls.MoveType        = i % 4 == 0 ? MoveType.AutoPromote : MoveType.AutoDemote;

                        if (lls.MoveType == MoveType.AutoPromote)       //promote
                        {
                            if (target.Cards.Cards[i].Box == 10)
                            {
                                lls.NewBox = 10;
                            }
                            else if (target.Cards.Cards[i].Box == 0)
                            {
                                lls.NewBox = 2;
                            }
                            else
                            {
                                lls.NewBox = target.Cards.Cards[i].Box + 1;
                            }
                        }
                        else                                            //demote
                        {
                            lls.NewBox = 1;
                        }

                        lls.OldBox             = target.Cards.Cards[i].Box;
                        lls.PercentageKnown    = 100;
                        lls.PercentageRequired = 50;
                        lls.TimeStamp          = DateTime.Now;

                        Thread.Sleep(100);

                        Log.CreateLearnLogEntry(lls, target.Parent);
                    }

                    Log.CloseUserSession(target.Parent);

                    Thread.Sleep(250);

                    Assert.AreEqual(1, target.Statistics.Count, "Dictionary.Statistics should contain ONE entry");
                    Assert.AreEqual(3, target.Statistics[0].Right, "Dictionary.Statistics[0].Right should contain the number 3.");
                    Assert.AreEqual(7, target.Statistics[0].Wrong, "Dictionary.Statistics[0].Wrong should contain the number 7.");
                }
            }
        }
        /// <summary>
        /// Creates a learn log entry.
        /// </summary>
        /// <param name="learnLog">A learn log struct.</param>
        /// <remarks>Documented by Dev08, 2008-09-05</remarks>
        public void CreateLearnLogEntry(LearnLogStruct learnLog)
        {
            bool answeredCardCorrect = false;

            if (learnLog.MoveType != MoveType.Manual)
            {
                if (learnLog.NewBox > 1)
                {
                    answeredCardCorrect = true;
                }
            }

            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText  = "INSERT INTO \"LearnLog\" (session_id, user_id, lm_id, cards_id, old_box, new_box, timestamp, duration, learn_mode, move_type, answer, direction, case_sensitive, correct_on_the_fly, percentage_known, percentage_required) ";
                    cmd.CommandText += " VALUES(:sid, :uid, :lmid, :cid, :obox, :nbox, :ts, :dur, :lmode, :mtype, :answ, :dir, :csen, :cotf, :pknown, :preq); ";

                    if (learnLog.MoveType != MoveType.Manual && answeredCardCorrect)
                    {
                        cmd.CommandText += "UPDATE \"LearningSessions\" SET sum_right=sum_right + 1 WHERE id=:sid AND user_id=:uid AND lm_id=:lmid; ";
                    }
                    else if (learnLog.MoveType != MoveType.Manual && !answeredCardCorrect)
                    {
                        cmd.CommandText += "UPDATE \"LearningSessions\" SET sum_wrong=sum_wrong + 1 WHERE id=:sid AND user_id=:uid AND lm_id=:lmid; ";
                    }

                    string newBoxContent = string.Empty;
                    string oldBoxContent = string.Empty;
                    if (learnLog.NewBox.Value > 0)
                    {
                        newBoxContent = "box" + learnLog.NewBox.Value.ToString() + "_content";
                    }
                    else
                    {
                        newBoxContent = "pool_content";
                    }

                    if (learnLog.OldBox.Value > 0)
                    {
                        oldBoxContent = "box" + learnLog.OldBox.Value.ToString() + "_content";
                    }
                    else
                    {
                        oldBoxContent = "pool_content";
                    }

                    if (learnLog.NewBox.Value != learnLog.OldBox.Value)
                    {
                        cmd.CommandText += "UPDATE \"LearningSessions\" SET " + newBoxContent + "=" + newBoxContent + " + 1, " + oldBoxContent + "=" + oldBoxContent + " - 1 WHERE id=:sid AND user_id=:uid AND lm_id=:lmid; ";
                    }

                    cmd.Parameters.Add("sid", learnLog.SessionID.Value);
                    cmd.Parameters.Add("uid", Parent.CurrentUser.Id);
                    cmd.Parameters.Add("lmid", Parent.CurrentUser.ConnectionString.LmId);
                    cmd.Parameters.Add("cid", learnLog.CardsID.Value);
                    cmd.Parameters.Add("obox", learnLog.OldBox.Value);
                    cmd.Parameters.Add("nbox", learnLog.NewBox.Value);
                    cmd.Parameters.Add("ts", (NpgsqlTypes.NpgsqlTimeStamp)learnLog.TimeStamp.Value);
                    cmd.Parameters.Add("dur", learnLog.Duration.Value);
                    cmd.Parameters.Add("lmode", learnLog.LearnMode.Value.ToString());
                    cmd.Parameters.Add("mtype", learnLog.MoveType.Value.ToString());
                    cmd.Parameters.Add("answ", learnLog.Answer);
                    cmd.Parameters.Add("dir", learnLog.Direction.Value.ToString());
                    cmd.Parameters.Add("csen", learnLog.CaseSensitive);
                    cmd.Parameters.Add("cotf", learnLog.CorrectOnTheFly);
                    cmd.Parameters.Add("pknown", learnLog.PercentageKnown);
                    cmd.Parameters.Add("preq", learnLog.PercentageRequired);

                    PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);
                }
            }
        }