From 4ef206ff47641464b24717f54379950584a5e7b2 Mon Sep 17 00:00:00 2001 From: Ivan Ribakov Date: Thu, 3 May 2018 20:56:45 +0200 Subject: [PATCH] Refactored ExpertControl.ActionValidation(): fixed LogEntry ordering issues --- .../Its.ExpertModule/ExpertControl.cs | 492 ++++++++++-------- .../StudentLog.cs | 20 + .../Its.StudentModule/StudentControl.cs | 101 +++- .../AbstractTutor.cs | 6 +- 4 files changed, 395 insertions(+), 224 deletions(-) diff --git a/ExpertModule/Its.ExpertModule/ExpertControl.cs b/ExpertModule/Its.ExpertModule/ExpertControl.cs index 2619458..c23884d 100755 --- a/ExpertModule/Its.ExpertModule/ExpertControl.cs +++ b/ExpertModule/Its.ExpertModule/ExpertControl.cs @@ -13,6 +13,8 @@ namespace Its.ExpertModule { public class ExpertControl { + private delegate int ValidationStep(ActionAplication action, DomainActions domain, Student student, ref List logs); + /// /// The instance. /// @@ -172,26 +174,15 @@ from o in domain.Actions public int ActionValidation (string actionName, string domainKey, string studentKey, string objName, out List outputError, out bool blockObject) { - /* - * 1. Comprobar previa ejecución de la acción y si esta es repetitiva. Error si no es repetitiva. - * 2. Comprobar dependencias. - * 2.1. Si es bloqueante, se notifica error. - * 2.2. Si no es bloqueante, se guarda el error. - * 3. Comprobar incompatibilidades. - * 4. Comprobar si la acción debe mostrar todos los mensajes cometidos previamente. - */ //Creates a variable with the result to return. int result = 1; - //Sets the value of blockObject to a default value. blockObject = false; - //Gets the DomainActions. + DomainActions domain = _domainActionsList [domainKey]; - //Gets the Student. Student student = _instanceStudentControl.GetStudent (studentKey); - //Gets the StudentLog of the given student for the specific domain. StudentLog studentLog; - //Creates an auxiliar variable. Dictionary dic; + try { studentLog = _instanceStudentControl.GetStudentLog (domainKey, studentKey); } catch (ArgumentException e) { @@ -208,9 +199,10 @@ public int ActionValidation (string actionName, string domainKey, string student } } - //Searchs and gets the action with the actionName given. ActionAplication action = null; outputError = new List (); + + //Searchs and gets the action with the actionName given. var actQuery = from o in domain.Actions where o.Name == actionName && o.Phase == studentLog.CurrentPhase @@ -221,88 +213,100 @@ from o in domain.Actions } else { //Get the error. Error error = _otherErrors["actionnotfound"]; - //Creates the log. - _instanceStudentControl.CreateOtherErrorLog(action, domain, student, false, error); - //Adds the error to the answer param. + LogEntry log = StudentControl.CreateOtherErrorLog(action, false, error); + _instanceStudentControl.AddLog(domain, student, log); outputError.Add(error); - //Returns the value. + return 0; } - - if (studentLog.HasPerformedActionWithoutError(action) && !action.IsRepetitive) + + // Creating action log entry. Entry is created before futher validation is performed in order to + // ensure that action log appears before non-blocking errors in the ontology (important for predictive student model) + // + // Currently only NoCorrective Action log is supported. + // TODO: Consider what will happen to predictive student model automaton if action has MinTime and will be created later. + LogEntry actionLog = null; + if (!action.CorrectiveAction && action.MinTime <= 0) { - //Get the error. - Error error = _otherErrors["actionalreadyperformed"]; - //Creates the log. - _instanceStudentControl.CreateOtherErrorLog(action, domain, student, false, error); - //Adds the error to the answer param. - outputError.Add(error); - //Returns the value. - return 0; + actionLog = StudentControl.CreateNoCorrectiveActionLog (action, true); + Thread.Sleep(10); } - //Gets action dependence. - ComplexDependence actionDependence = action.Dependence; - //Creates an auxiliar variable. - int resultCheckDependence = 0; - //Creates an auxiliar list in which will be saved the dependencies with errors. - List dependenceErrors = new List(); - //Checks if the action has a dependence. - if (actionDependence != null) { - //Checks the dependence type. - if (actionDependence.GetType () == typeof(SeqComplexDependence)) - resultCheckDependence = CheckSeqComplexDependencies ((SeqComplexDependence)actionDependence, action.Key, - studentLog, domain, ref dependenceErrors); - else if (actionDependence.GetType () == typeof(OptComplexDependence)) - resultCheckDependence = CheckOptComplexDependencies ((OptComplexDependence)actionDependence, action.Key, - studentLog, domain, ref dependenceErrors); - //Checks the result. - if (resultCheckDependence == 0) { - //Creates the log. - _instanceStudentControl.CreateDepErrorLog (action, domain, student, false, - dependenceErrors.Last ()); - //Adds the error to the answer param. - outputError.Add (dependenceErrors.Last ().DependenceError); - //Returns the value. - return 0; - } else if (resultCheckDependence == -1) { - //Sets the result. + // Define validation steps + List steps = new List() + { + ValidateActionNotPerformed, + ValidateActionDependencies, + ValidateActionIncompatibilities, + InitActionTimers, + ValidateActionMaxTimer + }; + + List logs = new List(); + + // Execute validation steps + foreach (ValidationStep step in steps) + { + List stepLogs = new List(); + + int stepResult = step(action, domain, student, ref stepLogs); + + if (stepResult == 0) + { + // If blocking error was encountered, don't perform futher checks and log current blocking error. + // Blocking error log has priority over any previously encountered error logs. + result = 0; + logs = stepLogs; + break; + } else if (stepResult == -1) + { result = -1; - //Creates a log for each dependence with an error. - foreach (Dependence d in dependenceErrors) { - //Creates the log. - _instanceStudentControl.CreateDepErrorLog (action, domain, student, false, - d); - } + logs.AddRange(stepLogs); } } - //Checks if there are any incompatibility. - if (action.Incompatibilities != null) { - //Checks if an incompatibility of the action exist. - foreach (Incompatibility i in action.Incompatibilities) { - //Checks if the incompatibility was done before the action - if (_instanceStudentControl.CheckLogActionOrder (domainKey, studentKey, - i.IncompatibilityAction.Key, action.Key)) { - //Checks if the incompatibility blocks. - if (i.IncompatibilityError.IsBlock) { - //Creates the log. - _instanceStudentControl.CreateIncompErrorLog (action, domain, student, false, i); - //Adds the error to the answer param. - outputError.Add (i.IncompatibilityError); - //Returns the value. - return 0; - } else { - //Creates the log. - _instanceStudentControl.CreateIncompErrorLog (action, domain, student, false, i); - //Sets the result. - result = -1; - } - } + + // Update logs dependending on validation outcome + if (result == 0) + { + // Blocking error: Only log last error (presumably the blocking one) + LogEntry lastLog = logs.Last(); + _instanceStudentControl.AddLog(domain, student, lastLog); + + // Update outputErrors container with blocking error message + if (lastLog.GetType() == typeof(MaxTimeErrorLog)) + { + ActionAplication previousAction = domain.GetPreviousAction(action.Key); + outputError.Add(previousAction.MaxTimeError); + } + else + { + outputError.Add(lastLog.Error); + } + + } else if (result == -1) + { + // Non-blokcing error(s): add all logs (action + error) + if (actionLog != null) + { + _instanceStudentControl.AddLog(domain, student, actionLog); + } + + _instanceStudentControl.AddLog(domain, student, logs); + } else if (result == 1) + { + // Correct action - only capture action log + if (actionLog != null) + { + _instanceStudentControl.AddLog(domain, student, actionLog); } } + //Checks if the action blocks the object. if (action.LockObj) - blockObject = true; + { + blockObject = true; + } + //Check if the action validate the phase errors. if (action.ValidateErrors) { //Gets all errors done by the user previously. @@ -311,120 +315,13 @@ from o in domain.Actions outputError.Add (e); } } + //Checks if the action change the current phase. if (action.InitPhase) - studentLog.CurrentPhase += 1; - //Checks if the action has minimun and/or maximun time. - if (action.MinTime > 0) { - //Creates a thread to control the minimun timer. - Thread minTimerThread = new Thread (new ParameterizedThreadStart(MinTimer)); - //Checks if student has an entry. - if (_minTimerController.ContainsKey (student.Key)) { - //Checks if a entry for the specific action already exists. - if (_minTimerController.TryGetValue (student.Key, out dic)) { - if (dic.ContainsKey (action.Key)) { - //Get the error. - Error error = _otherErrors ["actionalreadyperformed"]; - //Creates the log. - _instanceStudentControl.CreateOtherErrorLog (action, domain, student, false, error); - //Adds the error to the answer param. - outputError.Add (error); - //Returns the value. - return 0; - } else { - //Adds a new entry to the dictionary. - if (_minTimerController.TryGetValue (student.Key, out dic)) - dic.Add (action.Key, minTimerThread); - } - } - } else { - //Adds a new entry to the dictionary. - _minTimerController.Add(student.Key, new Dictionary()); - //Adds the thread to the dictionary. - //Adds a new entry to the dictionary. - if (_minTimerController.TryGetValue(student.Key, out dic)) - dic.Add (action.Key, minTimerThread); - } - //Starts the thread. - ArrayList param = new ArrayList(); - param.Add (minTimerThread); - param.Add (action); - param.Add (domain); - param.Add (student); - minTimerThread.Start (param); - } - if (action.MaxTime > 0) { - //Creates a thread to control the minimun timer. - Thread maxTimerThread = new Thread (new ParameterizedThreadStart(MaxTimer)); - //Checks if student has an entry. - if (_maxTimerController.ContainsKey (student.Key)) { - //Checks if a entry for the specific action already exists. - if (_maxTimerController.TryGetValue (student.Key, out dic)) { - if (dic.ContainsKey (action.Key)) { - //Get the error. - Error error = _otherErrors ["actionalreadyperformed"]; - //Creates the log. - _instanceStudentControl.CreateOtherErrorLog (action, domain, student, false, error); - //Adds the error to the answer param. - outputError.Add (error); - //Returns the value. - return 0; - } else { - //Adds a new entry to the dictionary. - if (_maxTimerController.TryGetValue (student.Key, out dic)) - dic.Add (action.Key, maxTimerThread); - } - } - } else { - //Adds a new entry to the dictionary. - _maxTimerController.Add(student.Key, new Dictionary()); - //Adds the thread to the dictionary. - //Adds a new entry to the dictionary. - if (_maxTimerController.TryGetValue(student.Key, out dic)) - dic.Add (action.Key, maxTimerThread); - } - - //Creates a thread to control the maximun timer. - maxTimerThread = new Thread (new ParameterizedThreadStart(MaxTimer)); - //Starts the thread. - ArrayList param = new ArrayList(); - param.Add (maxTimerThread); - param.Add (action); - param.Add (student); - param.Add (action.MaxTime); - //Starts the thread. - maxTimerThread.Start (param); - } - //At this moment, the action has been successful. Then, the action will be registered. - if (!action.CorrectiveAction && action.MinTime <= 0) - _instanceStudentControl.CreateNoCorrectiveActionLog (action, domain, student, true); - //Gets the previous action. - ActionAplication previousAction = domain.GetPreviousAction(action.Key); - //Checks if this is the first action done by the student. - if (previousAction != null) { - //Creates an auxiliar variable that will not use. - Thread t; - Dictionary maxTDic; - //Checks if the previous action created a maximun timer. - if (_maxTimerController.TryGetValue (studentLog.Owner.Key, out maxTDic)) { - if (!maxTDic.TryGetValue (previousAction.Key, out t) && previousAction.MaxTime > 0) { - //Generates a max time error. - _instanceStudentControl.CreateMaxTimeErrorLog (previousAction, domain, studentLog.Owner, false, previousAction.MaxTime); - //Checks if the dependence blocks or not. - if (previousAction.MaxTimeError.IsBlock) { - //The result will be zero. - result = 0; - //Adds the dependence into the list. - outputError.Add (previousAction.MaxTimeError); - } else { - //The result will be -1. - result = -1; - } - } - } + { + studentLog.CurrentPhase += 1; } - //Returns. return result; } @@ -442,7 +339,8 @@ private static void MinTimer (object data) //Sleeps the thread during the time the action required. Thread.Sleep (action.MinTime * 1000); //Registers the action log. - _instanceStudentControl.CreateNoCorrectiveActionLog (action, domain, student, true); + LogEntry log = StudentControl.CreateNoCorrectiveActionLog (action, true); + _instanceStudentControl.AddLog(domain, student, log); //Gets the thread and removes it. Dictionary minTDic; if (_maxTimerController.TryGetValue (student.Key, out minTDic)) @@ -477,8 +375,8 @@ private static void MaxTimer (object data) /// Action. /// Student log. /// Errors. - private int CheckOptComplexDependencies (OptComplexDependence complexDependence, string actionKey, - StudentLog studentLog, DomainActions domain, ref List errors) + private static int CheckOptComplexDependencies (OptComplexDependence complexDependence, string actionKey, + StudentLog studentLog, ref List errors, ref List logs) { //Creates an auxiliar variable. int result = 2; @@ -487,7 +385,7 @@ private int CheckOptComplexDependencies (OptComplexDependence complexDependence, //Checks the dependence type. if (d.GetType () == typeof(SeqComplexDependence)) { //Calls the dependence check method. - result = CheckSeqComplexDependencies ((SeqComplexDependence)d, actionKey, studentLog, domain, ref errors); + result = CheckSeqComplexDependencies ((SeqComplexDependence)d, actionKey, studentLog, ref errors, ref logs); //Checks the result of the call. if (result == 0 || result == -1) { errors.Add (d); @@ -508,8 +406,7 @@ private int CheckOptComplexDependencies (OptComplexDependence complexDependence, //Checks if there is a timer for this action. if (_minTimerController.TryGetValue (studentLog.Owner.Key, out dic)) { if (dic.TryGetValue (dep.ActionDependence.Key, out t)) { - //Generates a min time error. - _instanceStudentControl.CreateMinTimeErrorLog (dep.ActionDependence, domain, studentLog.Owner, false, dep.ActionDependence.MinTime); + logs.Add(StudentControl.CreateMinTimeErrorLog (dep.ActionDependence, false, dep.ActionDependence.MinTime)); //Checks if the dependence blocks or not. if (dep.ActionDependence.MinTimeError.IsBlock) { //The result will be zero. @@ -575,8 +472,8 @@ private int CheckOptComplexDependencies (OptComplexDependence complexDependence, /// Action key. /// Student log. /// Errors. - private int CheckSeqComplexDependencies (SeqComplexDependence complexDependence,string actionKey, - StudentLog studentLog, DomainActions domain, ref List errors) + private static int CheckSeqComplexDependencies (SeqComplexDependence complexDependence,string actionKey, + StudentLog studentLog, ref List errors, ref List logs) { //Creates an auxiliar int variable. int result = 2; @@ -587,7 +484,7 @@ private int CheckSeqComplexDependencies (SeqComplexDependence complexDependence, //Checks the dependence type. if (d.GetType () == typeof(OptComplexDependence)) { //Calls the dependence check method. - result = CheckOptComplexDependencies ((OptComplexDependence)d, actionKey, studentLog, domain, ref errors); + result = CheckOptComplexDependencies ((OptComplexDependence)d, actionKey, studentLog, ref errors, ref logs); //Checks the result of the call. if (result == 0) { //Adds the dependence into the list. @@ -658,8 +555,7 @@ private int CheckSeqComplexDependencies (SeqComplexDependence complexDependence, //Checks if there is a timer for this action. if (_minTimerController.TryGetValue (studentLog.Owner.Key, out dic)) { if (dic.TryGetValue (dep.ActionDependence.Key, out t)) { - //Generates a min time error. - _instanceStudentControl.CreateMinTimeErrorLog (dep.ActionDependence, domain, studentLog.Owner, false, dep.ActionDependence.MinTime); + logs.Add(StudentControl.CreateMinTimeErrorLog (dep.ActionDependence, false, dep.ActionDependence.MinTime)); //Checks if the dependence blocks or not. if (dep.ActionDependence.MinTimeError.IsBlock) { //The result will be zero. @@ -745,7 +641,7 @@ private int CheckSeqComplexDependencies (SeqComplexDependence complexDependence, /// Dependence1. /// Dependence2. /// Student log. - private bool CheckDependenceOrder (Dependence dependence1, Dependence dependence2, StudentLog studentLog) + private static bool CheckDependenceOrder (Dependence dependence1, Dependence dependence2, StudentLog studentLog) { //Creates the variable will be returned. bool checkResult = false; @@ -887,5 +783,191 @@ public DomainActions GetDomainActions (string domainKey) return value; } + + private int ValidateActionNotPerformed(ActionAplication action, DomainActions domain, Student student, ref List logs) + { + int result = 1; + + StudentLog studentLog = _instanceStudentControl.GetStudentLog (domain.Key, student.Key); + + if (studentLog.HasPerformedActionWithoutError(action) && !action.IsRepetitive) + { + //Get the error. + Error error = _otherErrors["actionalreadyperformed"]; + //Creates the log. + logs.Add(StudentControl.CreateOtherErrorLog(action, false, error)); + result = 0; + } + + return result; + } + + private int ValidateActionDependencies(ActionAplication action, DomainActions domain, Student student, ref List logs) + { + int result = 1; + + StudentLog studentLog = _instanceStudentControl.GetStudentLog (domain.Key, student.Key); + + ComplexDependence actionDependence = action.Dependence; + int resultCheckDependence = 0; + List dependenceErrors = new List(); + + if (actionDependence != null) { + + if (actionDependence.GetType () == typeof(SeqComplexDependence)) + resultCheckDependence = CheckSeqComplexDependencies ((SeqComplexDependence)actionDependence, action.Key, + studentLog, ref dependenceErrors, ref logs); + else if (actionDependence.GetType () == typeof(OptComplexDependence)) + resultCheckDependence = CheckOptComplexDependencies ((OptComplexDependence)actionDependence, action.Key, + studentLog, ref dependenceErrors, ref logs); + + if (resultCheckDependence == 0) { + logs.Add(StudentControl.CreateDepErrorLog (action, false, dependenceErrors.Last ())); + result = 0; + } else if (resultCheckDependence == -1) { + foreach (Dependence d in dependenceErrors) { + logs.Add(StudentControl.CreateDepErrorLog (action, false, d)); + } + result = -1; + } + } + + return result; + } + + private int ValidateActionIncompatibilities(ActionAplication action, DomainActions domain, Student student, ref List logs) + { + int result = 1; + + StudentLog studentLog = _instanceStudentControl.GetStudentLog (domain.Key, student.Key); + + if (action.Incompatibilities != null) { + foreach (Incompatibility i in action.Incompatibilities) { + if (studentLog.CheckActionOrder(i.IncompatibilityAction.Key, action.Key)) { + logs.Add(StudentControl.CreateIncompErrorLog (action, false, i)); + if (i.IncompatibilityError.IsBlock) { + result = 0; + break; + } else { + result = -1; + } + } + } + } + + return result; + } + + private int InitActionTimers(ActionAplication action, DomainActions domain, Student student, ref List logs) + { + int result = 1; + + Dictionary dic; + + if (action.MinTime > 0) { + //Creates a thread to control the minimun timer. + Thread minTimerThread = new Thread (new ParameterizedThreadStart(MinTimer)); + //Checks if student has an entry. + if (_minTimerController.ContainsKey (student.Key)) { + //Checks if a entry for the specific action already exists. + if (_minTimerController.TryGetValue (student.Key, out dic)) { + if (dic.ContainsKey (action.Key)) { + Error error = _otherErrors ["actionalreadyperformed"]; + logs.Add(StudentControl.CreateOtherErrorLog (action, false, error)); + return 0; + } else { + //Adds a new entry to the dictionary. + if (_minTimerController.TryGetValue (student.Key, out dic)) + dic.Add (action.Key, minTimerThread); + } + } + } else { + //Adds a new entry to the dictionary. + _minTimerController.Add(student.Key, new Dictionary()); + //Adds the thread to the dictionary. + //Adds a new entry to the dictionary. + if (_minTimerController.TryGetValue(student.Key, out dic)) + dic.Add (action.Key, minTimerThread); + } + //Starts the thread. + ArrayList param = new ArrayList(); + param.Add (minTimerThread); + param.Add (action); + param.Add (domain); + param.Add (student); + minTimerThread.Start (param); + } + + if (action.MaxTime > 0) { + //Creates a thread to control the minimun timer. + Thread maxTimerThread = new Thread (new ParameterizedThreadStart(MaxTimer)); + //Checks if student has an entry. + if (_maxTimerController.ContainsKey (student.Key)) { + //Checks if a entry for the specific action already exists. + if (_maxTimerController.TryGetValue (student.Key, out dic)) { + if (dic.ContainsKey (action.Key)) { + Error error = _otherErrors ["actionalreadyperformed"]; + logs.Add(StudentControl.CreateOtherErrorLog (action, false, error)); + return 0; + } else { + //Adds a new entry to the dictionary. + if (_maxTimerController.TryGetValue (student.Key, out dic)) + dic.Add (action.Key, maxTimerThread); + } + } + } else { + //Adds a new entry to the dictionary. + _maxTimerController.Add(student.Key, new Dictionary()); + //Adds the thread to the dictionary. + //Adds a new entry to the dictionary. + if (_maxTimerController.TryGetValue(student.Key, out dic)) + dic.Add (action.Key, maxTimerThread); + } + + //Creates a thread to control the maximun timer. + maxTimerThread = new Thread (new ParameterizedThreadStart(MaxTimer)); + //Starts the thread. + ArrayList param = new ArrayList(); + param.Add (maxTimerThread); + param.Add (action); + param.Add (student); + param.Add (action.MaxTime); + //Starts the thread. + maxTimerThread.Start (param); + } + + return result; + } + + private int ValidateActionMaxTimer(ActionAplication action, DomainActions domain, Student student, ref List logs) + { + int result = 1; + + StudentLog studentLog = _instanceStudentControl.GetStudentLog (domain.Key, student.Key); + + //Gets the previous action. + ActionAplication previousAction = domain.GetPreviousAction(action.Key); + //Checks if this is the first action done by the student. + if (previousAction != null) { + //Creates an auxiliar variable that will not use. + Thread t; + Dictionary maxTDic; + //Checks if the previous action created a maximun timer. + if (_maxTimerController.TryGetValue (studentLog.Owner.Key, out maxTDic)) { + if (!maxTDic.TryGetValue (previousAction.Key, out t) && previousAction.MaxTime > 0) { + //Generates a max time error. + logs.Add(StudentControl.CreateMaxTimeErrorLog (previousAction, false, previousAction.MaxTime)); + //Checks if the dependence blocks or not. + if (previousAction.MaxTimeError.IsBlock) { + result = 0; + } else { + result = -1; + } + } + } + } + + return result; + } } } \ No newline at end of file diff --git a/StudentModule/Its.StudentModule.ObjectModel/StudentLog.cs b/StudentModule/Its.StudentModule.ObjectModel/StudentLog.cs index a26e40e..d5b5ce0 100755 --- a/StudentModule/Its.StudentModule.ObjectModel/StudentLog.cs +++ b/StudentModule/Its.StudentModule.ObjectModel/StudentLog.cs @@ -116,6 +116,16 @@ public void AddLog (LogEntry log) this._logs.Add (log); } + /// + /// Adds the log. + /// + /// Logs. + public void AddLog (List logs) + { + //Adds the log into the list. + this._logs.AddRange(logs); + } + /// /// Adds the log to the buffer that will be flushed to disk at a later stage. /// @@ -125,6 +135,16 @@ public void AddToLogBuffer(LogEntry log) //Adds the log into the list. this._actionLogBuffer.Add (log); } + + /// + /// Adds the log to the buffer that will be flushed to disk at a later stage. + /// + /// Logs. + public void AddToLogBuffer(List logs) + { + //Adds the log into the list. + this._actionLogBuffer.AddRange(logs); + } /// /// Checks the action order. diff --git a/StudentModule/Its.StudentModule/StudentControl.cs b/StudentModule/Its.StudentModule/StudentControl.cs index 2bb0d7c..62eefdd 100755 --- a/StudentModule/Its.StudentModule/StudentControl.cs +++ b/StudentModule/Its.StudentModule/StudentControl.cs @@ -71,7 +71,49 @@ public static void DisposeInstance() { } } - /// + public static LogEntry CreateCorrectiveActionLog(ActionAplication action, bool wasApplied, bool errorsFixed) + { + return new CorrectiveActionLog (action, wasApplied, errorsFixed); + } + + public static LogEntry CreateNoCorrectiveActionLog(ActionAplication action, bool wasApplied) + { + return new NoCorrectiveActionLog(action, wasApplied); + } + + public static LogEntry CreateMinTimeErrorLog(ActionAplication action, bool wasApplied, int time) + { + return new MinTimeErrorLog(action, wasApplied, time); + } + + public static LogEntry CreateMaxTimeErrorLog(ActionAplication action, bool wasApplied, int time) + { + return new MaxTimeErrorLog(action, wasApplied, time); + } + + public static LogEntry CreateOtherErrorLog(ActionAplication action, bool wasApplied, Error error) + { + return new OtherErrorLog(action, wasApplied, error); + } + + public static LogEntry CreateWorldErrorLog(ActionAplication action, bool wasApplied, Error error, string type) + { + return new WorldErrorLog(action, wasApplied, error, type); + } + + public static LogEntry CreateDepErrorLog(ActionAplication action, bool wasApplied, Dependence failedDependence) + { + bool isOrderError = failedDependence.GetType() == typeof(SeqComplexDependence); + + return new DepErrorLog(action, wasApplied, failedDependence, isOrderError); + } + + public static LogEntry CreateIncompErrorLog(ActionAplication action, bool wasApplied, Incompatibility failedIncomp) + { + return new IncompErrorLog(action, wasApplied, failedIncomp); + } + +/* /// /// Creates the corrective action log. /// /// Action. @@ -109,21 +151,6 @@ public void CreateCorrectiveActionLog (ActionAplication action, DomainActions do } } - /*public void MultiplyLogs(int mult, DomainActions domain){ - int countStudents = _instance._students.Count; - int maxStudent = countStudents * mult; - DomainLog domTemp = _domainLogs [domain.Key]; - int j = 1; - for (int i = _instance._students.Count; i < maxStudent; i++) { - Student stdTemp = _students [j.ToString ()]; - _domainLogs [domain.Key].AddStudentLog (stdTemp, domTemp.GetStudentLog (stdTemp.Key)); - if (j <= countStudents) - j++; - else - j = 1; - } - }*/ - /// /// Creates the no corrective action log. /// @@ -400,7 +427,7 @@ public void CreateIncompErrorLog (ActionAplication action, DomainActions domain, sw.WriteLine (log.TxtLogString()); } } - +*/ /// /// Creates the domain log. /// @@ -572,6 +599,46 @@ public void ResetPractice (string domainName, string studentKey) //Resets the log of the student. GetStudentLog (domainName, studentKey).ResetLog (); } + + /// + /// Adds LogEntry to student log and to buffer that will be flushed to file (ontology xml) + /// upon calling FlushLastActionLogs() + /// + /// Domain name. + /// Student key. + /// Log entry. + public void AddLog(DomainActions domain, Student student, LogEntry logEntry) + { + //Gets the domainLog. + DomainLog domainLog; + if (!_domainLogs.TryGetValue (domain.Key, out domainLog)) + throw new ArgumentException ("There is not any DomainLog with the given domain."); + //Gets the StudentLog. + StudentLog studentLog = domainLog.GetStudentLog (student.Key); + + studentLog.AddLog(logEntry); + studentLog.AddToLogBuffer(logEntry); + } + + /// + /// Adds list of LogEntry objects to student log and to buffer that will be flushed to file (ontology xml) + /// upon calling FlushLastActionLogs() + /// + /// Domain name. + /// Student key. + /// List of Log entry objects. + public void AddLog(DomainActions domain, Student student, List logEntries) + { + //Gets the domainLog. + DomainLog domainLog; + if (!_domainLogs.TryGetValue (domain.Key, out domainLog)) + throw new ArgumentException ("There is not any DomainLog with the given domain."); + //Gets the StudentLog. + StudentLog studentLog = domainLog.GetStudentLog (student.Key); + + studentLog.AddLog(logEntries); + studentLog.AddToLogBuffer(logEntries); + } /// /// Writes log entries generated by last user action to ontology. diff --git a/TutoringModule/Its.TutoringModule.Common/AbstractTutor.cs b/TutoringModule/Its.TutoringModule.Common/AbstractTutor.cs index 1af0cbd..1681cd9 100644 --- a/TutoringModule/Its.TutoringModule.Common/AbstractTutor.cs +++ b/TutoringModule/Its.TutoringModule.Common/AbstractTutor.cs @@ -185,7 +185,8 @@ public int Validate(string actionName, string domainName, string studentKey, str //Gets the domain. DomainActions domain = _expertControl.GetDomainActions (domainName); //Registers the error. - _studentControl.CreateWorldErrorLog (action, domain, student, false, worldError, "objectblocked"); + LogEntry log = StudentControl.CreateWorldErrorLog (action, false, worldError, "objectblocked"); + _studentControl.AddLog(domain, student, log); //Adds the error into the list. errorMessages = new List(); errorMessages.Add(worldError.Message.Message); @@ -277,7 +278,8 @@ public string WorldError (string domainKey, string actionName, string studentKey //Gets the student with the given key. Student student = _studentControl.GetStudent(studentKey); //Generates the world error log. - _studentControl.CreateWorldErrorLog(action, domain, student, false, worldError, type); + LogEntry log = StudentControl.CreateWorldErrorLog(action, false, worldError, type); + _studentControl.AddLog(domain, student, log); //Returns the world error message. return worldError.Message.Message; } else {