예제 #1
0
        public void RecursiveGetUser(string uid, int gen)
        {
            gen++;
            var result = ThriftTool.GetSingleKey(ThriftTool.ToByte(uid), "M01UserRelaction", 5000);

            var node = new RelactionNode {
                id = uid, weight = result.Count
            };

            if (!NodeList.Contains(node))
            {
                NodeList.Add(node); //add new node
                NodeStringList.Add(uid);
            }

            if (gen >= 4)
            {
                return;
            }
            foreach (var ks in result)
            {
                var target = ThriftTool.ToString(ks.Counter_column.Name);
                var weight = (int)ks.Counter_column.Value;
                var edge   = new RelactionEdge {
                    id = uid + "_" + target, source = uid, target = target, weight = weight
                };
                EdgeList.Add(edge);
                if (!NodeStringList.Contains(target))
                {
                    RecursiveGetUser(target, gen);
                }
            }
        }
예제 #2
0
        public List <string> BahaGetDayList(string mode)
        {
            var result = new List <string>();
            var client = ThriftTool.GetClient("default", ref _transport);

            CqlResult cqlResult = client.execute_cql_query(ThriftTool.ToByte("select first 30 Date from BahamutDays where Mode='" + mode + "'"), Compression.NONE);

            foreach (CqlRow t in cqlResult.Rows)
            {
                foreach (var col in t.Columns)
                {
                    var name = ThriftTool.ToString(col.Name);
                    switch (name)
                    {
                    case "Date":
                        result.Add(ThriftTool.ToString(col.Value));
                        break;
                    }
                }
            }
            ThriftTool.TransportClose(ref _transport);
            result.Sort();

            return(result);
        }
예제 #3
0
        static void ShowCounterOrder(string cf, int limit)
        {
            Utility.Logging("ShowCounterOrder CF:" + cf + " limit:" + limit, Utility.DebugLevel.Info);
            var ar = new Dictionary <string, long>();
            var re = ThriftTool.GetAllFromCF(cf, limit);

            Utility.Logging("org count:" + re.Count, Utility.DebugLevel.Info);

            foreach (var ks in re)
            {
                foreach (var keySlice in ks.Columns)
                {
                    if (ThriftTool.ToString(keySlice.Counter_column.Name) != "sum")
                    {
                        continue;
                    }
                    var key = ThriftTool.ToString(ks.Key);
                    var val = keySlice.Counter_column.Value;
                    ar.Add(key, val);
                }
            }

            var res = from pair in ar orderby pair.Value descending select pair;

            foreach (var r in res.Take(500))
            {
                Console.WriteLine("key:" + r.Key + "\tvalue:" + r.Value);
            }
            Utility.Logging("end", Utility.DebugLevel.Info);
        }
예제 #4
0
        static void ProcessN3(string n1, string n2)
        {
            CqlResult n1Result = ThriftTool.GetByCql("Select * from M01UserRelaction where key='" + n1 + "' limit 50000");
            CqlResult n2Result = ThriftTool.GetByCql("Select * from M01UserRelaction where key='" + n2 + "' limit 50000");
            var       n1List   = n1Result.Rows.First().Columns.Select(col => ThriftTool.ToString(col.Name)).Where(name => name != "KEY").ToList();
            var       n2List   = n2Result.Rows.First().Columns.Select(col => ThriftTool.ToString(col.Name)).Where(name => name != "KEY").ToList();

            foreach (var n3 in n1List.Intersect(n2List))
            {
                //Utility.Logging("n3=" + n3, Utility.DebugLevel.Info);
                if (n1 == n3 || n2 == n3)
                {
                    continue;
                }
                var sum       = Get2NodeValue(n1, n2) + Get2NodeValue(n2, n3) + Get2NodeValue(n1, n3);
                var orderList = new List <int> {
                    int.Parse(n1), int.Parse(n2), int.Parse(n3)
                };
                orderList.Sort();
                var key = orderList[2] + "_" + orderList[1] + "_" + orderList[0];
                ThriftTool.CounterAdd(key, "M01UserRelactionN3", "sum", sum);
                ThriftTool.CounterAdd(key, "M01UserRelactionN3", orderList[2] + "_" + orderList[1], Get2NodeValue(orderList[2].ToString(CultureInfo.InvariantCulture), orderList[1].ToString(CultureInfo.InvariantCulture)));
                ThriftTool.CounterAdd(key, "M01UserRelactionN3", orderList[2] + "_" + orderList[0], Get2NodeValue(orderList[2].ToString(CultureInfo.InvariantCulture), orderList[0].ToString(CultureInfo.InvariantCulture)));
                ThriftTool.CounterAdd(key, "M01UserRelactionN3", orderList[1] + "_" + orderList[0], Get2NodeValue(orderList[1].ToString(CultureInfo.InvariantCulture), orderList[0].ToString(CultureInfo.InvariantCulture)));
            }
        }
