コード例 #1
0
        public void CalCategory(ref int iTotalAlarmNum)
        {
            CategoryStatistics tmp = new CategoryStatistics();
            int j = 0;

            int[] rate = new int[PVar.ERROR_CODE.Length - 1 + 1];
            iTotalAlarmNum = 0;
            for (int i = 0; i <= m_AlarmHistoryDataList.Count - 1; i++)
            {
                for (j = 0; j <= PVar.ERROR_CODE.Length - 1; j++)
                {
                    if (m_AlarmHistoryDataList[i].strErrcode == PVar.ERROR_CODE[j].ErrorCode)
                    {
                        rate[j] = rate[j] + 1;
                        iTotalAlarmNum++;
                    }
                }
            }
            ////加载数据到CateGory列表
            m_AlarmCategoryDataList.Clear();
            for (int K = 0; K <= PVar.ERROR_CODE.Length - 1; K++)
            {
                if (rate[K] != 0)
                {
                    tmp.Category = System.Convert.ToString(PVar.ERROR_CODE[K].ErrorCode);
                    tmp.Rate     = rate[K];
                    m_AlarmCategoryDataList.Add(tmp);
                }
            }
        }
コード例 #2
0
 private static CategoryStatisticsDto Map(CategoryStatistics category)
 {
     return(new CategoryStatisticsDto
     {
         Name = category.Name,
         Amount = category.Amount
     });
 }
コード例 #3
0
 public static async Task AddOrUpdateAsync(this IMongoCollection <CategoryStatistics> collection,
                                           CategoryStatistics statistics)
 {
     await collection.ReplaceOneAsync(x => x.Name == statistics.Name, statistics, new UpdateOptions
     {
         IsUpsert = true
     });
 }
コード例 #4
0
ファイル: VariableMapper.cs プロジェクト: Colectica/curation
        static CodeList CreateCodeList(PhysicalInstance physicalInstance, DataRelationship dataRelationship, Variable variable, VariableStatistic stats)
        {
            using (IDataReader reader = GetReaderForPhysicalInstance(physicalInstance))
            {
                if (reader == null)
                {
                    return(null);
                }

                int columnIdx = GetColumnIndex(physicalInstance, dataRelationship, variable);
                if (columnIdx == -1)
                {
                    return(null);
                }

                var gatherer = new DataValueFrequencyGatherer(reader);
                var values   = gatherer.CountValueFrequencies(columnIdx);

                var codeList = new CodeList()
                {
                    AgencyId = variable.AgencyId
                };
                codeList.ItemName.Copy(variable.ItemName);
                codeList.Label.Copy(variable.Label);

                // Clear any existing category statistics.
                stats.UnfilteredCategoryStatistics.Clear();

                foreach (var pair in values.OrderBy(x => x.Key))
                {
                    string value = pair.Key;
                    int    count = pair.Value;

                    // Create the code and category.
                    var category = new Category()
                    {
                        AgencyId = variable.AgencyId
                    };
                    var code = new Code()
                    {
                        AgencyId = variable.AgencyId
                    };
                    code.Value    = value;
                    code.Category = category;

                    codeList.Codes.Add(code);

                    // Update the statistics with category frequency.
                    var catStats = new CategoryStatistics();
                    catStats.CategoryValue = value.ToString();
                    catStats.Frequency     = count;
                    stats.UnfilteredCategoryStatistics.Add(catStats);
                }

                return(codeList);
            }
        }
コード例 #5
0
        public async Task <IActionResult> GetEntriesByCategoryAsync(Guid categoryId, DateTime startDate, DateTime endDate)
        {
            MeasureCategory measureCategory = await _measureCategoryRepository.GetByIdAndProfileIdAsync(categoryId, _currentProfileId);

            if (measureCategory == null)
            {
                return(CreateErrorResponse("Erro de categoria", "Nenhuma categoria de medição com esse Id foi encontrada no banco de dados."));
            }

            CategoryStatistics statistics = await _measureStatisticsDomainService.GetEntriesByCategoryAsync(measureCategory, startDate, endDate);

            return(CreateResponse(statistics));
        }
コード例 #6
0
        private CategoryStatistics GetCategoryStatistics(IEnumerable <Operation> operations, CurrencyName currency)
        {
            var statistics = new CategoryStatistics();
            var info       = new List <CategoryInfo>();
            var categories = operations.UsedCategories();

            foreach (var category in categories)
            {
                info.Add(GetCategoryInfo(operations, category, currency));
            }
            statistics.Currency = currency.ToString();
            statistics.Info     = info.OrderByDescending(x => x.Persentage);
            return(statistics);
        }
