コード例 #1
0
        public static IEnumerable <(string idDotace, string ico, int ageInDays)> CompanyAgeDuringSubsidy()
        {
            var dotSer = new Dotace.DotaceService();

            foreach (var dotace in dotSer.YieldAllDotace())
            {
                bool missingEssentialData = string.IsNullOrWhiteSpace(dotace.Prijemce?.Ico) ||
                                            !dotace.DatumPodpisu.HasValue;

                if (missingEssentialData)
                {
                    continue;
                }

                Firma firma = Firmy.Get(dotace.Prijemce.Ico);

                if (firma.PatrimStatu()) //nechceme státní firmy
                {
                    continue;
                }

                if (!firma.Datum_Zapisu_OR.HasValue) //nechceme firmy s chybějící hodnotou data zapisu do OR
                {
                    continue;
                }

                var companyAgeInDays = (dotace.DatumPodpisu.Value - firma.Datum_Zapisu_OR.Value).Days;

                yield return(idDotace : dotace.IdDotace, ico : firma.ICO, ageInDays : companyAgeInDays);
            }
        }
コード例 #2
0
        public Dictionary <string, (decimal Sum, int Count)> GetStatisticsForHolding(string ico)
        {
            var dotaceAggsH = new AggregationContainerDescriptor <Dotace>()
                              .Terms("icos", s => s
                                     .Field(f => f.Prijemce.Ico)
                                     .Size(5000)
                                     .Aggregations(a => a
                                                   .Sum("sum", ss => ss.Field(ff => ff.DotaceCelkem))
                                                   )
                                     );
            var dotaceSearchH = new DotaceService().SimpleSearch($"holding:{ico}", 1, 1,
                                                                 Searching.DotaceSearchResult.DotaceOrderResult.FastestForScroll, false,
                                                                 dotaceAggsH, exactNumOfResults: true);

            var items = ((BucketAggregate)dotaceSearchH.ElasticResults.Aggregations["icos"]).Items;

            Dictionary <string, (decimal Sum, int Count)> dict = items.ToDictionary(
                i => ((KeyedBucket <object>)i).Key.ToString(),
                i => ((decimal)((KeyedBucket <object>)i).Sum("sum").Value,
                      (int)((KeyedBucket <object>)i).DocCount)
                );

            return(dict);
        }
