예제 #1
0
    private void SaveButton()
    {
        // Create a list to hold new dataValues
        List <string> newDataInputList = new List <string>();

        // Get list of values from newData InputFields
        foreach (GameObject dataInput in GameObject.FindGameObjectsWithTag("PCPNewDataInputField"))
        {
            newDataInputList.Add(dataInput.GetComponent <TMP_InputField>().text);
            dataInput.GetComponent <TMP_InputField>().text = null;
        }
        ;

        // Get & Set kValue InputField and weighted Toggle for KNN
        KNN.kValue      = Convert.ToInt32(GameObject.FindGameObjectWithTag("PCPkValue").GetComponent <TMP_InputField>().text);
        KNN.trueOrFalse = GameObject.FindGameObjectWithTag("PCPWeighted").GetComponent <Toggle>().isOn;

        // Run Cancel() to clear and hide the NewData Panel after the values have been stored
        CancelButton();
        // Add the new data
        NewDataPoint.AddDataPoint(newDataInputList);

        ColorManager.Blink(KNN.kPoints, pointList);

        // Target the last DataBall (column4) within the newly added instance
        GameObject newBall = (GameObject)pointList.Last()["DataBall4"] as GameObject;

        TargetingScript.selectedTarget = newBall;
        TargetingScript.colorOff       = TargetingScript.selectedTarget.GetComponent <Renderer>().material.color;
        TargetingScript.selectedTarget.GetComponent <Renderer>().material.color = Color.white;
        TargetingScript.selectedTarget.transform.localScale += new Vector3(+0.01f, +0.01f, +0.01f);
    }
예제 #2
0
    public static void ChangeDataPoint()
    {
        int countBalancer;

        //TODO: 'countBalancer' skulle kanske kunna vara en input-parameter istället. (Johannes)
        if (SceneManager.GetActiveScene().name == "ParallelCoordinatePlot")
        {
            countBalancer = 6;
        }
        else
        {
            countBalancer = 3;
        }

        Dictionary <string, object> KnnPoint = CSVläsare.pointList.Last();

        CSVläsare.pointList.Remove(KnnPoint);

        double[] unknown = new double[KnnPoint.Count - countBalancer];

        for (int i = 0; i < KnnPoint.Count - countBalancer; ++i)
        {
            unknown[i] = (Convert.ToDouble(KnnPoint[CSVläsare.columnList[i + 1]], CultureInfo.InvariantCulture));
        }

        var predict = CSVläsare.dataClass.Knn(unknown);

        KnnPoint[CSVläsare.columnList.Last()] = predict;
        CSVläsare.pointList.Add(KnnPoint);

        if (SceneManager.GetActiveScene().name == "ScatterPlotMatrix")
        {
            ScatterPlotMatrix.ThisInstans.PlottData();
        }

        else if (SceneManager.GetActiveScene().name == "ParallelCoordinatePlot")
        {
            ParallelCoordinatePlotter.ThisInstans.ReorderColumns();
            if (KNN.kPoints != null && KNN.kPoints.Count > 0) //TODO: Skall flyttas. (Johannes)
            {
                ColorManager.Blink(KNN.kPoints, CSVläsare.pointList);
            }
        }

        else if (SceneManager.GetActiveScene().name == "ValfriTeknik")
        {
            ScatterplotDimensions.ThisInstans.PlottData();
        }

        else
        {
            DataPlotter.ThisInstans.PlottData();
        }
    }
