Ejemplo n.º 1
0
        HashSet <Block /*!*/> /*!*/ ComputeReachableNodes(Block /*!*/ b)
        {
            Contract.Requires(b != null);
            Contract.Ensures(cce.NonNull(Contract.Result <HashSet <Block /*!*/> >()));
            BlockStats s = GetBlockStats(b);

            if (s.reachableBlocks != null)
            {
                return(s.reachableBlocks);
            }

            HashSet <Block /*!*/> blocks = new HashSet <Block /*!*/>();

            s.reachableBlocks = blocks;
            blocks.Add(b);
            foreach (Block /*!*/ succ in b.Exits())
            {
                Contract.Assert(succ != null);
                foreach (Block r in ComputeReachableNodes(succ))
                {
                    Contract.Assert(r != null);
                    blocks.Add(r);
                }
            }

            return(blocks);
        }
Ejemplo n.º 2
0
        void UpdateIncommingPaths(BlockStats s)
        {
            Contract.Requires(s != null);
            if (s.incomingPaths < 0.0)
            {
                int count = 0;
                s.incomingPaths = 0.0;
                if (!keepAtAll.Contains(s.block))
                {
                    return;
                }
                foreach (Block b in s.virtualPredecessors)
                {
                    Contract.Assert(b != null);
                    BlockStats ch = GetBlockStats(b);
                    Contract.Assert(ch != null);
                    UpdateIncommingPaths(ch);
                    if (ch.incomingPaths > 0.0)
                    {
                        s.incomingPaths += ch.incomingPaths;
                        count++;
                    }
                }

                if (count > 1)
                {
                    s.incomingPaths *= CommandLineOptions.Clo.VcsPathJoinMult;
                }
            }
        }
Ejemplo n.º 3
0
        public void DumpDot(int no)
        {
            using (System.IO.StreamWriter sw = System.IO.File.CreateText(string.Format("split.{0}.dot", no)))
            {
                sw.WriteLine("digraph G {");

                ComputeBestSplit();
                List <Block> saved = assumizedBranches;
                Contract.Assert(saved != null);
                assumizedBranches = new List <Block>();
                DoComputeScore(false);
                assumizedBranches = saved;

                foreach (Block b in bigBlocks)
                {
                    Contract.Assert(b != null);
                    BlockStats s = GetBlockStats(b);
                    foreach (Block t in s.virtualSuccessors)
                    {
                        Contract.Assert(t != null);
                        sw.WriteLine("n{0} -> n{1};", s.id, GetBlockStats(t).id);
                    }

                    sw.WriteLine("n{0} [label=\"{1}:\\n({2:0.0}+{3:0.0})*{4:0.0}\"{5}];",
                                 s.id, b.Label,
                                 s.assertionCost, s.assumptionCost, s.incomingPaths,
                                 s.assertionCost > 0 ? ",shape=box" : "");
                }

                sw.WriteLine("}");
                sw.Close();
            }

            string filename = string.Format("split.{0}.bpl", no);

            using (System.IO.StreamWriter sw = System.IO.File.CreateText(filename))
            {
                int oldPrintUnstructured = CommandLineOptions.Clo.PrintUnstructured;
                CommandLineOptions.Clo.PrintUnstructured = 2; // print only the unstructured program
                bool oldPrintDesugaringSetting = CommandLineOptions.Clo.PrintDesugarings;
                CommandLineOptions.Clo.PrintDesugarings = false;
                List <Block> backup = impl.Blocks;
                Contract.Assert(backup != null);
                impl.Blocks = blocks;
                impl.Emit(new TokenTextWriter(filename, sw, /*setTokens=*/ false, /*pretty=*/ false), 0);
                impl.Blocks = backup;
                CommandLineOptions.Clo.PrintDesugarings  = oldPrintDesugaringSetting;
                CommandLineOptions.Clo.PrintUnstructured = oldPrintUnstructured;
            }
        }
