Пример #1
0
        public static GetStatsResponse Create(IDictionary <string, long> stats)
        {
            var result = new GetStatsResponse()
            {
                Success = true
            };

            result.Statistics.Add(stats);
            return(result);
        }
Пример #2
0
        /// <nodoc />
        public async Task <GetStatsResponse> GetStatsAsync(GetStatsRequest request, CancellationToken token)
        {
            var cacheContext = new Context(Guid.NewGuid(), _logger);
            var counters     = await _sessionHandler.GetStatsAsync(new OperationContext(cacheContext, token));

            if (!counters)
            {
                return(GetStatsResponse.Failure());
            }

            return(GetStatsResponse.Create(counters.Value.ToDictionaryIntegral()));
        }
Пример #3
0
        public async Task <GetStatsResponse> GetStatsAsync(GetStatsRequest request, CancellationToken token)
        {
            var cacheContext = new Context(Guid.NewGuid(), Logger);
            var counters     = await ContentSessionHandler.GetStatsAsync(new OperationContext(cacheContext, token));

            if (!counters)
            {
                return(GetStatsResponse.Failure());
            }

            var result = counters.Value !;

            result.Merge(Counters.ToCounterSet(), "GrpcContentServer");
            return(GetStatsResponse.Create(result.ToDictionaryIntegral()));
        }
Пример #4
0
        internal static GetStatsResponse GetStats()
        {
            using (SqlConnection conn = GetConnection())
            {
                GetStatsResponse ret;
                using (SqlCommand comm = new SqlCommand("SELECT CASE num_of_rows WHEN 0 THEN 0 ELSE (num_of_characters / num_of_words) END chars_per_word, " +
                                                        "CASE num_of_rows WHEN 0 THEN 0 ELSE(num_of_words / num_of_rows) END words_in_row, " +
                                                        "CASE num_of_verses WHEN 0 THEN 0 ELSE(num_of_rows / num_of_verses) END rows_in_verse, " +
                                                        "CASE num_of_songs WHEN 0 THEN 0 ELSE(num_of_verses / num_of_songs) END verses_in_songs " +
                                                        "FROM stats", conn))
                    using (SqlDataReader dr = comm.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            ret = new GetStatsResponse()
                            {
                                CharsPerWord  = Convert.ToDecimal(dr["chars_per_word"]),
                                RowsInVerse   = Convert.ToDecimal(dr["rows_in_verse"]),
                                VersesInSongs = Convert.ToDecimal(dr["verses_in_songs"]),
                                WordsInRow    = Convert.ToDecimal(dr["words_in_row"]),
                                WordCloud     = new List <Tuple <int, string> >(),
                            };
                        }
                        else
                        {
                            return(null);
                        }
                    }

                using (SqlCommand comm = new SqlCommand("SELECT TOP 100 w.word, COUNT(*) count " +
                                                        "FROM word w " +
                                                        "JOIN location l ON w.word_id = l.word_id " +
                                                        "GROUP BY w.word_id, w.word " +
                                                        "ORDER BY count DESC", conn))
                    using (SqlDataReader dr = comm.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            ret.WordCloud.Add(new Tuple <int, string>(Convert.ToInt32(dr["count"]), dr["word"].ToString()));
                        }
                    }

                return(ret);
            }
        }
Пример #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     stat = ServiceAccessor.MakeRequest <GetStatsRequest, GetStatsResponse>(new GetStatsRequest(), "GetStats");
 }