Esempio n. 1
0
    private void Awake()
    {
        tutorialbg   = GameObject.Find("tutorialbg").GetComponent <Image>();
        tutorialText = GameObject.Find("tutorialText").GetComponent <Text>();

        db = GameObject.Find("DataBucket").GetComponent <DataBucket>();
    }
Esempio n. 2
0
        public void HistogramCompactionIsCorrect()
        {
            const int numBuckets       = 5;
            const int samplesPerBucket = 100;
            var       buckets          = new DataBucket <InternalHistogram> [numBuckets];

            for (int i = 0; i < numBuckets; i++)
            {
                var newBucket =
                    new DataBucket <InternalHistogram>(this.dimensionSet, DateTime.Now,
                                                       TimeSpan.FromMinutes(1).Ticks,
                                                       this.storagePath,
                                                       this.properties.MemoryStreamManager);
                buckets[i] = newBucket;

                for (int sample = 0; sample < samplesPerBucket; sample++)
                {
                    newBucket.AddValue(this.dimensions, sample);
                }
                newBucket.Seal();
            }

            var compactedBucket =
                new DataBucket <InternalHistogram>(buckets, this.dimensionSet, DateTime.Now,
                                                   TimeSpan.FromMinutes(60).Ticks,
                                                   this.storagePath,
                                                   this.properties.MemoryStreamManager);

            var data      = compactedBucket.GetMatches(this.dimensions);
            var singleVal = data.First().Data;

            Assert.IsNotNull(singleVal);
            Assert.AreEqual(numBuckets * samplesPerBucket, (int)singleVal.SampleCount);
            compactedBucket.Dispose();
        }
Esempio n. 3
0
    //private Animator currAnim, prevAnim, nextAnim;

    private void Awake()
    {
        databucket = GameObject.Find("DataBucket").GetComponent <DataBucket>();
        document   = GameObject.Find("Document").GetComponent <Document>();
        load_game  = GameObject.Find("LoadLevelManager").GetComponent <load_game>();

        currText  = GameObject.Find("currPageText").GetComponent <Text>();
        nextText  = GameObject.Find("nextPageText").GetComponent <Text>();
        prevText  = GameObject.Find("prevPageText").GetComponent <Text>();
        levelInfo = GameObject.Find("levelInfo").GetComponent <Text>();

        prevPageImage   = GameObject.Find("prevPage").GetComponent <Image>();
        nextPageImage   = GameObject.Find("nextPage").GetComponent <Image>();
        mediumLockImage = GameObject.Find("mediumLock").GetComponent <Image>();
        hardLockImage   = GameObject.Find("hardLock").GetComponent <Image>();
        nextLockImage   = GameObject.Find("nextLock").GetComponent <Image>();
        prevButtonImage = GameObject.Find("prevButton").GetComponent <Image>();
        nextButtonImage = GameObject.Find("nextButton").GetComponent <Image>();
        prevButtonText  = GameObject.Find("prevButtonText").GetComponent <Text>();
        nextButtonText  = GameObject.Find("nextButtonText").GetComponent <Text>();



        prevButton = GameObject.Find("prevButton").GetComponent <Button>();
        nextButton = GameObject.Find("nextButton").GetComponent <Button>();

        //currAnim = GameObject.Find("currPage").GetComponent<Animator>();
        //nextAnim = GameObject.Find("nextPage").GetComponent<Animator>();
        //prevAnim = GameObject.Find("prevPage").GetComponent<Animator>();
    }
Esempio n. 4
0
 private void Awake()
 {
     illustration = GameObject.Find("endingIllustration").GetComponent <Image>();
     textbox      = GameObject.Find("bottomUI").GetComponent <Image>();
     endingText   = GameObject.Find("endingText").GetComponent <Text>();
     databucket   = GameObject.Find("DataBucket").GetComponent <DataBucket>();
 }