Ejemplo n.º 4
0
// Start is called before the first frame update
    void Start()
    {
        // if player prefs hasnt been populated initialize the values
        if (!PlayerPrefs.HasKey("NumCoins"))
        {
            PlayerPrefs.SetInt("NumCoins", 0);
            PlayerPrefs.SetInt("Experience", 0);
            PlayerPrefs.SetInt("ExpLevel", 0);
            PlayerPrefs.SetInt("NextCase", 0);
            PlayerPrefs.SetInt("total_correct", 0);
            BlockStats firstBlock = new BlockStats();
            PlayerPrefs.SetString("CurrentBlock", JsonUtility.ToJson(firstBlock));
        }
    }
Ejemplo n.º 5
0
    // Function that is called from PlaySummary when the user has completed diagnosing a case
    public void CompleteCase(int coins, int xp, char casetype, bool correct)
    {
        // Update the values of the player based upon rewards from the diagnostic session
        PlayerPrefs.SetInt("NumCoins", this.NumCoins + coins);
        PlayerPrefs.SetInt("Experience", this.Experience + xp);
        PlayerPrefs.SetInt("NextCase", this.NextCase + 1);

        // Update experience level using helper below
        // This must be called AFTER the Experience value is updated above
        UpdateExperienceLevel();

        BlockStats CurrentBlock = JsonUtility.FromJson <BlockStats>(this.Block);

        if (casetype == 'c')
        {
            CurrentBlock.COPD++;
            if (correct)
            {
                CurrentBlock.COPDCorrect++;
            }
        }
        if (casetype == 'h')
        {
            CurrentBlock.CHF++;
            if (correct)
            {
                CurrentBlock.CHFCorrect++;
            }
        }
        if (casetype == 'p')
        {
            CurrentBlock.Pneumonia++;
            if (correct)
            {
                CurrentBlock.PneumoniaCorrect++;
            }
        }
        if (NextCase % 10 == 0)
        {
            string key = "block" + (NextCase / 10);
            PlayerPrefs.SetString(key, JsonUtility.ToJson(CurrentBlock));

            UnityEngine.Debug.Log(key);
            UnityEngine.Debug.Log(PlayerPrefs.GetString(key));

            CurrentBlock = new BlockStats();
        }
        PlayerPrefs.SetString("CurrentBlock", JsonUtility.ToJson(CurrentBlock));
    }
Ejemplo n.º 6
0
        BlockStats GetBlockStats(Block b)
        {
            Contract.Requires(b != null);
            Contract.Ensures(Contract.Result <BlockStats>() != null);

            BlockStats s;

            if (!stats.TryGetValue(b, out s))
            {
                s        = new BlockStats(b, bsid++);
                stats[b] = s;
            }

            return(cce.NonNull(s));
        }
Ejemplo n.º 7
0
        void CountAssertions(Block b)
        {
            Contract.Requires(b != null);
            BlockStats s = GetBlockStats(b);

            if (s.assertionCost >= 0)
            {
                return; // already done
            }
            s.bigBlock       = true;
            s.assertionCost  = 0;
            s.assumptionCost = 0;
            foreach (Cmd c in b.Cmds)
            {
                if (c is AssertCmd)
                {
                    double cost = AssertionCost((AssertCmd)c);
                    s.assertionCost += cost;
                    assertionCount++;
                    assertionCost += cost;
                }
                else if (c is AssumeCmd)
                {
                    s.assumptionCost += AssertionCost((AssumeCmd)c);
                }
            }

            foreach (Block c in b.Exits())
            {
                Contract.Assert(c != null);
                s.virtualSuccessors.Add(c);
            }

            if (s.virtualSuccessors.Count == 1)
            {
                Block      next = s.virtualSuccessors[0];
                BlockStats se   = GetBlockStats(next);
                CountAssertions(next);
                if (next.Predecessors.Count > 1 || se.virtualSuccessors.Count != 1)
                {
                    return;
                }
                s.virtualSuccessors[0] = se.virtualSuccessors[0];
                s.assertionCost       += se.assertionCost;
                s.assumptionCost      += se.assumptionCost;
                se.bigBlock            = false;
            }
        }
