private NewDoor AnswerSetToCellMatrix(AnswerSets answers, Partition oldRoom)
        {
            IList <AnswerSet> answerSetsList = answers.Answersets;

            NewDoor door = null;

            if (answerSetsList.Count > 0)
            {
                int       index = randomGenerator.Next(answerSetsList.Count);
                AnswerSet a     = answerSetsList[index];

                foreach (Object obj in a.Atoms)
                {
                    if (obj is Cell)
                    {
                        matrixCells.AddCell((Cell)obj);
                    }
                    else if (obj is NewDoor)
                    {
                        door = (NewDoor)obj;
                    }
                }
            }
            return(door);
        }
    public static void LoadQADatabase(int sceneID, AnswerSet[] mainQASetSrc, AnswerSet[] subQASetSrc)
    {
        //Connect to sql databse
        SqlConnection conn = DBUltils.GetDBConnection();



        conn.Open();

        //Query data
        string sqlQuery = "SELECT Question,AnswerA,AnswerB,AnswerC,AnswerD,RightAnswer,isBonus FROM QUESTION WHERE SceneID = " + sceneID.ToString();

        SqlCommand cmd = new SqlCommand(sqlQuery, conn);

        DbDataReader reader = cmd.ExecuteReader();

        int       mainQACount = 0;
        int       subQACount  = 0;
        AnswerSet answerSet;

        if (reader.HasRows)
        {
            //Read the data and add it to the mainQASetList an subQASetList
            while (reader.Read())
            {
                int    questionIndex = reader.GetOrdinal("Question");
                string questionText  = reader.GetString(questionIndex);

                int    answerAIndex = reader.GetOrdinal("AnswerA");
                string answerAText  = reader.GetString(answerAIndex);

                int    answerBIndex = reader.GetOrdinal("AnswerB");
                string answerBText  = reader.GetString(answerBIndex);

                int    answerCIndex = reader.GetOrdinal("AnswerC");
                string answerCText  = reader.GetString(answerCIndex);

                int    answerDIndex = reader.GetOrdinal("AnswerD");
                string answerDText  = reader.GetString(answerDIndex);

                int rightAnswerIndex = reader.GetOrdinal("RightAnswer");
                int rightAnswer      = Convert.ToInt32(reader.GetValue(rightAnswerIndex));

                int isBonusIndex = reader.GetOrdinal("isBonus");
                int isBonus      = Convert.ToInt32(reader.GetValue(isBonusIndex));

                answerSet = new AnswerSet(questionText, answerAText, answerBText, answerCText, answerDText, rightAnswer);
                if (isBonus == 0) //This is the main QA set
                {
                    mainQASetSrc[mainQACount++] = answerSet;
                }
                else if (isBonus == 1) // This is the sub QA set
                {
                    subQASetSrc[subQACount++] = answerSet;
                }
            }
        }

        conn.Close();
    }
        private NewDoor AnswerSetToCellMatrix(AnswerSets answers)
        {
            IList <AnswerSet> answerSetsList = answers.Answersets;

            NewDoor door = null;

            if (answerSetsList.Count > 0)
            {
                int       index = randomGenerator.Next(answerSetsList.Count);
                AnswerSet a     = answers.Answersets[index];

                try {
                    foreach (object obj in a.Atoms)
                    {
                        if (obj is Cell)
                        {
                            matrixCells.AddCell((Cell)obj);
                        }
                        else if (obj is NewDoor)
                        {
                            door = (NewDoor)obj;
                        }
                    }
                }
                catch (Exception e) {
                    UnityEngine.Debug.Log(e.ToString());
                    UnityEngine.Debug.Log(e.StackTrace);
                }
            }
            return(door);
        }
Beispiel #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            AnswerSet answerSet = db.AnswerSets.Find(id);

            db.AnswerSets.Remove(answerSet);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void AddQA(AnswerSet set)
 {
     answerSet.question   = set.question;
     answerSet.answerA    = set.answerA;
     answerSet.answerB    = set.answerB;
     answerSet.answerC    = set.answerC;
     answerSet.answerD    = set.answerD;
     answerSet.trueAnswer = set.trueAnswer;
     QASetCount           = 1;
 }
        public static Question GenerateGuessTheAtomicNumber()
        {
            AnswerSet<ChemicalElement> answerSet = new AnswerSet<ChemicalElement>(ChemicalElement.ChemicalElements);

            return new Question(string.Format(CultureInfo.CurrentCulture, "What is the atomic number of {0}?", answerSet.CorrectAnswer.Name),
                answerSet.CorrectAnswerIndex,
                answerSet[0].AtomicNumber.ToString(),
                answerSet[1].AtomicNumber.ToString(),
                answerSet[2].AtomicNumber.ToString(),
                answerSet[3].AtomicNumber.ToString());
        }
