Example #1
0
        /// <summary>
        /// Returns the top three categories averaged from the RID Analysis.
        /// </summary>
        /// <param name="baseline">The baseline to use.</param>
        /// <returns>the top three categories averaged from the RID Analysis.</returns>
        static public string[] GetTopThreeCategories(RIDBaselines baseline)
        {
            string[] cat = new string[3];
            double[] avg = { double.MinValue, double.MinValue, double.MinValue };

            foreach (string category in categories)
            {
                double d = GetAverage(category, baseline);
                if (d > avg[0])
                {
                    avg[2] = avg[1]; avg[1] = avg[0]; avg[0] = d;
                    cat[2] = cat[1]; cat[1] = cat[0]; cat[0] = category;
                }
                else if (d > avg[1])
                {
                    avg[2] = avg[1]; avg[1] = d;
                    cat[2] = cat[1]; cat[1] = category;
                }
                else if (d > avg[2])
                {
                    avg[2] = d;
                    cat[2] = category;
                }
            }
            return(cat);
        }
Example #2
0
        /// <summary>
        /// Returns a graph that provides a summary of the RID Analysis.
        /// </summary>
        /// <param name="categories">The categories to report.</param>
        /// <param name="title">The title of the graph.</param>
        /// <param name="width">The width of the graph to return.</param>
        /// <param name="height">The height of the graph to return.</param>
        /// <param name="baseline">The baseline to use.</param>
        /// <returns>a graph that provides a summary of the RID Analysis.</returns>
        static public GraphPane GetSummaryGraph(string[] categories, string title, int width, int height,
                                                RIDBaselines baseline)
        {
            GraphPane pane;
            CurveItem curve;
            TextItem  text;

            string[] labels;
            double[] values;
            double[] averageLine;
            labels      = new string[categories.Length];
            values      = new double[categories.Length];
            averageLine = new double[categories.Length];
            pane        = new GraphPane(new Rectangle(0, 0, width, height),
                                        title + " (%)", string.Empty, string.Empty);
            for (int i = 0; i < categories.Length; ++i)
            {
                string category = categories[i];
                double d        = GetAverage(category, baseline);
                values[i]              = double.IsNaN(d) ? 0F : d;
                labels[i]              = category.Substring(category.LastIndexOf(':') + 1);
                averageLine[i]         = 50F;
                text                   = new TextItem(string.Format("{0:0.0}%", d), i + 1, (float)d / 2F);
                text.FontSpec.IsFramed = false;
                text.FontSpec.IsFilled = false;
                pane.TextList.Add(text);
            }
            curve                          = pane.AddCurve("Average", null, averageLine, Color.Green);
            curve.Symbol.Type              = SymbolType.Diamond;
            curve.Symbol.Size             *= 2;
            curve.Line.Width               = 2.0F;
            curve                          = pane.AddCurve("Bar Values", null, values, Color.Red);
            curve.IsBar                    = true;
            pane.Legend.IsVisible          = false;
            pane.XAxis.IsTicsBetweenLabels = true;
            pane.XAxis.TextLabels          = labels;
            pane.XAxis.ScaleFontSpec.Angle = 45F;
            pane.XAxis.Step                = 1;
            pane.XAxis.Type                = AxisType.Text;
            pane.YAxis.Min                 = 0;
            pane.YAxis.Max                 = 100;
            pane.AxisChange();
            return(pane);
        }
Example #3
0
        /// <summary>
        /// Returns an HTML string that provides a summary of the RID Analysis.
        /// </summary>
        /// <param name="categories">The categories to report.</param>
        /// <param name="title">The title of the summary.</param>
        /// <param name="baseline">The baseline to use.</param>
        /// <returns>an HTML string that provides a summary of the RID Analysis.</returns>
        static public string GetHTMLSummary(string[] categories, string title, RIDBaselines baseline)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<!-- BEGIN RID ANALYSIS CODE -->");
            sb.Append("<div style='text-align: center'>");
            sb.Append("<div style='width: 450px; background-color: #666; color: #fff; border: 5px solid #ccc; margin-left: auto; margin-right: auto; font-family: Verdana, Arial, Helvetica; font-size: 10px'><b>");
            sb.Append(title);
            sb.Append("</b><br/>Regressive Imagery Analysis for ");
            sb.Append(j.Options[0].UserName);
            sb.Append("'s journal<br />Compared to: <b>");
            switch (baseline)
            {
            case RIDBaselines.All: sb.Append("Everyone"); break;

            case RIDBaselines.Gender: sb.Append("Same Gender"); break;

            case RIDBaselines.Age: sb.Append("Same Age Group"); break;
            }
            sb.Append("</b><table>");
            for (int i = 0; i < categories.Length; ++i)
            {
                string category = categories[i];
                double d        = GetAverage(category, baseline);
                string bar      = string.Format("<tr valign='middle' style='font-size:10px; color: #fff'>" +
                                                "<td align='right'>{0}</td>" +
                                                "<td align='left'><img src='http://stat.livejournal.com/img/poll/leftbar.gif' align='absmiddle' height='14' width='7' />" +
                                                "<img src='http://stat.livejournal.com/img/poll/mainbar.gif' align='absmiddle' height='14' width='{1}' alt='{2:00.0}%' />" +
                                                "<img src='http://stat.livejournal.com/img/poll/rightbar.gif' align='absmiddle' height='14' width='7' /></td><td><b>{2:0.0}%</b></td></tr>",
                                                category.Substring(category.LastIndexOf(':') + 1),
                                                Convert.ToInt32((double.IsNaN(d) ? 0F : d) * 2.7F), d);
                sb.Append(bar);
            }
            sb.Append("</table>");
            sb.Append("<a style='color: #fff' href='http://fawx.com/software/ljarchive/rid'>What does this mean?</a><br />&nbsp;");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<!-- END RID ANALYSIS CODE -->");
            return(sb.ToString());
        }
