Beispiel #1
0
 private static void UpdateCountryStatisticsForPlatform(DevicePlatform devicePlatform, DateTime creationDate, CountryStatistics countryStats)
 {
     UserWeeklyStatistics(devicePlatform, creationDate, countryStats);
     UserMonthlyStatistics(devicePlatform, creationDate, countryStats);
     UserQuarterlyStatistics(devicePlatform, creationDate, countryStats);
 }
Beispiel #2
0
 private static void UpdateUserStatistics(DevicePlatform devicePlatform, DateTime creationDate, CountryStatistics countryStats)
 {
     if (devicePlatform == DevicePlatform.Android)
     {
         bool isMatched = false;
         countryStats.Android.TotalCount += 1;
         for (int x = 0; x < 7; x++)
         {
             if (creationDate.ToString("d") == countryStats.Android.RecentHistory.WeeklyHistory[x].Date)
             {
                 countryStats.Android.RecentHistory.WeeklyHistory[x].TotalCount += 1;
                 countryStats.RecentHistory.WeeklyHistory[x].TotalCount         += 1;
                 isMatched = true;
                 break;
             }
         }
         if (!isMatched)
         {
             countryStats.Android.PreviousCountBeforeHistory += 1;
         }
     }
     else if (devicePlatform == DevicePlatform.iOS)
     {
         bool isMatched = false;
         countryStats.Ios.TotalCount += 1;
         for (int x = 0; x < 7; x++)
         {
             if (creationDate.ToString("d") == countryStats.Ios.RecentHistory.WeeklyHistory[x].Date)
             {
                 countryStats.Ios.RecentHistory.WeeklyHistory[x].TotalCount += 1;
                 countryStats.RecentHistory.WeeklyHistory[x].TotalCount     += 1;
                 isMatched = true;
                 break;
             }
         }
         if (!isMatched)
         {
             countryStats.Ios.PreviousCountBeforeHistory += 1;
         }
     }
 }
Beispiel #3
0
        public static UserStatistics GetCountryBasedUserStatistics()
        {
            DateTime lastSyncTime = Utility.ConvertLocalToUtc(Convert.ToDateTime(DbManager.GetLastSyncTime()));

            var userStats = new UserStatistics(lastSyncTime);

            try
            {
                DataTable dtAllRegisteredUsers = DbManager.GetAllRegisteredUsers();
                UpdateActiveUsersCount(lastSyncTime, userStats);
                var countryCodeDictionary = new Dictionary <string, string>();

                if (File.Exists(FilePath))
                {
                    string fileContent = File.ReadAllText(FilePath);
                    if (!Utility.IsNullOrEmpty(fileContent))
                    {
                        countryCodeDictionary =
                            JsonConvert.DeserializeObject <Dictionary <string, string> >(fileContent);
                    }
                }
                else
                {
                    countryCodeDictionary = new Dictionary <string, string>();
                }

                if (dtAllRegisteredUsers.Rows.Count > 0)
                {
                    int countryCode = 0;
                    for (int i = 0; i < dtAllRegisteredUsers.Rows.Count; i++)
                    {
                        //try
                        //{
                        var devicePlatform = (DevicePlatform)Convert.ToInt16(dtAllRegisteredUsers.Rows[i]["devicePlatform"]);
                        var creationDate   = Convert.ToDateTime(dtAllRegisteredUsers.Rows[i]["creationDate"]);
                        countryCode = Utility.GetCountry(dtAllRegisteredUsers.Rows[i]["username"].ToString());

                        if (userStats.CountryStats.ContainsKey(countryCode))
                        {
                            var countryStats = userStats.CountryStats[countryCode];
                            UpdateCountryStatisticsForPlatform(devicePlatform, creationDate, countryStats);
                        }
                        else
                        {
                            var countryStats = new CountryStatistics(lastSyncTime);

                            if (countryCodeDictionary.ContainsKey(countryCode.ToString()))
                            {
                                countryStats.CountryName = countryCodeDictionary[countryCode.ToString()];
                            }
                            else
                            {
                                countryStats.CountryName = Utility.GetCountryNameOnline(countryCode.ToString(),
                                                                                        FilePath, countryCodeDictionary);
                            }
                            UpdateCountryStatisticsForPlatform(devicePlatform, creationDate, countryStats);
                            userStats.CountryStats.Add(countryCode, countryStats);
                        }
                        //}
                        //catch (ApplicationException applicationException)
                        //{
                        //}
                        //catch (Exception exception)
                        //{
                        //}
                    }
                }
            }
            catch (Exception exception)
            {
                LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception, System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw new ApplicationException("Opertaion failed due to some internal error");
            }

            return(userStats);
        }
Beispiel #4
0
 private static void UserQuarterlyStatistics(DevicePlatform devicePlatform, DateTime creationDate, CountryStatistics countryStats)
 {
     if (creationDate >= countryStats.RecentHistory.QuarterlyCounts.LowerBoundDate && creationDate <= countryStats.RecentHistory.QuarterlyCounts.UpperBoundDate)
     {
         if (devicePlatform == DevicePlatform.Android)
         {
             countryStats.Android.RecentHistory.QuarterlyCounts.TotalCount += 1;
             countryStats.RecentHistory.QuarterlyCounts.TotalCount         += 1;
         }
         else if (devicePlatform == DevicePlatform.iOS)
         {
             countryStats.Ios.RecentHistory.QuarterlyCounts.TotalCount += 1;
             countryStats.RecentHistory.QuarterlyCounts.TotalCount     += 1;
         }
     }
 }