示例#1
0
    public void ConvertToCountryData()
    {
        TextAsset   jsonData = Resources.Load <TextAsset>("population");
        SeriesArray data     = JsonUtility.FromJson <SeriesArray>(jsonData.text);

        CountryData[] countryDataList = new CountryData[data.AllData.Length];
        for (int i = 0; i < data.AllData.Length; i++)
        {
            SeriesData seriesData = data.AllData[i];

            CountryData countryData = new CountryData();
            countryDataList[i] = countryData;
            countryData.Name   = "UNKNOWN";
            countryData.Points = new CountryPoint[seriesData.Data.Length / 3];

            for (int j = 0, k = 0; j < seriesData.Data.Length; j += 3, k++)
            {
                CountryPoint p = new CountryPoint();
                p.y                   = Convert.ToInt32(seriesData.Data[j]);
                p.x                   = Convert.ToInt32(seriesData.Data[j + 1]);
                p.population          = seriesData.Data[j + 2];
                p.infection           = 0;
                countryData.Points[k] = p;
            }
        }

        WorldData worldData = new WorldData();

        worldData.Countries = countryDataList;
        string json = JsonUtility.ToJson(worldData);
    }
示例#2
0
    void serializeNodes(List <testbed_node> nodes, int action)
    {
        SeriesData    data      = new SeriesData();
        SeriesArray   array     = new SeriesArray();
        List <string> nodeNames = new List <string>();

        data.Name = "Testbed_Nodes";
        List <float>      values    = new List <float>();
        List <SeriesData> arrayVals = new List <SeriesData>();
        string            jsonString;

        foreach (testbed_node n in nodes)
        {
            values.Add(n.xVal);
            values.Add(n.yVal);
            nodeNames.Add(n.shortName);
        }

        data.Data  = values.ToArray();
        jsonString = JsonConvert.SerializeObject(data);
        arrayVals.Add(data);
        array.AllData = arrayVals.ToArray();

        print(array.AllData);

        if (action == 0)
        {
            visualizer.CreateMeshes(array.AllData, nodeNames);
        }
        else
        {
            visualizer.updateMeshes(array.AllData, nodeNames);
        }
    }
示例#3
0
 // Use this for initialization
 void Start()
 {
     TextAsset   jsonData = Resources.Load <TextAsset>("population");
     string      json     = jsonData.text;
     SeriesArray data     = JsonUtility.FromJson <SeriesArray>(json);
     //Visualizer.CreateMeshes(data.AllData);
 }
示例#4
0
        public void Given_DataFrameWithNoHeaders_When_IndexingWithString_Then_ThrowsException()
        {
            // Arrange
            Series      s1     = new Series(new object[] { 151.40, 155.40, 151.00, 154.10 });
            SeriesArray series = new SeriesArray(new Series[] { s1 });
            DataFrame   df     = new DataFrame(series);

            // Act
            var assert = df["test"];
        }
示例#5
0
        public void Setup()
        {
            Series      s1     = new Series(new object[] { 10, 20 });
            Series      s2     = new Series(new object[] { 20, 40 });
            Series      s3     = new Series(new object[] { 30, 60 });
            Series      s4     = new Series(new object[] { 40, 80 });
            Series      s5     = new Series(new object[] { 50, 100 });
            SeriesArray series = new SeriesArray(new Series[] { s1, s2, s3, s4, s5 });

            df = new DataFrame(series);
        }
示例#6
0
        public void Given_Initiating_When_ArrayObjectHaveDifferentLengths_Then_ThrowsException()
        {
            // Arrange
            Series s1 = new Series(new object[] { 151.40, 155.40, 151.00, 154.10 });
            Series s2 = new Series(new object[] { 154.50, 155.90 });

            Series[] array = new Series[] { s1, s2 };

            // Act, Assert
            SeriesArray sa = new SeriesArray(array);
        }
