示例#1
0
        private async void GetInsightDataResponse(HttpResponseMessage restResponse)
        {
            if (restResponse != null && restResponse.StatusCode == System.Net.HttpStatusCode.OK && restResponse.Content != null)
            {
                string strContent = await restResponse.Content.ReadAsStringAsync();

                InsightDataModel response = JsonConvert.DeserializeObject <InsightDataModel>(strContent);
                GenerateInsightsHeader(response);
            }
            else
            {
                yAxisRecomendation = NavigationController.NavigationBar.Bounds.Bottom + 20;
            }
        }
示例#2
0
 private void ShowInsights(InsightDataModel response)
 {
     if (response == null)
     {
         LayoutInsightData.Visibility = ViewStates.Gone;
     }
     else
     {
         LayoutInsightData.Visibility = ViewStates.Visible;
         textViewConsumed.Text        = Convert.ToString(Math.Round((response.ConsumptionValue / 1000), 2)) + " K";
         textViewExpected.Text        = Convert.ToString(Math.Round((response.PredictedValue / 1000), 2)) + " K";
         textViewOverused.Text        = Convert.ToString(Math.Round((response.ConsumptionValue - response.PredictedValue) / 1000, 2));
     }
 }
示例#3
0
        private async void GetInsightDataResponse(HttpResponseMessage restResponse)
        {
            if (restResponse != null && restResponse.StatusCode == System.Net.HttpStatusCode.OK && restResponse.Content != null)
            {
                Log.Debug(TAG, restResponse.Content.ToString());
                string strContent = await restResponse.Content.ReadAsStringAsync();

                InsightDataModel response = JsonConvert.DeserializeObject <InsightDataModel>(strContent);
                ShowInsights(response);
            }
            else
            {
                Log.Debug(TAG, "Login Failed");
                ShowInsights(null);
            }
        }
示例#4
0
        private void ShowInsights(InsightDataModel response)
        {
            if (response == null)
            {
                LayoutInsightData.Visibility = ViewStates.Gone;
            }
            else
            {
                LayoutInsightData.Visibility = ViewStates.Visible;

                textViewConsumed.Text = "" + response.ConsumptionValue;
                textViewExpected.Text = "" + response.PredictedValue;
                float ovr = response.ConsumptionValue - response.PredictedValue;
                //textViewOverused.Text = "" + ((ovr < 0 ? 0 : ovr));
                textViewOverused.Text = ovr + "";
            }
        }
        private async void GetInsightDataResponse(HttpResponseMessage restResponse)
        {
            if (restResponse != null && restResponse.StatusCode == System.Net.HttpStatusCode.OK && restResponse.Content != null)
            {
                string strContent = await restResponse.Content.ReadAsStringAsync();

                InsightDataModel response = JsonConvert.DeserializeObject <InsightDataModel>(strContent);
                GenerateInsightsHeader(response);
            }
            else if (restResponse.StatusCode == HttpStatusCode.Unauthorized)
            {
                await IOSUtil.RefreshToken(this, loadingOverlay);
            }
            else
            {
                HideOverlay();
            }
        }
示例#6
0
        private InsightDataModel GetInsightData(IQueryable <MeterDetails> meterdetails)
        {
            InsightDataModel insightData = new InsightDataModel();

            if (meterdetails.Count() > 0)
            {
                var now = ServiceUtil.GetCurrentDateTime(meterdetails.First().UTCConversionTime);

                var count = meterdetails.Count() * ((int)now.DayOfWeek == 0 ? 7 : (int)now.DayOfWeek);

                var consumptionValue = this.dbContext.DailyConsumptionDetails.WhereInDateRange().Where(d => meterdetails.Any(m => m.PowerScout.Equals(d.PowerScout, StringComparison.InvariantCultureIgnoreCase))).OrderByDescending(d => d.Timestamp).Take(count).Sum(data => data.Daily_KWH_System);

                insightData.ConsumptionValue = consumptionValue.HasValue ? Math.Round(consumptionValue.Value, 2) : default(double);

                var predictedValue = this.dbContext.WeeklyConsumptionPrediction.WhereInDateRange().Where(w => meterdetails.Any(m => m.PowerScout.Equals(w.PowerScout, StringComparison.InvariantCultureIgnoreCase))).OrderByDescending(w => w.End_Time).Take(meterdetails.Count()).Sum(w => w.Weekly_Predicted_KWH_System);

                insightData.PredictedValue = predictedValue.HasValue ? Math.Round(predictedValue.Value, 2) : default(double);
            }

            return(insightData);
        }
