Ejemplo n.º 1
0
        public void Add(NetworkData data)
        {
            if (data.Date < MinDate)
            {
                MinDate = data.Date;
            }
            if (data.Date > MaxDate)
            {
                MaxDate = data.Date;
            }

            if (data.Mbps < 0)
            {
                // this is an error
                if (string.IsNullOrWhiteSpace(data.Message))
                {
                    throw new Exception("Error without a message");
                }
                ErrorCount++;
                ErrorDuration += data.Duration;
            }
            else
            {
                // this is a success case
                if (!string.IsNullOrWhiteSpace(data.Message))
                {
                    throw new Exception("Success with a message");
                }
                Count++;
                Duration += data.Duration;
                Mbps     += data.Mbps;

                if (data.Duration < MinDuration)
                {
                    MinDuration = data.Duration;
                }
                if (data.Duration > MaxDuration)
                {
                    MaxDuration = data.Duration;
                }
                if (data.Mbps < MinMbps)
                {
                    MinMbps = data.Mbps;
                }
                if (data.Mbps > MaxMbps)
                {
                    MaxMbps = data.Mbps;
                }
            }
        }
Ejemplo n.º 2
0
        public static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("./analytics InputDirectory <Day|Hour|Minute|Second>");
                Console.WriteLine("  this tool will parse the *.tsv files");
                Console.WriteLine("  and provide analytics");
                return(1);
            }

            // check that the TimeOfDay has the first letter upper case
            var todstr = args[1].ToLower();

            todstr = Char.ToUpper(todstr[0]) + todstr.Substring(1);

            // input
            var path = args[0];
            var tod  = Enum.Parse <TimeOfDay>(todstr);

            // load data
            var results = new Dictionary <string, List <NetworkData> >();

            foreach (var file in Directory.GetFiles(path, "*.tsv"))
            {
                Console.WriteLine($"Opening {file}...");
                var data = NetworkData.Parse(file);
                results.Add(Path.GetFileNameWithoutExtension(file), data);
            }

            // gather day long stats
            DisplayHeader();
            foreach (var kvp in results)
            {
                var stats = Analyze(kvp.Value, tod);
                Display(kvp.Key, stats);
            }

            return(0);
        }