Exemple #1
0
        public static Firma FromIco(string ico, bool getMissingFromExternal = false)
        {
            Firma f = External.FirmyDB.FromIco(ico);

            if (Firma.IsValid(f))
            {
                return(f);
            }


            //f = External.OR_Elastic.FromIco(ico);
            //if (Firma.IsValid(f))
            //    return f;

            else if (getMissingFromExternal)
            {
                f = External.Merk.FromIco(ico);
                if (Firma.IsValid(f))
                {
                    return(f);
                }

                //f = External.Firmo.GetFirmaFromIco(ico);
                //if (Firma.IsValid(f))
                //    return f;
                //f = Lib.Data.External.GovData.FromIco(ico);

                if (!Firma.IsValid(f)) //try firmo
                {
                    f = External.RZP.FromIco(ico);
                }
                //if (!Firma.IsValid(f)) //try firmo
                //{
                //    f = Lib.Data.External.Firmo.GetFirmaFromIco(ico);
                //}
                if (f == null)
                {
                    return(Firma.NotFound);
                }
                else if (f == Firma.NotFound || f == Firma.LoadError)
                {
                    return(f);
                }

                f.RefreshDS();
                f.Save();
                return(f);
            }
            else
            {
                return(Firma.NotFound);
            }
        }
Exemple #2
0
        public static Firma FromDS(string ds, bool getMissingFromExternal = false)
        {
            Firma f = External.FirmyDB.FromDS(ds);

            if (!Firma.IsValid(f) && getMissingFromExternal)
            {
                var d = External.DatoveSchranky.ISDS.GetSubjektyForDS(ds);
                if (d != null)
                {
                    return(Firma.FromIco(d.ICO, getMissingFromExternal));
                }
            }

            return(f);
        }
        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.PatrimStatu())
                            {
                                //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
            });
        }
        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.PatrimStatu()) //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 #5
0
        public static IEnumerable <IcoSmlouvaMinMax> GetFirmyCasovePodezreleZalozene(Action <string> logOutputFunc = null, Action <ActionProgressData> progressOutputFunc = null)
        {
            HlidacStatu.Util.Consts.Logger.Debug("GetFirmyCasovePodezreleZalozene - getting all ico");
            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)
                                                                                      );


            HlidacStatu.Util.Consts.Logger.Debug("GetFirmyCasovePodezreleZalozene - getting first smlouva for all ico from ES");
            Devmasters.Batch.Manager.DoActionForAll <string, object>(allIcos,
                                                                     (ico, param) =>
            {
                Firma ff = Firmy.Get(ico);
                if (Firma.IsValid(ff))
                {
                    if (ff.PatrimStatu()) //statni firmy tam nechci
                    {
                        return(new Devmasters.Batch.ActionOutputData()
                        {
                            CancelRunning = false, Log = null
                        });
                    }
                    else
                    {
                        var res = HlidacStatu.Lib.Data.Smlouva.Search.SimpleSearch("ico:" + ico, 0, 0, HlidacStatu.Lib.Data.Smlouva.Search.OrderResult.FastestForScroll, aggs, exactNumOfResults: true);
                        if (res.ElasticResults.Aggregations.Count > 0)
                        {
                            var epoch = ((Nest.ValueAggregate)res.ElasticResults.Aggregations.First().Value).Value;
                            if (epoch.HasValue)
                            {
                                var mindate = Devmasters.DT.Util.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.DT.Util.FromEpochTimeToUTC((long)epoch / 1000)
                                        });
                                    }
                                    if (ff.Datum_Zapisu_OR.HasValue)
                                    {
                                        firmy[ico].vznikIco = ff.Datum_Zapisu_OR.Value;
                                        firmy[ico].jmeno    = ff.Jmeno;
                                    }
                                }
                            }
                        }
                    }
                }
                return(new Devmasters.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            },
                                                                     null,
                                                                     logOutputFunc ?? Devmasters.Batch.Manager.DefaultOutputWriter,
                                                                     progressOutputFunc ?? new Devmasters.Batch.ActionProgressWriter(0.1f).Write,
                                                                     true
                                                                     );


            //List<string> privateCompanyIcos = new List<string>();
            ////filter statni firmy && add vznik

            //Devmasters.Batch.Manager.DoActionForAll<string, object>(firmy.Keys,
            //(ico, param) =>
            //{
            //    Firma ff = Firmy.Get(ico);
            //    if (Firma.IsValid(ff))
            //    {
            //        if (ff.PatrimStatu()) //statni firmy tam nechci
            //        {
            //            return new Devmasters.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.Batch.ActionOutputData() { CancelRunning = false, Log = null };
            //},
            //null,
            //Devmasters.Batch.Manager.DefaultOutputWriter,
            //new Devmasters.Batch.ActionProgressWriter(1f).Write,
            //true, maxDegreeOfParallelism: 5
            //);

            HlidacStatu.Util.Consts.Logger.Debug("GetFirmyCasovePodezreleZalozene - filter with close dates");

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

            //.Take(100)

            HlidacStatu.Util.Consts.Logger.Debug($"GetFirmyCasovePodezreleZalozene - returning {badF.Count()} records.");

            return(badF);
        }