예제 #5
0
        static void PraseNnN()
        {
            var count = 0;
            //Utility.Logging("Calculating N vs N from: " + count, Utility.DebugLevel.Info);
            //var re = ThriftTool.GetAllFromCF("M01UserRelaction", 120000);
            var re = ThriftTool.GetAllFromCF("M01UserRelaction", 100);

            foreach (var node in re)
            {
                if (count % 1000 == 0)
                {
                    Utility.Logging("Calculating N vs N from: " + count, Utility.DebugLevel.Info);
                }
                var key = ThriftTool.ToString(node.Key);
                Utility.Logging("Key= " + key, Utility.DebugLevel.Info);

                foreach (var keySlice in node.Columns)
                {
                    var columnName = ThriftTool.ToString(keySlice.Counter_column.Name);
                    Utility.Logging("column.Name= " + columnName + " value=" + keySlice.Counter_column.Value, Utility.DebugLevel.Info);
                    if (key == columnName)
                    {
                        continue;
                    }
                    Utility.Logging("go check> " + key + "_" + columnName, Utility.DebugLevel.Info);
                    Check2NodeValue(key, columnName, keySlice.Counter_column.Value);
                }
                count++;
            }
            Utility.Logging("total count: " + count, Utility.DebugLevel.Info);
        }
예제 #6
0
        public HighChart[] BahaGetOneGame(string game, string startDate, string endDate)
        {
            var gameList  = game.Split(',');
            var chartList = new HighChart[gameList.Length];
            var client    = ThriftTool.GetClient("default", ref _transport);

            for (var i = 0; i < gameList.Length; i++)
            {
                var       rank      = new List <ScoreList>();
                CqlResult cqlResult = client.execute_cql_query(ThriftTool.ToByte("select * from BahamutGames where Title='" + gameList[i] + "'"), Compression.NONE);

                foreach (CqlRow t in cqlResult.Rows)
                {
                    var rl = new ScoreList();
                    foreach (var col in t.Columns)
                    {
                        var name = ThriftTool.ToString(col.Name);
                        switch (name)
                        {
                        case "Title":
                            rl.Title = ThriftTool.ToString(col.Value);
                            break;

                        case "Link":
                            rl.Link = ThriftTool.ToString(col.Value);
                            break;

                        case "Article":
                            rl.Article = ThriftTool.ToString(col.Value);
                            break;

                        case "Popular":
                            rl.Popular = ThriftTool.ToString(col.Value);
                            break;

                        case "Date":
                            rl.Date = ThriftTool.ToInt(col.Value);
                            break;
                        }
                    }
                    rank.Add(rl);
                }

                var ranks = from n in rank orderby n.Date select n;

                chartList[i] = ParseToHighChart(ranks);
            }
            ThriftTool.TransportClose(ref _transport);

            return(chartList);
        }
예제 #7
0
        public static MvcHtmlString GenDayList()
        {
            var result = ThriftTool.GetAllFromCF("BahamutDays", 30);

            ThriftTool.TransportClose();
            var sb = new StringBuilder();

            foreach (var ks in result)
            {
                foreach (var keySlice in ks.Columns)
                {
                    var key = ThriftTool.ToString(keySlice.Column.Name);
                    sb.Append("<option value='" + key + "'>" + key + "</option>");
                }
            }
            return(new MvcHtmlString(sb.ToString()));
        }
예제 #8
0
        public static MvcHtmlString GenGameList()
        {
            var client = ThriftTool.GetClient("default", ref _transport);
            var result = ThriftTool.GetAllFromCF("GameList", 200, client);

            ThriftTool.TransportClose(ref _transport);
            var sb = new StringBuilder();

            foreach (var ks in result)
            {
                foreach (var keySlice in ks.Columns)
                {
                    var key = ThriftTool.ToString(keySlice.Column.Name);
                    sb.Append("<option value='" + key + "'>" + key + "</option>");
                }
            }
            return(new MvcHtmlString(sb.ToString()));
        }
