Example #1
0
        public void GenerateTotals()
        {
            StatSerie total = new StatSerie()
            {
                Name = "Total"
            };
            Dictionary <string, StatValue> values = new Dictionary <string, StatValue> ();

            foreach (StatSerie s in Series)
            {
                foreach (StatValue v in s.Values)
                {
                    StatValue cval;
                    if (!values.TryGetValue(v.Label, out cval))
                    {
                        cval = new StatValue()
                        {
                            Label = v.Label, Value = v.Value, StartDate = v.StartDate, EndDate = v.EndDate
                        };
                        values [v.Label] = cval;
                        total.Values.Add(cval);
                    }
                    else
                    {
                        cval.Value += v.Value;
                    }
                }
            }
            totalsSerie = total;
            Series.Add(total);
        }
Example #2
0
        public void AddValue(string serie, string label, int value, DateTime rangeStart, DateTime rangeEnd)
        {
            StatSerie s = Series.FirstOrDefault(t => t.Name == serie);

            if (s == null)
            {
                s      = new StatSerie();
                s.Name = serie;
                Series.Add(s);
            }
            s.Values.Add(new StatValue()
            {
                Label = label, Value = value, StartDate = rangeStart, EndDate = rangeEnd
            });
        }
Example #3
0
        public string SeriesToJson()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append('[');
            for (int n = 0; n < Series.Count; n++)
            {
                if (n > 0)
                {
                    sb.Append(',');
                }
                StatSerie s = Series [n];
                sb.Append('\'').Append(Series [n]).Append('\'');
                sb.Append('}');
            }
            sb.Append(']');
            return(sb.ToString());
        }
Example #4
0
        public string ToJson()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{\"series\":");
            sb.Append('[');
            for (int n = 0; n < Series.Count; n++)
            {
                if (n > 0)
                {
                    sb.Append(',');
                }
                StatSerie s = Series [n];
                sb.Append("{\"name\":\"").Append(s.Name).Append("\",\"values\":");
                s.ToJson(sb);
                sb.Append('}');
            }
            sb.Append(']');
            sb.Append(", \"totals\":[");
            bool fa = false;

            for (int n = 0; n < Series.Count; n++)
            {
                StatSerie s = Series [n];
                if (s == totalsSerie)
                {
                    continue;
                }
                if (fa)
                {
                    sb.Append(',');
                }
                sb.Append("[\"").Append(s.Name).Append("\",").Append(s.GetTotal()).Append("]");
                fa = true;
            }
            sb.Append("]}");
            return(sb.ToString());
        }
Example #5
0
 public void GenerateTotals()
 {
     StatSerie total = new StatSerie () { Name = "Total" };
     Dictionary<string,StatValue> values = new Dictionary<string, StatValue> ();
     foreach (StatSerie s in Series) {
         foreach (StatValue v in s.Values) {
             StatValue cval;
             if (!values.TryGetValue (v.Label, out cval)) {
                 cval = new StatValue () { Label = v.Label, Value = v.Value, StartDate = v.StartDate, EndDate = v.EndDate };
                 values [v.Label] = cval;
                 total.Values.Add (cval);
             } else
                 cval.Value += v.Value;
         }
     }
     totalsSerie = total;
     Series.Add (total);
 }
Example #6
0
 public void AddValue(string serie, string label, int value, DateTime rangeStart, DateTime rangeEnd)
 {
     StatSerie s = Series.FirstOrDefault (t => t.Name == serie);
     if (s == null) {
         s = new StatSerie ();
         s.Name = serie;
         Series.Add (s);
     }
     s.Values.Add (new StatValue () { Label=label, Value=value, StartDate=rangeStart, EndDate=rangeEnd });
 }