Esempio n. 5
0
        public void ExistingDataFilesAreCompactedOnCompactCall()
        {
            // Create one bucket at present time so that remaining buckets
            // being created are out of compaction
            var timeStamp = DateTime.UtcNow;
            var bucket    =
                new DataBucket <InternalHitCount>(this.dimensionSet, timeStamp, TimeSpan.TicksPerMinute,
                                                  this.storagePath,
                                                  this.properties.MemoryStreamManager);

            bucket.AddValue(this.dimensions, 5);
            bucket.Seal();
            bucket.Persist();

            // Create buckets manually at 1 min and 5 min quantum
            // but they actually belong at a 10 min once compacted
            var expectedNewBucketQuantum = customCompaction.Intervals.ElementAt(2).Interval.Ticks;
            var timeStamp2 = RoundTimeStamp(timeStamp.Subtract(new TimeSpan(2, 20, 0)), expectedNewBucketQuantum);

            // The buckets will have files written out but not be
            // part of the dataset until it is created
            var bucket1 =
                new DataBucket <InternalHitCount>(this.dimensionSet, timeStamp2, TimeSpan.TicksPerMinute,
                                                  this.storagePath,
                                                  this.properties.MemoryStreamManager);

            bucket1.AddValue(this.dimensions, 5);
            bucket1.Seal();
            bucket1.Persist();
            var timeStamp3 = timeStamp2.Add(new TimeSpan(0, 5, 0));
            var bucket2    =
                new DataBucket <InternalHitCount>(this.dimensionSet, timeStamp3,
                                                  TimeSpan.TicksPerMinute * 5,
                                                  this.storagePath,
                                                  this.properties.MemoryStreamManager);

            bucket2.AddValue(this.dimensions, 2);
            bucket2.Seal();
            bucket2.Persist();

            bucket.Dispose();
            bucket1.Dispose();
            bucket2.Dispose();

            this.InitializeDataSet(null);
            this.dataSet.Compact();

            // Verify that a 10 minute compacted bucket was created
            var newBucket = this.dataSet.GetDataBucket(timeStamp2);

            Assert.AreEqual(timeStamp2.Ticks, newBucket.StartTicks);
            Assert.AreEqual(expectedNewBucketQuantum, newBucket.EndTicks - newBucket.StartTicks);
            var matches = newBucket.GetMatches(this.dimensions).ToList();

            Assert.AreEqual(1, matches.Count);
            var result = matches[0].Data;

            Assert.AreEqual((ulong)7, result.HitCount);
        }
Esempio n. 6
0
 private void RecreateDataBucket(DimensionSet set = null)
 {
     if (this.bucket != null)
     {
         this.bucket.Dispose();
     }
     this.bucket =
         new DataBucket <InternalHitCount>(
             new DimensionSet(set ?? this.twoDimensionSet), this.timestamp, DefaultBucketTimeSpanTicks,
             this.currentDirectory, this.properties.MemoryStreamManager);
 }
Esempio n. 7
0
        private void RecreateFileBackedDataBucket(DimensionSet set = null)
        {
            if (this.bucket != null)
            {
                this.bucket.Dispose();
            }

            this.bucket =
                new DataBucket <InternalHitCount>(
                    new DimensionSet(set ?? this.twoDimensionSet),
                    this.bucket.Filename, this.properties.MemoryStreamManager, null);
        }
