Example #1
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string userid    = "nlubold";
                int    sessionid = 1;

                List <int> problemStep       = SQLProblemStepTracker.ReadProbStep(userid);
                int        problem           = problemStep[0];
                int        nextproblem       = problem + 1;
                int        step              = problemStep[1];
                int        problemimgkey     = problemStep[2];
                int        answerKey         = problemStep[3];
                int        newanswer         = problemStep[4];
                int        numautoresponses  = problemStep[5];
                int        nextstepanswerkey = 0;
                int        numAutoResponses  = 0;

                if (step == 0)
                {
                    step = 1;
                }

                nextstepanswerkey = SQLProblemStepTracker.CalculateNewAnswerKey(1, answerKey, step);
                newanswer         = step;
                SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, step, problemimgkey, nextstepanswerkey, newanswer, numAutoResponses);
            }
            catch (Exception error)
            {
                SQLLog.InsertLog(DateTime.Now, error.Message, error.ToString(), "UpdateAnswer.ashx.cs", 0, "nlubold");
            }
        }
Example #2
0
        public void ProcessRequest(HttpContext context)
        {
            // General variables
            DateTime            timeStart = DateTime.Now;
            string              path      = context.Request.PhysicalApplicationPath;
            string              userid    = HttpContext.Current.User.Identity.Name;
            Tuple <string, int> imageInfo = new Tuple <string, int>("", 2);
            string              page      = "";

            // Variables important to the speaker's state
            string     audioFile         = path + "data\\userAudio\\blob.wav";
            string     transcript        = "";
            string     dialogueAct       = "";
            int        speakerSpoke      = 0;
            List <int> problemStep       = new List <int>();                                                                // [0] is problem, [1] is the step, and [2] is the image key loaded for this step, [3] is the answer pattern
            int        sessionid         = 1;                                                                               // ************************* FIX THIS ********
            int        nextstepanswerkey = 0;

            // Variables important to Nico's state
            Tuple <string, int, string> nicoResponse;                                                                           // string => Nico's response, int is the movement code, string contains whether Nico is 'answering', 'confirming', or 'not answering'

            try
            {
                problemStep = SQLProblemStepTracker.ReadProbStep(userid);                                                   // Get current step
                int    problem          = problemStep[0];
                int    step             = problemStep[1];
                int    probImg          = problemStep[2];
                int    answerKey        = problemStep[3];
                int    numAutoResponses = problemStep[5];
                int    numturns         = problemStep[6];
                string clickstep        = "none";
                int    newanswer        = 0;

/*
 *              if (step == 0)
 *              {
 *                  step = 1;
 *              }
 */
                transcript = context.Request.Params["transcript"];    // Get transcript (if there is one)
                page       = context.Request.Params["page_loc"];

                if (context.Request.Files.Count > 0)                                                                       // Write out audio file (if it's there)
                {
                    HttpFileCollection files = context.Request.Files;
                    //audioFile = writeFile(files, path, userid, timeStart);
                }
                if (transcript == "problem start")
                {
                    speakerSpoke = 0;
                    clickstep    = "problem start";
                    step         = 1;
                }
                else if (transcript == "no response")
                {
                    speakerSpoke      = 0;
                    clickstep         = "null";
                    numAutoResponses += 1;
                    transcript        = "Triggered Speech " + numAutoResponses.ToString();
                }
                else if (transcript == "HELLO FIRST TIME")
                {
                    speakerSpoke = 0;
                    clickstep    = "hello nico start";
                }
                else if ((transcript != "") && (transcript != null))                                                             // Is there a transcript? If there is get the speaker's dialogue act
                {
                    dialogueAct  = estimateDialogueAct(transcript);
                    speakerSpoke = 1;                                                                                           // Set that the speaker actually spoke this turn
                }
                else
                {
                    speakerSpoke = 2;
                    transcript   = "transcript empty or null";
                }

                nicoResponse = ResponseGeneration.NicoResponse(path, problemStep, speakerSpoke, transcript, timeStart, page, userid, audioFile);     // Generate and initiate Nico's response
                SQLUserState.UpdateSpeakerState(userid, dialogueAct, transcript, speakerSpoke, problemStep, timeStart, clickstep, numAutoResponses); // Write out speaker state info
                SQLNicoState.UpdateNicoState(userid, nicoResponse, problemStep, timeStart);                                                          // Write out Nico's state info & update problem/step


                // Nico response: string => Nico's response, int is the movement code, the boolean indicates whether Nico answered the step
                // To update the step, we check if Nico answered the question.

                numturns += 1;
                if (nicoResponse.Item3 == "answering")
                {
                    nextstepanswerkey = SQLProblemStepTracker.CalculateNewAnswerKey(1, answerKey, step, userid);                // Passing 1 as first argument because Nico DID answer this step
                    newanswer         = step;
                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, step, probImg, nextstepanswerkey, newanswer, numAutoResponses, numturns);
                }
                else
                {
                    nextstepanswerkey = answerKey;                                                                                 // current answer key
                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, step, probImg, nextstepanswerkey, newanswer, numAutoResponses, numturns);
                }
            }
            catch (Exception error)
            {
                SQLLog.InsertLog(DateTime.Now, error.Message, error.ToString(), "DialogueEngine.ashx.cs", 0, userid);
            }

            string transResponse = "Saved User Wav File!";

            context.Response.ContentType = "audio/wav";
            context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
            context.Response.AppendHeader("Access-Control-Allow-Headers", "x-requested-with");
            context.Response.Write(transResponse);
        }
