Ejemplo n.º 1
0
        private SGSeriesCollection GetSeries(Dictionary <string, object> file)
        {
            SGSeriesCollection series_collection = new SGSeriesCollection();
            JObject            all_series        = (JObject)jo_parsed_file["series"];

            foreach (var series in all_series)
            {
                SGSeries parsed_series = new SGSeries();

                parsed_series.Type   = 0;
                parsed_series.ID     = 1;
                parsed_series.Status = 4;
                parsed_series.Name   = series.Key;
                JObject values = (JObject)series.Value;


                List <Object> val_range        = new List <Object>();
                List <Object> key_range        = new List <Object>();
                List <Object> val_range_copy   = new List <object>();
                int           last_value_index = -1;
                foreach (var data in values)
                {
                    try
                    {
                        val_range.Add((Double)data.Value);
                        key_range.Add((String)data.Key);

                        val_range_copy.Add((Double)data.Value);

                        last_value_index += 1;
                    }
                    catch (System.ArgumentException e)
                    {
                        val_range.Add("none");
                        val_range_copy.Add("none");
                    }
                }
                parsed_series.Values               = val_range;
                parsed_series.EndsAt               = (Double)val_range.OfType <Double>().Last();
                parsed_series.CategoryEndsAt       = Convert.ToDouble(key_range[last_value_index]);
                parsed_series.CategoryStartsAt     = Convert.ToDouble(key_range.First());
                parsed_series.StartsAt             = (Double)val_range.OfType <Double>().First();
                parsed_series.Trend                = (string)jo_parsed_file["trends"][series.Key];
                parsed_series.ValuesIncludingNones = val_range_copy;

                // add series to collection
                series_collection.Add(parsed_series);
            }

            return(series_collection);
        }