Example #4
0
        static private double GetAverage(string category, RIDBaselines baseline)
        {
            double d = 0, mean = 0, variance = 0;

            foreach (string findCategory in categories)
            {
                if (findCategory.StartsWith(category))
                {
                    d        += (double)localAverages[findCategory];
                    mean     += (double)averages[(int)baseline][findCategory];
                    variance += Math.Pow((double)stdDev[(int)baseline][findCategory], 2);
                }
            }
            if (variance > 0F)
            {
                return((new NormalDist(mean, variance)).CDF(d) * 100F);
            }
            else
            {
                return(50);
            }
        }
Example #5
0
        /// <summary>
        /// Returns a graph that provides an over-time RID Analysis.
        /// </summary>
        /// <param name="categories">The categories to report.</param>
        /// <param name="title">The title of the graph.</param>
        /// <param name="width">The width of the graph to return.</param>
        /// <param name="height">The height of the graph to return.</param>
        /// <param name="baseline">The baseline to use.</param>
        /// <returns>a graph that provides an over-time RID Analysis.</returns>
        static public GraphPane GetOverTimeGraph(string[] categories, string title, int width, int height,
                                                 RIDBaselines baseline)
        {
            GraphPane pane;
            CurveItem curve;
            Random    r = new Random();

            pane = new GraphPane(new Rectangle(0, 0, width, height),
                                 title + " Over Time (%)", string.Empty, string.Empty);

            foreach (string category in categories)
            {
                NormalDist nd;
                SortedList sl = new SortedList();
                Hashtable  counts = new Hashtable();
                double     mean = 0, variance = 0;
                double[]   x, y;

                foreach (string findCategory in RIDAnalysis.categories)
                {
                    if (findCategory.StartsWith(category))
                    {
                        mean     += (double)averages[(int)baseline][findCategory];
                        variance += Math.Pow((double)stdDev[(int)baseline][findCategory], 2);
                    }
                }
                for (int i = 0; i < j.Events.Count; ++i)
                {
                    Journal.EventsRow er = j.Events[i];
                    double            d  = 0F;
                    DateTime          dt;
                    if (er.IsDateNull())
                    {
                        continue;
                    }
                    dt = new DateTime(er.Date.Year, er.Date.Month, 1);

                    foreach (string findCategory in RIDAnalysis.categories)
                    {
                        if (findCategory.StartsWith(category))
                        {
                            d += ((double[])frequencies[findCategory])[i];
                        }
                    }

                    if (sl.ContainsKey(dt))
                    {
                        sl[dt]     = (double)sl[dt] + d;
                        counts[dt] = (int)counts[dt] + 1;
                    }
                    else
                    {
                        sl.Add(dt, d);
                        counts.Add(dt, 1);
                    }
                }
                if (variance > 0F)
                {
                    nd = new NormalDist(mean, variance);
                    foreach (object key in counts.Keys)
                    {
                        sl[key] = nd.CDF(((double)sl[key]) / ((double)(int)counts[key])) * 100F;
                    }
                }
                else
                {
                    foreach (object key in counts.Keys)
                    {
                        sl[key] = (double)50F;
                    }
                }

                x = new double[sl.Count];
                y = new double[sl.Count];
                for (int i = 0; i < sl.Count; ++i)
                {
                    DateTime dt = (DateTime)sl.GetKey(i);
                    double   d  = (double)sl.GetByIndex(i);
                    x[i] = (double)new XDate(dt.Year, dt.Month, dt.Day);
                    y[i] = double.IsNaN(d) ? 0F : d;
                }
                curve = pane.AddCurve(category.Substring(category.LastIndexOf(':') + 1), x, y,
                                      Color.FromArgb(r.Next(200), r.Next(200), r.Next(200)),
                                      SymbolType.Diamond);
            }
            pane.XAxis.Type        = AxisType.Date;
            pane.XAxis.ScaleFormat = "&yyyy";
            pane.XAxis.IsShowGrid  = true;
            pane.YAxis.IsShowGrid  = true;
            pane.YAxis.Min         = 0;
            pane.YAxis.Max         = 100;
            pane.XAxis.GridColor   = Color.LightGray;
            pane.YAxis.GridColor   = Color.LightGray;
            pane.AxisBackColor     = Color.LightCyan;
            pane.Legend.IsVisible  = true;
            pane.AxisChange();
            return(pane);
        }