public void TestCompletenessReportGenerationSmard()
        {
            MiniProfiler profiler             = MiniProfiler.StartNew(nameof(TestCompletenessReportGenerationSmard));
            IList <CompletenessReport> crlist = new List <CompletenessReport>();

            foreach (string boFile in Directory.GetFiles("Energiemenge/completeness", "50hz_prognose*.json"))
            {
                using (MiniProfiler.Current.Step($"Processing file {boFile}"))
                {
                    JObject json;
                    using (StreamReader r = new StreamReader(boFile))
                    {
                        string jsonString = r.ReadToEnd();
                        json = JsonConvert.DeserializeObject <JObject>(jsonString);
                    }
                    Energiemenge       em = (Energiemenge)BoMapper.MapObject(json, LenientParsing.Strict);
                    CompletenessReport cr = em.GetCompletenessReport();
                    crlist.Add(cr);
                    if (boFile.Contains("onshore.json"))
                    {
                        Assert.IsNotNull(cr.UserProperties);
                        Assert.AreEqual <string>("yippi yippi yeah", cr.UserProperties["meineUp0"].Value <string>());
                        Assert.AreEqual <string>("krawall und remmidemmi", cr.UserProperties["meineUp1"].Value <string>());
                    }
                }
            }
            string resultString = JsonConvert.SerializeObject(crlist, new StringEnumConverter());

            profiler.Stop();
            System.Diagnostics.Debug.WriteLine($"Profiler results: {profiler.RenderPlainText()}");
        }
示例#2
0
 protected async override Task OnInitializedAsync()
 {
     _profiler = MiniProfiler.StartNew(nameof(OnInitializedAsync));
     using (_profiler.Step(nameof(StartAsync)))
     {
         await StartAsync();
     }
     Console.WriteLine(_profiler.RenderPlainText());
 }
示例#3
0
        public void Save(MiniProfiler profiler)
        {
            if (!_logger.IsEnabled(_profilingLevel))
            {
                return;
            }

            using (_logger.BeginScope(_formatter.Invoke(profiler)))
            {
                _logger.Log(_profilingLevel, profiler.RenderPlainText());
            }
        }