示例#7
0
        private void GenerateInsightsHeader(InsightDataModel insightDM)
        {
            double insightsHeight = NavigationController.NavigationBar.Bounds.Bottom;

            UIButton btnInsights = new UIButton()
            {
                Frame           = new CGRect(0, insightsHeight + 20, View.Bounds.Width, 50),
                BackgroundColor = UIColor.FromRGB(228, 228, 228),
                Font            = UIFont.FromName("Futura-Medium", 12f),
            };

            UILabel.Appearance.Font = UIFont.FromName("Futura-Medium", 20f);

            double lblWidth    = (View.Bounds.Width / 3) - 10;
            string strConsumed = Convert.ToString(Math.Round(insightDM.ConsumptionValue / 1000, 2)) + " k";
            string strExpected = Convert.ToString(Math.Round(insightDM.PredictedValue / 1000, 2)) + " k";
            string strOverused = Convert.ToString(Math.Round((insightDM.ConsumptionValue - insightDM.PredictedValue) / 1000, 2)) + " k";

            UIImageView imgConsumed = new UIImageView()
            {
                Frame = new CGRect(5, 5, 10, 20),
                Image = UIImage.FromBundle("Arrow_Blue.png"),
            };

            UILabel lblConsumedCount = new UILabel()
            {
                Frame           = new CGRect(30, 0, lblWidth, 30),
                Text            = strConsumed,
                Font            = UIFont.FromName("Futura-Medium", 18f),
                TextColor       = UIColor.DarkTextColor,
                BackgroundColor = UIColor.Clear,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Lines           = 3,
                TextAlignment   = UITextAlignment.Center
            };

            UIImageView imgExpected = new UIImageView()
            {
                Frame = new CGRect(5, 5, 10, 20),
                Image = UIImage.FromBundle("Arrow_Green.png"),
            };

            UILabel lblExpectedCount = new UILabel()
            {
                Frame           = new CGRect(lblWidth + 30, 0, lblWidth, 30),
                Text            = strExpected,
                Font            = UIFont.FromName("Futura-Medium", 18f),
                TextColor       = UIColor.DarkTextColor,
                BackgroundColor = UIColor.Clear,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Lines           = 3,
                TextAlignment   = UITextAlignment.Center
            };



            UILabel lblOverusedCount = new UILabel()
            {
                Frame           = new CGRect((lblWidth * 2) + 20, 0, lblWidth, 30),
                Text            = strOverused,
                Font            = UIFont.FromName("Futura-Medium", 18f),
                TextColor       = UIColor.DarkTextColor,
                BackgroundColor = UIColor.Clear,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Lines           = 3,
                TextAlignment   = UITextAlignment.Center
            };

            lblConsumedCount.AddSubview(imgConsumed);
            lblExpectedCount.AddSubview(imgExpected);


            UILabel lblConsumed = new UILabel()
            {
                Frame           = new CGRect(10, 25, lblWidth, 30),
                Text            = "CONSUMED",
                Font            = UIFont.FromName("Futura-Medium", 10f),
                TextColor       = UIColor.Gray,
                BackgroundColor = UIColor.Clear,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Lines           = 3,
                TextAlignment   = UITextAlignment.Center
            };

            UILabel lblExpected = new UILabel()
            {
                Frame           = new CGRect(new CGPoint(lblWidth + 20, 25), new CGSize(lblWidth, 30)),
                Text            = "EXPECTED",
                Font            = UIFont.FromName("Futura-Medium", 10f),
                TextColor       = UIColor.Gray,
                BackgroundColor = UIColor.Clear,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Lines           = 3,
                TextAlignment   = UITextAlignment.Center
            };

            UILabel lblOverused = new UILabel()
            {
                Frame           = new CGRect(new CGPoint((lblWidth * 2) + 10, 25), new CGSize(lblWidth, 30)),
                Text            = "OVERUSED",
                Font            = UIFont.FromName("Futura-Medium", 10f),
                TextColor       = UIColor.Gray,
                BackgroundColor = UIColor.Clear,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Lines           = 3,
                TextAlignment   = UITextAlignment.Center
            };

            if ((Math.Round((insightDM.ConsumptionValue - insightDM.PredictedValue) / 1000, 2)) > 0)
            {
                lblOverused.Text = "OVERUSED";
                UIImageView imgOverused = new UIImageView()
                {
                    Frame = new CGRect(5, 5, 10, 20),
                    Image = UIImage.FromBundle("Arrow_Red.png"),
                };
                lblOverusedCount.AddSubview(imgOverused);
            }
            else
            {
                lblOverused.Text = "UNDERUSED";
                UIImageView imgOverused = new UIImageView()
                {
                    Frame = new CGRect(5, 5, 10, 20),
                    Image = UIImage.FromBundle("Arrow_Green_Down.png"),
                };
                lblOverusedCount.AddSubview(imgOverused);
            }

            btnInsights.AddSubviews(lblConsumed, lblExpected, lblOverused, lblConsumedCount, lblExpectedCount, lblOverusedCount);
            View.AddSubviews(btnInsights);
        }