Ejemplo n.º 8
0
 void Update()
 {
     if (holding != null)
     {
         Physics.Raycast(camera.transform.position, camera.transform.forward, out lookingAt, maxDistance, onlyBlocks);
         if (lookingAt.collider != null)
         {
             holding.GetComponent <BoxCollider>().enabled = false;
             holding.SetActive(true);
             Vector3 pointedBlock = lookingAt.collider.transform.position;
             Vector3 placeBlock   = new Vector3(pointedBlock.x, pointedBlock.y + 1f, pointedBlock.z);
             holding.transform.position = placeBlock;
             if (Input.GetMouseButton(0))
             {
                 Place(holding, placeBlock);
             }
             else if (Input.GetMouseButton(1))
             {
                 holding.SetActive(false);
                 holding = null;
             }
         }
         else
         {
             holding.SetActive(false);
         }
     }
     else
     {
         Physics.Raycast(camera.transform.position, camera.transform.forward, out lookingAt, maxDistance, onlyBlocks);
         if (lookingAt.collider != null)
         {
             GameObject pointedBlock = lookingAt.collider.gameObject;
             if (Input.GetMouseButtonUp(0))
             {
                 if (pointedBlock.GetComponent <BlockStats>() != null)
                 {
                     BlockStats stats       = pointedBlock.GetComponent <BlockStats>();
                     float      damageDealt = 100f - stats.Durability;
                     stats.DamageHealth(damageDealt, true);
                 }
             }
         }
     }
 }
Ejemplo n.º 9
0
        double DoComputeScore(bool aa)
        {
            assertToAssume = aa;
            ComputeBlockSets(false);

            foreach (Block b in bigBlocks)
            {
                Contract.Assert(b != null);
                GetBlockStats(b).incomingPaths = -1.0;
            }

            GetBlockStats(blocks[0]).incomingPaths = 1.0;

            double cost = 0.0;

            foreach (Block b in bigBlocks)
            {
                Contract.Assert(b != null);
                if (keepAtAll.Contains(b))
                {
                    BlockStats s = GetBlockStats(b);
                    UpdateIncommingPaths(s);
                    double local = s.assertionCost;
                    if (ShouldAssumize(b))
                    {
                        local = (s.assertionCost + s.assumptionCost) * CommandLineOptions.Clo.VcsAssumeMult;
                    }
                    else
                    {
                        local = s.assumptionCost * CommandLineOptions.Clo.VcsAssumeMult + s.assertionCost;
                    }

                    local = local + local * s.incomingPaths * CommandLineOptions.Clo.VcsPathCostMult;
                    cost += local;
                }
            }

            return(cost);
        }