예제 #3
0
    public void PlottData()
    {
        Max      = new float[dropDownList.Length - 1];
        Min      = new float[dropDownList.Length - 1];
        nameList = new string[dropDownList.Length - 1];

        if (TargetingScript.selectedTarget != null)
        {
            selectedIndex = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index;
        }

        foreach (GameObject dataValues in GameObject.FindGameObjectsWithTag("DataBall"))
        {
            Destroy(dataValues);
        }

        foreach (var axisValue in GameObject.FindGameObjectsWithTag("3D_Axis_ValueText"))
        {
            Destroy(axisValue);
        }

        feature1Name = columnListDropDown[dropDownList[0].value];
        feature2Name = columnListDropDown[dropDownList[1].value];
        feature3Name = columnListDropDown[dropDownList[2].value];
        feature4Name = columnListDropDown[dropDownList[3].value];
        feature5Name = columnListDropDown[dropDownList[4].value];

        for (int i = 0; i < dropDownList.Length - 1; i++)
        {
            nameList[i]      = columnList[dropDownList[i].value + 1];
            textList[i].text = nameList[i];
            Min[i]           = CalculationHelpers.FindMinValue(nameList[i], pointList);
            Max[i]           = CalculationHelpers.FindMaxValue(nameList[i], pointList);
        }

        InstantiateDataPoint(Max, Min, nameList);

        RenderAxisValues(Max, Min);

        // Focus camera on new dataPoint
        if (CameraBehavior.teleportCamera)
        {
            CameraBehavior.RefocusCamera(pointList);
        }

        if (KNN.kPoints != null)
        {
            if (KNN.kPoints.Count > 0)
            {
                ColorManager.Blink(KNN.kPoints, pointList);
            }
        }
    }
예제 #4
0
    public void PlottData()
    {
        if (TargetingScript.selectedTarget != null)
        {
            selectedIndex = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index;
        }

        DestroyDataBallsAndAxisValues();

        xName = columnList[xList.value + 1];
        yName = columnList[yList.value + 1];

        xAxisText.text = xName;
        yAxisText.text = yName;

        // Get maxes of each axis
        xMax = CalculationHelpers.FindMaxValue(xName, pointList);
        yMax = CalculationHelpers.FindMaxValue(yName, pointList);
        zMax = 0f;

        // Get minimums of each axis
        xMin = CalculationHelpers.FindMinValue(xName, pointList);
        yMin = CalculationHelpers.FindMinValue(yName, pointList);
        zMin = 0f;

        // If renderMode is 3D
        if (MainMenu.renderMode == 1)
        {
            zName          = columnList[zList.value + 1];
            zAxisText.text = zName;
            zMax           = CalculationHelpers.FindMaxValue(zName, pointList);
            zMin           = CalculationHelpers.FindMinValue(zName, pointList);
        }

        string valueString;

        // If renderMode is 2D
        if (MainMenu.renderMode == 0)
        {
            // Destroy all dataValues before plotting new ones
            foreach (GameObject dataValues in GameObject.FindGameObjectsWithTag("dataValues"))
            {
                Destroy(dataValues);
            }

            DrawBackgroundGridAndValues();
        }

        // If renderMode is 3D
        if (MainMenu.renderMode == 1)
        {
            RenderAxisValues();
        }

        // Loop through Pointlist
        for (var i = 0; i < pointList.Count; i++)
        {
            GameObject dataPoint;

            // Get value in poinList at ith "row", in "column" Name, normalize
            valueString = pointList[i][xName].ToString();
            float x = (float.Parse(valueString, CultureInfo.InvariantCulture) - xMin) / (xMax - xMin);

            valueString = pointList[i][yName].ToString();
            float y = (float.Parse(valueString, CultureInfo.InvariantCulture) - yMin) / (yMax - yMin);

            float z = 1;

            //Instantiate datapoints
            if (MainMenu.renderMode == 0)
            {
                dataPoint = Instantiate(PointPrefab, new Vector3(x, y, 0) * plotScale, Quaternion.identity);
                dataPoint.transform.name   = pointList[i][columnList[0]] + " " + pointList[i][xName] + " " + pointList[i][yName] + " " + pointList[i][columnList[columnList.Count() - 1]];
                dataPoint.transform.parent = PointHolder.transform;
            }
            else
            {
                valueString = pointList[i][zName].ToString();
                z           = (float.Parse(valueString, CultureInfo.InvariantCulture) - zMin) / (zMax - zMin);
                dataPoint   = Instantiate(PointPrefab, new Vector3(x, y, z) * plotScale, Quaternion.identity);
                dataPoint.transform.name   = pointList[i][columnList[0]] + " " + pointList[i][xName] + " " + pointList[i][yName] + " " + pointList[i][zName] + " " + pointList[i][columnList[columnList.Count() - 1]];
                dataPoint.transform.parent = PointHolder.transform;
            }

            if (!pointList[i].ContainsKey("DataBall"))
            {
                pointList[i].Add("DataBall", dataPoint);
            }
            else
            {
                pointList[i]["DataBall"] = dataPoint;
            }

            //Store values in dataPoint
            dataPoint.GetComponent <StoreIndexInDataBall>().Index         = i;
            dataPoint.GetComponent <StoreIndexInDataBall>().TargetFeature = pointList[i][columnList[columnList.Count - 1]].ToString();
            dataPoint.GetComponent <StoreIndexInDataBall>().Feature1      = xName;
            dataPoint.GetComponent <StoreIndexInDataBall>().Feature2      = yName;
            if (zName != null)
            {
                dataPoint.GetComponent <StoreIndexInDataBall>().Feature3 = zName;
            }

            //Assign color to dataPoint
            int index = targetFeatures.IndexOf(pointList[i][columnList[columnList.Count - 1]].ToString());
            if (targetFeatures.Count() <= 10)
            {
                ColorManager.ChangeColor(dataPoint, index);
            }
            else
            {
                dataPoint.GetComponent <Renderer>().material.color = new Color(x, y, z, 1.0f);
            }

            //Reselect target if one was selected before.
            if (selectedIndex == i)
            {
                TargetingScript.selectedTarget = dataPoint;
                TargetingScript.colorOff       = TargetingScript.selectedTarget.GetComponent <Renderer>().material.color;
                TargetingScript.selectedTarget.GetComponent <Renderer>().material.color = Color.white;
                TargetingScript.selectedTarget.transform.localScale += new Vector3(+0.01f, +0.01f, +0.01f);
                selectedIndex = -1;
            }
        }

        // Focus camera on new dataPoint
        if (CameraBehavior.teleportCamera)
        {
            CameraBehavior.RefocusCamera(pointList);
        }

        if (KNN.kPoints != null)
        {
            if (KNN.kPoints.Count > 0)
            {
                ColorManager.Blink(KNN.kPoints, pointList);
            }
        }
    }