コード例 #3
0
        private static MultiResult GeneralSearch(Elastic.Apm.Api.ITransaction apmtran, string query, int page = 1, int pageSize = 10, bool showBeta = false, string order = null)
        {
            MultiResult res = new MultiResult()
            {
                Query = query
            };

            if (string.IsNullOrEmpty(query))
            {
                return(res);
            }

            if (!Lib.Searching.Tools.ValidateQuery(query))
            {
                res.Smlouvy         = new Searching.SmlouvaSearchResult();
                res.Smlouvy.Q       = query;
                res.Smlouvy.IsValid = false;

                return(res);
            }

            var totalsw = new Devmasters.DT.StopWatchEx();

            totalsw.Start();

            ParallelOptions po = new ParallelOptions();

            //po.MaxDegreeOfParallelism = 20;
            po.MaxDegreeOfParallelism = System.Diagnostics.Debugger.IsAttached ? 1 : po.MaxDegreeOfParallelism;

            Parallel.Invoke(po,
                            () =>
            {
                Elastic.Apm.Api.ISpan sp = null;
                try
                {
                    apmtran.CaptureSpan("Smlouvy", "search", () =>
                    {
                        res.Smlouvy = HlidacStatu.Lib.Data.Smlouva.Search.SimpleSearch(query, 1, pageSize, order,
                                                                                       anyAggregation: new Nest.AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Sum("sumKc", m => m.Field(f => f.CalculatedPriceWithVATinCZK))
                                                                                       );
                    });
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Smlouvy query" + query, e);
                }
                finally
                {
                    sp?.End();
                }
            },
                            () =>
            {
                try
                {
                    Devmasters.DT.StopWatchEx sw = new Devmasters.DT.StopWatchEx();
                    sw.Start();

                    res.Firmy = Firma.Search.SimpleSearch(query, 0, 50);
                    sw.Stop();
                    res.Firmy.ElapsedTime = sw.Elapsed;
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Firmy query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    res.VZ = VZ.VerejnaZakazka.Searching.SimpleSearch(query, null, 1, pageSize, order);
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Verejne zakazky query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    Devmasters.DT.StopWatchEx sw = new Devmasters.DT.StopWatchEx();
                    sw.Start();

                    res.Osoby = Osoba.Search.SimpleSearch(query, 1, 10, Osoba.Search.OrderResult.Relevance);
                    sw.Stop();
                    res.Osoby.ElapsedTime = sw.Elapsed;
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Osoba query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    var iqu = new Searching.InsolvenceSearchResult {
                        Q = query, PageSize = pageSize, Order = order
                    };
                    res.Insolvence = iqu;
                    //if (showBeta)
                    res.Insolvence = Insolvence.Insolvence.SimpleSearch(new Searching.InsolvenceSearchResult {
                        Q = query, PageSize = pageSize, Order = order
                    });
                }
                catch (System.Exception e)
                {
                    Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    var dotaceService = new Dotace.DotaceService();
                    var iqu           = new Searching.DotaceSearchResult {
                        Q = query, PageSize = pageSize, Order = order
                    };
                    res.Dotace = dotaceService.SimpleSearch(
                        new Searching.DotaceSearchResult {
                        Q = query, PageSize = pageSize, Order = order
                    },
                        anyAggregation: new Nest.AggregationContainerDescriptor <Lib.Data.Dotace.Dotace>().Sum("souhrn", s => s.Field(f => f.DotaceCelkem))
                        );
                }
                catch (System.Exception e)
                {
                    Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    apmtran.CaptureSpan("Dataset GeneralSearch", "search", () =>
                    {
                        res.Datasets = Lib.Data.Search.DatasetMultiResult.GeneralSearch(query, null, 1, 5);
                        if (res.Datasets.Exceptions.Count > 0)
                        {
                            HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query,
                                                                 res.Datasets.GetExceptions());
                        }
                    });
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query, e);
                }
                finally
                {
                }
            }

                            );

            //TODO too slow, temporarily disabled

            totalsw.Stop();
            res.TotalSearchTime = totalsw.Elapsed;

            return(res);
        }
