Exemple #1
0
        public static VazbyFiremNaPolitiky LoadFirmySVazbamiNaPolitiky(Relation.AktualnostType aktualnostVztahu, bool showProgress = false)
        {
            Dictionary <string, List <int> > pol_SVazbami             = new Dictionary <string, List <int> >();
            Dictionary <string, List <int> > pol_SVazbami_StatniFirmy = new Dictionary <string, List <int> >();

            Devmasters.Core.Batch.Manager.DoActionForAll <Osoba>(StaticData.Politici.Get(),
                                                                 (p) =>
            {
                var vazby = p.AktualniVazby(aktualnostVztahu);
                if (vazby != null && vazby.Count() > 0)
                {
                    foreach (var v in vazby)
                    {
                        if (!string.IsNullOrEmpty(v.To.Id))
                        {
                            //check if it's GovType company
                            Firma f = Firmy.Get(v.To.Id);
                            //if (f == null)
                            //{
                            //    f = External.GovData.FromIco(v.To.Id);
                            //    if (f == null)
                            //        continue; //unknown company, skip
                            //}
                            if (!Firma.IsValid(f))
                            {
                                continue; //unknown company, skip
                            }
                            if (f.JsemStatniFirma())
                            {
                                //Gov Company
                                if (pol_SVazbami_StatniFirmy.ContainsKey(v.To.Id))
                                {
                                    var pol = pol_SVazbami_StatniFirmy[v.To.Id];
                                    if (!pol.Any(m => m == p.InternalId))
                                    {
                                        pol.Add(p.InternalId);
                                    }
                                }
                                else
                                {
                                    pol_SVazbami_StatniFirmy.Add(v.To.Id, new List <int>());
                                    pol_SVazbami_StatniFirmy[v.To.Id].Add(p.InternalId);
                                }
                            }
                            else
                            {
                                //private company
                                if (pol_SVazbami.ContainsKey(v.To.Id))
                                {
                                    var pol = pol_SVazbami[v.To.Id];
                                    if (!pol.Any(m => m == p.InternalId))
                                    {
                                        pol.Add(p.InternalId);
                                    }
                                }
                                else
                                {
                                    pol_SVazbami.Add(v.To.Id, new List <int>());
                                    pol_SVazbami[v.To.Id].Add(p.InternalId);
                                }
                            }
                        }
                    }
                }
                return(new Devmasters.Core.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            },
                                                                 showProgress ? Devmasters.Core.Batch.Manager.DefaultOutputWriter : (Action <string>)null,
                                                                 showProgress ? new Devmasters.Core.Batch.ActionProgressWriter().Write : (Action <ActionProgressData>)null,
                                                                 false
                                                                 , prefix: "LoadFirmySVazbamiNaPolitiky " + aktualnostVztahu.ToNiceDisplayName()
                                                                 );

            return(new VazbyFiremNaPolitiky()
            {
                SoukromeFirmy = pol_SVazbami, StatniFirmy = pol_SVazbami_StatniFirmy
            });
        }
Exemple #2
0
        public static IEnumerable <IcoSmlouvaMinMax> GetFirmyCasovePodezreleZalozene(Action <string> logOutputFunc = null, Action <ActionProgressData> progressOutputFunc = null)
        {
            var allIcos = Lib.Data.External.FirmyDB.AllIcoInRS();
            Dictionary <string, AnalysisCalculation.IcoSmlouvaMinMax> firmy = new Dictionary <string, AnalysisCalculation.IcoSmlouvaMinMax>();
            object lockFirmy = new object();
            var    client    = HlidacStatu.Lib.ES.Manager.GetESClient();
            AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva> aggs = new AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>()
                                                                                 .Min("minDate", m => m
                                                                                      .Field(f => f.datumUzavreni)
                                                                                      );


            Devmasters.Core.Batch.Manager.DoActionForAll <string, object>(allIcos,
                                                                          (ico, param) =>
            {
                var res = HlidacStatu.Lib.ES.SearchTools.SimpleSearch("ico:" + ico, 0, 0, HlidacStatu.Lib.ES.SearchTools.OrderResult.FastestForScroll, aggs);
                if (res.Result.Aggregations.Count > 0)
                {
                    var epoch = ((Nest.ValueAggregate)res.Result.Aggregations.First().Value).Value;
                    if (epoch.HasValue)
                    {
                        var mindate = Devmasters.Core.DateTimeUtil.FromEpochTimeToUTC((long)epoch / 1000);

                        lock (lockFirmy)
                        {
                            if (firmy.ContainsKey(ico))
                            {
                                if (firmy[ico].minUzavreni.HasValue == false)
                                {
                                    firmy[ico].minUzavreni = mindate;
                                }
                                else if (firmy[ico].minUzavreni.Value > mindate)
                                {
                                    firmy[ico].minUzavreni = mindate;
                                }
                            }
                            else
                            {
                                firmy.Add(ico, new AnalysisCalculation.IcoSmlouvaMinMax()
                                {
                                    ico         = ico,
                                    minUzavreni = Devmasters.Core.DateTimeUtil.FromEpochTimeToUTC((long)epoch / 1000)
                                });
                            }
                        }
                    }
                }

                return(new Devmasters.Core.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            },
                                                                          null,
                                                                          logOutputFunc ?? Devmasters.Core.Batch.Manager.DefaultOutputWriter,
                                                                          progressOutputFunc ?? new Devmasters.Core.Batch.ActionProgressWriter(0.1f).Write,
                                                                          true
                                                                          );


            List <string> privateCompanyIcos = new List <string>();

            //filter statni firmy && add vznik

            Devmasters.Core.Batch.Manager.DoActionForAll <string, object>(firmy.Keys,
                                                                          (ico, param) =>
            {
                Firma ff = Firmy.Get(ico);
                if (Firma.IsValid(ff))
                {
                    if (ff.JsemStatniFirma()) //statni firmy tam nechci
                    {
                        return(new Devmasters.Core.Batch.ActionOutputData()
                        {
                            CancelRunning = false, Log = null
                        });
                    }
                    else
                    {
                        if (ff.Datum_Zapisu_OR.HasValue)
                        {
                            firmy[ico].vznikIco = ff.Datum_Zapisu_OR.Value;
                            firmy[ico].jmeno    = ff.Jmeno;
                            privateCompanyIcos.Add(ico);
                        }
                    }
                }

                return(new Devmasters.Core.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            },
                                                                          null,
                                                                          Devmasters.Core.Batch.Manager.DefaultOutputWriter,
                                                                          new Devmasters.Core.Batch.ActionProgressWriter(1f).Write,
                                                                          true, maxDegreeOfParallelism: 5
                                                                          );


            DateTime minDate = new DateTime(1990, 01, 01);
            var      badF    = firmy
                               .Where(kv => privateCompanyIcos.Contains(kv.Key))
                               .Select(m => m.Value)
                               .Where(f => f.minUzavreni > minDate)
                               .Where(f => f.days.HasValue && f.days.Value < 60)
                               .OrderBy(f => f.days.Value);

            //.Take(100)

            return(badF);
        }
Exemple #3
0
        public static AnalysisCalculation.VazbyFiremNaUradyStat UradyObchodujiciSFirmami_s_vazbouNaPolitiky(Relation.AktualnostType aktualnost, bool showProgress = false)
        {
            HlidacStatu.Lib.Data.AnalysisCalculation.VazbyFiremNaPolitiky vazbyNaPolitiky = null;
            List <Lib.Data.FirmaEvent> sponzorujiciFirmy = null;

            QueryContainer qc = null;

            switch (aktualnost)
            {
            case HlidacStatu.Lib.Data.Relation.AktualnostType.Aktualni:
                vazbyNaPolitiky = StaticData.FirmySVazbamiNaPolitiky_aktualni_Cache.Get();
                qc = new QueryContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Term(t => t.Field(f => f.SVazbouNaPolitikyAktualni).Value(true));
                sponzorujiciFirmy = StaticData.SponzorujiciFirmy_Nedavne.Get();
                break;

            case HlidacStatu.Lib.Data.Relation.AktualnostType.Nedavny:
                vazbyNaPolitiky = StaticData.FirmySVazbamiNaPolitiky_nedavne_Cache.Get();
                qc = new QueryContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Term(t => t.Field(f => f.SVazbouNaPolitikyNedavne).Value(true));
                sponzorujiciFirmy = StaticData.SponzorujiciFirmy_Nedavne.Get();
                break;

            case HlidacStatu.Lib.Data.Relation.AktualnostType.Neaktualni:
            case HlidacStatu.Lib.Data.Relation.AktualnostType.Libovolny:
                vazbyNaPolitiky = StaticData.FirmySVazbamiNaPolitiky_vsechny_Cache.Get();
                qc = new QueryContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Term(t => t.Field(f => f.SVazbouNaPolitiky).Value(true));
                sponzorujiciFirmy = StaticData.SponzorujiciFirmy_Vsechny.Get();
                break;
            }


            Func <int, int, Nest.ISearchResponse <Lib.Data.Smlouva> > searchFunc = null;

            searchFunc = (size, page) =>
            {
                return(Lib.ES.Manager.GetESClient().Search <Lib.Data.Smlouva>(a => a
                                                                              .Size(size)
                                                                              .From(page * size)
                                                                              .Source(m => m.Excludes(e => e.Field(o => o.Prilohy)))
                                                                              .Query(q => qc)
                                                                              .Scroll("5m")
                                                                              ));
            };


            //TODO predelat z projeti vsech smluv na hledani pres vsechna ICO  v RS, vybrani statnich firem,
            //a dohlednai jejich statistiky vuci jednotlivym ostatnim firmam v RS
            Dictionary <string, Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > > > uradyStatni = new Dictionary <string, Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > > >();
            Dictionary <string, Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > > > uradySoukr  = new Dictionary <string, Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > > >();
            object lockObj = new object();

            Lib.ES.SearchTools.DoActionForQuery <Lib.Data.Smlouva>(Lib.ES.Manager.GetESClient(), searchFunc,
                                                                   (hit, param) =>
            {
                Lib.Data.Smlouva s = hit.Source;
                List <string> icos = new List <string>();
                try
                {
                    var objednatelIco = s.Platce.ico;
                    if (!string.IsNullOrEmpty(objednatelIco))
                    {
                        Firma ff = Firmy.Get(objednatelIco);
                        if (!ff.Valid || !ff.JsemStatniFirma())
                        {
                            goto end;
                        }

                        //vsichni prijemci smlouvy statniho subjektu
                        icos.AddRange(s.Prijemce.Select(m => m.ico).Where(m => !string.IsNullOrEmpty(m)).Distinct());

                        lock (lockObj)
                        {
                            foreach (var ico in icos)
                            {
                                if (vazbyNaPolitiky.SoukromeFirmy.ContainsKey(ico) || sponzorujiciFirmy.Any(m => m.ICO == ico))
                                {
                                    if (!uradySoukr.ContainsKey(objednatelIco))
                                    {
                                        uradySoukr.Add(objednatelIco, new Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > >());
                                        uradySoukr[objednatelIco].Ico = objednatelIco;
                                    }
                                    uradySoukr[objednatelIco].Add(1, s.CalculatedPriceWithVATinCZK);
                                    if (!uradySoukr[objednatelIco].Detail.Any(m => m.Item == ico))
                                    {
                                        uradySoukr[objednatelIco].Detail.Add(new Analysis.BasicData <string>()
                                        {
                                            Item = ico, CelkemCena = s.CalculatedPriceWithVATinCZK, Pocet = 1
                                        });
                                    }
                                    else
                                    {
                                        var item = uradySoukr[objednatelIco].Detail.First(m => m.Item == ico);
                                        item.Add(1, s.CalculatedPriceWithVATinCZK);
                                    }
                                }
                                else if (vazbyNaPolitiky.StatniFirmy.ContainsKey(ico))
                                {
                                    if (!uradyStatni.ContainsKey(objednatelIco))
                                    {
                                        uradyStatni.Add(objednatelIco, new Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > >());
                                        uradyStatni[objednatelIco].Ico = objednatelIco;
                                    }
                                    uradyStatni[objednatelIco].Add(1, s.CalculatedPriceWithVATinCZK);
                                    if (!uradyStatni[objednatelIco].Detail.Any(m => m.Item == ico))
                                    {
                                        uradyStatni[objednatelIco].Detail.Add(new Analysis.BasicData <string>()
                                        {
                                            Item = ico, CelkemCena = s.CalculatedPriceWithVATinCZK, Pocet = 1
                                        });
                                    }
                                    else
                                    {
                                        var item = uradyStatni[objednatelIco].Detail.First(m => m.Item == ico);
                                        item.Add(1, s.CalculatedPriceWithVATinCZK);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("ERROR UradyObchodujiciSFirmami_s_vazbouNaPolitiky", e);
                }

                end:
                return(new Devmasters.Core.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            }, null,
                                                                   showProgress ? Devmasters.Core.Batch.Manager.DefaultOutputWriter : (Action <string>)null,
                                                                   showProgress ? new Devmasters.Core.Batch.ActionProgressWriter().Write : (Action <ActionProgressData>)null
                                                                   , true
                                                                   , prefix: "UradyObchodujiciSFirmami_s_vazbouNaPolitiky " + aktualnost.ToNiceDisplayName()
                                                                   );


            AnalysisCalculation.VazbyFiremNaUradyStat ret = new VazbyFiremNaUradyStat();
            ret.SoukromeFirmy = uradySoukr
                                .Where(m => m.Value.Pocet > 0)
                                .Select(kv => kv.Value)
                                .OrderByDescending(o => o.Pocet);

            return(ret);
        }