示例#7
0
        public void Given_DataFrameWithNoHeaders_When_LocWithStringArray_Then_ThrowsException()
        {
            // Arrange
            Series      s1     = new Series(new object[] { 151.40, 155.40, 151.00, 154.10 });
            SeriesArray series = new SeriesArray(new Series[] { s1 });
            DataFrame   df     = new DataFrame(series);

            // Act
            var assert = df.Loc(new string[2] {
                "test1", "test2"
            });
        }
示例#8
0
        public void Given_InitiatingWithData_When_GetLengthMoreThenOne_Then_ThrowsException()
        {
            // Arrange
            Series s = new Series(new object[] { 151.40, 155.40, 151.00, 154.10 });

            Series[] array = new Series[] { s };

            // Act
            SeriesArray sa = new SeriesArray(array);

            sa.GetLength(2);
        }
示例#9
0
    // Use this for initialization
    void Start()
    {
        // Load json data file
        //TextAsset jsonData = Resources.Load<TextAsset>("population");
        //TextAsset jsonData = Resources.Load<TextAsset>("coronavirusConfirmed0210_3cols_v2");
        TextAsset jsonData = Resources.Load <TextAsset>("CoronavirusData0210_all");
        string    json     = jsonData.text;

        //SeriesArray data = JsonUtility.FromJson<SeriesArray>(json);
        data = JsonUtility.FromJson <SeriesArray>(json);
        dayVisualizer.CreateMeshes(data.AllData, 0, 4);

        // Process data to get dates
        dates = json.Split('\n');
        int hashIndex = -1;

        dateDropDown.options.Clear();

        for (int i = 3; i < dates.Length - 1; i += 4)
        {
            // Extract dates from the data source
            string[] dateStrings = dates[i].Split(':');
            string   dateString  = dateStrings[1].Replace("\"", "").Replace(",", "");
            //Debug.Log(dateString);

            // Index the dates and store them in a dictionary
            hashIndex++;
            hashedDates.Add(dateString, hashIndex);

            // Feed the dates into a drop down list
            dateDropDown.options.Add(new Dropdown.OptionData(dateString));

            // Create buttons for the dates
            CreateButton(dateString);
        }

        //// Debug dictionary
        //foreach (KeyValuePair<string, int> pair in hashedDates)
        //{
        //    Debug.Log("FOREACH KEY:" + pair.Key + "FOREACH Value: " + pair.Value);

        //}

        //dateDropDown.itemText.text = hashedDates.Keys.First().ToString();

        //dateDropDown.options.Clear();
        //foreach(string str in dates)
        //{
        //    Debug.Log("str: " + str);
        //    dateDropDown.options.Add(new Dropdown.OptionData(str));
        //    //Debug.Log("Added.");
        //}
    }
示例#10
0
        public void Given_InitiatingWithData_When_GetLengthOne_Then_ValueEqualTheNumberOfObjectsInSeries()
        {
            // Arrange
            Series s = new Series(new object[] { 151.40, 155.40, 151.00, 154.10 });

            Series[] array = new Series[] { s };

            // Act
            SeriesArray sa     = new SeriesArray(array);
            var         length = sa.GetLength(1);

            // Assert
            Assert.AreEqual(length, s.Length);
        }
示例#11
0
        public void Given_InitiatingWithData_When_GetSeriesByIndexer_Then_SeriesEqualSeries()
        {
            // Arrange
            Series s1 = new Series(new object[] { 151.40, 155.40, 151.00, 154.10 });
            Series s2 = new Series(new object[] { 154.50, 155.90, 154.10, 155.40 });

            Series[] array = new Series[] { s1, s2 };

            // Act
            SeriesArray sa  = new SeriesArray(array);
            var         obj = sa[1];

            // Assert
            Assert.AreEqual(obj, array[1]);
        }
