Exemple #1
0
        /// <summary>
        /// Gets a profile from the specified <var>JsonObject</var>.
        /// </summary>
        /// <param name="obj">The instance of <var>JsonObject</var> to parse.</param>
        public static AnalyticsProfile Parse(JsonObject obj)
        {
            // If the specified JsonObject is NULL, we just return NULL
            if (obj == null)
            {
                return(null);
            }

            // Since the profile might the root object of a response from the
            // Analytics API, we check the object for any errors
            AnalyticsResponse.Validate(obj);

            // Parse the JsonObject
            return(new AnalyticsProfile {
                JsonObject = obj,
                Id = obj.GetString("id"),
                AccountId = obj.GetString("accountId"),
                WebPropertyId = obj.GetString("webPropertyId"),
                InternalWebPropertyId = obj.GetString("internalWebPropertyId"),
                Name = obj.GetString("name"),
                Currency = obj.GetString("currency"),
                Timezone = obj.GetString("timezone"),
                WebsiteUrl = obj.GetString("websiteUrl"),
                Type = obj.GetString("type"),
                Created = obj.GetDateTime("created"),
                Updated = obj.GetDateTime("updated")
            });
        }
        // GET: GoogleAnalyticsReport
        public ActionResult Index()
        {
            var analyticsModel    = GetModel();
            var response          = ReportingManager.GetAnalyticsResponse(analyticsModel, analyticsModel.CredStr);
            var analyticsResponse = new AnalyticsResponse
            {
                Model    = analyticsModel,
                Response = response
            };

            return(View(analyticsResponse));
        }
        public AnalyticsResponse GetAnalytics(int id)
        {
            var response = new AnalyticsResponse();

            using (var cn = new SqlConnection(Config.GetConnectionString()))
            {
                var p = new DynamicParameters();
                p.Add("@ClassID", id);

                response.StudentGradeAggregate = cn.Query <GradeTableCount>("GetClassGradeCountById", p, commandType: CommandType.StoredProcedure).ToList();
                //response.GradeCounts = cn.Query("GetClassGradeCountById", p, commandType: CommandType.StoredProcedure).ToDictionary(m =>(string)m.LetterGrade, m=>(int)m.GradeCount);//complicated casting because we need to convert results back into dictionary

                //foreach (var item in rawGradeCounts)
                //{
                //    response.StudentGradeAggregate.Add(new GradeCount() { Count = (int)item.GradeCount, LetterGrade = item.LetterGrade.ToString() });
                //}
                response.StudentCount = cn.Query <int>("GetClassStudentCountById", p, commandType: CommandType.StoredProcedure).First();
            }

            return(response);
        }
        /// <summary>
        /// This operation extracts a rich set of visual features based on the image content.
        /// </summary>
        /// <returns></returns>
        public async Task <RecognitionResult> RecognizeTextService(byte[] imageBytes)
        {
            var httpClient  = BuildClient();
            var byteContent = new ByteArrayContent(imageBytes);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

            try
            {
                var response = await httpClient.PostAsync(_analyseImageUri, byteContent);

                var json = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    var operationLocationRequest        = GetOperationLocation(response.Headers);
                    AnalyticsResponse analyticsResponse = null;
                    while (analyticsResponse == null || analyticsResponse.Status.Equals("Running"))
                    {
                        var getReponse = await httpClient.GetAsync(operationLocationRequest);

                        var jsonResult = getReponse.Content.ReadAsStringAsync().Result;

                        analyticsResponse = JsonConvert.DeserializeObject <AnalyticsResponse>(jsonResult);
                    }
                    return(analyticsResponse.Status.Equals("Succeeded")
                        ? analyticsResponse.RecognitionResult
                        : null);
                }

                throw new Exception(json);
            }
            catch (Exception exception)
            {
                Console.Write(exception.Message);
                return(null);
            }
        }