コード例 #4
0
        private static MultiResult GeneralSearch(Elastic.Apm.Api.ITransaction apmtran, string query, int page = 1, int pageSize = 10, bool showBeta = false)
        {
            MultiResult res = new MultiResult()
            {
                Query = query
            };

            if (string.IsNullOrEmpty(query))
            {
                return(res);
            }

            if (!Lib.Searching.Tools.ValidateQuery(query))
            {
                res.Smlouvy         = new Searching.SmlouvaSearchResult();
                res.Smlouvy.Q       = query;
                res.Smlouvy.IsValid = false;

                return(res);
            }

            var totalsw = new Devmasters.Core.StopWatchEx();

            totalsw.Start();

            ParallelOptions po = new ParallelOptions();

            //po.MaxDegreeOfParallelism = 20;
            po.MaxDegreeOfParallelism = System.Diagnostics.Debugger.IsAttached ? 1 : po.MaxDegreeOfParallelism;

            Parallel.Invoke(po,
                            () =>
            {
                Elastic.Apm.Api.ISpan sp = null;
                try
                {
                    apmtran.CaptureSpan("Smlouvy", "search", () =>
                    {
                        res.Smlouvy = HlidacStatu.Lib.Data.Smlouva.Search.SimpleSearch(query, 1, 20, Smlouva.Search.OrderResult.Relevance,
                                                                                       anyAggregation: new Nest.AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Sum("sumKc", m => m.Field(f => f.CalculatedPriceWithVATinCZK))
                                                                                       );
                    });
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Smlouvy query" + query, e);
                }
                finally
                {
                    sp?.End();
                }
            },
                            () =>
            {
                try
                {
                    Devmasters.Core.StopWatchEx sw = new Devmasters.Core.StopWatchEx();
                    sw.Start();

                    res.Firmy = new GeneralResult <string>(Firma.Search.FindAllIco(query, 50));
                    sw.Stop();
                    res.Firmy.ElapsedTime = sw.Elapsed;
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Firmy query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    res.VZ = VZ.VerejnaZakazka.Searching.SimpleSearch(query, null, 1, 5, (int)Lib.Searching.VerejnaZakazkaSearchData.VZOrderResult.Relevance);
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Verejne zakazky query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    Devmasters.Core.StopWatchEx sw = new Devmasters.Core.StopWatchEx();
                    sw.Start();

                    if (!string.IsNullOrEmpty(query) && query.Length > 2)
                    {
                        res.Osoby = new GeneralResult <Osoba>(
                            HlidacStatu.Lib.Data.Osoba.GetPolitikByNameFtx(query, 100)
                            .OrderBy(m => m.Prijmeni)
                            .ThenBy(m => m.Jmeno)
                            );
                    }
                    else
                    {
                        res.Osoby = new GeneralResult <Osoba>(new Osoba[] { });
                    }
                    sw.Stop();
                    res.Osoby.ElapsedTime = sw.Elapsed;
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Osoba query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    var iqu = new Searching.InsolvenceSearchResult {
                        Q = query, PageSize = 5
                    };
                    res.Insolvence = iqu;
                    //if (showBeta)
                    res.Insolvence = Insolvence.Insolvence.SimpleSearch(new Searching.InsolvenceSearchResult {
                        Q = query, PageSize = 5
                    });
                }
                catch (System.Exception e)
                {
                    Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    if (showBeta)
                    {
                        var dotaceService = new Dotace.DotaceService();
                        var iqu           = new Searching.DotaceSearchResult {
                            Q = query, PageSize = 5
                        };
                        res.Dotace = iqu;
                        //if (showBeta)
                        res.Dotace = dotaceService.SimpleSearch(new Searching.DotaceSearchResult {
                            Q = query, PageSize = 5
                        });
                    }
                }
                catch (System.Exception e)
                {
                    Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e);
                }
            },
                            () =>
            {
                Elastic.Apm.Api.ISpan sp = null;
                try
                {
                    apmtran.CaptureSpan("Dataset GeneralSearch", "search", () =>
                    {
                        res.Datasets = Lib.Data.Search.DatasetMultiResult.GeneralSearch(query, null, 1, 5);
                        if (res.Datasets.Exceptions.Count > 0)
                        {
                            HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query,
                                                                 res.Datasets.GetExceptions());
                        }
                    });
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query, e);
                }
                finally
                {
                }
            }

                            );

            //TODO too slow, temporarily disabled
            if (false && res.HasFirmy && (res.Osoby == null || res.Osoby.Total < 5))
            {
                var sw = new Devmasters.Core.StopWatchEx();
                sw.Start();
                if (res.Osoby == null)
                {
                    res.Osoby = new GeneralResult <Osoba>(new Osoba[] { });
                }

                res.Osoby = new GeneralResult <Osoba>(res.Osoby.Result
                                                      .Concat(Osoba.GetPolitikByQueryFromFirmy(query, (int)(10 - (res.Osoby?.Total ?? 0)), res.Firmy.Result)
                                                              )
                                                      );
                res.OsobaFtx = true;
                sw.Stop();
                res.AddOsobyTime = sw.Elapsed;
            }

            totalsw.Stop();
            res.TotalSearchTime = totalsw.Elapsed;

            return(res);
        }