示例#12
0
        public void Given_InitiatingWithData_When_GetLengthZero_Then_ValueEqualTheNumberOfObjectsInArray()
        {
            // Arrange
            Series s1 = new Series(new object[] { 151.40, 155.40, 151.00, 154.10 });
            Series s2 = new Series(new object[] { 154.50, 155.90, 154.10, 155.40 });

            Series[] array = new Series[] { s1, s2 };

            // Act
            SeriesArray sa     = new SeriesArray(array);
            var         length = sa.GetLength(0);

            // Assert
            Assert.AreEqual(length, array.Length);
        }
示例#13
0
        static void Main(string[] args)
        {
            // open and close prices for ALFA.ST for the dates 2017-01-02 to 2017-01-05
            // creates four series, one for each date with open and close prices
            Series _2017_01_02 = new Series(new object[] { 151.40, 155.40, 151.00, 154.10 });
            Series _2017_01_03 = new Series(new object[] { 154.50, 155.90, 154.10, 155.40 });
            Series _2017_01_04 = new Series(new object[] { 155.50, 156.70, 154.10, 154.90 });
            Series _2017_01_05 = new Series(new object[] { 154.90, 155.00, 152.90, 153.20 });

            SeriesArray seriesArray = new SeriesArray(new Series[] { _2017_01_02, _2017_01_03, _2017_01_04, _2017_01_05 });

            // headers representing the different prices
            string[] headers = new string[] { "Open", "High", "Low", "Close" };
            // indexers representing the different dates
            string[] indexes = new string[] { "2017-01-02", "2017-01-03", "2017-01-04", "2017-01-05" };

            // create a datafram and print it out
            DataFrame dataFrame = new DataFrame(seriesArray, headers, indexes);

            Console.WriteLine(dataFrame);

            // addition
            // It's possible to add two columns together
            // Lets sum up Open and Close for all the rows
            var open  = dataFrame["Open"];
            var close = dataFrame["Close"];

            var addition = open + close;

            Console.WriteLine(addition);

            // subtraction
            var subtraction = close - open;

            Console.WriteLine(subtraction);;

            // multiplication
            var multiplication = open * close;

            Console.WriteLine(multiplication);

            //division
            var division = close / open;

            Console.WriteLine(division);

            Console.ReadKey();
        }
示例#14
0
    // Use this for initialization
    void Start()
    {
        // Load Data
        TextAsset   jsonData = Resources.Load <TextAsset>("covidGeoData");
        string      json     = jsonData.text;
        SeriesArray data     = JsonUtility.FromJson <SeriesArray>(json);

        Visualizer.CreateMeshes(data.AllData);
        Visualizer.CollateTotals(data.AllData);

        // Update date display
        endDateText.text = baseDate.AddDays(Visualizer.seriesObjects.Length - 1).ToString("dd MMMM");

        // Update slider value
        mainSlider.maxValue = Visualizer.seriesObjects.Length - 1;
    }
