Exemplo n.º 1
0
        /// <summary>
        /// Returns a formatted string of the statistics for this particular test
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        static public string QueryStatsByTest(string pid, string testName, string testSession, bool includeLeft, bool includeRight)
        {
            if (includeLeft == false && includeRight == false)
            {
                return("Nothing to do");
            }

            try
            {
                QueryData d = new QueryData()
                {
                    ProductId = pid, TestName = testName, TestSession = testSession, IncludeLeft = includeLeft, IncludeRight = includeRight
                };

                var json     = new JavaScriptSerializer().Serialize(d);
                var body     = new StringContent(json, Encoding.UTF8, "application/json");
                var response = Client.PostAsync(Url + "/api/QueryResults", body).Result;

                string content = response.Content.ReadAsStringAsync().Result;
                JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
                string        result = (string)jsSerializer.DeserializeObject(content);
                List <double> vals   = jsSerializer.Deserialize <List <double> >(result);

                StringBuilder sb = new StringBuilder();
                Maths.StdDev(vals, out double avg, out double stdDev);
                sb.AppendFormat("Total Data Points: {0}" + Environment.NewLine, vals.Count());
                sb.AppendFormat("Mean: {0:0.00}" + Environment.NewLine, avg);
                // BUGBUG: Should convert to linear first?
                sb.AppendFormat("StdDev: {0:0.00}" + Environment.NewLine, stdDev);
                sb.AppendFormat("Min: {0:0.00}" + Environment.NewLine, vals.Min());
                sb.AppendFormat("Max: {0:0.00}" + Environment.NewLine, vals.Max());

                return(sb.ToString());
            }
            catch (Exception ex)
            {
            }

            return("An error occurred. ");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a formatted string of all the tests in this group
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        static public string QueryTestsByGroup(string pid, string group)
        {
            try
            {
                QueryData d = new QueryData()
                {
                    ProductId = pid, TestGroup = group
                };

                var json     = new JavaScriptSerializer().Serialize(d);
                var body     = new StringContent(json, Encoding.UTF8, "application/json");
                var response = PostAsync(Url + "/api/QueryTests", body).Result;

                string content = response.Content.ReadAsStringAsync().Result;
                JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
                string           result           = (string)jsSerializer.DeserializeObject(content);
                List <AuditData> ad = jsSerializer.Deserialize <List <AuditData> >(result);

                StringBuilder sb = new StringBuilder();
                if (ad.Count > 0)
                {
                    sb.AppendLine("Unit: " + ad[0].SerialNumber);
                    sb.AppendLine("Date: " + ad[0].Time.ToString());
                    for (int i = 0; i < ad.Count; i++)
                    {
                        sb.AppendFormat("{0}[{1}] {2} [{3}]  {4}" + Environment.NewLine, ad[i].Name, ad[i].Channel, ad[i].ResultString, ad[i].TestLimits, ad[i].PassFail);
                    }
                }

                return(sb.ToString());
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogType.Database, "QueryTestsByGroup() exception: " + ex.Message);
            }

            return("An error occurred in QueryTestByGroup()");
        }