예제 #9
0
        static void PraseN3()
        {
            var count = 0;
            //Utility.Logging("Calculating N vs N from: " + count, Utility.DebugLevel.Info);
            var re = ThriftTool.GetAllFromCF("M01UserRelactionN2", 500000);

            foreach (var node in re)
            {
                //Utility.Logging("key="+ ThriftTool.ToString(node.Key), Utility.DebugLevel.Info);
                if (count % 1000 == 0)
                {
                    Utility.Logging("Calculating N vs N vs N from: " + count, Utility.DebugLevel.Info);
                }
                var ar = ThriftTool.ToString(node.Key).Split('_');
                //Utility.Logging("n1=" + ar[0] + " n2="+ar[1], Utility.DebugLevel.Info);
                ProcessN3(ar[0], ar[1]);

                count++;
            }
            Utility.Logging("total count: " + count, Utility.DebugLevel.Info);
        }
예제 #10
0
        static int GetCfCount(string cf, int limit)
        {
            var sqlStr = "select count(*) from \"M01UserRelaction\" limit 400000";
            //var sqlStr = "Select count(*) from '" + cf + "' limit " + limit;
            CqlResult n1Result = ThriftTool.GetByCql(sqlStr);

            Console.WriteLine("Type=" + n1Result.Type);
            Console.WriteLine("Num=" + n1Result.Num);
            foreach (var row in n1Result.Rows)
            {
                Console.WriteLine("row.Key=" + ThriftTool.ToString(row.Key));
                Console.WriteLine("row.Columns.Count=" + row.Columns.Count);
                foreach (var col in row.Columns)
                {
                    Console.WriteLine("Type=" + col.Value.GetType());
                    Console.WriteLine("\tcol.Name=" + ThriftTool.ToString(col.Name));
                    Console.WriteLine("\tcol.Value=" + ThriftTool.ToLong(col.Value));
                }
            }

            return(ThriftTool.ToInt(n1Result.Rows.First().Columns.First().Value));
        }
예제 #11
0
        public List <string> BahaGetDayList(string mode)
        {
            var result = new List <string>();

            var cqlResult = ThriftTool.GetByCql("select first 30 Date from BahamutDays where Mode='" + mode + "'");

            foreach (CqlRow t in cqlResult.Rows)
            {
                foreach (var col in t.Columns)
                {
                    var name = ThriftTool.ToString(col.Name);
                    switch (name)
                    {
                    case "Date":
                        result.Add(ThriftTool.ToString(col.Value));
                        break;
                    }
                }
            }
            //ThriftTool.TransportClose();
            result.Sort();

            return(result);
        }
예제 #12
0
        /// <summary>
        /// 取得Baha單日資料
        /// </summary>
        /// <param name="key">日期</param>
        /// <param name="columnFamily">CF name (BahamutOnline,BahamutAll)</param>
        /// <returns></returns>
        public IOrderedEnumerable <RankList> BahaGetOneDay(string key, string columnFamily)
        {
            var rank = new List <RankList>();

            var lb = new List <byte[]> {
                ThriftTool.ToByte(key)
            };



            Dictionary <byte[], List <ColumnOrSuperColumn> > results = Client.multiget_slice(lb, ThriftTool.GetParent(columnFamily), ThriftTool.GetPredicate(100), ConsistencyLevel.ONE);

            if (results.Count > 0) //if have result
            {
                foreach (var result in results)
                {
                    foreach (var scol in result.Value)
                    {
                        if (scol.GetType() == typeof(ColumnOrSuperColumn))
                        {
                            var rl = new RankList();
                            foreach (var col in scol.Super_column.Columns)
                            {
                                string name = ThriftTool.ToString(col.Name);
                                if (name == "Title")
                                {
                                    rl.Title = ThriftTool.ToString(col.Value);
                                }
                                if (name == "Rank")
                                {
                                    rl.Rank = int.Parse(ThriftTool.ToString(col.Value));
                                }
                                if (name == "Article")
                                {
                                    rl.Article = ThriftTool.ToString(col.Value);
                                }
                                if (name == "Link")
                                {
                                    rl.Link = ThriftTool.ToString(col.Value);
                                }
                                if (name == "Popular")
                                {
                                    rl.Popular = ThriftTool.ToString(col.Value);
                                }
                                if (name == "Date")
                                {
                                    rl.Date = DateTime.Parse(ThriftTool.ToString(col.Value));
                                }
                                if (name == "Change")
                                {
                                    rl.Change = ThriftTool.ToString(col.Value);
                                }
                            }
                            rank.Add(rl);
                        }
                    }
                }
            }

            ThriftTool.TransportClose();
            var ranks = from n in rank orderby n.Rank select n;

            return(ranks);
        }