Ejemplo n.º 2
0
        private void RoundDecimals(StatisticalGraph graph)
        {
            int num_ser       = graph.Series.Count;
            int decimals2show = 2;

            for (int i = 0; i < num_ser; i++)
            {
                SGSeries curr = graph.Series[i];
                if (graph.ValueAxis.ScaleUnit > 0)
                {
                    for (int j = 0; j < curr.Values.Count; j++)
                    {
                        curr.Values[j] = Math.Round((Double)curr.Values[j], decimals2show);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void CleanSomeNullValues(SGSeries s)
        {
            int n = s.Values.Count;

            for (int i = 0; i < n; i++)
            {
                if (s.Values[i].GetType().ToString() == "System.String")
                {
                    if (s.Values[i] == null ||
                        ((String)s.Values[i]).Length == 0 ||
                        (String)s.Values[i] == "none")
                    {
                        s.Values.RemoveAt(i);
                        i--;
                        n--;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void ScaleValues(StatisticalGraph graph)
        {
            int num_ser = graph.Series.Count;

            // Scaling data by unit of visualization

            graph.ValueAxis.EndsAt   = Convert.ToDouble(graph.ValueAxis.EndsAt) / graph.ValueAxis.ScaleUnit;
            graph.ValueAxis.StartsAt = Convert.ToDouble(graph.ValueAxis.StartsAt) / graph.ValueAxis.ScaleUnit;
            graph.ValueAxis.Stepping = Convert.ToDouble(graph.ValueAxis.Stepping) / graph.ValueAxis.ScaleUnit;

            for (int i = 0; i < num_ser; i++)
            {
                SGSeries curr = graph.Series[i];
                if (graph.ValueAxis.ScaleUnit > 0)
                {
                    for (int j = 0; j < curr.Values.Count; j++)
                    {
                        curr.Values[j] = Convert.ToDouble(curr.Values[j]) / graph.ValueAxis.ScaleUnit;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private SeriesNulls GetSeriesNullState(SGSeries s)
        {
            bool first       = false;
            bool last        = false;
            bool _hasnull    = false;
            int  num_nulls   = 0;
            int  vals_length = s.Values.Count;


            for (int i = 0; i < vals_length; i++)
            {
                _hasnull = false;
                object curr_value = s.Values[i];
                //When value is null, setted by string
                if (curr_value.GetType().ToString() == "System.String")
                {
                    if (curr_value == null ||
                        ((String)curr_value).Length == 0 ||
                        (String)curr_value == "none")
                    {
                        _hasnull = true;
                    }
                }
                //Double values
                else
                {
                    if (curr_value == null ||
                        (Double)curr_value == 0 ||
                        curr_value.ToString() == "none")
                    {
                        _hasnull = true;
                    }
                }


                if (_hasnull)
                {
                    if (i == 0)
                    {
                        first = true;
                    }

                    if (i == vals_length - 1)
                    {
                        last = true;
                    }

                    num_nulls++;
                }
            }

            if (num_nulls == vals_length)
            {
                return(SeriesNulls.ALL_NULL);
            }
            else if (num_nulls > 0)
            {
                return(SeriesNulls.SOME_NULL);
            }
            else if (first && last)
            {
                return(SeriesNulls.FIRST_LAST_NULL); // see graph c080229c
            }
            else if (first)
            {
                return(SeriesNulls.FIRST_NULL);
            }
            else if (last)
            {
                return(SeriesNulls.LAST_NULL);
            }

            return(SeriesNulls.NO_NULL);
        }
Ejemplo n.º 6
0
        public void Clean(StatisticalGraph graph)
        {
            log.Debug("Applying series cleaning algorithms.");
            int  num_ser = graph.Series.Count;
            bool problem = true;

            for (int i = 0; i < num_ser; i++)
            {
                SGSeries curr = graph.Series[i];

                switch (GetSeriesNullState(curr))
                {
                case SeriesNulls.ALL_NULL:
                    curr.Status = (int)SeriesNulls.ALL_NULL;
                    graph.Series.RemoveAt(i);
                    i--;
                    num_ser--;
                    log.Error("Empty series. Why?");
                    break;

                case SeriesNulls.SOME_NULL:
                    curr.Status = (int)SeriesNulls.SOME_NULL;
                    CleanSomeNullValues(curr);
                    break;

                case SeriesNulls.FIRST_LAST_NULL:
                    curr.Status        = (int)SeriesNulls.FIRST_LAST_NULL;
                    graph.Series.Dirty = true;
                    curr.Values.RemoveAt(0);
                    curr.Values.RemoveAt(curr.Values.Count - 1);
                    log.Error("Empty first and last elements. Why?");
                    break;

                case SeriesNulls.FIRST_NULL:
                    curr.Status        = (int)SeriesNulls.FIRST_NULL;
                    graph.Series.Dirty = true;
                    curr.Values.RemoveAt(0);
                    log.Error("Empty first element. Why?");
                    break;

                case SeriesNulls.LAST_NULL:
                    curr.Status        = (int)SeriesNulls.LAST_NULL;
                    graph.Series.Dirty = true;
                    curr.Values.RemoveAt(curr.Values.Count - 1);
                    log.Error("Empty last element. Why?");
                    break;

                default:
                    curr.Status = (int)SeriesNulls.NO_NULL;
                    problem     = false;
                    break;
                }
            }

            //Scale Values ;)
            ScaleValues(graph);

            //Round to 2 decimals
            RoundDecimals(graph);

            if (!problem)
            {
                log.Debug("All series seem OK. Bravo!");
            }
        }
Ejemplo n.º 7
0
        /***************************************************************************
         * Series are dealt with here. This is a very error prone method.
         **************************************************************************/
        private SGSeriesCollection GetXLSeries(Chart chart)
        {
            SGSeriesCollection sg_series_collection = new SGSeriesCollection();
            IEnumerator        series_enumerator    = ((SeriesCollection)
                                                       chart.SeriesCollection(Type.Missing)).GetEnumerator();
            int ctr = 0;

            // iterate through all the boxes in the chart area.
            while (series_enumerator.MoveNext())
            {
                SGSeries sg_series = new SGSeries();
                Series   xl_series = (Series)series_enumerator.Current;
                sg_series.ID = ctr;

                ///////////////////////////////////////
                // \internal find if there is a type (line, bar, etc.)
                //////////////////////////////////////
                try
                {
                    sg_series.Type = xl_series.Type;
                } catch
                {
                    sg_series.Type = -1;
                    log.Warn("Couldn't get the type of the series."
                             + "\n\tThis must be fixed!");
                    continue;
                }

                ///////////////////////////////////////
                // find if there is a name
                //////////////////////////////////////
                if (!String.IsNullOrEmpty(xl_series.Name))
                {
                    sg_series.Name = xl_series.Name;
                }
                else
                {
                    log.Warn("Couldn't find the name of the series."
                             + "\n\tSetting it to: \"none\".");
                    sg_series.Name = "none";
                }

                ///////////////////////////////////////
                // find if there are values
                //////////////////////////////////////

                try
                {
                    List <object> vals = new List <object>();
                    //vals.AddRange(((Array)xl_series.Values).Cast<object>());

                    foreach (object c in (Array)xl_series.Values)
                    {
                        if (c != null && c.ToString().Length != 0)
                        {
                            vals.Add(c);
                        }
                        else
                        {
                            vals.Add("");
                        }
                    }

                    sg_series.Values = vals;
                } catch
                {
                    log.Warn("Couldn't find the values for the series."
                             + "\n\tSetting it to: \"none\".");
                    continue;
                }

                sg_series_collection.Add(sg_series);
                log.Debug(sg_series.ToString() + ".");
                ctr++;
            }

            log.Debug(ctr + " legal series found and added to the list.");
            return(sg_series_collection);
        }