Beispiel #7
0
 public void AddAnswer(int questionId, bool isRight, string text)
 {
     var answer = new AnswerSet
     {
         IsRight = isRight,
         QuestionId = questionId,
         Text = text,
     };
     _dbContext.AnswerSets.Add(answer);
     _dbContext.SaveChanges();
 }
        public static Question GenerateGuessTheAtomicNumberOfSymbol()
        {
            AnswerSet<ChemicalElement> answerSet = new AnswerSet<ChemicalElement>(ChemicalElement.ChemicalElements);

            return new Question(string.Format(CultureInfo.CurrentCulture, "What is the atomic number of the chemical element represented by the symbol {0}?", answerSet.CorrectAnswer.Symbol),
                answerSet.CorrectAnswerIndex,
                answerSet[0].AtomicNumber.ToString(),
                answerSet[1].AtomicNumber.ToString(),
                answerSet[2].AtomicNumber.ToString(),
                answerSet[3].AtomicNumber.ToString());
        }
Beispiel #9
0
        public void AddAnswer(int questionId, bool isRight, string text)
        {
            var answer = new AnswerSet
            {
                IsRight    = isRight,
                QuestionId = questionId,
                Text       = text,
            };

            _dbContext.AnswerSets.Add(answer);
            _dbContext.SaveChanges();
        }
        private void GeneratePartitionGraph()
        {
            EmbASPManager controller = new EmbASPManager();

            controller.InitializeEmbASP(randomAnswersetNumber);

            InputProgram input   = controller.Input;
            Handler      handler = controller.Handler;

            input.AddFilesPath(encodingFolder + "3-partition_graph_generator.asp");
            handler.AddProgram(input);

            InputProgram facts = new ASPInputProgram();

            facts.AddProgram("col(1.." + maxColumns + ").");
            facts.AddProgram("row(1.." + maxRows + ").");

            foreach (Cell cell in matrixCells.SetCells)
            {
                facts.AddObjectInput(cell);
            }

            handler.AddProgram(facts);

            Output     o       = handler.StartSync();
            AnswerSets answers = (AnswerSets)o;


            IList <AnswerSet> answerSetsList = answers.Answersets;

            StringBuilder debugConnected = new StringBuilder();

            if (answerSetsList.Count > 0)
            {
                int       index = randomGenerator.Next(answerSetsList.Count);
                AnswerSet a     = answerSetsList[index];


                foreach (Object obj in a.Atoms)
                {
                    if (obj is Connected8)
                    {
                        Connected8 connected8 = (Connected8)obj;
                        connections.Add(connected8);
                        debugConnected.Append(connected8.ToString() + "\n");
                    }
                }
            }
            if (IS_DEBUG_MODE)
            {
                UnityEngine.Debug.Log(debugConnected.ToString());
            }
        }
Beispiel #11
0
 public ActionResult Edit([Bind(Include = "AnswerSetID,AnswerBundleID,QuestionMethodID")] AnswerSet answerSet)
 {
     if (ModelState.IsValid)
     {
         db.Entry(answerSet).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AnswerBundleID   = new SelectList(db.AnswerBundles, "AnswerBundleID", "TextFeedback", answerSet.AnswerBundleID);
     ViewBag.QuestionMethodID = new SelectList(db.QuestionMethods, "QuestionMethodID", "Value", answerSet.QuestionMethodID);
     return(View(answerSet));
 }
    public static void LoadDatabase(int sceneID, AnswerSet[] Resources)
    {
        //Connect to sql databse
        SqlConnection conn = DBUltils.GetDBConnection();



        conn.Open();

        Debug.Log("Connection Successfull!");
        //Query data
        string sqlQuery = "SELECT Question,AnswerA,AnswerB,AnswerC,AnswerD,RightAnswer FROM QUESTION WHERE SceneID = " + sceneID.ToString();

        SqlCommand cmd = new SqlCommand(sqlQuery, conn);

        DbDataReader reader = cmd.ExecuteReader();

        int       QACount = 0;
        AnswerSet answerSet;

        if (reader.HasRows)
        {
            //Read the data and add it to the mainQASetList an subQASetList
            while (reader.Read())
            {
                int    questionIndex = reader.GetOrdinal("Question");
                string questionText  = reader.GetString(questionIndex);

                int    answerAIndex = reader.GetOrdinal("AnswerA");
                string answerAText  = reader.GetString(answerAIndex);

                int    answerBIndex = reader.GetOrdinal("AnswerB");
                string answerBText  = reader.GetString(answerBIndex);

                int    answerCIndex = reader.GetOrdinal("AnswerC");
                string answerCText  = reader.GetString(answerCIndex);

                int    answerDIndex = reader.GetOrdinal("AnswerD");
                string answerDText  = reader.GetString(answerDIndex);

                int rightAnswerIndex = reader.GetOrdinal("RightAnswer");
                int rightAnswer      = Convert.ToInt32(reader.GetValue(rightAnswerIndex));

                answerSet = new AnswerSet(questionText, answerAText, answerBText, answerCText, answerDText, rightAnswer);

                Resources[QACount++] = answerSet;
            }
        }

        conn.Close();
    }
Beispiel #13
0
        // GET: AnswerSets/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AnswerSet answerSet = db.AnswerSets.Find(id);

            if (answerSet == null)
            {
                return(HttpNotFound());
            }
            return(View(answerSet));
        }