示例#15
0
        static void Main(string[] args)
        {
            // open and close prices for ALFA.ST for the dates 2017-01-02 to 2017-01-05
            // creates four series, one for each date with open and close prices
            Series _2017_01_02 = new Series(new object[] { "151.40", "155.40", "151.00", "154.10" });
            Series _2017_01_03 = new Series(new object[] { "154.50", "155.90", "154.10", "155.40" });
            Series _2017_01_04 = new Series(new object[] { "155.50", "156.70", "154.10", "154.90" });
            Series _2017_01_05 = new Series(new object[] { "154.90", "155.00", "152.90", "153.20" });

            SeriesArray seriesArray = new SeriesArray(new Series[] { _2017_01_02, _2017_01_03, _2017_01_04, _2017_01_05 });

            // indexers representing the different dates
            string[] indexes = new string[] { "2017-01-02", "2017-01-03", "2017-01-04", "2017-01-05" };

            // create a datafram and print it out
            DataFrame dataFrame = new DataFrame(seriesArray, indexers: indexes);

            Console.WriteLine("Fill and print a DataFrame");
            Console.WriteLine(dataFrame);

            // We can select rows by index and indexes
            // Use the methods ILoc to get rows by index
            DataFrame thirdRowByILocDataFrame = dataFrame.ILoc(2);

            Console.WriteLine("Third row using ILoc (dataFrame.ILoc(2))");
            Console.WriteLine(thirdRowByILocDataFrame);

            // It's also possible to select multiple rows nysing an array of indexes
            DataFrame thirdFourthRowByILocDataFrame = dataFrame.ILoc(new int[] { 2, 3 });

            Console.WriteLine("Third  and fourth row using ILoc (dataFrame.ILoc(new int[] { 2, 3 }))");
            Console.WriteLine(thirdFourthRowByILocDataFrame);

            // Use the method Loc to get rows by indexes
            DataFrame secondRowByLocDataFrame = dataFrame.Loc("2017-01-03");

            Console.WriteLine("Row 2017-01-03 using Loc (dataFrame.Loc(\"2017-01-03\"))");
            Console.WriteLine(secondRowByLocDataFrame);

            // Use the method Loc to get rows by indexes
            DataFrame secondAndFourthRowByLocDataFrame = dataFrame.Loc(new string[] { "2017-01-03", "2017-01-05" });

            Console.WriteLine("Rows 2017-01-03 and 2017-01-05 using Loc (dataFrame.Loc(new string[] { \"2017-01-03\", \"2017-01-05\" }))");
            Console.WriteLine(secondAndFourthRowByLocDataFrame);

            Console.ReadKey();
        }
示例#16
0
        static void Main(string[] args)
        {
            // open and close prices for ALFA.ST for the dates 2017-01-02 to 2017-01-05
            // creates four series, one for each date with open and close prices
            Series _2017_01_02 = new Series(new object[] { "151.40", "155.40", "151.00", "154.10" });
            Series _2017_01_03 = new Series(new object[] { "154.50", "155.90", "154.10", "155.40" });
            Series _2017_01_04 = new Series(new object[] { "155.50", "156.70", "154.10", "154.90" });
            Series _2017_01_05 = new Series(new object[] { "154.90", "155.00", "152.90", "153.20" });

            SeriesArray seriesArray = new SeriesArray(new Series[] { _2017_01_02, _2017_01_03, _2017_01_04, _2017_01_05 });

            // headers representing the different prices
            string[] headers = new string[] { "Open", "High", "Low", "Close" };

            // create a datafram and print it out
            DataFrame dataFrame = new DataFrame(seriesArray, headers: headers);

            Console.WriteLine("Fill and print a DataFrame");
            Console.WriteLine(dataFrame);

            // Based on dataFrame, select only column at index 0, the "Open" column
            DataFrame openDataFrame = dataFrame[0];

            Console.WriteLine("First column by index (dataFrame[0])");
            Console.WriteLine(openDataFrame);

            // Based on dataFrame, select the columns at index 0 and 1, "Open" and "High" columns
            DataFrame closeHighDataFrame = dataFrame[new int[] { 0, 1 }];

            Console.WriteLine("First and second column by index (dataFrame[new int[] { 0, 1}])");
            Console.WriteLine(closeHighDataFrame);

            // It's also posible to select by header
            DataFrame highDataFrame = dataFrame["High"];

            Console.WriteLine("Column High by header (dataFrame[\"High\"])");
            Console.WriteLine(highDataFrame);

            // It's also posible to select by header
            DataFrame highLowDataFrame = dataFrame[new string[] { "High", "Low" }];

            Console.WriteLine("Columns High and Low by header (dataFrame[new string[] { \"High\", \"Low\" }])");
            Console.WriteLine(highLowDataFrame);

            Console.ReadKey();
        }
示例#17
0
        public void Setup()
        {
            Series      s1      = new Series(new object[] { 10 });
            SeriesArray series1 = new SeriesArray(new Series[] { s1 });

            df1 = new DataFrame(series1);

            Series      s2      = new Series(new object[] { 20 });
            SeriesArray series2 = new SeriesArray(new Series[] { s2 });

            df2 = new DataFrame(series2);

            Series      s3      = new Series(new object[] { 20 });
            Series      s4      = new Series(new object[] { 40 });
            SeriesArray series3 = new SeriesArray(new Series[] { s1, s3 });

            df3 = new DataFrame(series3);

            SeriesArray series4 = new SeriesArray(new Series[] { s2, s4 });

            df4 = new DataFrame(series4);
        }