示例#4
0
        public async Task OnIterationAsync(int iterations)
        {
            using (_profiler.Step(nameof(OnIterationAsync)))
            {
                var lastPopulationKey = _populationHistory.Max(x => x.Key);

                var newPopulationHistory = EvolutionService.RunIterations(iterations: iterations,
                                                                          maxDiffBetweenNode: _maxDiffBetweenNode,
                                                                          population: _populationHistory[lastPopulationKey],
                                                                          matrix: _matrix);

                var bestChromosomeFromHistory = _populationHistory.Select(x => x.Value.BestChromosome)
                                                .OrderBy(x => x.FactorsSum)
                                                .FirstOrDefault()
                                                .DeepCopy();

                foreach (var populationHistory in newPopulationHistory)
                {
                    _populationHistory.Add(populationHistory.Iteration, populationHistory);
                }

                for (int populationKey = lastPopulationKey + 1; populationKey < _populationHistory.Max(x => x.Key); populationKey++)
                {
                    bestChromosomeFromHistory = bestChromosomeFromHistory.FactorsSum < _populationHistory[populationKey].BestChromosome.FactorsSum ?
                                                bestChromosomeFromHistory.DeepCopy() : _populationHistory[populationKey].BestChromosome.DeepCopy();

                    _bestChromosomeChartData.Add(CanvasJsChartService.MapToDataPoint(bestChromosomeFromHistory.FactorsSum, _populationHistory[populationKey].Iteration));

                    var dataPoints = CanvasJsChartService.MapPopulationToDataPoints(_populationHistory[populationKey]);
                    _evolutionChartData = CanvasJsChartService.AddToDataPoints(_evolutionChartData, dataPoints);
                }

                _paretoChartData = ParetoService.GetParetoFrontier(_populationHistory).ToList();

                _paretoConfig.Data = CanvasJsChartService.GetParetoChartData(_paretoChartData);

                _evolutionConfig.Data = CanvasJsChartService.GetEvolutionChartData(_evolutionChartData, _bestChromosomeChartData);

                _graphData    = GraphChartService.GraphDataFromChromosome(bestChromosomeFromHistory, _matrix);
                _graphOptions = GraphChartService.GetBestChromosomeGraphOptions();

                await Task.Run(() => { _graphChart.RenderAsync(_graphData, _graphOptions); });

                await Task.Run(() => { _evolutionChart.RenderAsync(_evolutionConfig); });

                await Task.Run(() => { _paretoChart.RenderAsync(_paretoConfig); });
            }
            Console.WriteLine(_profiler.RenderPlainText());
            GC.Collect();
        }
        public void TestParallization()
        {
            for (int i = 0; i < 10; i++)
            {
                Energiemenge em;
                using (StreamReader r = new StreamReader(Directory.GetFiles("Energiemenge/completeness", "threeyears.json").First()))
                {
                    string jsonString = r.ReadToEnd();
                    em = JsonConvert.DeserializeObject <Energiemenge>(jsonString);
                }
                MiniProfiler mpFixSapCds = MiniProfiler.StartNew("Fix SAP CDS");
                em.FixSapCDSBug();
                mpFixSapCds.Stop();
                Assert.IsTrue(mpFixSapCds.DurationMilliseconds < 500, mpFixSapCds.RenderPlainText());
                Console.Out.WriteLine(mpFixSapCds.RenderPlainText());

                MiniProfiler mpFixSapCds2 = MiniProfiler.StartNew("Fix SAP CDS");
                em.FixSapCDSBug();
                mpFixSapCds2.Stop();
                Assert.IsTrue(mpFixSapCds2.DurationMilliseconds * 10 < mpFixSapCds.DurationMilliseconds);


                MiniProfiler mpLinear = MiniProfiler.StartNew("Non-Parallel");
                em.GetMonthlyCompletenessReports(new TimeRange(new DateTime(2016, 1, 31, 23, 0, 0, DateTimeKind.Utc), new DateTime(2016, 12, 31, 23, 0, 0, DateTimeKind.Utc)), useParallelExecution: false);
                mpLinear.Stop();
                Console.Out.Write(mpLinear.RenderPlainText());
                Assert.IsTrue(mpLinear.DurationMilliseconds < 4000, $"Linear completeness report generation was too slow. Expected less than 4 seconds but was {mpLinear.DurationMilliseconds}ms: {mpLinear.RenderPlainText()}");

                MiniProfiler mpParallel = MiniProfiler.StartNew("Parallel");
                em.GetMonthlyCompletenessReports(new TimeRange(new DateTime(2016, 1, 31, 23, 0, 0, DateTimeKind.Utc), new DateTime(2016, 12, 31, 23, 0, 0, DateTimeKind.Utc)), useParallelExecution: true);
                mpParallel.Stop();
                Console.Out.Write(mpParallel.RenderPlainText());
                //Assert.IsTrue(mpParallel.DurationMilliseconds < 3000, $"Parallel completeness report generation was too slow. Expected less than 3 seconds but was {mpParallel.DurationMilliseconds}ms: {mpParallel.RenderPlainText()}");
                //Assert.IsTrue(mpParallel.DurationMilliseconds < (int)mpLinear.DurationMilliseconds * 1.25M, $"Parallel: {mpParallel.DurationMilliseconds}, Non-Parallel: {mpLinear.DurationMilliseconds}");
            }
            //int a = 0;
        }
        public void TestDailyParallization()
        {
            //Energiemenge em ;
            //using (StreamReader r = new StreamReader(Directory.GetFiles("BusinessObjectExtensions/Energiemenge/completeness", "threeyears.json").First()))
            //{
            //    string jsonString = r.ReadToEnd();
            //    em = JsonConvert.DeserializeObject<Energiemenge>(jsonString);
            //}
            Energiemenge     em       = new Energiemenge();
            DateTime         dateTime = DateTime.Parse("2015-01-31 22:45:00");
            List <Verbrauch> listvb   = new List <Verbrauch>();

            for (int u = 0; u < 1500; u++)
            {
                dateTime = dateTime.AddMinutes(15);
                DateTime endDateTime = dateTime.AddMinutes(15);

                listvb.Add(new Verbrauch()
                {
                    Startdatum = dateTime, Enddatum = endDateTime, Einheit = Mengeneinheit.JAHR, Wert = 12
                });
                dateTime = endDateTime;
            }
            em.Energieverbrauch = listvb;

            MiniProfiler mpLinear = MiniProfiler.StartNew("Non-Parallel");

            em.GetMonthlyCompletenessReports(new TimeRange(new DateTime(2015, 1, 1, 23, 00, 0, DateTimeKind.Utc), new DateTime(2019, 12, 31, 23, 0, 0, DateTimeKind.Utc)), useParallelExecution: false);
            mpLinear.Stop();
            Console.Out.Write(mpLinear.RenderPlainText());
            //Assert.IsTrue(mpLinear.DurationMilliseconds < 4000, $"Linear completeness report generation was too slow. Expected less than 4 seconds but was {mpLinear.DurationMilliseconds}ms: {mpLinear.RenderPlainText()}");

            MiniProfiler mpParallel = MiniProfiler.StartNew("Parallel");

            em.GetDailyCompletenessReports(new TimeRange(new DateTime(2015, 1, 01, 23, 0, 0, DateTimeKind.Utc), new DateTime(2019, 12, 31, 23, 0, 0, DateTimeKind.Utc)), useParallelExecution: true);
            mpParallel.Stop();
            Console.Out.Write(mpParallel.RenderPlainText());
            //Assert.IsTrue(mpParallel.DurationMilliseconds < 3000, $"Parallel completeness report generation was too slow. Expected less than 3 seconds but was {mpParallel.DurationMilliseconds}ms: {mpParallel.RenderPlainText()}");
            //Assert.IsTrue(mpParallel.DurationMilliseconds < (int)mpLinear.DurationMilliseconds * 1.25M, $"Parallel: {mpParallel.DurationMilliseconds}, Non-Parallel: {mpLinear.DurationMilliseconds}");
        }
        static void Main(string[] args)
        {
            var(listUser1, listUser2) = GetFakeData(10000);


            Console.WriteLine($"Starting Test");
            Profiler = MiniProfiler.StartNew(nameof(Profiler));
            using (Profiler.Step(nameof(ProcessList)))
            {
                // Do some work...
                ProcessList(
                    listUser1,
                    listUser2,
                    MINIMUM_INTERVAL_MINUTES,
                    MINIMUM_DISTANCE_METERS);
            }

            Console.WriteLine($"total loops => {innerLoopCount}");
            Console.WriteLine($"total match => {matchCount}");
            Console.WriteLine(Profiler.RenderPlainText());
            Console.ReadKey();
        }
