Beispiel #1
0
        public static void Upload(List <DeviceDetailDefault> devices, int insertsPerTransaction, string targetDb, int set)
        {
            var repo      = new SqlDbRepository();
            var converter = new DeviceDetailConvert();

            Console.WriteLine("Converting started!");
            var deviceToInsert = devices.Select(d => converter.Convert(d)).ToList();

            Console.WriteLine("Converting done!");

            int count = deviceToInsert.Count();

            Console.WriteLine($"Started uploading of {deviceToInsert.Count} devices at rate of {insertsPerTransaction} per transaction\n");
            // File.AppendAllText("results.csv", $"Started uploading of {deviceToInsert.Count} devices at rate of {insertsPerTransaction} per transaction\n");
            // File.AppendAllText("results.csv", "DbName,CurrentSet,TransactionsNumber,TimeInMilliseconds\n");
            var value             = "";
            var totalTransactions = count / insertsPerTransaction + 1;
            var startTime         = DateTime.Now;

            for (var i = 0; i < (count / insertsPerTransaction) + 1; i++)
            {
                var subStartTime = DateTime.Now;
                repo.AddDevices(deviceToInsert.Skip(i * insertsPerTransaction).Take(insertsPerTransaction));
                value = Math.Floor((DateTime.Now - subStartTime).TotalMilliseconds).ToString();
                File.AppendAllText("results.csv", $"{targetDb},Upload,{set},{(i + 1)},{value}\n");
                Console.Write($"{((double)(i + 1) / totalTransactions * 100).ToString("00.00")}% - {i + 1} out of {totalTransactions} done");
                Console.WriteLine($" {(DateTime.Now - subStartTime):mm\\m\\:ss\\s\\:fff\\m\\s}!");
            }

            Console.WriteLine($"{count / insertsPerTransaction + 1} transactions done in ~{(DateTime.Now - startTime):mm\\m\\:ss\\s\\:fff\\m\\s}!");
            // File.AppendAllText ("results.csv", $"{count / insertsPerTransaction + 1} transactions done in ~{(DateTime.Now - startTime):mm\\m\\:ss\\s\\:fff\\m\\s}!");
        }
Beispiel #2
0
        public static void Test(string targetDb, int set)
        {
            var repo      = new SqlDbRepository();
            var startTime = DateTime.Now;

            // Console.WriteLine ($"Started uploading of devices at rate of  per transaction\n");
            // File.AppendAllText ("results.csv", $"Download speed Testing\n");
            // File.AppendAllText("results.csv", "No,TimeInMilliseconds\n");

            System.Console.WriteLine("Getting devices");

            var devices = repo.GetDevices();
            // System.Console.WriteLine ("Devices got");
            var devicesList = devices.ToList();

            JsonConvert.SerializeObject(devices, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
            // System.Console.WriteLine ("Devices serialized");
            var value = Math.Floor((DateTime.Now - startTime).TotalMilliseconds).ToString();

            File.AppendAllText("results.csv", $"{targetDb},Download,{set},1,{value}\n");

            startTime = DateTime.Now;
            var data = repo.GetDevices()
                       .Where(p => p.Status.ReleasedDate.Year != null)
                       .OrderByDescending(p => p.Status.ReleasedDate.Year)
                       .GroupBy(p => p.Status.ReleasedDate.Year)
                       .Select(p => new {
                Year   = p.Key.ToString(),
                Memory = p
                         .Where(ph => ph.Memory.RandomAccess.HasValue)
                         .GroupBy(ph => ph.Memory.RandomAccess > 1000 ? $"{ph.Memory.RandomAccess/1024}GB" : $"<1GB")
                         .Select(ph => new {
                    RamInMB      = ph.Key,
                    PhonesAmount = ph.Select(d => d.Memory.RandomAccess).Count(),
                    Phones       = ph.Select(d => d.Name)
                })
            })
                       .ToList();

            JsonConvert.SerializeObject(data, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
            value = Math.Floor((DateTime.Now - startTime).TotalMilliseconds).ToString();
            File.AppendAllText("results.csv", $"{targetDb},RAM,{set},1,{value}\n");
            Console.WriteLine($"Query done in ~{(DateTime.Now - startTime):mm\\m\\:ss\\s\\:fff\\m\\s}!");
            // File.AppendAllText ("results.csv", $" done in ~{(DateTime.Now - startTime):mm\\m\\:ss\\s\\:fff\\m\\s}!");
        }