Exemplo n.º 1
0
        private void DoEIRProjectionTask(List <LifeTimeEADs> lifeTimeEAD, Guid masterGuid, int maxProjectionMonth)
        {
            //populate for EIR projections
            var eirProjections = new ECLTasks(this._eclId, this._eclType).EAD_EIRProjections(lifeTimeEAD, maxProjectionMonth);

            Log4Net.Log.Info("Completed EAD_EIRProjections");
            //insert into DB
            ExecuteNative.SaveEIRProjections(eirProjections, masterGuid, this._eclType);
            Log4Net.Log.Info("Completed SaveEIRProjections");
        }
Exemplo n.º 2
0
        private bool RunLGDJob(List <Loanbook_Data> lstRaw, Guid _eclId, EclType _eclType)
        {
            //lstRaw = lstRaw.Where(o => o.ContractNo.Contains("182NIFC162940002") || o.ContractId.Contains("182NIFC162940002")).ToList();
            //Next Line to be removed
            //lstRaw = lstRaw.Where(o => o.ContractStartDate == null && o.ContractEndDate == null).Take(5).ToList();
            _eclTask = new ECLTasks(_eclId, _eclType);
            var LGDPreCalc = _eclTask.LGDPreCalculation(lstRaw);

            Log4Net.Log.Info($"Done with LGD Precalculation - {DateTime.Now}");

            var collateral_R = _eclTask.Collateral_OMV_FSV(lstRaw, LGDPreCalc);

            Log4Net.Log.Info($"Computed Collateral OVM - {DateTime.Now}");

            ///
            /// Save Collateral OMV_FSV
            ///

            //Insert to Database
            ExecuteNative.SaveLGDCollaterals(collateral_R, _eclId, _eclType);
            Log4Net.Log.Info($"Save LGD Collateral - {DateTime.Now}");

            var corTable = _eclTask.CalculateCoR_Main(LGDPreCalc, lstRaw, collateral_R);

            Log4Net.Log.Info($"Done with Calculate CoR main - {DateTime.Now}");

            var accountData = _eclTask.AccountData(lstRaw, LGDPreCalc, collateral_R, corTable);

            Log4Net.Log.Info($"Done Calculating Account data - {DateTime.Now}");

            //Insert to Database
            ExecuteNative.SaveLGDAccountdata(accountData, _eclId, _eclType);
            Log4Net.Log.Info($"Saved LGD Account Data - {DateTime.Now}");

            return(true);
        }
