示例#1
0
        // read each file and compile their stats
        static void aggregate(List <string> match_ids, Items items, string cache_dir)
        {
            List <int> used_matches = new List <int>();
            Random     rng          = new Random();

            int availible_match_ids = match_ids.Count();

            RequestBlock blocker = new RequestBlock(10, 10, 500, 600);

            // loop on data
            // while (match_index < match_ids.Count())
            for (int game_count = 0; game_count < sample_size; game_count++)
            {
                // get random unused match
                int match_index = rng.Next(0, availible_match_ids);
                int attempts;
                for (attempts = 0; (used_matches.Contains(match_index)) && (attempts < availible_match_ids); attempts++)
                {
                    match_index = rng.Next(0, availible_match_ids);
                }

                // if no more availible matches, stop
                if (attempts == availible_match_ids)
                {
                    return;
                }

                used_matches.Add(match_index);

                string match_id = match_ids[match_index];
                Console.WriteLine("game {0,-4}: index {1,4}, match {2}", game_count, match_index, match_id);

                string cache_file = cache(cache_dir, match_id, blocker);
                if (cache_file == null)
                {
                    game_count--;
                    continue;
                }

                using (StreamReader file = File.OpenText(cache_file))
                {
                    try
                    {
                        JsonTextReader data = new JsonTextReader(file);
                        if (data != null)
                        {
                            read(data, items);
                            //simple output to show the # of items in the game
                            // Console.WriteLine("Match id: {0}", all_ids[match_index]);
                            // items.print(game_count + 1);
                            // Console.WriteLine("Number of games left to check: {0}\n", sample_size - game_count + 1);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                        game_count--;
                        continue;
                    }
                }
            }
        }