Example #3
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string userid    = "nlubold";
                int    sessionid = 1;
                int    maxprobs  = 4;

                List <int> problemStep      = SQLProblemStepTracker.ReadProbStep(userid);
                int        problem          = problemStep[0];
                int        nextproblem      = problem + 1;
                int        step             = problemStep[1];
                int        nextStep         = step + 1;
                int        priorStep        = step - 1;
                int        problemimgkey    = problemStep[2];
                int        answerKey        = problemStep[3];
                int        newanswer        = problemStep[4];
                int        numautoresponses = problemStep[5];

                // Variables important to Nico's state
                string   path      = HttpRuntime.AppDomainAppPath;
                DateTime now       = DateTime.Now;
                string   clickstep = "";

                string response = "continue";

                string clicked = context.Request.Params["button_info"];
                switch (clicked)
                {
                case "next":
                    problemStep[1] = nextStep;
                    newanswer      = 0;

                    clickstep = "step" + step.ToString() + "_" + nextStep.ToString();
                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, nextStep, problemimgkey, answerKey, newanswer, numautoresponses);

                    break;

                case "prior":
                    problemStep[1] = priorStep;
                    newanswer      = 0;

                    clickstep = "step" + step.ToString() + "_" + priorStep.ToString();
                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, priorStep, problemimgkey, answerKey, newanswer, numautoresponses);

                    break;

                case "problem":
                    if (nextproblem > maxprobs)
                    {
                        response = "end of session";
                    }
                    else
                    {
                        step      = 1;
                        answerKey = 1;
                        newanswer = 0;
                        SQLProblemStepTracker.UpdateProbStep(userid, sessionid, nextproblem, step, problemimgkey, answerKey, newanswer, numautoresponses);
                    }

                    break;

                default:

                    break;
                }

                context.Response.ContentType = "text/HTML";
                context.Response.Write(response);
            }
            catch (Exception error)
            {
                SQLLog.InsertLog(DateTime.Now, error.Message, error.ToString(), "UpdateStep.ashx.cs", 0, "nlubold");
            }
        }
