Esempio n. 1
0
    public void initialiseForm(Dataset _dataset)
    {
        dataset = _dataset;

        type = dataset.type;

        type_box.GetComponent <InputField> ().text = type.ToString();

        datagrid_z_size_Inputfield.GetComponent <InputField> ().text = dataset.seriesCount.ToString();
        datagrid_x_size_inputfield.GetComponent <InputField> ().text = dataset.categoriesCount.ToString();

        int z = int.Parse(datagrid_z_size_Inputfield.GetComponent <InputField> ().text) + 1;
        int x = int.Parse(datagrid_x_size_inputfield.GetComponent <InputField> ().text) + 1;

        datagrid_values = null;
        datagrid_values = new string[z, x];

        for (int x_counter = 0; x_counter < dataset.values.GetLength(1); x_counter++)
        {
            for (int z_counter = 0; z_counter < dataset.values.GetLength(0); z_counter++)
            {
                string s = dataset.values [z_counter, x_counter].ToString();
                datagrid_values [z_counter + 1, x_counter + 1] = s;
            }
        }

        for (int z_counter = 0; z_counter < dataset.values.GetLength(0); z_counter++)
        {
            string s = dataset.series[z_counter].ToString();
            datagrid_values [z_counter + 1, 0] = s;
        }
        for (int x_counter = 0; x_counter < dataset.values.GetLength(1); x_counter++)
        {
            string s = dataset.categories[x_counter].ToString();
            datagrid_values [0, x_counter + 1] = s;
        }

        Series_title_Inputfield.GetComponent <InputField> ().text   = dataset.seriesTitle;
        Category_title_Inputfield.GetComponent <InputField> ().text = dataset.catTitle;

        datagrid_z_size = z;
        datagrid_x_size = x;

        drawGrid();
    }
Esempio n. 2
0
 public void testCycle()
 {
     Dataset.Types oldType = ds.type;
     ds.cycleType();
     if (oldType == Dataset.Types.Line)
     {
         Assert.AreNotEqual(oldType, Dataset.Types.Point);
     }
     else if (oldType == Dataset.Types.Point)
     {
         Assert.AreNotEqual(oldType, Dataset.Types.Pie);
     }
     else if (oldType == Dataset.Types.Pie)
     {
         Assert.AreNotEqual(oldType, Dataset.Types.Bar);
     }
     else
     {
         Assert.AreNotEqual(oldType, Dataset.Types.Line);
     }
 }
Esempio n. 3
0
    //Generates a Dataset from the OCR result
    void MakeDataset(string text)
    {
        Dataset.Types type      = Dataset.Types.Null;
        string        firstline = text.Substring(0, text.IndexOf("\n"));

        try{
            text = text.Replace(firstline, null);
        } catch {
            resetApp();
        }
        Debug.Log("Title: " + firstline + "\n");
        text = text.TrimStart();

        string ser = text.Substring(0, text.IndexOf("\n"));

        try{
            text = text.Replace(ser, "");
        } catch {
            resetApp();
        }
        string[] tempSer = ser.Split(' ');

        string[] series = new string[tempSer.Length - 1];

        for (int i = 1; i < tempSer.Length; i++)
        {
            series [i - 1] = tempSer [i];
        }

        Debug.Log("Series: " + ser + "\n");
        text = text.TrimStart();



        System.Collections.Generic.List <string[]> tableList    = new System.Collections.Generic.List <string[]>();
        System.Collections.Generic.List <string>   categoryList = new System.Collections.Generic.List <string>();
        string temp    = "";
        bool   success = true;

        const int MIN_LENGTH = 1;

        while (text.Length > MIN_LENGTH && text.IndexOf("\n") > 0)
        {
            temp = text.Substring(0, text.IndexOf("\n"));
            text = text.Replace(temp, "");

            string catName = "";             //The row name

            //Remove the row name by assuming everything until the first digit is the name and removing that from the string.
            for (int x = 0; x < temp.Length; x++)
            {
                if (!Char.IsDigit(temp [x]))
                {
                    catName += temp [x];
                }
                else
                {
                    break;
                }
            }

            try{
                temp = temp.Replace(catName, "");
            } catch {
                resetApp();
            }

            categoryList.Add(catName);

            //Removes series entries from rows
            string[] prescreenRow = temp.Split(' ');
            string[] row          = new string[prescreenRow.Length];

            for (int i = 0; i < prescreenRow.Length; i++)
            {
                if (!prescreenRow [i].All(char.IsDigit))
                {
                    row [i] = StringManipulation.sanitizeString(prescreenRow [i]);
                }
                else
                {
                    row [i] = prescreenRow [i];
                }
            }

            tableList.Add(row);
            Debug.Log("Row: " + string.Join("", tableList.ElementAt(tableList.Count - 1)) + "\n");
            text = text.TrimStart();
        }
        string[] categories = categoryList.ToArray();

        float[,] table = new float[series.Length, tableList.Count];
        for (int i = 0; i < tableList.Count; i++)
        {
            for (int x = 0; x < series.Length; x++)
            {
                float tempFloat = 0;

                try{
                    if (Single.TryParse(tableList.ElementAt(i) [x], out tempFloat))
                    {
                    }
                    else if (Single.TryParse(StringManipulation.sanitizeString(tableList.ElementAt(i) [x]), out tempFloat))
                    {
                    }
                    else
                    {
                        tempFloat = 0;
                        success   = false;
                    }
                }catch (Exception e) {
                    tempFloat = 0;
                    success   = false;
                }

                table [x, i] = tempFloat;
            }
        }

        string dbg = "";

        for (int i = 0; i < tableList.Count; i++)
        {
            dbg  = "";
            dbg += categories [i] + " ";
            for (int x = 0; x < series.Length; x++)
            {
                dbg += " : " + table[x, i];
            }
            Debug.Log(dbg);
        }

        //Send to form
        Dataset dataset = new Dataset(type, firstline, categories, series, "", "", table, categories.Length, series.Length);

        UI.GetComponent <UI> ().initialiseForm(dataset);
        loadScreen.SetActive(false);
        form.SetActive(true);

        //Create graph directly
        //Dataset.dataset = new Dataset (type, firstline, categories, series, tempSer[0], firstline, table, categories.Length, series.Length);
    }