Exemple #5
0
        private AnalyticsResponse GetAnalyticsResponse(string url)
        {
            using (var handler = new HttpClientHandler())
            {
                HttpResponseMessage response;
                using (HttpClient client = new HttpClient(handler))
                {
                    response = client.GetAsync(url).Result;
                }
                string responseStr = response.Content.ReadAsStringAsync().Result;

                switch (response.StatusCode)
                {
                case HttpStatusCode.Forbidden:
                    throw new OAuthException(Strings.Analytics_Forbidden);

                case HttpStatusCode.NotFound:
                    throw new UrlNotFoundException(Strings.Analytics_NotFound);
                }
                AnalyticsResponse analyticsResponse = JsonConvert.DeserializeObject <AnalyticsResponse>(responseStr);
                return(analyticsResponse);
            }
        }
        public AnalyticsResponse GetNavMapData(Guid orgId, int timelineId, string[] userGroups, string userGroup = "", string country = "", string city = "")
        {
            var response = new AnalyticsResponse();
            // int timeLineID = 7;

            List <AccountDetail> accountDetail = new List <AccountDetail>();

            if (string.IsNullOrEmpty(country))
            {
                accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup)).ToList();
            }
            else if (!string.IsNullOrEmpty(country) && string.IsNullOrEmpty(city) && string.IsNullOrEmpty(userGroup))
            {
                accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup) && m.Country == country).ToList();
            }
            else if (!string.IsNullOrEmpty(country) && !string.IsNullOrEmpty(city) && string.IsNullOrEmpty(userGroup))
            {
                accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup) && m.Country == country && m.City == city).ToList();
            }
            else if (!string.IsNullOrEmpty(userGroup) && string.IsNullOrEmpty(country) && string.IsNullOrEmpty(city))
            {
                accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup) && m.UserGroup == userGroup).ToList();
            }
            else if (!string.IsNullOrEmpty(userGroup) && !string.IsNullOrEmpty(country) && string.IsNullOrEmpty(city))
            {
                accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup) && m.UserGroup == userGroup && m.Country == country).ToList();
            }
            else if (!string.IsNullOrEmpty(userGroup) && !string.IsNullOrEmpty(country) && !string.IsNullOrEmpty(city))
            {
                accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup) && m.UserGroup == userGroup && m.Country == country && m.City == city).Take(5).ToList();
            }
            var timeLineIds = accountDetail.SelectMany(x => x.AccountStats).Select(x => x.TimeLineId).Distinct().ToList();

            accountDetail.ForEach(x => x.AccountStats = x.AccountStats.Where(t => t.TimeLineId == timelineId).ToList());

            var accountsData = new AccountDetailModel().ToComparisonData(accountDetail);

            response.Data = accountsData;
            //response.Cities = accountDetail.Select(x => x.City).Distinct();
            // response.Countries = accountDetail.Select(x => x.Country).Distinct();
            // response.Accounts = accountDetail.Select(x => x.Name).Distinct();
            List <AccountDetailModel> aD = new List <AccountDetailModel>();

            foreach (string item in accountsData.Select(x => x.City).Distinct())
            {
                aD.Add(new AccountDetailModel()
                {
                    City = item, Nav = accountsData.Where(z => z.City == item).SelectMany(n => n.AccountStats).Sum(x => x.NAV)
                });
            }

            response.Cities = aD.OrderByDescending(n => n.Nav).Take(5).Select(x => x.City).Distinct();

            aD = new List <AccountDetailModel>();
            foreach (string item in accountDetail.Select(x => x.Country).Distinct())
            {
                aD.Add(new AccountDetailModel()
                {
                    Country = item, Nav = accountsData.Where(z => z.Country == item).SelectMany(n => n.AccountStats).Sum(x => x.NAV)
                });
            }

            response.Countries = aD.OrderByDescending(n => n.Nav).Take(5).Select(x => x.Country).Distinct();

            aD = new List <AccountDetailModel>();
            foreach (string item in accountsData.Select(x => x.Name).Distinct())
            {
                aD.Add(new AccountDetailModel()
                {
                    Name = item, Nav = accountsData.Where(z => z.Name == item).SelectMany(n => n.AccountStats).Sum(x => x.NAV)
                });
            }

            response.Accounts = accountDetail.OrderByDescending(n => n.Name).Take(5).Select(x => x.Name).Distinct();
            var timeLines = new List <EnumHelper>();

            foreach (var tline in Timelines.MasterTimelines)
            {
                var timeline = new EnumHelper
                {
                    stringValue = tline.Encrypt(),
                    DisplayName = ((TimeLineEnum)Enum.ToObject(typeof(TimeLineEnum), tline)).GetEnumDisplayName()
                };
                timeLines.Add(timeline);
            }
            //foreach (var timeLineId in timeLineIds.OrderBy(x => x).ToList())
            //{
            //    var timeline = new EnumHelper
            //    {
            //        stringValue = timeLineId.Encrypt(),
            //        DisplayName = ((TimeLineEnum)Enum.ToObject(typeof(TimeLineEnum), Convert.ToInt32(timeLineId))).GetEnumDisplayName()
            //    };
            //    timeLines.Add(timeline);
            //}
            response.Timelines = timeLines;
            response.WidgetId  = Convert.ToInt32(EmbedWidgetEnum.Nav).Encrypt();
            return(response);

            //var response = new AnalyticsResponse();
            //// int timeLineID = 7;

            //List<AccountDetail> accountDetail = new List<AccountDetail>();
            //if (string.IsNullOrEmpty(country))
            //{
            //    accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId).ToList();
            //}
            //else if (!string.IsNullOrEmpty(country) && string.IsNullOrEmpty(city) && string.IsNullOrEmpty(userGroup))
            //{
            //    accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && m.Country == country).ToList();
            //}
            //else if (!string.IsNullOrEmpty(country) && !string.IsNullOrEmpty(city) && string.IsNullOrEmpty(userGroup))
            //{
            //    accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && m.Country == country && m.City == city).ToList();
            //}
            //else if (!string.IsNullOrEmpty(userGroup) && string.IsNullOrEmpty(country) && string.IsNullOrEmpty(city))
            //{
            //    accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && m.UserGroup == userGroup).ToList();
            //}
            //else if (!string.IsNullOrEmpty(userGroup) && !string.IsNullOrEmpty(country) && string.IsNullOrEmpty(city))
            //{
            //    accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && m.UserGroup == userGroup && m.Country == country).ToList();
            //}
            //else if (!string.IsNullOrEmpty(userGroup) && !string.IsNullOrEmpty(country) && !string.IsNullOrEmpty(city))
            //{
            //    accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && m.UserGroup == userGroup && m.Country == country && m.City == city).Take(5).ToList();
            //}
            //var timeLineIds = accountDetail.SelectMany(x => x.AccountStats).Select(x => x.TimeLineId).Distinct().ToList();
            //accountDetail.ForEach(x => x.AccountStats = x.AccountStats.Where(t => t.TimeLineId == timelineId).ToList());

            //var accountsData = new AccountDetailModel().ToComparisonData(accountDetail);
            //response.Data = accountsData;
            ////response.Cities = accountDetail.Select(x => x.City).Distinct();
            //// response.Countries = accountDetail.Select(x => x.Country).Distinct();
            //// response.Accounts = accountDetail.Select(x => x.Name).Distinct();
            //List<AccountDetailModel> aD = new List<AccountDetailModel>();
            //foreach (string item in accountsData.Select(x => x.City).Distinct())
            //{
            //    aD.Add(new AccountDetailModel() { City = item, Nav = accountsData.Where(z => z.City == item).SelectMany(n => n.AccountStats).Sum(x => x.NAV) });
            //}

            //response.Cities = aD.OrderByDescending(n => n.Nav).Select(x => x.City).Distinct();

            //aD = new List<AccountDetailModel>();
            //foreach (string item in accountDetail.Select(x => x.Country).Distinct())
            //{
            //    aD.Add(new AccountDetailModel() { Country = item, Nav = accountsData.Where(z => z.Country == item).SelectMany(n => n.AccountStats).Sum(x => x.NAV) });
            //}

            //response.Countries = aD.OrderByDescending(n => n.Nav).Select(x => x.Country).Distinct();

            //aD = new List<AccountDetailModel>();
            //foreach (string item in accountsData.Select(x => x.Name).Distinct())
            //{
            //    aD.Add(new AccountDetailModel() { Name = item, Nav = accountsData.Where(z => z.Name == item).SelectMany(n => n.AccountStats).Sum(x => x.NAV) });
            //}

            //response.Accounts = accountDetail.OrderByDescending(n => n.Name).Select(x => x.Name).Distinct();
            //var timeLines = new List<EnumHelper>();
            //foreach (var timeLineId in timeLineIds.OrderBy(x => x).ToList())
            //{
            //    var timeline = new EnumHelper
            //    {
            //        stringValue = timeLineId.Encrypt(),
            //        DisplayName = ((TimeLineEnum)Enum.ToObject(typeof(TimeLineEnum), Convert.ToInt32(timeLineId))).GetEnumDisplayName()
            //    };
            //    timeLines.Add(timeline);
            //}
            //response.Timelines = timeLines;
            //return response;
        }
        public AnalyticsResponse GetInstrumentStats(Guid orgId, int timelineId, string[] userGroups, string instrument = "", string country = "", string city = "")
        {
            var response = new AnalyticsResponse();
            List <AccountDetail> accountDetail = new List <AccountDetail>();
            var topInstruments = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup)).SelectMany(x => x.InstrumentStats).GroupBy(x => x.InstrumentName)
                                 .Select(g => new
            {
                Key   = g.Key,
                Value = g.Sum(s => s.Volume),
            }).OrderByDescending(x => x.Value).Select(x => x.Key).Take(5).ToList();

            if (string.IsNullOrEmpty(country) && string.IsNullOrEmpty(city))
            {
                //var aaccountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && m.InstrumentStats.Any(x => x.TimeLineId == timelineId))
                //                   .SelectMany(x => x.InstrumentStats).OrderByDescending(x => x.Volume).ToList();
                accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup)).ToList();

                accountDetail.ForEach(x => x.InstrumentStats = x.InstrumentStats.Where(t => t.TimeLineId == timelineId && topInstruments.Contains(t.InstrumentName)).ToList());
            }
            else if (!string.IsNullOrEmpty(country) && string.IsNullOrEmpty(city))
            {
                accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup) && m.Country == country).ToList();
                accountDetail.ForEach(x => x.InstrumentStats = x.InstrumentStats.Where(t => t.TimeLineId == timelineId && t.InstrumentName == instrument && topInstruments.Contains(t.InstrumentName)).ToList());
            }
            if (!string.IsNullOrEmpty(country) && !string.IsNullOrEmpty(city))
            {
                accountDetail = _unitOfWork.AccountDetailRepository.GetAll().Where(m => m.OrganizationId == orgId && userGroups.Contains(m.UserGroup) && m.Country == country && m.City == city).ToList();
                accountDetail.ForEach(x => x.InstrumentStats = x.InstrumentStats.Where(t => t.TimeLineId == timelineId && t.InstrumentName == instrument && topInstruments.Contains(t.InstrumentName)).ToList());
            }


            var accountsData = new AccountDetailModel().ToAccountDetailWithInstrumentStatsModel(accountDetail);

            response.Data = accountsData.OrderByDescending(x => x.InstrumentStatsModel.Sum(y => y.Volume)).ToList();
            //response.Cities = accountDetail.Select(x => x.City).Distinct().ToList();

            //  response.Accounts = accountsData.Select(x => x.Name).Distinct();
            //response.Instruments = accountsData.SelectMany(x => x.InstrumentStatsModel).Select(x => x.InstrumentName).Distinct();
            response.Instruments = topInstruments;

            List <AccountDetailModel> aD = new List <AccountDetailModel>();

            foreach (string item in accountsData.Select(x => x.City).Distinct())
            {
                aD.Add(new AccountDetailModel()
                {
                    City = item, Nav = accountsData.Where(z => z.City == item).SelectMany(n => n.InstrumentStatsModel).Sum(x => x.Volume)
                });
            }

            response.Cities = aD.OrderByDescending(n => n.Nav).Take(5).Select(x => x.City).Distinct();

            aD = new List <AccountDetailModel>();
            foreach (string item in accountsData.Select(x => x.Name).Distinct())
            {
                aD.Add(new AccountDetailModel()
                {
                    Name = item, Nav = accountsData.Where(z => z.Name == item).SelectMany(n => n.InstrumentStatsModel).Sum(x => x.Volume)
                });
            }

            response.Accounts = aD.OrderByDescending(n => n.Nav).Take(5).Select(x => x.Name).Distinct();
            aD = new List <AccountDetailModel>();
            foreach (string item in accountDetail.Select(x => x.Country).Distinct())
            {
                aD.Add(new AccountDetailModel()
                {
                    Country = item, Nav = accountsData.Where(z => z.Country == item).SelectMany(n => n.InstrumentStatsModel).Sum(x => x.Volume)
                });
            }

            response.Countries = aD.OrderByDescending(n => n.Nav).Take(5).Select(x => x.Country).Distinct();
            var timeLineIds = accountDetail.SelectMany(x => x.AccountStats).Select(x => x.TimeLineId).Distinct().ToList();
            var timeLines   = new List <EnumHelper>();

            foreach (var tline in Timelines.MasterTimelines)
            {
                var timeline = new EnumHelper
                {
                    stringValue = tline.Encrypt(),
                    DisplayName = ((TimeLineEnum)Enum.ToObject(typeof(TimeLineEnum), tline)).GetEnumDisplayName()
                };
                timeLines.Add(timeline);
            }
            //foreach (var timeLineId in timeLineIds.OrderBy(x => x).ToList())
            //{
            //    var timeline = new EnumHelper
            //    {
            //        stringValue = timeLineId.Encrypt(),
            //        DisplayName = ((TimeLineEnum)Enum.ToObject(typeof(TimeLineEnum), Convert.ToInt32(timeLineId))).GetEnumDisplayName()
            //    };
            //    timeLines.Add(timeline);
            //}
            response.Timelines = timeLines;
            response.WidgetId  = Convert.ToInt32(EmbedWidgetEnum.InstrumentLocation).Encrypt();
            return(response);
        }