Exemplo n.º 3
0
        public bool ProcessTask(List <Loanbook_Data> loanbooks)
        {
            try
            {
                paymentScheduleProjections = new List <PaymentSchedule>();
                var qry = Queries.PaymentSchedule(this._eclId, this._eclType);
                var _payment_schedule = DataAccess.i.GetData(qry);
                Log4Net.Log.Info("Completed Getting Payment Schedule");

                var payment_schedule = new List <PaymentSchedule>();
                foreach (DataRow dr in _payment_schedule.Rows)
                {
                    var itm = DataAccess.i.ParseDataToObject(new TempPaymentSchedule(), dr);
                    itm.ContractRefNo = itm.ContractRefNo.ToUpper();
                    itm.Component     = itm.Component.ToUpper();

                    payment_schedule.Add(new PaymentSchedule {
                        Amount = itm.Amount, Component = itm.Component, ContractRefNo = itm.ContractRefNo, StartDate = itm.StartDate, Frequency = itm.Frequency, NoOfSchedules = itm.NoOfSchedules
                    });
                }
                //var ps_contract_nos = payment_schedule.Select(o => o.ContractRefNo).ToList();
                //var non_ps_lb = loanbooks.Where(o => !ps_contract_nos.Contains(o.ContractNo)).ToList();
                //var crt_non_ps_lb = non_ps_lb.Select(o=>o.ContractNo).Distinct().ToList();
                //foreach (var itm in crt_non_ps_lb)
                //{
                //   // payment_schedule.Add(new PaymentSchedule { ContractRefNo = itm, Component= "AMORTISE" });
                //}
                var tskStatusLst = new List <TaskStatus> {
                    TaskStatus.RanToCompletion, TaskStatus.Faulted, TaskStatus.Canceled
                };

                if (1 != 1)//loanbooks.Count<=1000)
                {
                    RunEADJob(loanbooks, this._eclId);
                }
                else
                {
                    //var checker = loanbooks.Count / 30;
                    var threads = loanbooks.Count / 500;
                    threads = threads + 1;

                    var taskLst = new List <Task>();

                    for (int i = 0; i < threads; i++)
                    {
                        var sub_LoanBook = loanbooks.Skip(i * 500).Take(500).ToList();

                        //var contractIds = sub_LoanBook.Select(o => o.ContractNo).ToList();
                        //var sub_payment_schedule = payment_schedule.Where(o => contractIds.Contains(o.ContractRefNo)).ToList();

                        var task = Task.Run(() =>
                        {
                            RunEADJob(sub_LoanBook, this._eclId);
                        });

                        taskLst.Add(task);
                    }
                    Log4Net.Log.Info($"Total Task : {taskLst.Count()}");

                    //Task t = Task.WhenAll(taskLst);

                    //try
                    //{
                    //    t.Wait();
                    //}
                    //catch(Exception ex)
                    //{
                    //    Log4Net.Log.Error(ex);
                    //}
                    //    Log4Net.Log.Info($"All Task status: {t.Status}");

                    //if (t.Status== TaskStatus.RanToCompletion)
                    //{
                    //    Log4Net.Log.Info($"All Task ran to completion");
                    //}
                    //if (t.Status == TaskStatus.Faulted)
                    //{
                    //    Log4Net.Log.Info($"All Task ran to fault");
                    //}

                    while (0 < 1)
                    {
                        if (taskLst.All(o => tskStatusLst.Contains(o.Status)))
                        {
                            break;
                        }
                        //Do Nothing
                    }
                }


                //EIR

                //Task.Run(() => {
                //    DoEIRProjectionTask(lifetimeEADs, this._eclId);
                //});
                var maxProjectionMonth = Convert.ToInt32(loanbooks.Max(o => o.LIM_MONTH));
                DoEIRProjectionTask(lifetimeEADs, this._eclId, maxProjectionMonth);
                // DoEIRProjectionTask(lifeTimeEAD, lstContractIds, masterGuid);

                //populate for CIR projections
                var cirProjections = new ECLTasks(this._eclId, this._eclType).EAD_CIRProjections(lifetimeEADs, maxProjectionMonth);
                Log4Net.Log.Info("Completed EAD_CIRProjections");
                //insert into DB
                ExecuteNative.SaveCIRProjections(cirProjections, this._eclId, this._eclType);
                Log4Net.Log.Info("Completed SaveCIRProjections");


                Log4Net.Log.Info("Completed Parsing Payment Schedule to object");

                //if (item.ContractRefNo != "701SMGA132120001")
                //{
                //    // continue;
                //}
                //payment_schedule = payment_schedule.Where(o => o.ContractRefNo == "701SMGA132120001").ToList();
                if (1 != 1)//payment_schedule.Count <= 1000)
                {
                    PaymentSchedule_Projection(payment_schedule, 1);
                }
                else
                {
                    //var checker = loanbooks.Count / 30;

                    //payment_schedule = payment_schedule.Where(o => o.ContractRefNo == "701SMGA132120001").ToList();



                    //==============


                    payment_schedule = payment_schedule.OrderBy(o => o.ContractRefNo).ToList();
                    var groupedPS = new List <List <PaymentSchedule> >();
                    var threads   = payment_schedule.Count / 500;
                    threads = threads + 1;

                    for (int i = 0; i < threads; i++)
                    {
                        var sub_items = payment_schedule.Skip(i * 500).Take(500).ToList();
                        if (sub_items.Count > 0)
                        {
                            groupedPS.Add(sub_items);
                        }
                    }

                    var allAccountsGrouped = false;

                    try
                    {
                        while (!allAccountsGrouped)
                        {
                            allAccountsGrouped = true;
                            for (int i = 1; i < groupedPS.Count; i++)
                            {
                                var lstfromPrev = groupedPS[i - 1].LastOrDefault();
                                var fstfromCurr = groupedPS[i].FirstOrDefault();
                                if (lstfromPrev.ContractRefNo == fstfromCurr.ContractRefNo)
                                {
                                    groupedPS[i - 1].Add(fstfromCurr);
                                    groupedPS[i].RemoveAt(0);
                                    allAccountsGrouped = false;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }


                    //==============

                    var taskLst = new List <Task>();

                    for (int i = 0; i < threads; i++)
                    {
                        try{
                            var sub_payment_schedule = groupedPS[i];

                            var task = Task.Run(() =>
                            {
                                PaymentSchedule_Projection(sub_payment_schedule, i);
                            });

                            taskLst.Add(task);
                        }catch (Exception ex)
                        {
                        }
                    }
                    Log4Net.Log.Info($"Total Task : {taskLst.Count()}");

                    //Task t = Task.WhenAll(taskLst);

                    //try
                    //{
                    //    t.Wait();
                    //}
                    //catch (Exception ex)
                    //{
                    //    Log4Net.Log.Error(ex);
                    //}
                    //Log4Net.Log.Info($"All Task status: {t.Status}");

                    //if (t.Status == TaskStatus.RanToCompletion)
                    //{
                    //    Log4Net.Log.Info($"All Task ran to completion");
                    //}
                    //if (t.Status == TaskStatus.Faulted)
                    //{
                    //    Log4Net.Log.Info($"All Task ran to fault");
                    //}

                    while (0 < 1)
                    {
                        if (taskLst.All(o => tskStatusLst.Contains(o.Status)))
                        {
                            break;
                        }
                        //Do Nothing
                    }
                }
                Log4Net.Log.Info("Completed Parsing PaymentSchedule_Projection");

                //var sb = new StringBuilder();
                //sb.Append($"Contract,StartDate,Component,Month,Value{Environment.NewLine}");
                //foreach (var itm in paymentScheduleProjections)
                //{
                //    sb.Append($"{itm.ContractId},{itm.StartDate},{itm.Component},{itm.Months},{itm.Value}{Environment.NewLine}");
                //}
                //File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PS.csv"), sb.ToString());

                var ccfData = new CalibrationInput_EAD_CCF_Summary_Processor().GetCCFData(this._eclId, this._eclType);

                ////populate for LifeTime  projections
                //var lifetimeProjections_ = new ECLTasks(this._eclId, this._eclType).EAD_LifeTimeProjections(refined_lstRaws, lifetimeEADs, cirProjections, PaymentScheduleProjection, ccfData);
                //Log4Net.Log.Info("Completed EAD_LifeTimeProjections");

                //ExecuteNative.SaveLifeTimeProjections(lifetimeProjections_, this._eclId, _eclType);
                //Log4Net.Log.Info("All Jobs Completed");

                // refined_lstRaws = refined_lstRaws.Where(o => o.contract_no == "7010121400169701").ToList();

                if (1 != 1)//loanbooks.Count <= 1000) //1 != 1) //
                {
                    //var _lifetimeProjections =
                    new ECLTasks(this._eclId, this._eclType).EAD_LifeTimeProjections(refined_lstRaws, lifetimeEADs, cirProjections, paymentScheduleProjections, ccfData);
                    //lifeTimeProjections.AddRange(_lifetimeProjections);
                }
                else
                {
                    //var checker = loanbooks.Count / 60;
                    Log4Net.Log.Info($"refined_lstRaws.Count - {refined_lstRaws.Count}");

                    var threads = refined_lstRaws.Count / 500;
                    threads = threads + 1;
                    Log4Net.Log.Info($"No of Thread - {threads}");
                    var taskLst = new List <Task>();

                    for (int i = 0; i < threads; i++)
                    {
                        Log4Net.Log.Info($"Thread - {i}");
                        var sub_refined_lstRaws = refined_lstRaws.Skip(i * 500).Take(500).ToList();

                        var contractnos      = sub_refined_lstRaws.Where(p => !string.IsNullOrEmpty(p.contract_no)).Select(o => o.contract_no).ToList();
                        var sub_lifetimeEADs = lifetimeEADs.Where(o => o != null && contractnos.Contains(o.contract_no)).ToList();
                        var actualContract   = contractnos.Select(o => Computation.GetActualContractId(o)).ToList();

                        paymentScheduleProjections = paymentScheduleProjections.Where(a => a != null).ToList();
                        var sub_PaymentScheduleProjection = paymentScheduleProjections.Where(o => actualContract.Contains(o.ContractId)).ToList();
                        var task = Task.Run(() =>
                        {
                            //populate for LifeTime  projections
                            //var _lifetimeProjections =
                            new ECLTasks(this._eclId, this._eclType).EAD_LifeTimeProjections(sub_refined_lstRaws, sub_lifetimeEADs, cirProjections, sub_PaymentScheduleProjection, ccfData);

                            // lifeTimeProjections.AddRange(_lifetimeProjections);
                            ////Console.ReadKey();
                            ///
                        });

                        taskLst.Add(task);
                    }
                    Log4Net.Log.Info($"Total Task : {taskLst.Count()}");

                    //var completedTask = taskLst.Where(o => o.Status == TaskStatus.RanToCompletion).Count();
                    //Log4Net.Log.Info($"Task Completed: {completedTask}");

                    //while (taskLst.Count != tasks.Count)
                    //while (!taskLst.Any(o => o.IsCompleted))

                    while (0 < 1)
                    {
                        if (taskLst.All(o => tskStatusLst.Contains(o.Status)))
                        {
                            break;
                        }
                        //Do Nothing
                    }

                    //Task t = Task.WhenAll(taskLst);

                    //try
                    //{
                    //    t.Wait();
                    //}
                    //catch (Exception ex)
                    //{
                    //    Log4Net.Log.Error(ex);
                    //}
                    //Log4Net.Log.Info($"All Task status: {t.Status}");

                    //if (t.Status == TaskStatus.RanToCompletion)
                    //{
                    //    Log4Net.Log.Info($"All Task ran to completion");
                    //}
                    //if (t.Status == TaskStatus.Faulted)
                    //{
                    //    Log4Net.Log.Info($"All Task ran to fault");
                    //}
                }

                Log4Net.Log.Info("Completed EAD_LifeTimeProjections");

                return(true);
            }
            catch (Exception ex)
            {
                Log4Net.Log.Error(ex.ToString());
                // //Console.ReadKey();
                return(false);
            }
        }