Beispiel #14
0
        // GET: AnswerSets/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AnswerSet answerSet = db.AnswerSets.Find(id);

            if (answerSet == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AnswerBundleID   = new SelectList(db.AnswerBundles, "AnswerBundleID", "TextFeedback", answerSet.AnswerBundleID);
            ViewBag.QuestionMethodID = new SelectList(db.QuestionMethods, "QuestionMethodID", "Value", answerSet.QuestionMethodID);
            return(View(answerSet));
        }
        /// <summary>
        /// Initializes default answer set for customer with specified id.
        /// </summary>
        /// <param name="customerId"></param>
        /// <returns></returns>
        private async Task <AnswerSet> InitDefaultOpenEndedAnswerSet(int customerId)
        {
            var defaultAnswerSet = await this.Get(Settings.CICustomerId);

            var newAnswerSet = new AnswerSet
            {
                CustomerId = customerId,
                Type       = defaultAnswerSet.Type,
                Name       = defaultAnswerSet.Name
            };

            answerSetRepository.Insert(newAnswerSet);

            await this.unitOfWork.SaveAsync();

            return(newAnswerSet);
        }
        public async Task <ActionResult <AnswerSet> > PostAnswerSet([FromBody] AnswerSet answerSet)
        {
            // At first, it was receiving a dictionary of fieldId/value as it was specified in the task, but later I decided to
            // switch the model over AnswerSet, that is properly mapped to questions. Alos, this helps to support multiple checkboxes per question
            // and values hidden behind dropwowns, radio buttons and checkboxes

            // I would implement answer set mapping to the corresponding question set (if the answers and options of those match), but I will not,
            // since it's already a bit over-engineered for an assignment task

            if (answerSet.Answers.Count < 1)
            {
                return(BadRequest());
            }

            await m_repoWrapper.AnswerSet.CreateAnswerSetAsync(answerSet);

            return(CreatedAtAction(nameof(GetAnswerSet), new { id = answerSet.AnswerSetId }, answerSet));
        }
        public static Question GenerateGuessTheSubstance()
        {
            AnswerSet<Molecule> answerSet = new AnswerSet<Molecule>(SubstanceBank.Bank);

            string info = string.Empty;
            if (!string.IsNullOrWhiteSpace(answerSet.CorrectAnswer.Notes))
            {
                info = string.Join(" ", answerSet.CorrectAnswer.Name, answerSet.CorrectAnswer.Notes);
            }

            return new Question(string.Format(CultureInfo.CurrentCulture, "What is {0}?", answerSet.CorrectAnswer.ToString()),
                answerSet.CorrectAnswerIndex,
                answerSet[0].Name,
                answerSet[1].Name,
                answerSet[2].Name,
                answerSet[3].Name,
                info);
        }
Beispiel #18
0
        public void SaveAnswer()
        {
            var answerPath = "data.solved.csv";
            var lines      = new List <string>();
            var header     = parameters.ProblemType == ProblemTypeEnum.Classification ? "x,y,cls" : "x,y";

            lines.Add(header);
            if (parameters.ProblemType == ProblemTypeEnum.Classification)
            {
                lines.AddRange(AnswerSet.Select(r => GetTextClass(r)));
            }
            else
            {
                lines.AddRange(AnswerSet.Select(r => GetTextRegg(r)));
            }
            File.WriteAllLines(answerPath, lines);
            // AnswerPath = answerPath;
        }