Example #4
0
        public void ProcessRequest(HttpContext context)
        {
            /* ----------Retrieve current user & session ID ----------------
             * Should be dynamic - need to fix this
             */
            string userid    = "nlubold";
            int    sessionid = 1;


            /* ----------Retrieve current problem and step information----------------
             * Problem Step Info: 1st value is the problem, second value contains the current step, third value contains the
             * problem image key (may remove this, currently unused), fourth value contains the key to the current answer pattern,
             * fifth value indicates whether Nico just answered this step.
             */
            List <int> problemStep   = SQLProblemStepTracker.ReadProbStep(userid);
            int        problem       = problemStep[0];
            int        step          = problemStep[1];
            int        problemimgkey = problemStep[2];
            int        answerKey     = problemStep[3];
            int        newanswer     = problemStep[4];


            /* ----------Retrieve the problem content----------------
             * Problem Text - contains description of problem plus headers for columns
             * Problem Design Answers - contains the full content, including answers
             * Problem Design Blanks - contains the content of the problem with question marks where Nico must provide the answer
             * Answer Pattern - contains the current pattern of answered steps because technically they don't have to go in order
             * ChAnswerPattern - the character array of the current answer pattern
             * Max step - maximum number of steps for the problem
             * Num Rows - number of rows for the problem
             * Num Cells - number of columns for the problem
             * Step Answer Pattern - indicates which cells need to be answered
             */
            List <string> problemText           = SQLProblemText.ReadProbText(problem);
            List <string> problemDesign_Answers = SQLProblemDesign.GetProbDesign(problem, 1);
            List <string> problemDesign_Blanks  = SQLProblemDesign.GetProbDesign(problem, 0);
            string        answerPattern         = SQLAnswerPattern.GetAnswerPattern(answerKey)[1];

            char[] chAnswerPattern = answerPattern.ToCharArray();
            int    maxsteps        = Convert.ToInt32(problemDesign_Blanks[0]);
            int    numrows         = Convert.ToInt32(problemDesign_Blanks[1]);
            int    numcells        = Convert.ToInt32(problemDesign_Blanks[2]);

            char[] stepAnswerPattern = problemDesign_Blanks[3].ToCharArray();


            /* ----------Answer display variables----------------
             * Calculate the cell which is a 'new' answer, if there is one.
             * Will only be a 'new' answer when new answer does not equal zero
             * If new answer is not zero, then it is equal to the step which was answered
             * Can get the cell that is 'new' using step answer pattern
             */
            int cellAnswer = 0;

            if (newanswer != 0)
            {
                cellAnswer = (int)Char.GetNumericValue(stepAnswerPattern[newanswer - 1]);
                newanswer  = 1;
            }


            /* ----------Set variables for Nico and User----------------
             * Tuple:
             *      string: Nico's response
             *      int: the movement code
             *      bool: indicates whether Nico answered this step
             * clickstep: string to populate in user log how we got to this page
             */
            Tuple <string, int, bool> nicoResponse;
            string path      = HttpRuntime.AppDomainAppPath;
            string clickstep = "none";


            /* ---------- Create Table Data----------------
             * Create a list of objects which can then be serialized into a single Json object and passed back to client.
             * The list of objects - each object is a row in the table
             * Steps:
             *      (1) Store how many columns, step that currently on, max steps, and if a cell on this step was newly answered
             *      (2) Create header row
             *      (3) Create the rest of the rows
             * Also pass info regarding buttons to display and problem description text (ProblemDescription.Text = problemText[0];)
             */

            List <TableInfo> rowsList = new List <TableInfo>();

            // Step (1): Populate important variables including if new answer and what cell that answer is
            rowsList.Add(new TableInfo(Convert.ToString(numcells), Convert.ToString(step), Convert.ToString(maxsteps), Convert.ToString(newanswer), Convert.ToString(cellAnswer), Convert.ToString(problemText[0])));

            // Step (2): Create header row
            rowsList.Add(new TableInfo(problemText.GetRange(1, numcells).ToArray()));

            // Step (3): Create the rest of the rows
            int index = 0;

            for (int j = 0; j < numrows; j++)
            {
                if (chAnswerPattern[j] == '1')
                {
                    rowsList.Add(new TableInfo(problemDesign_Answers.GetRange(4 + index, numcells).ToArray()));
                }
                else
                {
                    rowsList.Add(new TableInfo(problemDesign_Blanks.GetRange(4 + index, numcells).ToArray()));
                }
                index += numcells;
            }

            var json = new JavaScriptSerializer().Serialize(rowsList);

            context.Response.Write(json);
        }
        public void ProcessRequest(HttpContext context)
        {
            string userid = HttpContext.Current.User.Identity.Name;

            try
            {
                int    sessionid = 1;
                int    maxprobs  = 9;
                string page      = "ProblemPage";


                List <int> problemStep      = SQLProblemStepTracker.ReadProbStep(userid);
                int        problem          = problemStep[0];
                int        nextproblem      = problem + 1;
                int        step             = problemStep[1];
                int        nextStep         = step + 1;
                int        priorStep        = step - 1;
                int        problemimgkey    = problemStep[2];
                int        answerKey        = problemStep[3];
                int        newanswer        = problemStep[4];
                int        numautoresponses = problemStep[5];
                int        numturns         = problemStep[6];



                if (step == 0)
                {
                    step     = 1;
                    nextStep = 2;
                }

                // Variables important to Nico's state
                Tuple <string, int, string> nicoResponse;                                                                      // string => Nico's response, int is the movement code, string is whether nico is answering
                string   path      = HttpRuntime.AppDomainAppPath;
                string   useraudio = path + "data\\userAudio\\blob.wav";
                DateTime now       = DateTime.Now;
                string   clickstep = "";

                string response = "continue";

                string clicked = context.Request.Params["button_info"];
                switch (clicked)
                {
                case "next":
                    problemStep[1] = nextStep;
                    newanswer      = 0;
                    numturns       = 0;

                    clickstep    = "step_" + step.ToString() + "_" + nextStep.ToString();
                    nicoResponse = ResponseGeneration.NicoResponse(path, problemStep, 0, "next step", now, page, userid, useraudio);
                    SQLUserState.UpdateSpeakerState(userid, "", "", 0, problemStep, now, clickstep, numautoresponses);              // Write out speaker state info
                    SQLNicoState.UpdateNicoState(userid, nicoResponse, problemStep, now);                                           // Write out Nico's state info & update problem/step

                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, nextStep, problemimgkey, answerKey, newanswer, numautoresponses, numturns);

                    break;

                case "prior":
                    problemStep[1] = priorStep;
                    newanswer      = 0;
                    numturns       = 0;

                    clickstep    = "step_" + step.ToString() + "_" + priorStep.ToString();
                    nicoResponse = ResponseGeneration.NicoResponse(path, problemStep, 0, "prior step", now, page, userid, useraudio);
                    SQLUserState.UpdateSpeakerState(userid, "", "", 0, problemStep, now, clickstep, numautoresponses);              // Write out speaker state info
                    SQLNicoState.UpdateNicoState(userid, nicoResponse, problemStep, now);                                           // Write out Nico's state info & update problem/step

                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, priorStep, problemimgkey, answerKey, newanswer, numautoresponses, numturns);

                    break;

                case "problem":
                    if (nextproblem > maxprobs)
                    {
                        response = "end of session";
                    }
                    else
                    {
                        step           = 1;
                        answerKey      = 1;
                        newanswer      = 0;
                        problemStep[0] = nextproblem;
                        numturns       = 0;

                        clickstep = "problem_" + problem.ToString() + "_" + nextproblem.ToString();

                        nicoResponse = ResponseGeneration.NicoResponse(path, problemStep, 0, "problem start", now, page, userid, useraudio);
                        SQLUserState.UpdateSpeakerState(userid, "", "", 0, problemStep, now, clickstep, numautoresponses);              // Write out speaker state info
                        SQLNicoState.UpdateNicoState(userid, nicoResponse, problemStep, now);                                           // Write out Nico's state info & update problem/step


                        SQLProblemStepTracker.UpdateProbStep(userid, sessionid, nextproblem, step, problemimgkey, answerKey, newanswer, numautoresponses, numturns);
                    }

                    break;

                default:

                    break;
                }

                context.Response.ContentType = "text/HTML";
                context.Response.Write(response);
            }
            catch (Exception error)
            {
                SQLLog.InsertLog(DateTime.Now, error.Message, error.ToString(), "UpdateStep.ashx.cs", 0, userid);
            }
        }