Ejemplo n.º 10
0
        void ComputeBestSplit()
        {
            if (scoreComputed)
            {
                return;
            }
            scoreComputed = true;

            assertionCount = 0;

            foreach (Block b in blocks)
            {
                Contract.Assert(b != null);
                CountAssertions(b);
            }

            foreach (Block b in blocks)
            {
                Contract.Assert(b != null);
                BlockStats bs = GetBlockStats(b);
                if (bs.bigBlock)
                {
                    bigBlocks.Add(b);
                    foreach (Block ch in bs.virtualSuccessors)
                    {
                        Contract.Assert(ch != null);
                        BlockStats chs = GetBlockStats(ch);
                        if (!chs.bigBlock)
                        {
                            Console.WriteLine("non-big {0} accessed from {1}", ch, b);
                            DumpDot(-1);
                            Contract.Assert(false);
                            throw new cce.UnreachableException();
                        }

                        chs.virtualPredecessors.Add(b);
                    }
                }
            }

            assumizedBranches.Clear();
            totalCost = ProverCost(DoComputeScore(false));

            score = double.PositiveInfinity;
            Block        bestSplit     = null;
            List <Block> savedBranches = new List <Block>();

            foreach (Block b in bigBlocks)
            {
                Contract.Assert(b != null);
                GotoCmd gt = b.TransferCmd as GotoCmd;
                if (gt == null)
                {
                    continue;
                }
                List <Block> targ = cce.NonNull(gt.labelTargets);
                if (targ.Count < 2)
                {
                    continue;
                }
                // caution, we only consider two first exits

                double left0, right0, left1, right1;
                splitBlock = b;

                assumizedBranches.Clear();
                assumizedBranches.Add(cce.NonNull(targ[0]));
                left0  = DoComputeScore(true);
                right0 = DoComputeScore(false);

                assumizedBranches.Clear();
                for (int idx = 1; idx < targ.Count; idx++)
                {
                    assumizedBranches.Add(cce.NonNull(targ[idx]));
                }

                left1  = DoComputeScore(true);
                right1 = DoComputeScore(false);

                double currentScore = ProverCost(left1) + ProverCost(right1);
                double otherScore   = ProverCost(left0) + ProverCost(right0);

                if (otherScore < currentScore)
                {
                    currentScore = otherScore;
                    assumizedBranches.Clear();
                    assumizedBranches.Add(cce.NonNull(targ[0]));
                }

                if (currentScore < score)
                {
                    score     = currentScore;
                    bestSplit = splitBlock;
                    savedBranches.Clear();
                    savedBranches.AddRange(assumizedBranches);
                }
            }

            if (CommandLineOptions.Clo.VcsPathSplitMult * score > totalCost)
            {
                splitBlock = null;
                score      = -1;
            }
            else
            {
                assumizedBranches = savedBranches;
                splitBlock        = bestSplit;
            }
        }
