示例#1
0
 /// <summary>
 /// Update properties.
 /// </summary>
 /// <param name="fp">TDRCFrequencyPoint used to copy its values to this data structure.</param>
 public void updateData(TDRCFrequencyPoint fp)
 {
     dimension = fp.dimension;
     time      = fp.time;
     value     = fp.value;
     pos       = fp.pos;
     color     = fp.color;
 }
示例#2
0
    /// <summary>
    /// Method to parse and process the loaded data.
    /// </summary>
    /// <param name="dataText">String representing the loaded text data.</param>
    private void parseLoadedData(string textData)
    {
        // Note: CSV model / template (= loaded text data) has three field names (string) "dimension", (string) "time", and (int) value, and uses , as a delimiter

        // Method structure documentation:
        // [1] Parse the loaded text data to dynamically detect all existing unique dimension values.
        // [2] Create a dictionary with List<TDRCFrequencyPoint> (values) for each unique dimension (key).
        // [3] Parse through the loaded data again to populate individual list values (TDRCFrequencyPoint) for each dimension.


        // [1] Parse the loaded text data to dynamically detect all existing unique dimension values.
        //

        // prepare text processing
        StringReader strReader = new StringReader(textData);

        // dynamically detect individual dimensions in the loaded data (based on the "dimension" field)
        // by analyzing all rows in the data
        List <string> detectedDimensions = new List <string>();

        while (strReader.Peek() > -1)
        {
            // read and dismantle current line
            string   currentLine = strReader.ReadLine();
            string[] clParts     = currentLine.Split(',');  // indexes: 0 = dimension, 1 = time, 2 = value

            // get current dimension, and cut pre-/post-quote " of the string
            string currentDimension = removeStringQuotes(clParts[0]);

            // ignore header row
            if (currentDimension.Equals("dimension") == false)
            {
                // if current dimension is not yet in the captured key list, capture it
                if (detectedDimensions.Contains(currentDimension) != true)
                {
                    detectedDimensions.Add(currentDimension);
                }
            }
        }

        // ATTENTION: Data visualzation as a 3D Radar Chart only makes sense if there are at least three data variables (= dimensions) in the data set (in order to create a radar mesh).
        // Developer Note: Consider deciding / implementing a maximum count for different data variables (= dimensions) in the future.
        if (detectedDimensions.Count < 3)
        {
            Debug.LogError("[TDRCDataLoader] parseLoadedData detected less than 3 (required) dimensions (= data variables), with textData = " + textData);
            return;     // abort further data processing and (GameObject) initialization
        }

        // [2] Create a dictionary with List<TDRCFrequencyPoint> (values) for each unique dimension (key).
        //

        // initialize lists of TDRCFrequencyPoints for individual dimensions (based on identified dimensions from parsed data)
        // and keep track of them in a dictionary (key = dimension, value = List of TDRCFrequencyPoints for that dimension)
        dataDict = new Dictionary <string, List <TDRCFrequencyPoint> >();
        for (int d = 0; d < detectedDimensions.Count; d++)
        {
            dataDict.Add(detectedDimensions[d], new List <TDRCFrequencyPoint>());
        }

        // [3] Parse through the loaded data again to populate individual list values (TDRCFrequencyPoint) for each dimension.
        //

        // populate data structure with content from loaded data
        strReader = new StringReader(textData);     // reset string reader for processing from the start
        while (strReader.Peek() > -1)
        {
            // read and dismantle current line
            string   currentLine = strReader.ReadLine();
            string[] clParts     = currentLine.Split(',');  // indexes: 0 = dimension, 1 = time, 2 = value

            // ignore header row
            if (removeStringQuotes(clParts[0]).Equals("dimension") == false)
            {
                // set up new TDRCFrequencyPoint based on current line
                TDRCFrequencyPoint fp = new TDRCFrequencyPoint();
                fp.dimension = removeStringQuotes(clParts[0]);
                fp.time      = removeStringQuotes(clParts[1]);
                bool wasCurrentValueParsed = int.TryParse(clParts[2], out fp.value);
                if (wasCurrentValueParsed == false)
                {
                    Debug.LogError("[TDRCDataLoader] Error parsing int value for current line = " + currentLine);
                }

                // determine to which dimension the current TDRCFrequencyPoint should be added
                foreach (string dimensionKey in dataDict.Keys)
                {
                    // check if current dimension key corresponds to the current TDRCFrequencyPoint's dimension
                    // if yes: add it to the List of TDRCFrequencyPoints, and break
                    if (dimensionKey.Equals(fp.dimension) == true)
                    {
                        dataDict[dimensionKey].Add(fp);
                        break;
                    }
                }
            }
        }


        // [3] Initiate GameObject set up based on loaded data (follow up from at the end of initiateDataLoading()).
        //

        tdrcInterface.freqPolyManager.initWithTDRCFrequencyPointListAndColorDictionary(dataDict, colorDict);
    }