コード例 #1
0
    private static structCountPercent[] TechnologyBrowser(DataTable _DataTable)
    {
        int i = 0;

        // Set MetricsCount Size
        structCountPercent[] _MetricsCount = new structCountPercent[(_DataTable.Rows.Count < DefaultRowLimit ? _DataTable.Rows.Count : DefaultRowLimit)];
        foreach (DataRow dr in _DataTable.Rows)
        {
            _MetricsCount[i].c1 = Convert.ToString(dr["Browser"]) == "" ? "Other" : Convert.ToString(dr["Browser"]);
            _MetricsCount[i].c2 = Convert.ToInt32(dr["BrowserCount"]);
            _MetricsCount[i].c3 = Math.Round((decimal)_MetricsCount[i].c2 / TotalUsers * 100, 2);
            i++;
        }
        return(_MetricsCount);
    }
コード例 #2
0
    private structCountPercent[] countWholeByValueGivenKey(string UserKey, string SortKey, int Limit = 20, bool orderByDesc = false)
    {
        Dictionary <string, structCountPercent> MetricsCount = new Dictionary <string, structCountPercent>();

        try
        {
            var _DictionaryTable = ((UserInformation)SessionObjects.wincache_ucache_get(String.Concat(Utils.SERVER_NAME, Utils.SQL_USERS, UserKey))).OnlineClients;

            if (_DictionaryTable != null)
            {
                int TotalCount = jsonTotalOnlineCount(UserKey);

                foreach (var onlineuserpair in _DictionaryTable.Keys.ToList())
                {
                    Dictionary <string, string> OnlineUserValue = (Dictionary <string, string>)SessionObjects.wincache_ucache_get(_DictionaryTable, onlineuserpair);
                    if (OnlineUserValue != null)
                    {
                        string MetricKey = Regex.Split((OnlineUserValue[SortKey] == "" || OnlineUserValue[SortKey] == null ? "Other" : OnlineUserValue[SortKey]).Replace("http://", "").Replace("https://", ""), @"[/?#]")[0];
                        if (MetricsCount.ContainsKey(MetricKey))
                        {
                            structCountPercent _structCountPercent = (structCountPercent)MetricsCount[MetricKey];
                            _structCountPercent.c2++;
                            _structCountPercent.c3  = Math.Round((decimal)_structCountPercent.c2 / TotalCount * 100, 2);
                            MetricsCount[MetricKey] = _structCountPercent;
                        }
                        else
                        {
                            structCountPercent _structCountPercent = new structCountPercent();
                            _structCountPercent.c2  = 1;
                            _structCountPercent.c3  = Math.Round((decimal)_structCountPercent.c2 / TotalCount * 100, 2);
                            MetricsCount[MetricKey] = _structCountPercent;
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.WriteLine("FGS Server Online : " + e.StackTrace);
        }

        // Set MetricsCount Size
        structCountPercent[] _MetricsCount = new structCountPercent[(MetricsCount.Keys.Count < Limit ? MetricsCount.Keys.Count : Limit)];
        int i = 0;

        if (orderByDesc)
        {
            //foreach (var pair in MetricsCount.OrderByDescending(p => ((structCountPercent)p.Value).c2).Skip((TotalSize > Pager * Limit ? Pager * Limit : 0)).Take(Limit))
            foreach (var pair in MetricsCount.OrderByDescending(p => ((structCountPercent)p.Value).c2).Take(Limit))
            {
                _MetricsCount[i].c1 = pair.Key;
                _MetricsCount[i].c2 = pair.Value.c2;
                _MetricsCount[i].c3 = pair.Value.c3;
                i++;
            }
            return(_MetricsCount);
        }
        else
        {
            //foreach (var pair in MetricsCount.OrderBy(p => ((structCountPercent)p.Value).c2).Skip((TotalSize > Pager * Limit ? Pager * Limit : 0)).Take(Limit))
            foreach (var pair in MetricsCount.OrderBy(p => ((structCountPercent)p.Value).c2).Take(Limit))
            {
                _MetricsCount[i].c1 = pair.Key;
                _MetricsCount[i].c2 = pair.Value.c2;
                _MetricsCount[i].c3 = pair.Value.c3;
                i++;
            }
            return(_MetricsCount);
        }
    }