Ejemplo n.º 1
0
        /// <summary>
        /// 汇总输出
        /// </summary>
        public static void OutPutData()
        {
            string host = "localhost";

            using (RedisClient redisClient = new RedisClient(host))
            {
                var locateCount = redisClient.ZCard("AllLocates");
                var allLocateData = redisClient.ZRange("AllLocates", 0, (int)locateCount);
                List<string> allLocate = new List<string>();
                for (int i = 0; i < allLocateData.Length; i++)
                {
                    allLocate.Add(System.Text.Encoding.UTF8.GetString(allLocateData[i]));
                }
                allLocate = allLocate.OrderBy(p => p).ToList();

                Console.WriteLine("开始输出时间序列数据");
                FileStream fs = new FileStream(OutputPath, FileMode.Create);
                StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
                long total = 0;
                for (int h = 0; h < 24; h++)
                {
                    for (int m = 0; m < 60; m += 5)
                    {
                        var pre = string.Format("2014-09-07-{0:D2}:{1:D2}", h, m);
                        Console.WriteLine(string.Format("------------时段:{0}------------", pre));
                        for (int i = 0; i < allLocate.Count; i++)
                        {
                            string key = pre + "@" + allLocate[i];
                            var value = redisClient.Get(key);
                            string count = (value == null ? "0" : System.Text.Encoding.Default.GetString(value));
                            total += int.Parse(count);
                            sw.WriteLine(string.Format("{0},{1},{2}", pre, allLocate[i], count));
                        }
                    }

                }
                sw.Close();
                fs.Close();
                Console.WriteLine(string.Format("------------总和:{0}------------", total));
            }
        }