示例#18
0
    // Use this for initialization
    void Start()

    {
        //Access the Unity scenes through the scene manager, using the function .GetActiveScene()
        Scene scene = SceneManager.GetActiveScene();

        //loads selected json data set corrleating with correct scene
        if (scene.name == "Level1_Rlobe")
        {
            TextAsset jsonData = Resources.Load <TextAsset>("RLobe1");
            //TextAsset jsonData = Resources.Load<TextAsset>("N_simulated_braincoordinates");
            //Debug.Log(jsonData);
            // TextAsset jsonData = Resources.Load<TextAsset>("Data_Test");


            string      json = jsonData.text;
            SeriesArray data = JsonUtility.FromJson <SeriesArray>(json);
            //accesses all data variable where all the timestamp arrays are stored.
            Visualizer.CreateMeshes(data.AllData);
        }


        //loads selected json data set corrleating with correct scene
        if (scene.name == "Level2_Elsewhere")
        {
            TextAsset jsonData = Resources.Load <TextAsset>("Elsewhere1");
            Debug.Log(jsonData);
            //TextAsset jsonData = Resources.Load<TextAsset>("TestBrainCoordinates");


            string      json = jsonData.text;
            SeriesArray data = JsonUtility.FromJson <SeriesArray>(json);
            //accesses all data variable where all the timestamp arrays are stored.
            Visualizer.CreateMeshes(data.AllData);
        }
    }
示例#19
0
 public void Given_Initiating_When_ArrayIsNull_Then_ThrowsException()
 {
     // Arrange , Act, Assert
     SeriesArray sa = new SeriesArray(null);
 }
示例#20
0
        /// <summary>
        /// Get a DataSet from a file
        /// </summary>
        /// <param name="filePath">File to read data from</param>
        /// <param name="separator">char representing seperator used to define columns</param>
        /// <param name="skipRows">Number of rows to skip when reading, start at 1</param>
        /// <param name="headerRow">Index pointing at what row to use as header</param>
        /// <param name="indexerColumn">Index pointing at what column to use as indexers</param>
        /// <param name="includeNullRows">True/False if rows where all values is null should be included</param>
        /// <returns>A DataFrame</returns>
        public static DataFrame ReadCsv(string filePath, int?headerRow = null, int?indexerColumn = null, char separator = ';', int skipRows = 0, bool includeNullRows = true)
        {
            int numerOfRows = 0;
            var AllLines    = new string[10000]; //only allocate memory here

            using (StreamReader sr = File.OpenText(filePath))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (numerOfRows >= skipRows)
                    {
                        AllLines[numerOfRows - skipRows] = line;
                    }

                    numerOfRows += 1;
                }
            }

            // Get the number of columns
            int numberOfColumns = AllLines[headerRow != null ? (int)headerRow : 0].Split(separator).Length - (indexerColumn != null ? 1 : 0);

            string[] headers = null;
            string[] indexes = indexerColumn != null ? new string[numerOfRows - skipRows - 1] : null;

            Series[] series = new Series[headerRow != null ? numerOfRows - 1 : numerOfRows];

            for (int i = 0; i < numerOfRows - skipRows; i++)
            {
                var line = AllLines[i].Split(separator);

                if (i == headerRow && headerRow != null)
                {
                    headers = line;

                    if (indexerColumn != null)
                    {
                        headers = headers.Where((source, index) => index != (int)indexerColumn).ToArray();
                    }
                }
                else
                {
                    object[] data = new object[numberOfColumns];
                    for (int j = 0; j < line.Length; j++)
                    {
                        if (indexerColumn != null && j == indexerColumn)
                        {
                            indexes[headerRow != null ? i - 1 : i] = line[j];
                        }
                        else
                        {
                            data[indexerColumn != null ? j - 1 : j] = line[j];
                        }
                    }

                    if (!includeNullRows && data.All(d => d == null))
                    {
                        continue;
                    }

                    series[headerRow != null ? i - 1 : i] = new Series(data);
                }
            }

            SeriesArray array = new SeriesArray(series);

            return(new DataFrame(array, headers, indexes));
        }
 public void AddSeries(Series series)
 {
     SeriesArray.Add(series);
 }
