Beispiel #1
0
        protected virtual GeckoLineChart BuildLinechartData(LineChartArgs args,
                                                            IEnumerable <LineChartData> sourceData,
                                                            List <DateTime> xAxis,
                                                            GeckoValues yAxis)
        {
            var data = new GeckoLineChart();

            for (var i = 0; i < sourceData.Count(); i++)
            {
                if (i != 0 && (i % args.Sample != 0))
                {
                    continue;
                }

                // start at the newest and work backwards
                var j   = sourceData.Count() - i - 1;
                var lci = sourceData.ElementAt(j);

                xAxis.Add(lci.When);
                yAxis.Add(lci.Value);
                data.Item.Add(Scale(lci.Value,
                                    args.ScaleUp,
                                    args.ScaleDown,
                                    args.DecimalPlaces).ToString());
            }

            // finally reverse the data order oldest->newest
            data.Item.Reverse();
            return(data);
        }
Beispiel #2
0
        public GeckoLineChart GetGeckoboardLineChartForCheckRate(LineChartArgs args)
        {
            GeckoLineChart data = null;

            try
            {
                var yAxis = new GeckoValues();
                var xAxis = new List <DateTime>();

                CalculateLinechartSample(args);

                DateTime oldestDate;
                DateTime newestDate;
                CalculateLinechartDateRange(args, out oldestDate, out newestDate);

                // get the actual data from the provider and a "zero set" - a set
                // of zero values for the entire date range
                var dbData   = myDataProvider.GetLineChartDataForCheckRate(args);
                var zeroData = GenerateLinechartZeroSet(args, oldestDate, newestDate);
                // merge the two data sets, using the actual data value where
                // available, otherwise use a zero value
                var mergedData = MergeLinechartData(dbData, zeroData);
                data = BuildLinechartData(args, mergedData, xAxis, yAxis);
                CalculateLinechartSettings(args, data, yAxis, xAxis);
            }
            catch (Exception ex)
            {
                Logger.Error(Logger.Event.During("GetGeckoboardLineChartForCheckRate")
                             .Encountered(ex));
                throw;
            }

            return(data);
        }
 public void TheLinechartCheckRateMethodIsInvoked()
 {
     SafeExecute(() =>
     {
         var impl = new GeckoboardDataServiceImpl(myDataProvider, myColourPicker);
         myResult = impl.GetGeckoboardLineChartForCheckRate(myArgs);
     });
 }
Beispiel #4
0
        protected void CalculateLinechartSettings(LineChartArgs args,
                                                  GeckoLineChart data,
                                                  GeckoValues yAxis,
                                                  List <DateTime> xAxis)
        {
            var minY = args.ScaleY
                           ? Scale(yAxis.Min(), args.ScaleUp, args.ScaleDown, args.ScaleYDecimalPlaces)
                           : Scale(yAxis.Min(), 1, 1, args.ScaleYDecimalPlaces);
            var midY = args.ScaleY
                           ? Scale(yAxis.Mid(), args.ScaleUp, args.ScaleDown, args.ScaleYDecimalPlaces)
                           : Scale(yAxis.Mid(), 1, 1, args.ScaleYDecimalPlaces);
            var maxY = args.ScaleY
                           ? Scale(yAxis.Max(), args.ScaleUp, args.ScaleDown, args.ScaleYDecimalPlaces)
                           : Scale(yAxis.Max(), 1, 1, args.ScaleYDecimalPlaces);

            var colourKey = string.Format("linechart.{0}.{1}", args.Site, args.Check);

            data.Settings.Colour = myColourPicker.Next(colourKey).ToString();
            data.Settings.Y.Add(minY.ToString());
            data.Settings.Y.Add(midY.ToString());
            data.Settings.Y.Add(maxY.ToString());

            var minDate = xAxis.Min();
            var maxDate = xAxis.Max();

            if (maxDate.Subtract(minDate).TotalDays < 1)
            {
                data.Settings.X.Add(minDate.ToShortTimeString());
                data.Settings.X.Add(minDate.AddMinutes(
                                        maxDate.Subtract(minDate).TotalMinutes / 2).ToShortTimeString());
                data.Settings.X.Add(maxDate.ToShortTimeString());
            }
            else
            {
                var midMins = maxDate.Subtract(minDate).TotalMinutes / 2;
                var midDate = maxDate.Subtract(TimeSpan.FromMinutes(midMins));


                data.Settings.X.Add(minDate.ToString(Linechart.X_Axis_DateFormat));
                data.Settings.X.Add(midDate.ToString(Linechart.X_Axis_DateFormat));
                data.Settings.X.Add(maxDate.ToString(Linechart.X_Axis_DateFormat));
            }
        }
Beispiel #5
0
        public HttpResponseMessage Line([FromUri] string format = "JSON", [FromUri] string type = "1")
        {
            try
            {
                if (!User.Identity.IsAuthenticated)
                {
                    return(this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception("API key not specified.")));
                }
                if (Guid.Parse(ConfigurationManager.AppSettings["GeckoAPIkey"]).ToString() != User.Identity.Name)
                {
                    return(this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception(string.Format("Unknown API key, should be '{0}'.", ConfigurationManager.AppSettings["GeckoAPIkey"]))));
                }
                //if (int.Parse(type) != 1) { return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(string.Format("Type parameter '{0}' is wrong.", type))); }

                // You would modify what gets returned here to make it meaningful
                var retVal = new GeckoLineChart()
                {
                    Items = new List <string>()
                    {
                        "12.3", "2.3", "10", "15", "15", "13", "12.1", "9.8", "12.3", "2.3", "10"
                    },
                    Settings = new GeckoLineChartSettings()
                    {
                        XAxisLabels = new List <string>()
                        {
                            "Jun", "Jul", "Aug"
                        },
                        YAxisLabels = new List <string>()
                        {
                            "Min", "Max"
                        },
                        Colour = "ff9900"
                    }
                };

                return(this.Request.CreateResponse <GeckoLineChart>(HttpStatusCode.OK, retVal));
            }
            catch (Exception ex)
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Beispiel #6
0
        public HttpResponseMessage Line([FromUri]string format = "JSON", [FromUri]string type = "1")
        {
            try
            {
                if (!User.Identity.IsAuthenticated) { return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception("API key not specified.")); }
                if (Guid.Parse(ConfigurationManager.AppSettings["GeckoAPIkey"]).ToString() != User.Identity.Name) { return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception(string.Format("Unknown API key, should be '{0}'.", ConfigurationManager.AppSettings["GeckoAPIkey"]))); }
                //if (int.Parse(type) != 1) { return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(string.Format("Type parameter '{0}' is wrong.", type))); }

                // You would modify what gets returned here to make it meaningful
                var retVal = new GeckoLineChart()
                {
                    Items = new List<string>() { "12.3", "2.3", "10", "15", "15", "13", "12.1", "9.8", "12.3", "2.3", "10" },
                    Settings = new GeckoLineChartSettings()
                    {
                        XAxisLabels = new List<string>() { "Jun", "Jul", "Aug" },
                        YAxisLabels = new List<string>() { "Min", "Max" },
                        Colour = "ff9900"
                    }
                };

                return this.Request.CreateResponse<GeckoLineChart>(HttpStatusCode.OK, retVal);
            }
            catch (Exception ex)
            {
                return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
        }