Beispiel #1
0
        public void TestCreateKeyValue()
        {
            // The expected JSON String
            String expected = "\"name\": \"Dave\"";
            // The actual JSON String
            String actual = JSONWriter.CreateKeyValue("name", "Dave");

            // Ensure the expected JSON String and the actual JSON String are equal
            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        /// <summary>
        /// This method will create a well formed key based upon the values of
        /// Device and WeekNumber. If the device is null, then the week number
        /// will be used to create a name key. E.g. "name": "9800" or
        /// "name": "Week 1".
        /// </summary>
        /// <returns>A well formed key/value pair</returns>
        private String GetDataKey()
        {
            // Return the device name as a key if avaiable.
            if (Device != null)
            {
                return(JSONWriter.CreateKeyValue("name", Device));
            }

            return(JSONWriter.CreateKeyValue("name", "Week " + WeekNumber));
        }
Beispiel #3
0
        public void TestCreateJSONObjectKeyValue()
        {
            // The expected JSON String
            String expected = "{ \"name\": \"Dave\", \"age\": \"30\" }";
            //The input data
            String name = JSONWriter.CreateKeyValue("name", "Dave");
            String age  = JSONWriter.CreateKeyValue("age", "30");
            // The actual JSON String
            String actual = JSONWriter.CreateJSONObject(name, age);

            // Ensure the expected JSON String and the actual JSON String are equal
            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        /// <summary>
        /// This method will return a well formatted JSON String based upon the
        /// elements that are held within this object.
        /// </summary>
        /// <returns>A well formatted JSON String</returns>
        public String ToJSON()
        {
            // Stores a list of the various JSON objects
            List <String> elements = new List <String>();

            // Loop oever each event collection
            foreach (KeyValuePair <String, EventCollection> pair in this)
            {
                // Get the event collection grouping name
                String name = JSONWriter.CreateKeyValue("name", pair.Key);
                // Get the count of the event collection
                String value = JSONWriter.CreateKeyValue("size", pair.Value.Count.ToString());
                // Create a JSON object
                String json = JSON.JSONWriter.CreateJSONObject(name, value);
                // Add to the know elements
                elements.Add(json);
            }
            return(String.Join(", ", elements.ToArray()));
        }
        /// <summary>
        /// This method will merge all the Fail MixBand JSON formatted strings for
        /// each given week within this object. The method will the ultimatley
        /// return a new JSON string which will contain the multi-week analysis.
        /// </summary>
        /// <returns>A well formed JSON string</returns>
        private String MergeFailMixBandJSON()
        {
            // Stores all the JSON strings for each week
            List <String> weeks = new List <String>();

            // Loop over each week
            foreach (KeyValuePair <int, WeekAnalysis> pair in WeeklyAnalysis)
            {
                // Create the JSON String
                String json = pair.Value.CreateFailMixBandJSON();
                // Add the string to the list of weeks
                weeks.Add(json);
            }
            // Create the name of the data structure
            String name = JSONWriter.CreateKeyValue("name", "Fail Events Mix-Band Usage");
            // Create the children JSON array
            String children = JSONWriter.CreateJSONArray("children", weeks);

            // Create and return the final JSON object
            return(JSONWriter.CreateJSONObject(name, children));
        }
        /// <summary>
        /// This method will merge all the Fail RAT JSON formatted strings for each
        /// given device within this object. The method will ultimately return a
        /// new JSON string which will contain the multi-device analysis.
        /// </summary>
        /// <returns>A well formed JSON string</returns>
        private String MergeFailRATJSON()
        {
            // Stores all the JSON strings for each device
            List <String> devices = new List <String>();

            // Loop over each week
            foreach (KeyValuePair <String, ProductAnalysis> pair in ProductsAnalysis)
            {
                // Create the JSON String
                String json = pair.Value.CreateFailRATJSON();
                // Add the string to the list of weeks
                devices.Add(json);
            }
            // Create the name of the data structure
            String name = JSONWriter.CreateKeyValue("name", "Fail Events RAT Usage");
            // Create the children JSON array
            String children = JSONWriter.CreateJSONArray("children", devices);

            // Create and return the final JSON object
            return(JSONWriter.CreateJSONObject(name, children));
        }
Beispiel #7
0
        /// <summary>
        /// This method will return a well formatted JSON String based upon the
        /// elements that are held within this object.
        /// </summary>
        /// <returns>A well formatted JSON String</returns>
        public override String ToString()
        {
            // List of each JSON cluster
            List <String> clusters = new List <String>();

            // Loop over each of the clusters
            foreach (KeyValuePair <int, AnalysisResultsCollection> pair in this)
            {
                // Generate the cluster name
                String cluster_name = JSONWriter.CreateKeyValue("name", "Cluster " + pair.Key);
                // Used to store the children JSON array
                List <String> cluster_children = new List <String>();
                // Loop over the children data (E.g. 2G, or 3G, or Freq1)
                foreach (KeyValuePair <String, AnalysisResults> results in pair.Value)
                {
                    // Generate the name
                    String name = JSONWriter.CreateKeyValue("name", results.Key);
                    // Generate the Children array
                    String children = JSONWriter.CreateJSONArray("children", results.Value.ToJSON());
                    // merge the two above together
                    String element = JSONWriter.CreateJSONObject(name, children);
                    // Add to the cluster
                    cluster_children.Add(element);
                }
                // Merge all the children values into an Array
                String children_values = JSONWriter.CreateJSONArray("children", cluster_children);
                // Create the cluster JSON Object
                String cluster = JSONWriter.CreateJSONObject(cluster_name, children_values);
                // Add the cluster JSON object to all the known clusters
                clusters.Add(cluster);
            }
            // Format the key (either the device name or the week number)
            String key = GetDataKey();
            // Format the children data
            String data = JSONWriter.CreateJSONArray("children", clusters);

            // Final Formatting of the string
            return(JSONWriter.CreateJSONObject(key, data));
        }