示例#22
0
    // Use this for initialization
    void Start()
    {
        // Load json data file
        //TextAsset jsonData = Resources.Load<TextAsset>("population");
        //TextAsset jsonData = Resources.Load<TextAsset>("coronavirusConfirmed0210_3cols_v2");
        TextAsset jsonData = Resources.Load <TextAsset>("CoronavirusData0311_all");
        //TextAsset jsonData = Resources.Load<TextAsset>("CoronavirusData0210_all");
        string json = jsonData.text;

        //SeriesArray data = JsonUtility.FromJson<SeriesArray>(json);


        // Process data to get dates
        dates = json.Split('\n');
        int hashIndex = -1;

        dateDropDown.options.Clear();

        data = JsonUtility.FromJson <SeriesArray>(json);
        dayVisualizer.CreateMeshes(data.AllData, 0, 4, dates[4].Split(':')[1].Replace("[", "").Replace("]", "").Trim().Split(','));
        newCaseVisualizer.CreateMeshes(data.AllData, 0, 5, dates[4].Split(':')[1].Replace("[", "").Replace("]", "").Trim().Split(','));

        for (int i = 3; i < dates.Length - 1; i += 4)
        {
            // Extract dates from the data source
            string[] dateStrings = dates[i].Split(':');
            string   dateString  = dateStrings[1].Replace("\"", "").Replace(",", "").Trim();
            //Debug.Log(dateString);

            // Index the dates and store them in a dictionary
            hashIndex++;
            hashedDates.Add(dateString, hashIndex);

            // Feed the dates into a drop down list
            //dateDropDown.options.Add(new Dropdown.OptionData(dateString));

            // Create buttons for the dates
            CreateButton(dateString);

            // Extract data from the data source
            hashedData.Add(dateString, dates[i + 1].Split(':')[1].Replace("[", "").Replace("]", "").Trim().Split(','));
        }

        // set day1 date in the header
        headDateText.text = FindDateStringByIndex(0);

        //// Debug dictionary
        //foreach (KeyValuePair<string, int> pair in hashedDates)
        //{
        //    Debug.Log("FOREACH KEY:" + pair.Key + "FOREACH Value: " + pair.Value);

        //}

        //dateDropDown.itemText.text = hashedDates.Keys.First().ToString();

        //dateDropDown.options.Clear();
        //foreach(string str in dates)
        //{
        //    Debug.Log("str: " + str);
        //    dateDropDown.options.Add(new Dropdown.OptionData(str));
        //    //Debug.Log("Added.");
        //}

        animateButton = canvas.transform.GetChild(0).GetChild(1).GetChild(0).gameObject;
        animateButton.GetComponent <Button>().onClick.AddListener(OnStart);

        stopButton = canvas.transform.GetChild(0).GetChild(1).GetChild(1).gameObject;
        stopButton.GetComponent <Button>().onClick.AddListener(OnStop);

        resetButton = canvas.transform.GetChild(0).GetChild(1).GetChild(2).gameObject;
        resetButton.GetComponent <Button>().onClick.AddListener(OnReset);

        selectionPanel = canvas.transform.GetChild(2).gameObject;

        //Debug.Log("buttons: " + animateButton.name + stopButton.name + resumeButton.name);

        //Start the coroutine we define below named ExampleCoroutine.
        //StartCoroutine(ExampleCoroutine());
    }