Esempio n. 8
0
 void Awake()
 {
     if (instance == null)
     {
         DontDestroyOnLoad(this);
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Esempio n. 9
0
 public void GetEntryPass()
 {
     try
     {
         var bucket = DataBucket.LoadDataBucket("TestBucket", "../../../Db/");
         var result = bucket.Get("TestKey1");
         Assert.IsTrue(result.Equals("This is test data for the document database."));
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message);
     }
 }
Esempio n. 10
0
        public void CombinedBucketsAreMergedCorrectly()
        {
            var ts1 = new DateTime(2014, 05, 10, 0, 0, 0);
            var ts2 = new DateTime(2014, 05, 10, 0, 5, 0);
            var sharedDimensions = new DimensionSpecification {
                { "one", "a1" }, { "two", "a2" }
            };
            var bucket1Dimensions = new DimensionSpecification {
                { "one", "b1" }, { "two", "b2" }
            };
            var bucket2Dimensions = new DimensionSpecification {
                { "one", "c1" }, { "two", "c2" }
            };

            var bucket1 =
                new DataBucket <InternalHitCount>(new DimensionSet(this.twoDimensionSet), ts1,
                                                  TimeSpan.FromMinutes(5).Ticks, null,
                                                  this.properties.MemoryStreamManager);

            bucket1.AddValue(sharedDimensions, 867);
            bucket1.AddValue(bucket1Dimensions, 5309);

            var bucket2 =
                new DataBucket <InternalHitCount>(new DimensionSet(this.twoDimensionSet), ts2,
                                                  TimeSpan.FromMinutes(5).Ticks, null,
                                                  this.properties.MemoryStreamManager);

            bucket2.AddValue(sharedDimensions, 867);
            bucket2.AddValue(bucket2Dimensions, 42);

            bucket1.Seal();
            bucket2.Seal();
            var bucket3 =
                new DataBucket <InternalHitCount>(new[] { bucket1, bucket2 },
                                                  new DimensionSet(this.twoDimensionSet), ts1,
                                                  TimeSpan.FromMinutes(10).Ticks, null,
                                                  this.properties.MemoryStreamManager);

            var match = bucket3.GetMatches(bucket1Dimensions).First().Data;

            Assert.AreEqual((ulong)5309, match.HitCount);
            match = bucket3.GetMatches(bucket2Dimensions).First().Data;
            Assert.AreEqual((ulong)42, match.HitCount);

            match = bucket3.GetMatches(sharedDimensions).First().Data;
            Assert.AreEqual((ulong)867 * 2, match.HitCount);

            bucket1.Dispose();
            bucket2.Dispose();
            bucket3.Dispose();
        }
Esempio n. 11
0
        public void AddEntryPass()
        {
            try
            {
                var bucket = DataBucket.LoadDataBucket("TestBucket", "../../../Db/");
                bucket.Add("TestKey1", "This is test data for the document database.");

                Assert.IsTrue(true);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Esempio n. 12
0
        public void TearDown()
        {
            if (this.bucket != null)
            {
                var file = this.bucket.Filename;

                this.bucket.Dispose();
                this.bucket = null;

                if (File.Exists(file))
                {
                    File.Delete(file);
                }
            }
        }
Esempio n. 13
0
        public void AddEntryFail()
        {
            try
            {
                var bucket = DataBucket.LoadDataBucket("TestBucket", "../../../Db/");
                bucket.Add("TestKey1", "This is test data for the document database.");
                bucket.Add("TestKey1", "This is test data for the document database.");

                Assert.Fail("This should not be possible");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(true);
            }
        }
Esempio n. 14
0
        public void TearDown()
        {
            if (this.bucket != null)
            {
                var file = this.bucket.Filename;

                this.bucket.Dispose();
                this.bucket = null;

                if (File.Exists(file))
                {
                    File.Delete(file);
                }

            }
        }
Esempio n. 15
0
    private void Awake()
    {
        databucket = GameObject.Find("DataBucket").GetComponent <DataBucket>();

        spacesSavedText    = GameObject.Find("spacesSavedText").GetComponent <Text>();
        glitchesKilledText = GameObject.Find("glitchesKilledText").GetComponent <Text>();
        errorsMadeText     = GameObject.Find("errorsMadeText").GetComponent <Text>();
        percentSavedText   = GameObject.Find("percentSavedText").GetComponent <Text>();
        QAText             = GameObject.Find("QAText").GetComponent <Text>();
        ratingText         = GameObject.Find("ratingText").GetComponent <Text>();

        nextButtonImage = GameObject.Find("nextPageButton").GetComponent <Image>();
        returnButton    = GameObject.Find("returnButton").GetComponent <Image>();
        nextButtonText  = GameObject.Find("nextButtonText").GetComponent <Text>();


        kittyStamp = GameObject.Find("kittyStamp").GetComponent <Image>();
    }
Esempio n. 16
0
        public DataBucket GetData(string filename)
        {
            var dataBucket = new DataBucket();

            if (!string.IsNullOrEmpty(filename))
            {
                foreach (var sheetName in Utility.GetExcelSheetNames(filename))
                {
                    if (IsDataTable(filename, sheetName))
                    {
                        var dataProvider = new ExcelStorage(typeof(UIDataRaw));
                        dataProvider.FileName    = filename;
                        dataProvider.StartRow    = 1;
                        dataProvider.StartColumn = 1;
                        dataProvider.SheetName   = sheetName;
                        var d1 = new UIData(dataProvider.SheetName, (UIDataRaw[])dataProvider.ExtractRecords());
                        if (!dataBucket.DataTables.ContainsKey(d1.DataName.ToLower()))
                        {
                            dataBucket.DataTables.Add(d1.DataName.ToLower(), d1);
                        }
                    }
                    else
                    {
                        var dataProvider = new ExcelStorage(typeof(UIMappingValueRaw));
                        dataProvider.SheetName   = sheetName;
                        dataProvider.FileName    = filename;
                        dataProvider.StartRow    = 2;
                        dataProvider.StartColumn = 1;
                        dataBucket.DataValues.Add(dataProvider.SheetName.ToLower(), new Dictionary <string, string>());
                        var d1 = (UIMappingValueRaw[])dataProvider.ExtractRecords();
                        foreach (var uiMappingValueRaw in d1)
                        {
                            string key = uiMappingValueRaw.Key.ToLower().TrimEnd();
                            if (!dataBucket.DataValues[dataProvider.SheetName.ToLower()].ContainsKey(key))
                            {
                                dataBucket.DataValues[dataProvider.SheetName.ToLower()].Add(key, uiMappingValueRaw.Value);
                            }
                        }
                    }
                }
            }
            return(dataBucket);
        }
Esempio n. 17
0
        public void SealAndReleaseAreThreadSafe()
        {
            var filterableDimension = new DimensionSet(new HashSet <Dimension> {
                new Dimension("thing")
            });

            using (
                var filterableBucket =
                    new DataBucket <InternalHitCount>(filterableDimension,
                                                      this.timestamp,
                                                      DefaultBucketTimeSpanTicks,
                                                      this.currentDirectory,
                                                      properties.MemoryStreamManager))
            {
                var allDims = new DimensionSpecification {
                    { "thing", "thing" }
                };
                Parallel.For(0, 10, (i) => filterableBucket.AddValue(allDims, i));

                Parallel.For(0, 100, (i) =>
                {
                    switch (i % 3)
                    {
                    case 0:
                        foreach (var item in filterableBucket.GetMatches(allDims))
                        {
                            Assert.IsNotNull(item);
                        }
                        break;

                    case 1:
                        filterableBucket.AddValue(allDims, 11);
                        break;

                    case 2:
                        filterableBucket.ReleaseData();
                        break;
                    }
                });
            }
        }
Esempio n. 18
0
        public void SplitByDimensionWithFiltersWorksProperly()
        {
            var filterableDimension = new DimensionSet(new HashSet <Dimension> {
                new Dimension("thing"), new Dimension("meat")
            });

            using (
                var filterableBucket =
                    new DataBucket <InternalHitCount>(filterableDimension, this.timestamp,
                                                      DefaultBucketTimeSpanTicks,
                                                      this.currentDirectory,
                                                      this.properties.MemoryStreamManager))
            {
                var queryDimensions = new DimensionSpecification();
                queryDimensions["thing"] = "thingOne";
                queryDimensions["meat"]  = "bacon";
                filterableBucket.AddValue(queryDimensions, 100);

                queryDimensions["thing"] = "thingTwo";
                queryDimensions["meat"]  = "pepperoni";
                filterableBucket.AddValue(queryDimensions, 200);
                filterableBucket.Seal();

                // thingOne and thingTwo will match with no filter
                Assert.AreEqual(2,
                                filterableBucket.GetMatchesSplitByDimension(new DimensionSpecification(), "thing")
                                .Sum(match => match.DataCount));

                // only thingOne matches bacon
                var bestMatchFilter = new DimensionSpecification {
                    { "meat", "bacon" }
                };
                Assert.AreEqual(1,
                                filterableBucket.GetMatchesSplitByDimension(bestMatchFilter, "thing")
                                .Sum(match => match.DataCount));
            }
        }
Esempio n. 19
0
        public void LoadBucket()
        {
            var bucket = DataBucket.LoadDataBucket("TestBucket", "../../../Db/");

            Assert.IsTrue(bucket != null);
        }
Esempio n. 20
0
    private void Start()
    {
        cursor       = GetComponentInChildren <CursorController>();
        db           = GameObject.Find("DataBucket").GetComponent <DataBucket>();
        document     = GetComponentInChildren <Document>();
        textBox      = document.GetComponent <Text>();
        clock        = GameObject.Find("Clock").GetComponent <Text>();
        spaceCounter = GameObject.Find("SpaceCounter").GetComponent <Text>();

        BGM = GameObject.Find("BGM").GetComponent <AudioSource>();
        SFX = GameObject.Find("SFX").GetComponent <AudioSource>();

        error = (AudioClip)Resources.Load("SFX/error", typeof(AudioClip));

        //Fetch the Raycaster from the GameObject (the Canvas)
        m_Raycaster = GameObject.Find("BGCanvas").GetComponent <GraphicRaycaster>();
        //Fetch the Event System from the Scene
        m_EventSystem = GameObject.Find("EventSystem").GetComponent <EventSystem>();

        document.SetUpDocument(db.level);

        GUIStyle style = new GUIStyle();

        style.font     = textBox.font;
        style.fontSize = textBox.fontSize;

        Vector2 fontSize = style.CalcSize(new GUIContent("1\n2\n3\n4\n5\n6\n7\n8\n9\n0"));

        fontWidth  = fontSize.x;
        fontHeight = fontSize.y / 10;

        cursor.SetSize(textBox.fontSize, fontWidth, fontHeight);
        cursorLocation = Vector2Int.zero;
        cursor.MoveCursor(cursorLocation);

        RectTransform monitorRect  = GetComponent <RectTransform>();
        RectTransform documentRect = GameObject.Find("Document").GetComponent <RectTransform>();

        screenDocumentLeft = Camera.main.pixelWidth * monitorRect.anchorMin.x +
                             (Camera.main.pixelWidth * (monitorRect.anchorMax.x - monitorRect.anchorMin.x)) * documentRect.anchorMin.x;

        screenDocumentTop = Camera.main.pixelWidth * 0.75f * monitorRect.anchorMax.y -
                            (Camera.main.pixelWidth * 0.75f * (monitorRect.anchorMax.y - monitorRect.anchorMin.y)) * (1 - documentRect.anchorMax.y) -
                            (Camera.main.pixelWidth * 0.75f - Camera.main.pixelHeight) / 2;

        if (db.levelData.data[db.level].difficulty == Difficulty.easy)
        {
            cursor.GetComponent <Image>().enabled                    = false;
            cursor.GetComponentInChildren <Text>().enabled           = false;
            GameObject.Find("Postit").GetComponent <Image>().enabled = false;
            GameObject.Find("memo").GetComponent <Image>().enabled   = false;
        }

        AudioClip music = null;

        switch (Random.Range(0, 3))
        {
        case 0:
            music = (AudioClip)Resources.Load("Music/game theme 1 fixed-ld42", typeof(AudioClip));
            break;

        case 1:
            music = (AudioClip)Resources.Load("Music/game music 2 loop-ld42", typeof(AudioClip));
            break;

        default:
            music = (AudioClip)Resources.Load("Music/game_music_3", typeof(AudioClip));
            break;
        }

        BGM.clip = music;
        BGM.Play();
        BGM.loop = true;

        playingLevel = false;

        StartCoroutine(LoadLevel());
    }
Esempio n. 21
0
        private void RecreateFileBackedDataBucket(DimensionSet set = null)
        {
            if (this.bucket != null)
            {
                this.bucket.Dispose();
            }

            this.bucket =
                new DataBucket<InternalHitCount>(
                    new DimensionSet(set ?? this.twoDimensionSet),
                                        this.bucket.Filename, this.properties.MemoryStreamManager, null);
        }
Esempio n. 22
0
 private void RecreateDataBucket(DimensionSet set = null)
 {
     if (this.bucket != null)
     {
         this.bucket.Dispose();
     }
     this.bucket =
         new DataBucket<InternalHitCount>(
             new DimensionSet(set ?? this.twoDimensionSet), this.timestamp, DefaultBucketTimeSpanTicks,
             this.currentDirectory, this.properties.MemoryStreamManager);
 }
Esempio n. 23
0
        public void CombinedBucketsAreMergedCorrectly()
        {
            var ts1 = new DateTime(2014, 05, 10, 0, 0, 0);
            var ts2 = new DateTime(2014, 05, 10, 0, 5, 0);
            var sharedDimensions = new DimensionSpecification { {"one", "a1"}, {"two", "a2"}};
            var bucket1Dimensions = new DimensionSpecification { {"one", "b1"}, {"two", "b2"}};
            var bucket2Dimensions = new DimensionSpecification { {"one", "c1"}, {"two", "c2"}};

            var bucket1 =
                new DataBucket<InternalHitCount>(new DimensionSet(this.twoDimensionSet), ts1,
                                                                            TimeSpan.FromMinutes(5).Ticks, null,
                                                                            this.properties.MemoryStreamManager);
            bucket1.AddValue(sharedDimensions, 867);
            bucket1.AddValue(bucket1Dimensions, 5309);

            var bucket2 =
                new DataBucket<InternalHitCount>(new DimensionSet(this.twoDimensionSet), ts2,
                                                                            TimeSpan.FromMinutes(5).Ticks, null,
                                                                            this.properties.MemoryStreamManager);
            bucket2.AddValue(sharedDimensions, 867);
            bucket2.AddValue(bucket2Dimensions, 42);

            bucket1.Seal();
            bucket2.Seal();
            var bucket3 =
                new DataBucket<InternalHitCount>(new[] {bucket1, bucket2},
                                                                            new DimensionSet(this.twoDimensionSet), ts1,
                                                                            TimeSpan.FromMinutes(10).Ticks, null,
                                                                            this.properties.MemoryStreamManager);

            var match = bucket3.GetMatches(bucket1Dimensions).First().Data;
            Assert.AreEqual((ulong)5309, match.HitCount);
            match = bucket3.GetMatches(bucket2Dimensions).First().Data;
            Assert.AreEqual((ulong)42, match.HitCount);

            match = bucket3.GetMatches(sharedDimensions).First().Data;
            Assert.AreEqual((ulong)867 * 2, match.HitCount);

            bucket1.Dispose();
            bucket2.Dispose();
            bucket3.Dispose();
        }
Esempio n. 24
0
    public bool SetUpDocument(int level)
    {
        paw = GameObject.Find("Kitty").GetComponent <Image>();
        db  = GameObject.Find("DataBucket").GetComponent <DataBucket>();
        SFX = GameObject.Find("SFX").GetComponent <AudioSource>();


        string text = ParseDocument(level);
        Font   font = documentText.font;

        if (text == "")
        {
            return(false);
        }

        //width = GetComponent<RectTransform>().rect.width;
        //height = GetComponent<RectTransform>().rect.height;

        RectTransform monitorRect  = GameObject.Find("Monitor").GetComponent <RectTransform>();
        RectTransform documentRect = GetComponent <RectTransform>();


        width = Camera.main.pixelWidth *
                (monitorRect.anchorMax.x - monitorRect.anchorMin.x) *
                (documentRect.anchorMax.x - documentRect.anchorMin.x);

        height = Camera.main.pixelWidth * 0.75f *
                 (monitorRect.anchorMax.y - monitorRect.anchorMin.y) *
                 (documentRect.anchorMax.y - documentRect.anchorMin.y);

        monitorLeft   = Camera.main.pixelWidth * (monitorRect.anchorMax.x - monitorRect.anchorMin.x) / -2.0f;
        monitorRight  = Camera.main.pixelWidth * (monitorRect.anchorMax.x - monitorRect.anchorMin.x) / 2.0f;
        monitorTop    = Camera.main.pixelWidth * 0.75f * (monitorRect.anchorMax.y - monitorRect.anchorMin.y) / 2.0f;
        monitorBottom = Camera.main.pixelWidth * 0.75f * (monitorRect.anchorMax.y - monitorRect.anchorMin.y) / -2.0f;

        documentLeft   = Camera.main.pixelWidth * (monitorRect.anchorMax.x - monitorRect.anchorMin.x) * (documentRect.anchorMin.x - 0.5f);
        documentRight  = Camera.main.pixelWidth * (monitorRect.anchorMax.x - monitorRect.anchorMin.x) * (documentRect.anchorMax.x - 0.5f);
        documentTop    = Camera.main.pixelWidth * 0.75f * (monitorRect.anchorMax.y - monitorRect.anchorMin.y) * (documentRect.anchorMax.y - 0.5f);
        documentBottom = Camera.main.pixelWidth * 0.75f * (monitorRect.anchorMax.y - monitorRect.anchorMin.y) * (documentRect.anchorMin.y - 0.5f);

        //Debug.Log("Document size: " + width + " x " + height);
        //Debug.Log("Monitor Left: " + monitorLeft + ", Top: " + monitorTop + ", Right: " + monitorRight + ", Bottom: " + monitorBottom);
        //Debug.Log("Document Left: " + documentLeft + ", Top: " + documentTop + ", Right: " + documentRight + ", Bottom: " + documentBottom);

        bool working  = true;
        int  fontSize = 60;

        while (working)
        {
            int maxWidth;
            int maxHeight;

            do
            {
                GUIStyle style = new GUIStyle();

                style.font     = font;
                style.fontSize = fontSize;

                Vector2 charSize = style.CalcSize(new GUIContent("1\n2\n3\n4\n5\n6\n7\n8\n9\n0"));
                charWidth  = charSize.x;
                charHeight = charSize.y / 10;

                maxWidth  = Mathf.FloorToInt(width / charWidth);
                maxHeight = Mathf.FloorToInt(height / charHeight);

                // Debug.Log("Font Size: " + fontSize + ", Char Size: " + charWidth + " x " + charHeight + ", Max Width: " + maxWidth + ", Max Height: " + maxHeight);


                if (maxWidth < 20)
                {
                    if (fontSize == 10)
                    {
                        Debug.Log("Too much text");
                        return(false);
                    }
                    else
                    {
                        fontSize -= 5;
                    }
                }
            } while (maxWidth < 20);
            string testText = text;

            int lastSpace     = -1;
            int lastWordBreak = -1;
            int x             = 0;
            int y             = 0;

            spaces    = new List <Space>();
            lineStart = new List <int>();

            lineStart.Add(0);

            for (int pos = 0; pos < testText.Length; pos++)
            {
                if (testText[pos] == '\t')
                {
                    testText      = testText.Substring(0, pos) + "   " + testText.Substring(pos + 1);
                    pos          += 2;
                    x            += 2;
                    lastWordBreak = pos;
                }
                else if (testText[pos] == '\n')
                {
                    x = -1;
                    y++;
                    lastWordBreak = pos;
                    lineStart.Add(pos + 1);
                }
                else if (testText[pos] == ' ')
                {
                    spaces.Add(new Space(x, y, ' ', new Vector2(documentLeft + (x + 0.5f) * charWidth, documentTop - (y + 0.5f) * charHeight)));
                    lastSpace++;
                    lastWordBreak = pos;
                }

                if (x >= maxWidth)
                {
                    testText = testText.Substring(0, lastWordBreak) + "\n" + testText.Substring(lastWordBreak + 1);
                    spaces.Remove(spaces[lastSpace]);
                    lastSpace--;

                    x = pos - lastWordBreak - 1;
                    lineStart.Add(lastWordBreak + 1);
                    y++;
                }

                if (y >= maxHeight)
                {
                    if (fontSize == 10)
                    {
                        Debug.Log("Too much text");
                        return(false);
                    }
                    else
                    {
                        fontSize -= 5;
                        break;
                    }
                }

                if (pos == testText.Length - 1)
                {
                    working = false;
                    //Debug.Log("Parse Successful");
                }

                x++;
            }

            documentText.text     = testText;
            documentText.fontSize = fontSize;
        }

        //Debug.Log("spaces: " + spaces.Count);

        //Debug.Log("level " + db.level);

        int initialFill = Mathf.RoundToInt(spaces.Count * db.levelData.data[db.level].percentInitialSpacesFilled);

        for (int x = 0; x < initialFill; x++)
        {
            int random = 0;
            do
            {
                random = Random.Range(0, spaces.Count);
            } while (spaces[random].currentChar != ' ');
            spaces[random] = FillSpace(spaces[random]);
        }


        return(true);
    }
Esempio n. 25
0
        public void ExistingDataFilesAreCompactedOnCompactCall()
        {
            // Create one bucket at present time so that remaining buckets
            // being created are out of compaction
            var timeStamp = DateTime.UtcNow;
            var bucket =
                new DataBucket<InternalHitCount>(this.dimensionSet, timeStamp, TimeSpan.TicksPerMinute,
                                                                            this.storagePath,
                                                                            this.properties.MemoryStreamManager);
            bucket.AddValue(this.dimensions, 5);
            bucket.Seal();
            bucket.Persist();

            // Create buckets manually at 1 min and 5 min quantum
            // but they actually belong at a 10 min once compacted
            var expectedNewBucketQuantum = customCompaction.Intervals.ElementAt(2).Interval.Ticks;
            var timeStamp2 = RoundTimeStamp(timeStamp.Subtract(new TimeSpan(2, 20, 0)), expectedNewBucketQuantum);

            // The buckets will have files written out but not be 
            // part of the dataset until it is created
            var bucket1 =
                new DataBucket<InternalHitCount>(this.dimensionSet, timeStamp2, TimeSpan.TicksPerMinute,
                                                                            this.storagePath,
                                                                            this.properties.MemoryStreamManager);
            bucket1.AddValue(this.dimensions, 5);
            bucket1.Seal();
            bucket1.Persist();
            var timeStamp3 = timeStamp2.Add(new TimeSpan(0, 5, 0));
            var bucket2 =
                new DataBucket<InternalHitCount>(this.dimensionSet, timeStamp3,
                                                                            TimeSpan.TicksPerMinute * 5,
                                                                            this.storagePath,
                                                                            this.properties.MemoryStreamManager);
            bucket2.AddValue(this.dimensions, 2);
            bucket2.Seal();
            bucket2.Persist();

            bucket.Dispose();
            bucket1.Dispose();
            bucket2.Dispose();

            this.InitializeDataSet(null);
            this.dataSet.Compact();

            // Verify that a 10 minute compacted bucket was created
            var newBucket = this.dataSet.GetDataBucket(timeStamp2);
            Assert.AreEqual(timeStamp2.Ticks, newBucket.StartTicks);
            Assert.AreEqual(expectedNewBucketQuantum, newBucket.EndTicks - newBucket.StartTicks);
            var matches = newBucket.GetMatches(this.dimensions).ToList();
            Assert.AreEqual(1, matches.Count);
            var result = matches[0].Data;
            Assert.AreEqual((ulong)7, result.HitCount);
        }
Esempio n. 26
0
        public void CreateBucket()
        {
            var bucket = DataBucket.CreateNewBucket("TestBucket", "../../../Db/", 300, 250000);

            Assert.IsTrue(Directory.Exists(Path.Combine("../../../Db/", "TestBucket")));
        }
Esempio n. 27
0
    // Use this for initialization

    void Start()
    {
        //buttonSound = GameObject.Find ("ButtonSound").GetComponent<AudioSource> ();
        databucket = GameObject.Find("DataBucket").GetComponent <DataBucket>();
    }
Esempio n. 28
0
        public void SplitByDimensionWithFiltersWorksProperly()
        {
            var filterableDimension = new DimensionSet(new HashSet<Dimension> {new Dimension("thing"), new Dimension("meat")});
            using (
                var filterableBucket =
                    new DataBucket<InternalHitCount>(filterableDimension, this.timestamp,
                                                                                DefaultBucketTimeSpanTicks,
                                                                                this.currentDirectory,
                                                                                this.properties.MemoryStreamManager))
            {
                var queryDimensions = new DimensionSpecification();
                queryDimensions["thing"] = "thingOne";
                queryDimensions["meat"] = "bacon";
                filterableBucket.AddValue(queryDimensions, 100);

                queryDimensions["thing"] = "thingTwo";
                queryDimensions["meat"] = "pepperoni";
                filterableBucket.AddValue(queryDimensions, 200);
                filterableBucket.Seal();

                // thingOne and thingTwo will match with no filter
                Assert.AreEqual(2,
                                filterableBucket.GetMatchesSplitByDimension(new DimensionSpecification(), "thing")
                                                .Sum(match => match.DataCount));

                // only thingOne matches bacon
                var bestMatchFilter = new DimensionSpecification {{"meat", "bacon"}};
                Assert.AreEqual(1,
                                filterableBucket.GetMatchesSplitByDimension(bestMatchFilter, "thing")
                                                .Sum(match => match.DataCount));
            }
        }
Esempio n. 29
0
        public void HistogramCompactionIsCorrect()
        {
            const int numBuckets = 5;
            const int samplesPerBucket = 100;
            var buckets = new DataBucket<InternalHistogram>[numBuckets];

            for (int i = 0; i < numBuckets; i++)
            {
                var newBucket =
                    new DataBucket<InternalHistogram>(this.dimensionSet, DateTime.Now,
                                                                                          TimeSpan.FromMinutes(1).Ticks,
                                                                                          this.storagePath,
                                                                                          this.properties.MemoryStreamManager);
                buckets[i] = newBucket;

                for (int sample = 0; sample < samplesPerBucket; sample++)
                {
                    newBucket.AddValue(this.dimensions, sample);
                }
                newBucket.Seal();
            }

            var compactedBucket =
                new DataBucket<InternalHistogram>(buckets, this.dimensionSet, DateTime.Now,
                                                                                      TimeSpan.FromMinutes(60).Ticks,
                                                                                      this.storagePath,
                                                                                      this.properties.MemoryStreamManager);

            var data = compactedBucket.GetMatches(this.dimensions);
            var singleVal = data.First().Data;
            Assert.IsNotNull(singleVal);
            Assert.AreEqual(numBuckets * samplesPerBucket, (int)singleVal.SampleCount);
            compactedBucket.Dispose();
        }
Esempio n. 30
0
        public void SealAndReleaseAreThreadSafe()
        {
            var filterableDimension = new DimensionSet(new HashSet<Dimension> { new Dimension("thing") });
            using (
                var filterableBucket =
                    new DataBucket<InternalHitCount>(filterableDimension,
                                                                                this.timestamp,
                                                                                DefaultBucketTimeSpanTicks,
                                                                                this.currentDirectory,
                                                                                properties.MemoryStreamManager))
            {


                var allDims = new DimensionSpecification {{"thing", "thing"}};
                Parallel.For(0, 10, (i) => filterableBucket.AddValue(allDims, i));

                Parallel.For(0, 100, (i) =>
                                     {
                                         switch (i % 3)
                                         {
                                         case 0:
                                             foreach (var item in filterableBucket.GetMatches(allDims))
                                             {
                                                 Assert.IsNotNull(item);
                                             }
                                             break;

                                         case 1:
                                             filterableBucket.AddValue(allDims, 11);
                                             break;

                                         case 2:
                                             filterableBucket.ReleaseData();
                                             break;
                                         }
                                     });
            }
        }