コード例 #7
0
        public ICategoryStatistics GetUserCategoryStatistics(string username)
        {
            var stats        = new CategoryStatistics();
            var accountIds   = _accountRepository.GetUserBills(username);
            var transactions = new List <ITransaction>();

            foreach (var id in accountIds)
            {
                transactions.AddRange(_transactionRepository.GetBillTransactions(id.AccountId).Where(trans =>
                                                                                                     (trans.Category != "Upload") && (trans.Category != "Start") && (trans.Category != "SavingPlan")).ToList());
            }
            stats.Categories = transactions.Select(trans => trans.Category).Distinct();
            var avgCostCategories = stats.Categories.Select(category => transactions.Where(trans => trans.Category == category).Average(trans => trans.TransactionAmount)).ToList();

            stats.AvgCostPerCategory = avgCostCategories;

            return(stats);
        }
        private async Task HandleCategoryStatisticsAsync(T @event)
        {
            var remarkStats = await _remarkStatisticsRepository.GetAsync(@event.RemarkId);

            if (remarkStats.HasNoValue)
            {
                return;
            }

            var categoryStats = await _categoryStatisticsRepository.GetByNameAsync(remarkStats.Value.Category);

            if (categoryStats.HasNoValue)
            {
                categoryStats = new CategoryStatistics(remarkStats.Value.Category,
                                                       new RemarksCountStatistics());
            }
            _updateCategory(categoryStats.Value);
            await _categoryStatisticsRepository.AddOrUpdateAsync(categoryStats.Value);
        }
コード例 #9
0
        public ActionResult Statistics()
        {
            var model = new CategoryStatistics();

            var position = _categoryRepository.GetAll();

            // Count
            model.Count = position.Count();

            // Latest
            model.Latest = position.OrderByDescending(c => c.Id).Take(3).Select(i => new
            {
                name           = i.Title,
                image          = _imageService.BuildUrl(i.ImageBlob?.Name, i.Title, 40, 40),
                creationDate   = Globalization.GetLocalDateTime(i.UTCCreation).DateTime.ToLongDateString(),
                navigationPath = Url.Action(nameof(CategoryController.Edit), nameof(CategoryController).RemoveControllerSuffix(), new { @id = i.Id })
            }).Cast <object>().ToList();

            // Weekly data
            var maxDate = DateTime.UtcNow;
            var minDate = maxDate.AddDays(-7);

            position = position.Where(c => c.UTCCreation.Date >= minDate.Date);
            position = position.Where(c => c.UTCCreation.Date <= maxDate.Date);

            var items = new List <object>();

            for (DateTime date = minDate.Date; date <= maxDate.Date; date = date.AddDays(1))
            {
                var dayName  = date.ToString("MMM/dd");
                var dayValue = position.Where(c => c.UTCCreation.Date.Equals(date)).Count();

                items.Add(new List <object>()
                {
                    dayName, dayValue
                });
            }

            model.WeeklyRegistrations = items;

            return(Json(model));
        }
コード例 #10
0
        /// <summary>
        /// This method retrieves the most up-to-date list of statistics from the database.
        /// </summary>
        /// <returns>True if success, false otherwise.</returns>
        public async Task <bool> RefreshStatisticsAsync()
        {
            // Load the general statistics from the Database.
            string query = "SELECT * FROM general_statistics";

            SqlCommand cmd = DBSqlHelper.Connection.CreateCommand();

            cmd.CommandText = query;

            using (DbDataReader reader = await cmd.ExecuteReaderAsync())
            {
                // Check if statistics exist.
                if (reader.HasRows)
                {
                    Statistics.Clear();

                    while (await reader.ReadAsync())
                    {
                        Statistic statistic = new Statistic((int)reader[0], (int)reader[1], (int)reader[2], new ObservableCollection <CategoryStatistics>(), new ObservableCollection <BestProjects>());
                        Statistics.Add(statistic);
                    }
                }
                else
                {
                    return(false);
                }
            }

            // Load the category statistics from the Database.
            query = "SELECT * FROM project_category_stats";

            cmd             = DBSqlHelper.Connection.CreateCommand();
            cmd.CommandText = query;

            // Execute query.
            using (DbDataReader reader = cmd.ExecuteReader())
            {
                // Check if statistics exists.
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        // Get the year of the current statistic.
                        int year = reader.GetInt32(0);

                        // Get the category id.
                        int categoryId = reader.GetInt32(1);

                        // Get the corresponding category from the category list.
                        Category category = new Category();

                        foreach (Category tempCategory in this.Categories)
                        {
                            // Check if it's the category we want.
                            if (tempCategory.Id == categoryId)
                            {
                                category = tempCategory;
                                break;
                            }
                        }

                        // Create the category statistic from all gathered data.
                        CategoryStatistics categoryStatistics = new CategoryStatistics(category, reader.GetInt32(2));

                        // Cycle through all statistics until we get to the appropriate year
                        // If no appropriate one is found, ignore it, although it shouldn't happen on the database side.
                        foreach (Statistic statistic in Statistics)
                        {
                            if (statistic.Year == year)
                            {
                                statistic.CategoryStatistics.Add(categoryStatistics);
                            }
                        }
                    }
                }
            }

            return(true);
        }
 public async Task AddOrUpdateAsync(CategoryStatistics statistics)
 => await _database.CategoryStatistics()
 .AddOrUpdateAsync(statistics);