示例#8
0
        public IMatrix GenerateMatrix(int nodeCount, double probability)
        {
            var tryCount = 0;

            int[][] result;
            var     random = new Random();

            using (_profiler.Step(nameof(GenerateMatrix)))
            {
                do
                {
                    result      = new int[nodeCount][];
                    probability = ProbabilityUtils.AdaptProbability(probability, tryCount);

                    for (var i = 0; i < nodeCount; i++)
                    {
                        result[i] = new int[nodeCount];
                        for (var j = 0; j < nodeCount; j++)
                        {
                            result[i][j] = _weigthIfHasNotEdge;
                        }
                    }
                    for (var i = 0; i < nodeCount; i++)
                    {
                        for (var j = (i + 1); j < nodeCount; j++)
                        {
                            var hasEdge = random.NextDouble() < probability;
                            result[i][j] = hasEdge ? (int)Math.Floor((random.NextDouble() * _maxEdgeWeigth) + _weigthIfHasEdge) : _weigthIfHasNotEdge;
                            result[j][i] = _weigthIfHasNotEdge;
                        }
                    }

                    tryCount++;
                } while (_graphConsistentService.IsConsistent(result) == false);
            }
            _profiler.Stop();
            Console.WriteLine(_profiler.RenderPlainText());
            return(new Matrix(result));
        }
示例#9
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            Logger.LogDebug("SchemaScripter started");

            var hasConfigError = false;

            if (string.IsNullOrWhiteSpace(Config.Server))
            {
                Logger.LogError($"Invalid {nameof(Config.Server)}");
                hasConfigError = true;
            }
            if (string.IsNullOrWhiteSpace(Config.User))
            {
                Logger.LogError($"Invalid {nameof(Config.User)}");
                hasConfigError = true;
            }
            if (string.IsNullOrWhiteSpace(Config.Password))
            {
                Logger.LogError($"Invalid {nameof(Config.Password)}");
                hasConfigError = true;
            }
            if (string.IsNullOrWhiteSpace(Config.Database))
            {
                Logger.LogError($"Invalid {nameof(Config.Database)}");
                hasConfigError = true;
            }
            if (string.IsNullOrWhiteSpace(Config.ExportFolder))
            {
                Logger.LogError($"Invalid {nameof(Config.ExportFolder)}");
                hasConfigError = true;
            }

            if (hasConfigError)
            {
                ApplicationLifetime.StopApplication();
                return;
            }

            var availability = await DB.CheckAvailabilityAsync();

            if (!availability.IsSuccess)
            {
                Logger.LogError(availability.ErrorMessage ?? "Error connecting to server");
                ApplicationLifetime.StopApplication();
                return;
            }
            if (!await DB.UseDatabaseAsync(Config.Database))
            {
                Logger.LogError($"Cannot connect to database {Config.Database}");
                ApplicationLifetime.StopApplication();
                return;
            }

            Profiler = MiniProfiler.StartNew(nameof(SchemaScripterService));

            using (Profiler.Step("Tables"))
            {
                await ExportTablesAsync(cancellationToken);
            }

            using (Profiler.Step("Stored Procedures"))
            {
                await ExportStoredProceduresAsync(cancellationToken);
            }

            using (Profiler.Step("Views"))
            {
                await ExportViewsAsync(cancellationToken);
            }

            using (Profiler.Step("Functions"))
            {
                await ExportFunctionsAsync(cancellationToken);
            }

            ExportViaSMO();

            await Profiler.StopAsync();

            Logger.LogDebug(Profiler.RenderPlainText());

            ApplicationLifetime.StopApplication();
        }
示例#10
0
 public void Profile()
 {
     Debug.WriteLine(m_profiler.RenderPlainText());
 }
示例#11
0
 private string GetProfilerText(MiniProfiler profiler)
 {
     return(profiler.RenderPlainText());
 }