예제 #5
0
    public void PlottData()
    {
        if (TargetingScript.selectedTarget != null)
        {
            selectedIndex  = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index;
            selectedRow    = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row;
            selectedColumn = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column;
        }

        ResetDataPlot();

        for (int j = 0; j < 4; j++)
        {
            for (int k = 0; k < 4; k++)
            {
                try
                {
                    feature1Name = featureList[columnDropdownList[j].value];
                    feature2Name = featureList[columnDropdownList[k].value];
                    feature1     = featureList[columnDropdownList[0].value];
                    feature2     = featureList[columnDropdownList[1].value];
                    feature3     = featureList[columnDropdownList[2].value];
                    feature4     = featureList[columnDropdownList[3].value];

                    if (j == k)
                    {
                        GameObject summonPlane = Instantiate(planePointBackground,
                                                             new Vector3(k * 1.2F + 0.5F, j * 1.2F + 0.5F, 0) * plotScale,
                                                             Quaternion.Euler(0, 90, -90));

                        //Le textfält
                        TMP_Text textField = Instantiate(ScatterplotMatrixText,
                                                         new Vector3(k * 1.2F + 1, j * 1.2F + 0.3F, -0.01f) * plotScale,
                                                         Quaternion.identity);

                        textField.text = featureList[columnDropdownList[j].value];
                    }
                    else if (k < j)
                    {
                        GameObject summonPlane = Instantiate(planePointBackground,
                                                             new Vector3(k * 1.2F + 0.5F, j * 1.2F + 0.5F, 0) * plotScale,
                                                             Quaternion.Euler(0, 90, -90));

                        // Get maxes of each axis
                        float xMax = CalculationHelpers.FindMaxValue(feature1Name, pointList);
                        float yMax = CalculationHelpers.FindMaxValue(feature2Name, pointList);

                        // Get minimums of each axis
                        float xMin = CalculationHelpers.FindMinValue(feature1Name, pointList);
                        float yMin = CalculationHelpers.FindMinValue(feature2Name, pointList);

                        string valueString;

                        //Loop through Pointlist
                        for (var i = 0; i < pointList.Count; i++)
                        {
                            GameObject dataPoint;

                            // Get value in poinList at ith "row", in "column" Name, normalize
                            valueString = pointList[i][feature1Name].ToString();
                            float x = (float.Parse(valueString, CultureInfo.InvariantCulture) - xMin) / (xMax - xMin);

                            valueString = pointList[i][feature2Name].ToString();
                            float y = (float.Parse(valueString, CultureInfo.InvariantCulture) - yMin) / (yMax - yMin);

                            int index = targetFeatures.IndexOf(pointList[i][columnList[columnList.Count - 1]].ToString());

                            // Instantiate dataPoint
                            dataPoint = Instantiate(PointPrefab,
                                                    new Vector3(x + k * 1.2F, y + j * 1.2F, 0) * plotScale,
                                                    Quaternion.identity);
                            // Set transform name
                            dataPoint.transform.name = pointList[i][feature1Name] + " " + pointList[i][feature2Name];
                            // Set parent
                            dataPoint.transform.parent = PointHolder.transform;

                            dataPoint.GetComponent <StoreIndexInDataBall>().Index         = i;
                            dataPoint.GetComponent <StoreIndexInDataBall>().TargetFeature =
                                pointList[i][columnList[columnList.Count - 1]].ToString();

                            dataPoint.GetComponent <StoreIndexInDataBall>().Feature1 = feature1;
                            dataPoint.GetComponent <StoreIndexInDataBall>().Feature2 = feature2;
                            dataPoint.GetComponent <StoreIndexInDataBall>().Column   = featureList[columnDropdownList[j].value];
                            dataPoint.GetComponent <StoreIndexInDataBall>().Row      = featureList[columnDropdownList[k].value];
                            dataPoint.GetComponent <StoreIndexInDataBall>().Feature3 = feature3;
                            dataPoint.GetComponent <StoreIndexInDataBall>().Feature4 = feature4;
                            dataPoint.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder  = new Vector3(k * 1.2F + 0.5F, j * 1.2F + 0.5F, 0) * plotScale;
                            dataPoint.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder += new Vector3(-5, -5, 0);


                            if (!pointList[i].ContainsKey("DataBall"))
                            {
                                pointList[i].Add("DataBall", dataPoint);
                            }
                            else
                            {
                                pointList[i]["DataBall"] = dataPoint;
                            }

                            // Set color
                            if (targetFeatures.Count() <= 10)
                            {
                                ColorManager.ChangeColor(dataPoint, index);
                            }
                            else
                            {
                                dataPoint.GetComponent <Renderer>().material.color = new Color(x, y, y, 1.0f);
                            }

                            //Reselect target if one was selected before.
                            if (selectedIndex == i && dataPoint.GetComponent <StoreIndexInDataBall>().Column == selectedColumn && dataPoint.GetComponent <StoreIndexInDataBall>().Row == selectedRow)
                            {
                                TargetingScript.selectedTarget = dataPoint;
                                TargetingScript.colorOff       = TargetingScript.selectedTarget.GetComponent <Renderer>().material.color;
                                TargetingScript.selectedTarget.GetComponent <Renderer>().material.color = Color.white;
                                TargetingScript.selectedTarget.transform.localScale += new Vector3(+0.01f, +0.01f, +0.01f);
                                selectedIndex = -1;
                            }
                            if (KNN.KNNMode && i == pointList.Count() - 1)
                            {
                                dataPoint.GetComponent <Renderer>().material.color = Color.white;
                                dataPoint.transform.localScale += new Vector3(-0.01f, -0.01f, -0.01f);
                            }
                        }
                    }
                }
                catch (Exception) { }

                if (KNN.kPoints != null)
                {
                    if (KNN.kPoints.Count > 0)
                    {
                        ColorManager.Blink(KNN.kPoints, pointList);
                    }
                }
            }
        }

        // Focus camera on new dataPoint
        if (CameraBehavior.teleportCamera)
        {
            CameraBehavior.RefocusCamera(pointList);
        }
    }