Ejemplo n.º 11
0
    // Start is called before the first frame update
    void Start()
    {
        TextObject = GameObject.FindGameObjectWithTag("coins_disp");
        coins_text = TextObject.GetComponent <Text>();

        //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format("https://diagnostic-gamification-api.herokuapp.com/api/test"));
        //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        //StreamReader reader = new StreamReader(response.GetResponseStream());
        //string jsonResponse = reader.ReadToEnd();
        //TestMessage info = JsonUtility.FromJson<TestMessage>(jsonResponse);

        //UnityEngine.Debug.Log(info.message);

        BlockStats AllTime = new BlockStats();

        string key   = "block";
        int    index = 1;

        coins_text.text = "Your diagnostic accuracy over time:\n";
        if (!PlayerPrefs.HasKey(key + index))
        {
            coins_text.text = "Check back here after completeing more cases to see your progress over time!\n ";
        }
        while (PlayerPrefs.HasKey(key + index))
        {
            BlockStats CurrentBlock = JsonUtility.FromJson <BlockStats>(PlayerPrefs.GetString(key + index));

            string copdplaceholder      = ("COPD Accuracy: " + RoundToSignificantDigits(((double)CurrentBlock.COPDCorrect / CurrentBlock.COPD) * 100, 2) + "%\n");
            string CHFplaceholder       = ("CHF Accuracy: " + RoundToSignificantDigits(((double)CurrentBlock.CHFCorrect / CurrentBlock.CHF) * 100, 2) + "%\n");
            string Pneumoniaplaceholder = ("Pneumonia Accuracy: " + RoundToSignificantDigits(((double)CurrentBlock.PneumoniaCorrect / CurrentBlock.Pneumonia) * 100, 2) + "%\n");
            string totalplaceholder     = ("Total Accuracy: " + RoundToSignificantDigits(((double)CurrentBlock.PneumoniaCorrect + (double)CurrentBlock.CHFCorrect + (double)CurrentBlock.COPDCorrect) / 10 * 100, 2) + "%\n");

            // check for blocks in which there are no cases of a specific type
            if (CurrentBlock.COPD == 0)
            {
                copdplaceholder = "no COPD cases attempted\n";
            }
            if (CurrentBlock.CHF == 0)
            {
                CHFplaceholder = "no CHF cases attempted\n";
            }
            if (CurrentBlock.Pneumonia == 0)
            {
                Pneumoniaplaceholder = "no Pneumonia cases attempted\n";
            }

            coins_text.text = coins_text.text + "Cases " + ((index - 1) * 10) + "-" + (index * 10) + "\n" + copdplaceholder + CHFplaceholder + Pneumoniaplaceholder + totalplaceholder + "\n";

            //add this block to the tracking of all blocks
            AllTime.COPDCorrect      += CurrentBlock.COPDCorrect;
            AllTime.CHFCorrect       += CurrentBlock.CHFCorrect;
            AllTime.PneumoniaCorrect += CurrentBlock.PneumoniaCorrect;
            AllTime.COPD             += CurrentBlock.COPD;
            AllTime.CHF       += CurrentBlock.CHF;
            AllTime.Pneumonia += CurrentBlock.Pneumonia;

            index++;
        }
        //add non completed blocks to alltime
        if (PlayerPrefs.HasKey("CurrentBlock"))
        {
            BlockStats nonCompletedBlock = JsonUtility.FromJson <BlockStats>(PlayerPrefs.GetString("CurrentBlock"));
            AllTime.COPDCorrect      += nonCompletedBlock.COPDCorrect;
            AllTime.CHFCorrect       += nonCompletedBlock.CHFCorrect;
            AllTime.PneumoniaCorrect += nonCompletedBlock.PneumoniaCorrect;
            AllTime.COPD             += nonCompletedBlock.COPD;
            AllTime.CHF       += nonCompletedBlock.CHF;
            AllTime.Pneumonia += nonCompletedBlock.Pneumonia;
        }

        //display the alltime block


        string copdplaceholderalltime      = "COPD Accuracy: " + RoundToSignificantDigits(((double)AllTime.COPDCorrect / AllTime.COPD) * 100, 2) + "%\n";
        string CHFplaceholderalltime       = "CHF Accuracy: " + RoundToSignificantDigits(((double)AllTime.CHFCorrect / AllTime.CHF) * 100, 2) + "%\n";
        string Pneumoniaplaceholderalltime = "Pneumonia Accuracy: " + RoundToSignificantDigits(((double)AllTime.PneumoniaCorrect / AllTime.Pneumonia) * 100, 2) + "%\n";
        string totalplaceholderalltime     = "Total Accuracy: " + RoundToSignificantDigits(((double)AllTime.PneumoniaCorrect + (double)AllTime.CHFCorrect + (double)AllTime.COPDCorrect) / (PlayerPrefs.GetInt("DatabaseCaseIndex")) * 100, 2) + "%\n";

        // check for blocks in which there are no cases of a specific type
        if (AllTime.COPD == 0)
        {
            copdplaceholderalltime = "no COPD cases attempted\n";
        }
        if (AllTime.CHF == 0)
        {
            CHFplaceholderalltime = "no CHF cases attempted\n";
        }
        if (AllTime.Pneumonia == 0)
        {
            Pneumoniaplaceholderalltime = "no Pneumonia cases attempted\n";
        }
        if (AllTime.Pneumonia == 0 && AllTime.CHF == 0 && AllTime.COPD == 0)
        {
            totalplaceholderalltime = "no cases attempted\n";
        }

        UnityEngine.Debug.Log(copdplaceholderalltime);

        totalStats      = GameObject.FindGameObjectWithTag("test_message");
        totalStats_text = totalStats.GetComponent <Text>();

        totalStats_text.text = "All time statistics \n" + copdplaceholderalltime + CHFplaceholderalltime + Pneumoniaplaceholderalltime + totalplaceholderalltime + "\n";
    }