Beispiel #19
0
        public async Task <Application> GetApplication(int scholarshipId, int profileId, int questionSetId)
        {
            var application = await _context.Application.FirstOrDefaultAsync(app => app.ScholarshipId == scholarshipId && app.ProfileId == profileId);

            if (application == null)
            {
                // First we need to create a default answer set for the user
                var answerSet = new AnswerSet
                {
                    QuestionSetId = questionSetId,
                    ProfileId     = profileId
                };
                _context.AnswerSet.Add(answerSet);
                await _context.SaveChangesAsync();

                // Create an answergroup, which is basically a generic container of answersets
                // Really we only use answerGroups for their unique id
                var answerGroup = new AnswerGroup();

                _context.AnswerGroup.Add(answerGroup);
                await _context.SaveChangesAsync();

                // Next create an answergroupset that will hold our first answerset
                var answerGroupSet = new AnswerGroupSets
                {
                    AnswerGroupId = answerGroup.AnswerGroupId,
                    AnswerSetId   = answerSet.AnswerSetId
                };
                _context.AnswerGroupSets.Add(answerGroupSet);
                await _context.SaveChangesAsync();

                // Last, we need to create an application and attach the answer group
                application = new Application
                {
                    ProfileId     = profileId,
                    ScholarshipId = scholarshipId,
                    AnswerGroupId = answerGroup.AnswerGroupId
                };
                _context.Application.Add(application);
                await _context.SaveChangesAsync();
            }

            return(application);
        }
Beispiel #20
0
        public SymbolicConstant GetNextMove(InputProgram facts)
        {
            SymbolicConstant move             = new SymbolicConstant();
            string           encodingResource = @".\encodings\pacman.asp";
            //string encodingResource2 = @"encodings\min_distances_5.asp";
            //Debug.Log("DLV Started: " + numberOfSteps++);
            Handler      handler  = new DesktopHandler(new DLVDesktopService(@".\lib\dlv.exe"));
            InputProgram encoding = new ASPInputProgram();

            encoding.AddFilesPath(encodingResource);
            //InputProgram encoding2 = new ASPInputProgram();
            //encoding.AddFilesPath(encodingResource2);
            handler.AddProgram(encoding);
            //handler.AddProgram(encoding2);
            handler.AddProgram(facts);
            handler.AddOption(new OptionDescriptor("-filter=next"));
            Output o = handler.StartSync();
            //EmbaspCall++;



            AnswerSets answers = (AnswerSets)o;

            System.Random r      = new System.Random();
            int           answer = r.Next(answers.Answersets.Count);
            AnswerSet     a      = answers.Answersets[answer];

            foreach (object obj in a.Atoms)
            {
                //Debug.Log(obj.ToString());
                if (obj is Next)
                {
                    Next nextAction = (Next)obj;

                    move = nextAction.getAction();
                    return(move);
                    //Debug.Log("Next Action: " + move);
                }
            }
            return(move);
        }
        internal void parse(AnswerSet set)
        {
            //Debug.Log("parsing " + actuatorName);
            MappingManager mapper         = MappingManager.getInstance();
            IMapper        actuatorMapper = mapper.getMapper(typeof(SimpleActuator));

            string[] mappedProperties = actuatorMapper.Map(this).Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string literal in set.GetAnswerSet())
            {
                //Debug.Log("literal "+literal);
                foreach (string mapped in mappedProperties)
                {
                    //Debug.Log("mapped " + mapped);
                    string withoutVariable = mapped.Substring(0, mapped.LastIndexOf('('));
                    if (literal.StartsWith(withoutVariable))
                    {
                        string clean = literal.Substring(("setOnActuator(" + actuatorName + "(" + gOName + "(").Length);
                        clean = clean.Replace('(', '^');
                        clean = clean.Remove(clean.IndexOf(')'));
                        string val = clean.Substring(clean.LastIndexOf('^') + 1);
                        clean = clean.Remove(clean.LastIndexOf('^'));
                        //Debug.Log(clean+" has value "+val);
                        string property = unityASPVariationNames[clean];
                        foreach (Type t in dictionaryPerType.Keys)
                        {
                            //Debug.Log(t + " " + property);
                            IDictionary dic = dictionaryPerType[t];
                            if (dic.Contains(property))
                            {
                                dic[property] = Convert.ChangeType(val, dic.GetType().GetGenericArguments()[1]);
                                //Debug.Log(property + " " + dic[property]);
                            }
                        }
                        break;
                    }
                }
            }
        }
Beispiel #22
0
        private void GenerateFacts(int dimension)
        {
            string encodingResource = @".\encodings\min_distances_" + dimension + ".asp";
            //Debug.Log("DLV Started: " + numberOfSteps++);
            Handler      handler  = new DesktopHandler(new DLVDesktopService(@".\lib\dlv.exe"));
            InputProgram encoding = new ASPInputProgram();

            encoding.AddFilesPath(encodingResource);
            handler.AddProgram(encoding);

            Output     o       = handler.StartSync();
            AnswerSets answers = (AnswerSets)o;

            //Debug.Log("Answers: " + o.OutputString);
            AnswerSet a = answers.Answersets[0];

            foreach (object obj in a.Atoms)
            {
                //Debug.Log(obj.ToString());
                if (obj is Distance)
                {
                    Distance d = (Distance)obj;
                    if (dimension == 10)
                    {
                        distances_10[d.getX1(), d.getY1()].Add(d);
                    }
                    else if (dimension == 5)
                    {
                        distances_5[d.getX1(), d.getY1()].Add(d);
                    }

                    //move = nextAction.getAction();
                    //Debug.Log("Next Action: " + move);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="keyValuePairs">Значения тип вопроса</param>
        /// <param name="questionVariable">Ответы на вопросы</param>
        /// <param name="langId">Айди языка</param>
        /// <param name="typeId">Айди типа</param>
        /// <returns></returns>
        public bool NewQuestion(Dictionary <StringTypeQuestion, string> keyValuePairs, List <string> questionVariable, int LangId, int correctOtvet)
        {
            using (ForumContainer container = new ForumContainer())
            {
                int langId      = LangId;
                int questTypeId = Convert.ToInt32(keyValuePairs[StringTypeQuestion.QuestionType]);

                QuestionSet setQuest = new QuestionSet()
                {
                    QuestionText               = keyValuePairs[StringTypeQuestion.QuestionText],
                    CorrectOption              = correctOtvet,
                    LanguageLanguageId         = langId,
                    QuestionTypeQuestionTypeId = questTypeId,
                    AccountAccountId           = 0,
                    AccountSet      = container.AccountSet.Single(x => x.Login == "admin"),
                    QuestionTypeSet = container.QuestionTypeSet.Single(x => x.QuestionTypeId == questTypeId),
                    LanguageSet     = container.LanguageSet.Single(x => x.LanguageId == langId),
                };

                container.QuestionSet.Add(setQuest);

                for (int i = 0; i < 4; i++)
                {
                    AnswerSet secAnswer = new AnswerSet()
                    {
                        AnswerVarible = questionVariable[i],
                        QuestionSet   = setQuest
                    };
                    container.AnswerSet.Add(secAnswer);
                    container.SaveChanges();
                }
                container.SaveChanges();
            }

            return(true);
        }
        public void SudokuTest()
        {
            try
            {
                Handler      handler      = new DesktopHandler(new DLVDesktopService(GetPath()));
                InputProgram inputProgram = new ASPInputProgram();

                for (int i = 0; i < N; i++)
                {
                    for (int j = 0; j < N; j++)
                    {
                        if (sudokuMatrix[i, j] != 0)
                        {
                            inputProgram.AddObjectInput(new Cell(i, j, sudokuMatrix[i, j]));
                        }
                    }
                }

                inputProgram.AddFilesPath(".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "test-resources" + Path.DirectorySeparatorChar + "asp" + Path.DirectorySeparatorChar + "sudoku");
                handler.AddProgram(inputProgram);
                handler.StartAsync(new CallbackAction(o =>
                {
                    if (!(o is AnswerSets))
                    {
                        return;
                    }

                    answerSets = (AnswerSets)o;

                    @lock.Signal();
                }));
                @lock.Wait(new TimeSpan(0, 0, 0, 0, 5000));
                Assert.IsNotNull(answerSets);
                Assert.IsTrue(String.IsNullOrEmpty(answerSets.ErrorsString), "Found error in the Plan\n" + answerSets.ErrorsString);

                if (answerSets.Answersets.Count == 0)
                {
                    return;
                }

                AnswerSet @as = answerSets.Answersets[0];

                foreach (object obj in @as.Atoms)
                {
                    Cell cell = (Cell)obj;
                    sudokuMatrix[cell.getRow(), cell.getColumn()] = cell.getValue();
                }

                for (int i = 0; i < N; i++)
                {
                    for (int j = 0; j < N; j++)
                    {
                        Console.Write(sudokuMatrix[i, j] + " ");

                        if (sudokuMatrix[i, j] == 0)
                        {
                            Assert.Fail("NumberNotValid");
                        }
                    }

                    Console.WriteLine();
                }
            }
            catch (Exception e)
            {
                Assert.Fail("Exception " + e.Message);
            }
        }
Beispiel #25
0
        public IHttpActionResult PostSurveyAnswers([FromBody] AnswersAndBundleExtrasDTO abe)
        {
            // Model state check. If State is not valid, BadRequest will be returned with ModelState.
            if (!ModelState.IsValid)
            {
                Debug.WriteLine("ModelState not valid!");
                return(BadRequest(ModelState));
            }

            // Unpacking abe-object
            List <AnswerDTO> answerDtos = abe.AnswerDtos.ToList();
            int    answererTypeId       = abe.AnswerBundleExtrasDto.AnswererTypeID;
            string textFb = abe.AnswerBundleExtrasDto.TextFeedback;


            Debug.WriteLine("answerDtos<AnswerDTO>.Count: " + answerDtos.Count);
            Debug.WriteLine("answererTypeId: " + answererTypeId);
            Debug.WriteLine("textFb: " + textFb);


            // - If answerDtos is empty, BadRequest will be returned.
            if (answerDtos.Count == 0)
            {
                return(BadRequest());
            }

            // - Sorting answerDtos by QuestionSetIndex and ChosenQuestionIndex (in this order)
            var rawSortedDtos = from sa in answerDtos
                                orderby sa.QuestionSetIndex, sa.ChosenQuestionIndex
            select sa;

            // - Converting IOrderedEnumerable as list
            List <AnswerDTO> cleanSortedDtos = rawSortedDtos.ToList();

            // Creating AnswerBundle bundle
            AnswerBundle bundle = new AnswerBundle();

            // Adding variables to bundle
            bundle.Date           = DateTime.Now;
            bundle.AnswererTypeID = answererTypeId;
            bundle.TextFeedback   = textFb;

            // Adding bundle is to the database
            db.AnswerBundles.Add(bundle);

            // - Saving database changes
            // TODO: TRANSACTION MANAGEMENT
            db.SaveChanges();

            // - Creating helper variables
            int currentSetId    = -2;
            int currentSetIndex = -2;

            foreach (AnswerDTO aDto in cleanSortedDtos)
            {
                // - If new QuestionMethodID in answerDtos,
                //   new AnswerSet is created and saved to the database
                if (aDto.QuestionSetIndex != currentSetIndex)
                {
                    // currentQmId = aDto.QuestionMethodID;
                    currentSetIndex = aDto.QuestionSetIndex;
                    AnswerSet newSet = new AnswerSet();
                    newSet.QuestionMethodID = aDto.QuestionMethodID;
                    newSet.AnswerBundleID   = bundle.AnswerBundleID;
                    db.AnswerSets.Add(newSet);
                    db.SaveChanges();
                    currentSetId = newSet.AnswerSetID;
                }
                db.Answers.Add(new Answer
                {
                    Value       = aDto.Value,
                    QuestionID  = aDto.QuestionID,
                    AnswerSetID = currentSetId
                });
                db.SaveChanges();
            }

            return(Ok());
        }
Beispiel #26
0
 void Create(AnswerSet answer, GameController gameContr)
 {
     GetComponent <SpriteRenderer>().sprite = answer.pic;
     transform.position = answer.pos;
     gameContr.addAnswer(gameObject);
 }
Beispiel #27
0
 public void CreateAnswerSet(AnswerSet AnswerSet)
 {
     _AnswerService.CreateAnswerSet(AnswerSet);
 }
Beispiel #28
0
        public IHttpActionResult PostSurveyAnswers([FromBody] AnswersAndBundleExtrasDTO abe)
        {
            if (!ModelState.IsValid)
            {
                Debug.WriteLine("ModelState not valid!");
                return(BadRequest(ModelState));
            }

            List <AnswerDTO> answerDtos = abe.AnswerDtos.ToList();
            int    answererTypeId       = abe.AnswerBundleExtrasDto.AnswererTypeID;
            string textFb = abe.AnswerBundleExtrasDto.TextFeedback;


            Debug.WriteLine("answerDtos<AnswerDTO>.Count: " + answerDtos.Count);
            Debug.WriteLine("answererTypeId: " + answererTypeId);
            Debug.WriteLine("textFb: " + textFb);



            if (answerDtos.Count == 0)
            {
                return(BadRequest());
            }
            var rawSortedDtos = from sa in answerDtos
                                orderby sa.QuestionSetIndex, sa.ChosenQuestionIndex
            select sa;

            List <AnswerDTO> cleanSortedDtos = rawSortedDtos.ToList();

            for (int i = 0; i < cleanSortedDtos.Count; i++)
            {
                Debug.WriteLine("cleanSortedDtos[" + i + "].Value: " + cleanSortedDtos[i].Value);
                Debug.WriteLine("cleanSortedDtos[" + i + "].QuestionSetIndex: " + cleanSortedDtos[i].QuestionSetIndex);
                Debug.WriteLine("cleanSortedDtos[" + i + "].ChosenQuestionIndex: " + cleanSortedDtos[i].ChosenQuestionIndex);
                Debug.WriteLine("cleanSortedDtos[" + i + "].QuestionID: " + cleanSortedDtos[i].QuestionID);
                Debug.WriteLine("cleanSortedDtos[" + i + "].QuestionMethodID: " + cleanSortedDtos[i].QuestionMethodID);
            }
            // CREATE AnswerBundle bundle

            AnswerBundle bundle = new AnswerBundle();

            bundle.Date           = DateTime.Now;
            bundle.AnswererTypeID = answererTypeId;
            bundle.TextFeedback   = textFb;
            // NEW: CHECK IF WORKS
            // TODO: TRANSACTION MANAGEMENT
            db.AnswerBundles.Add(bundle);

            db.SaveChanges();

            // ADD AnswerSets TO bundle
            // int currentQmId = -2;
            int currentSetId    = -2;
            int currentSetIndex = -2;

            foreach (AnswerDTO aDto in cleanSortedDtos)
            {
                // IF NEW QuestionMethodID IN answerDtos,
                // NEW AnswerSet IS CREATED
                if (aDto.QuestionSetIndex != currentSetIndex)
                {
                    // currentQmId = aDto.QuestionMethodID;
                    currentSetIndex = aDto.QuestionSetIndex;
                    AnswerSet newSet = new AnswerSet();
                    newSet.QuestionMethodID = aDto.QuestionMethodID;
                    newSet.AnswerBundleID   = bundle.AnswerBundleID;
                    db.AnswerSets.Add(newSet);
                    db.SaveChanges();
                    currentSetId = newSet.AnswerSetID;
                }
                db.Answers.Add(new Answer
                {
                    Value       = aDto.Value,
                    QuestionID  = aDto.QuestionID,
                    AnswerSetID = currentSetId
                });
                db.SaveChanges();
                Debug.WriteLine("currentSetId:" + currentSetId);
                Debug.WriteLine("currentSetIndex:" + currentSetIndex);
            }

            Debug.WriteLine("answerBundleId: " + bundle.AnswerBundleID);
            return(Ok());
        }
        public void ShortestPathTest()
        {
            try
            {
                DesktopHandler handler = new DesktopHandler(new DLV2DesktopService(GetPath()));

                ASPMapper.Instance.RegisterClass(typeof(Edge));
                ASPMapper.Instance.RegisterClass(typeof(Path));

                InputProgram input = new ASPInputProgram();

                from = 0;   // source node
                to   = 7;   // destination node

                String rules = "from(" + from + ").to(" + to + ")." +
                               "path(X,Y,W) | notPath(X,Y,W) :- from(X), edge(X,Y,W)." +
                               "path(X,Y,W) | notPath(X,Y,W) :- path(_,X,_), edge(X,Y,W), not to(X)." +
                               "visited(X) :- path(_,X,_)." +
                               ":- to(X), not visited(X)." +
                               ":~ path(X,Y,W). [W@1 ,X,Y]";

                input.AddProgram(rules);

                foreach (Edge edge in getEdges())
                {
                    input.AddObjectInput(edge);
                }

                handler.AddProgram(input);

                DLV2AnswerSets answerSets = (DLV2AnswerSets)handler.StartSync();

                Assert.IsNotNull(answerSets);
                Assert.IsTrue(answerSets.GetOptimalAnswerSets().Count != 0);
                Assert.IsTrue(answerSets.ErrorsString == "", "Found error:\n" + answerSets.ErrorsString);

                AnswerSet answerSet = answerSets.GetOptimalAnswerSets()[0];

                List <Path> path = new List <Path>();  //  edges in the shortest path (unsorted)
                int         sum  = 0;                  //  total weight of the path

                foreach (object obj in answerSet.Atoms)
                {
                    if (typeof(Path).IsInstanceOfType(obj))
                    {
                        path.Add((Path)obj);
                        sum += ((Path)obj).getWeight();
                    }
                }

                sortedPath = new List <int>();     // edges in the shorted path (sorted)
                sortedPath.Add(from);

                join(from, path, sortedPath);     // sorts the edges
                print(sortedPath, sum);           // shows the result
            }
            catch (Exception e)
            {
                Assert.Fail("Exception " + e.Message);
            }
        }
Beispiel #30
0
 public void GetAnswers(int questionId, AnswerSet answerSet)
 {
     IDataParameter[] p = AdapterAnswersByQuestionId.GetFillParameters();
     p[0].Value = questionId;
     AdapterAnswersByQuestionId.Fill(answerSet);
 }
        /// <summary>
        /// Seeds the measurement elements.
        /// </summary>
        /// <param name="context">The context.</param>
        private void SeedMeasurementElements(HealthLibraryServiceDbContext context)
        {
            #region Measurements

            var measurementElement1 = new MeasurementElement
            {
                Id = SequentialGuidGenerator.Generate(),
                MeasurementType = MeasurementType.BloodGlucose,
                Name            = "Glucose Meter",
                Type            = ElementType.Measurement,
                CustomerId      = Settings.CICustomerId
            };

            var measurementElement2 = new MeasurementElement
            {
                Id = SequentialGuidGenerator.Generate(),
                MeasurementType = MeasurementType.OxygenSaturation,
                Name            = "Pulse Oximeter",
                Type            = ElementType.Measurement,
                CustomerId      = Settings.CICustomerId
            };

            var measurementElement3 = new MeasurementElement
            {
                Id = SequentialGuidGenerator.Generate(),
                MeasurementType = MeasurementType.Temperature,
                Name            = "Thermometer",
                Type            = ElementType.Measurement,
                CustomerId      = Settings.CICustomerId
            };

            var measurementElement4 = new MeasurementElement
            {
                Id = SequentialGuidGenerator.Generate(),
                MeasurementType = MeasurementType.BloodPressure,
                Name            = "Blood Pressure Monitor",
                Type            = ElementType.Measurement,
                CustomerId      = Settings.CICustomerId
            };

            var measurementElement5 = new MeasurementElement
            {
                Id = SequentialGuidGenerator.Generate(),
                MeasurementType = MeasurementType.PeakFlow,
                Name            = "Peak Flow Meter",
                Type            = ElementType.Measurement,
                CustomerId      = Settings.CICustomerId
            };

            var measurementElement6 = new MeasurementElement
            {
                Id = SequentialGuidGenerator.Generate(),
                MeasurementType = MeasurementType.Weight,
                Name            = "Weight Scale",
                Type            = ElementType.Measurement,
                CustomerId      = Settings.CICustomerId
            };

            var measurementElement7 = new MeasurementElement
            {
                Id = SequentialGuidGenerator.Generate(),
                MeasurementType = MeasurementType.Pedometer,
                Name            = "Pedometer",
                Type            = ElementType.Measurement,
                CustomerId      = Settings.CICustomerId
            };

            if (!IsMeasurementExists(context, measurementElement1))
            {
                context.MeasurementElements.AddOrUpdate(measurementElement1);
            }

            if (!IsMeasurementExists(context, measurementElement2))
            {
                context.MeasurementElements.AddOrUpdate(measurementElement2);
            }

            if (!IsMeasurementExists(context, measurementElement3))
            {
                context.MeasurementElements.AddOrUpdate(measurementElement3);
            }

            if (!IsMeasurementExists(context, measurementElement4))
            {
                context.MeasurementElements.AddOrUpdate(measurementElement4);
            }

            if (!IsMeasurementExists(context, measurementElement5))
            {
                context.MeasurementElements.AddOrUpdate(measurementElement5);
            }

            if (!IsMeasurementExists(context, measurementElement6))
            {
                context.MeasurementElements.AddOrUpdate(measurementElement6);
            }

            if (!IsMeasurementExists(context, measurementElement7))
            {
                context.MeasurementElements.AddOrUpdate(measurementElement7);
            }

            #endregion

            #region Assessments

            var assessmentElement1 = new AssessmentElement
            {
                Id             = SequentialGuidGenerator.Generate(),
                AssessmentType = AssessmentType.Stethoscope,
                Name           = "Stethoscope",
                Type           = ElementType.Assessment,
                CustomerId     = Settings.CICustomerId
            };

            if (!IsAssessmentExists(context, assessmentElement1))
            {
                context.AssessmentElements.AddOrUpdate(assessmentElement1);
            }

            #endregion

            #region Answer Sets

            if (!IsOpenEndedAnswerSetExists(context, Settings.CICustomerId))
            {
                var openEndedAnswerSet = new AnswerSet
                {
                    CustomerId = Settings.CICustomerId,
                    IsDeleted  = false,
                    Name       = "Open Ended Answer Set",
                    Type       = AnswerSetType.OpenEnded
                };

                context.AnswerSets.Add(openEndedAnswerSet);
            }

            #endregion

            context.SaveChanges();
        }
Beispiel #32
0
 public void CreateAnswerSet(AnswerSet answerSet)
 {
     _context.AnswerSets.Add(answerSet);
     _context.SaveChanges();
 }
Beispiel #33
0
 public void UpdateAnswerSet(AnswerSet answerSet)
 {
     _context.AnswerSets.Update(answerSet);
     _context.SaveChanges();
 }
Beispiel #34
0
 public void UpdateAnswerSet(AnswerSet AnswerSet)
 {
     _AnswerService.UpdateAnswerSet(AnswerSet);
 }