src/Controller/CoverageController.php line 805

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Psr\Log\LoggerInterface;
  9. use App\Entity\Event;
  10. use App\Entity\ProfileMenu;
  11. use App\Entity\Product;
  12. use App\Entity\Portfolio;
  13. use App\Entity\ProviderDatabaseConfiguration;
  14. use App\Entity\Observation;
  15. use App\Entity\EventDomain;
  16. use App\Entity\EventLevel;
  17. use App\Entity\EventType;
  18. use App\Entity\Coverage;
  19. use App\Entity\Units;
  20. use App\Entity\Insured;
  21. class CoverageController extends AbstractController
  22. {
  23.     #[Route('/api/coverage/cat/getpremium'name'CatPremium'methods: ['POST'])]
  24.     public function getCatPremium(Request $request,EntityManagerInterface $entityManagerLoggerInterface $logger): JsonResponse
  25.     {
  26.         $user $this->getUSer();
  27.         if ($user){
  28.             $EventCoumter $entityManager->getRepository(Event::class)->counterTodayByUsers($user);
  29.             $Menulist $entityManager->getRepository(ProfileMenu::class)->findByProfile($user->getProfile()->getId());
  30.             $control FALSE;
  31.             foreach ($Menulist as $value){
  32.                 if(strpos($value->getMenu()->getMenuLink(), $request->getPathInfo()) !== false){
  33.                     $control TRUE;
  34.                 }
  35.             }
  36.             if($control && $EventCoumter<$user->getMaxRequest()){
  37.                 $logger->alert('coverage/cat/getpremium as '.$user->getUsername().' alowed');
  38.                 $formData=json_decode($request->getContent(),true);
  39.                 $totalIndex = array();
  40.                 $product $entityManager->getRepository(Product::class)->findOneById($formData["product_id"]);
  41.                 $portfolio $entityManager->getRepository(Portfolio::class)->findOneById($product->getPortfolio());
  42.                 $min_start_date 10000;
  43.                 $max_end_date 0;
  44.                 $strucCount 0;
  45.                 if(!isset($formData["geteventnames"])){
  46.                     $formData["geteventnames"] = "PAYOUT";
  47.                 }
  48.                 if(!isset($formData["dointerpol"])){
  49.                     $formData["dointerpol"] = "YES";
  50.                 }
  51.                 
  52.                 foreach ($formData["structures"] as $key=>$value){
  53.                     $strucCount $strucCount +1;
  54.                     $databaseConf $entityManager->getRepository(ProviderDatabaseConfiguration::class)->createQueryBuilder('o')->where('o.providerDatabase = :databaseId')->andWhere('o.configuration = :config')->setParameter('databaseId'$product->getProductDatabase()->getId())->setParameter('config''GetCatIndex')->getQuery()->getResult();
  55.                     
  56.                     if(!isset($value["reference"])){
  57.                         $value["reference"] = "Struc".$strucCount;
  58.                         $formData["structures"][$key]["reference"] = "Struc".$strucCount;
  59.                     }
  60.                     
  61.                     if(!isset($value["geteventnames"])){
  62.                         $value["geteventnames"] = $formData["geteventnames"];
  63.                         $formData["structures"][$key]["geteventnames"] = $formData["geteventnames"];
  64.                     }
  65.                     
  66.                     if(!isset($value["units"])){
  67.                         $value["units"] = "CAT";
  68.                         $formData["structures"][$key]["units"] = "CAT";
  69.                     }
  70.                     
  71.                     if(!isset($value["replica_period"])){
  72.                         $value["replica_period"] = 30;
  73.                         $formData["structures"][$key]["replica_period"] = 30;
  74.                     }
  75.                     
  76.                     if(!isset($value["history_length"])){
  77.                         if(is_null($product->getHistoryLength())){
  78.                             $value["history_length"] = 50;
  79.                             $formData["structures"][$key]["history_length"] = 50;
  80.                         }else{
  81.                             $value["history_length"] = $product->getHistoryLength();
  82.                             $formData["structures"][$key]["history_length"] = $product->getHistoryLength();
  83.                         }
  84.                     }
  85.                     
  86.                     $value["period"]=$formData["period"];
  87.                     $formData["structures"][$key]["period"]=$formData["period"];
  88.                     $value["dointerpol"]=$formData["dointerpol"];
  89.                     
  90.                     $indexTemp = array();
  91.                     $counterLoop=0;
  92.                     while(count($indexTemp)==&& $counterLoop<3){
  93.                         $counterLoop=$counterLoop+1;
  94.                         $indexTemp $entityManager->getRepository(Observation::class)->getDataLakeCatPayOut($product,$databaseConf[0]->getConfigurationValue(),json_encode($value));
  95.                     }
  96.                     if(count($indexTemp)!=0){
  97.                         foreach ($indexTemp as $indexValues){
  98.                             if(str_contains($indexValues["historic_payout_org"],':')){
  99.                                 $filteredZone[$value["reference"]][] = $indexValues;
  100.                             }else{
  101.                                 $totalIndex[] = $indexValues;
  102.                             }
  103.                         }
  104.                     }else{
  105.                         $response = new JsonResponse($value["reference"]." Pricing error"422);
  106.                         $response->headers->set('Content-Type''application/json');
  107.                         return $response;
  108.                     }
  109.                 }
  110.                 $originalPayout=array();
  111.                 foreach ($totalIndex as $value){
  112.                     $originalPayout[] = array(
  113.                         "date_year" => $value["date_year"],
  114.                         "historic_payout_org" => $value["historic_payout_org"]
  115.                     );
  116.                 }
  117.                 $Years array_column($totalIndex,'date_year');
  118.                 $totalPayout = array();
  119.                 for($i=min($Years);$i<=max($Years);$i++){
  120.                     $yearIndex array_keys($Years,$i);
  121.                     $total array_fill(0110);
  122.                     foreach ($yearIndex as $value2){
  123.                         $total[0] = $total[0] + $totalIndex[$value2]["historic_payout_org"];
  124.                         $total[1] = $total[1] + $totalIndex[$value2]["historic_payout_varcat_minus"];
  125.                         $total[2] = $total[2] + $totalIndex[$value2]["historic_payout_varcat_plus"];
  126.                         $total[3] = $total[3] + $totalIndex[$value2]["historic_payout_varpoint1"];
  127.                         $total[4] = $total[4] + $totalIndex[$value2]["historic_payout_varpoint2"];
  128.                         $total[5] = $total[5] + $totalIndex[$value2]["historic_payout_varpoint3"];
  129.                         $total[6] = $total[6] + $totalIndex[$value2]["historic_payout_varpoint4"];
  130.                         $total[7] = $total[7] + $totalIndex[$value2]["historic_payout_varpoint5"];
  131.                         $total[8] = $total[8] + $totalIndex[$value2]["historic_payout_varpoint6"];
  132.                         $total[9] = $total[9] + $totalIndex[$value2]["historic_payout_varpoint7"];
  133.                         $total[10] = $total[10] + $totalIndex[$value2]["historic_payout_varpoint8"];
  134.                     }
  135.                     if(!isset($formData["general_deductible"])){
  136.                         $formData["general_deductible"]=0;
  137.                     }
  138.                     for($j=0;$j<11;$j++){
  139.                         if($total[$j] < $formData["general_deductible"]){
  140.                             $total[$j] = 0;
  141.                         }else{
  142.                             $total[$j] = $total[$j] - $formData["general_deductible"];
  143.                         }
  144.                         if($total[$j]>$formData["general_limit"]) $total[$j] = $formData["general_limit"];
  145.                     }
  146.                     $total_mean array_sum($total)/count($total);
  147.                     if($total_mean>$formData["general_limit"]){
  148.                         $total_mean $formData["general_limit"];
  149.                     }
  150.                     $totalPayout[]=array(
  151.                         "date_year" => $i,
  152.                         "total_mean" => $total_mean,
  153.                         "historic_payout_org" => $total[0],
  154.                         "historic_payout_varcat_minus" => $total[1],
  155.                         "historic_payout_varcat_plus" => $total[2],
  156.                         "historic_payout_varpoint1" => $total[3],
  157.                         "historic_payout_varpoint2" => $total[4],
  158.                         "historic_payout_varpoint3" => $total[5],
  159.                         "historic_payout_varpoint4" => $total[6],
  160.                         "historic_payout_varpoint5" => $total[7],
  161.                         "historic_payout_varpoint6" => $total[8],
  162.                         "historic_payout_varpoint7" => $total[9],
  163.                         "historic_payout_varpoint8" => $total[10]
  164.                     );
  165.                 }
  166.                 $payoutMean array_fill(0120);
  167.                 $payoutMean[0] =  array_sum(array_column($totalPayout,'total_mean'))/(count(array_column($totalPayout,'total_mean')));
  168.                 $payoutMean[1] =  array_sum(array_column($totalPayout,'historic_payout_org'))/(count(array_column($totalPayout,'historic_payout_org')));
  169.                 $payoutMean[2] =  array_sum(array_column($totalPayout,'historic_payout_varcat_minus'))/(count(array_column($totalPayout,'historic_payout_varcat_minus')));
  170.                 $payoutMean[3] =  array_sum(array_column($totalPayout,'historic_payout_varcat_plus'))/(count(array_column($totalPayout,'historic_payout_varcat_plus')));
  171.                 
  172.                 for($j=4;$j<12;$j++){
  173.                     $payoutMean[$j] =  array_sum(array_column($totalPayout,'historic_payout_varpoint'.($j-3)))/(count(array_column($totalPayout,'historic_payout_varpoint'.($j-3))));
  174.                 }
  175.                 
  176.                 if(!isset($formData["load_tail"])){
  177.                     $formData["load_tail"]=0.01;
  178.                 }
  179.                 if(!isset($formData["load_fronting"])){
  180.                     $formData["load_fronting"]=0;
  181.                 }
  182.                 if(!isset($formData["load_brokerage"])){
  183.                     $formData["load_brokerage"]=0.325;
  184.                 }
  185.                 if(!isset($formData["load_el"])){
  186.                     $formData["load_el"]=1;
  187.                 }
  188.                 if(!isset($formData["load_std"])){
  189.                     $formData["load_std"]=0.2;
  190.                 }
  191.                 if(!isset($formData["load_min"])){
  192.                     $formData["load_min"]=0.02538462;
  193.                 }
  194.                 if(!isset($formData["load_deduction_cg"])){
  195.                     $formData["load_deduction_cg"]=0.125;
  196.                 }
  197.                 if(!isset($formData["load_factor_uw"])){
  198.                     $formData["load_factor_uw"]=0.15;
  199.                 }
  200.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_org')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  201.                 $ExpectedLoss[] = $payoutMean[1];
  202.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  203.                 $Iteration[] = "STRICT";
  204.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'total_mean')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  205.                 $ExpectedLoss[] = $payoutMean[0];
  206.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  207.                 $Iteration[] = "AVERAGE";
  208.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varcat_minus')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  209.                 $ExpectedLoss[] = $payoutMean[2];
  210.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  211.                 $Iteration[] = "SPEED_MINUS10PCT";
  212.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varcat_plus')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  213.                 $ExpectedLoss[] = $payoutMean[3];
  214.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  215.                 $Iteration[] = "SPEED_PLUS10PCT";
  216.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint1')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  217.                 $ExpectedLoss[] = $payoutMean[4];
  218.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  219.                 $Iteration[] = "VAR_NORTH";
  220.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint2')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  221.                 $ExpectedLoss[] = $payoutMean[5];
  222.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  223.                 $Iteration[] = "VAR_SOUTH";
  224.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint3')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  225.                 $ExpectedLoss[] = $payoutMean[6];
  226.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  227.                 $Iteration[] = "VAR_EAST";
  228.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint4')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  229.                 $ExpectedLoss[] = $payoutMean[7];
  230.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  231.                 $Iteration[] = "VAR_WEST";
  232.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint5')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  233.                 $ExpectedLoss[] = $payoutMean[8];
  234.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  235.                 $Iteration[] = "VAR_NORTHWEST";
  236.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint6')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  237.                 $ExpectedLoss[] = $payoutMean[9];
  238.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  239.                 $Iteration[] = "VAR_NORTHEAST";
  240.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint7')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  241.                 $ExpectedLoss[] = $payoutMean[10];
  242.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  243.                 $Iteration[] = "VAR_SOUTHWEST";
  244.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint8')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  245.                 $ExpectedLoss[] = $payoutMean[11];
  246.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  247.                 $Iteration[] = "VAR_SOUTHEAST";
  248.                 
  249.                 $primes=array();
  250.                 foreach ($Premiums as $key => $value2){
  251.                     $primes["Analysis"][] = array(
  252.                         "Iteration" => $Iteration[$key],
  253.                         "ExpectedLoss"=> $ExpectedLoss[$key],
  254.                         "Premiums" => $Premiums[$key]
  255.                     );
  256.                 }
  257.                 
  258.                 $totalyears=max($Years)-min($Years)+1;
  259.                 
  260.                 for($i=min($Years);$i<=max($Years);$i++){
  261.                     $yearIndex array_keys($Years,$i);
  262.                     $strucCount 0;
  263.                     foreach ($yearIndex as $key=>$value2){
  264.                         $primes["Payouts"][$formData["structures"][$strucCount]["reference"]][] = array(
  265.                         //$primes["Payouts"][$formData["structures"][intval($value2/$totalyears)]["reference"]][] = array(
  266.                             "Year" => $totalIndex[$value2]["date_year"],
  267.                             "Payout" => $totalIndex[$value2]["historic_payout_org"]
  268.                         );
  269.                         $strucCount $strucCount 1;
  270.                     }
  271.                 }
  272.                 if (isset($filteredZone)) {
  273.                     foreach ($filteredZone as $key=>$value){
  274.                         if($formData["geteventnames"]=="ALL"){
  275.                             foreach ($value as $key2=>$value2){
  276.                                 $primes["Events"][$key][]=array(
  277.                                     "ID"=>$value2["date_year"],
  278.                                     "Name"=>$value2["historic_payout_varpoint1"],
  279.                                     "TIME"=>$value2["historic_payout_org"],
  280.                                     "LAT"=>floatval($value2["historic_payout_varcat_minus"]),
  281.                                     "LON"=>floatval($value2["historic_payout_varcat_plus"]),
  282.                                     "Mg"=>floatval($value2["historic_payout_varpoint2"]),
  283.                                     "MgSec"=>floatval($value2["historic_payout_varpoint3"])
  284.                                 );
  285.                             }
  286.                         }else{
  287.                             foreach ($value as $key2=>$value2){
  288.                                 $primes["Events"][$key][]=array(
  289.                                     "ID"=>$value2["date_year"],
  290.                                     "Name"=>$value2["historic_payout_varpoint1"],
  291.                                     "TIME"=>$value2["historic_payout_org"],
  292.                                     "LAT"=>floatval($value2["historic_payout_varcat_minus"]),
  293.                                     "LON"=>floatval($value2["historic_payout_varcat_plus"]),
  294.                                     "Mg"=>floatval($value2["historic_payout_varpoint2"]),
  295.                                     "MgSec"=>floatval($value2["historic_payout_varpoint3"]),
  296.                                     "Circle"=>floatval($value2["historic_payout_varpoint7"]),
  297.                                     "PayOut"=>floatval($value2["historic_payout_varpoint8"])
  298.                                 );
  299.                             }
  300.                         }
  301.                     }
  302.                 }
  303.                 $EventDomain $entityManager->getRepository(EventDomain::class)->findOneById(1);
  304.                 $EventLevel $entityManager->getRepository(EventLevel::class)->findOneById(1);
  305.                 $EventType $entityManager->getRepository(EventType::class)->findOneById(1);
  306.                 $Event = new Event();
  307.                 $Event->setDateEvent(new \DateTime('now'));
  308.                 $Event->setDescription('{"entry_point":"'.$request->getPathInfo().'","vivaldi_version":"'.$_ENV["VIVALDI_VERSION"].'","input_json":'.json_encode($formData).',"output_json":'.json_encode($primes).'}');
  309.                 $Event->setUsers($user);
  310.                 $Event->setEventType($EventType);
  311.                 $Event->setEventDomain($EventDomain);
  312.                 $Event->setEventLevel($EventLevel);
  313.                 
  314.                 
  315.                 $entityManager->persist($Event);
  316.                 $entityManager->flush();
  317.                 $primes["Reference"] = $Event->getId();
  318.                 $primes["VivaldiVersion"] = $_ENV["VIVALDI_VERSION"];
  319.                 $primes["Time"] = $Event->getDateEvent();
  320.                 
  321.                 return $this->json($primes);
  322.             }else{
  323.                 $response = new JsonResponse(null401);
  324.                 $response->headers->set('Content-Type''application/json');
  325.                 return $response;
  326.             }
  327.         }else{
  328.             $response = new JsonResponse(null401);
  329.             $response->headers->set('Content-Type''application/json');
  330.             return $response;
  331.         }
  332.     }
  333.     
  334.     #[Route('/api/coverage/cat/getpremiumstruc'name'CatPremiumStruc'methods: ['POST'])]
  335.     public function getCatPremiumStruc(Request $request,EntityManagerInterface $entityManagerLoggerInterface $logger): JsonResponse
  336.     {
  337.         $user $this->getUSer();
  338.         if ($user){
  339.             $EventCoumter $entityManager->getRepository(Event::class)->counterTodayByUsers($user);
  340.             $Menulist $entityManager->getRepository(ProfileMenu::class)->findByProfile($user->getProfile()->getId());
  341.             $control FALSE;
  342.             foreach ($Menulist as $value){
  343.                 if(strpos($value->getMenu()->getMenuLink(), $request->getPathInfo()) !== false){
  344.                     $control TRUE;
  345.                 }
  346.             }
  347.             if($control && $EventCoumter<$user->getMaxRequest()){
  348.                 $logger->alert('coverage/getcatpremium as '.$user->getUsername().' alowed');
  349.                 $formData=json_decode($request->getContent(),true);
  350.                 $outStruct["general_limit"]= "general_limit_value";
  351.                 $outStruct["product_id"]="product_id_value";
  352.                 $outStruct["period"]=array(
  353.                     "start_date"=>"start_date_value",
  354.                     "end_date"=>"end_date_value"
  355.                 );
  356.                 for($x=0;$x<$formData["structures"];$x++){
  357.                     $structuresTemp = array();
  358.                     $structuresTemp["reference"]="reference_value_".$x;
  359.                     $structuresTemp["limit"]="limit_value_".$x;
  360.                     if($formData["form_type"][$x]=="rings"){
  361.                         $structuresTemp["latitude"]="latitude_value_".$x;
  362.                         $structuresTemp["longitude"]="longitude_value_".$x;
  363.                         $rings=array();
  364.                         unset($ringsTemp);
  365.                         for($y=0;$y<$formData["form_type_number"][$x];$y++){
  366.                             $ringsTemp["radius"]="radius_value_".$x."_".$y;
  367.                             $strike=array();
  368.                             unset($strikeTemp);
  369.                             for($z=0;$z<$formData["strikes_number"][$x];$z++){
  370.                                 $strikeTemp["strike"]="strike_value_".$x."_".$y."_".$z;
  371.                                 $strikeTemp["payout"]="payout_value_".$x."_".$y."_".$z;
  372.                                 $strike[]=$strikeTemp;
  373.                             }
  374.                             $ringsTemp["strikes"]=$strike;
  375.                             $rings[]=$ringsTemp;
  376.                         }
  377.                         $structuresTemp["rings"]=$rings;
  378.                     }else{
  379.                         $polygon=array();
  380.                         unset($polygonTemp);
  381.                         for($y=0;$y<$formData["form_type_number"][$x];$y++){
  382.                             $lat=array();
  383.                             $lon=array();
  384.                             for($z=0;$z<$formData["form_type_coord"][$x];$z++){
  385.                                 $lat[]="latitude_value_".$x."_".$y."_".$z;
  386.                                 $lon[]="longitude_value_".$x."_".$y."_".$z;
  387.                             }
  388.                             $polygonTemp["latitude"]=$lat;
  389.                             $polygonTemp["longitude"]=$lon;
  390.                             $strike=array();
  391.                             unset($strikeTemp);
  392.                             for($z=0;$z<$formData["strikes_number"][$x];$z++){
  393.                                 $strikeTemp["strike"]="strike_value_".$x."_".$y."_".$z;
  394.                                 $strikeTemp["payout"]="payout_value_".$x."_".$y."_".$z;
  395.                                 $strike[]=$strikeTemp;
  396.                             }
  397.                             $polygonTemp["strikes"]=$strike;
  398.                             $polygon[]=$polygonTemp;
  399.                         }
  400.                         $structuresTemp["polygons"]=$polygon;
  401.                     }
  402.                     $structures[]=$structuresTemp;
  403.                 }
  404.                 $outStruct["structures"]=$structures;
  405.                 return $this->json($outStruct);
  406.             }else{
  407.                 $response = new JsonResponse(null401);
  408.                 $response->headers->set('Content-Type''application/json');
  409.                 return $response;
  410.             }
  411.         }else{
  412.             $response = new JsonResponse(null401);
  413.             $response->headers->set('Content-Type''application/json');
  414.             return $response;
  415.         }
  416.     }
  417.     #[Route('/api/coverage/cat/getmultipremium'name'CatMultiPremium'methods: ['POST'])]
  418.     public function getCatMultiPremium(Request $request,EntityManagerInterface $entityManagerLoggerInterface $logger): JsonResponse
  419.     {
  420.         $user $this->getUSer();
  421.         if ($user){
  422.             $EventCoumter $entityManager->getRepository(Event::class)->counterTodayByUsers($user);
  423.             $Menulist $entityManager->getRepository(ProfileMenu::class)->findByProfile($user->getProfile()->getId());
  424.             $control FALSE;
  425.             foreach ($Menulist as $value){
  426.                 if(strpos($value->getMenu()->getMenuLink(), $request->getPathInfo()) !== false){
  427.                     $control TRUE;
  428.                 }
  429.             }
  430.             if($control && $EventCoumter<$user->getMaxRequest()){
  431.                 $logger->alert('coverage/cat/getmultipremium as '.$user->getUsername().' alowed');
  432.                 $formData=json_decode($request->getContent(),true);
  433.                 $min_start_date 10000;
  434.                 $max_end_date 0;
  435.                 $strucCount 0;
  436.                 if(!isset($formData["dointerpol"])){
  437.                     $formData["dointerpol"] = "YES";
  438.                 }
  439.                 foreach ($formData["structures"] as $key=>$value){
  440.                     $totalIndex = array();
  441.                     $filteredZone = array();
  442.                     $strucCount=$strucCount+1;
  443.                     $product $entityManager->getRepository(Product::class)->findOneById($value["product_id"]);
  444.                     $portfolio $entityManager->getRepository(Portfolio::class)->findOneById($product->getPortfolio());
  445.                     $databaseConf $entityManager->getRepository(ProviderDatabaseConfiguration::class)->createQueryBuilder('o')->where('o.providerDatabase = :databaseId')->andWhere('o.configuration = :config')->setParameter('databaseId'$product->getProductDatabase()->getId())->setParameter('config''GetCatIndex')->getQuery()->getResult();
  446.                     
  447.                     if(!isset($value["reference"])){
  448.                         $value["reference"] = "Struc".$strucCount;
  449.                         $formData["structures"][$key]["reference"] = "Struc".$strucCount;
  450.                     }
  451.                     
  452.                     if(!isset($value["geteventnames"])){
  453.                         if(!isset($formData["geteventnames"])){
  454.                             $value["geteventnames"] = "PAYOUT";
  455.                             $formData["structures"][$key]["geteventnames"] = "PAYOUT";
  456.                         }else{
  457.                             $value["geteventnames"] = $formData["geteventnames"];
  458.                             $formData["structures"][$key]["geteventnames"] = $formData["geteventnames"];
  459.                         }
  460.                     }
  461.                     
  462.                     if(!isset($value["replica_period"])){
  463.                         $value["replica_period"] = 30;
  464.                         $formData["structures"][$key]["replica_period"] = 30;
  465.                     }
  466.                     if(!isset($value["history_length"])){
  467.                         if(is_null($product->getHistoryLength())){
  468.                             $formData["structures"][$key]["history_length"] = 50;
  469.                         }else{
  470.                             $formData["structures"][$key]["history_length"] = $product->getHistoryLength();
  471.                         }
  472.                     }
  473.                     if(!isset($value["period"])){
  474.                         $value["period"]=$formData["period"];
  475.                         $formData["structures"][$key]["period"]=$formData["period"];
  476.                     }
  477.                     
  478.                     $value["dointerpol"]=$formData["dointerpol"];
  479.                     
  480.                     $indexTemp = array();
  481.                     $counterLoop=0;
  482.                     while(count($indexTemp)==&& $counterLoop<6){
  483.                         $counterLoop=$counterLoop+1;
  484.                         $indexTemp $entityManager->getRepository(Observation::class)->getDataLakeCatPayOut($product,$databaseConf[0]->getConfigurationValue(),json_encode($value));
  485.                     }
  486.                     
  487.                     if(count($indexTemp)==0){
  488.                         $response = new JsonResponse($value["reference"]." Pricing error"422);
  489.                         $response->headers->set('Content-Type''application/json');
  490.                         return $response;
  491.                     }else{
  492.                         foreach ($indexTemp as $indexValues){
  493.                             if(str_contains($indexValues["historic_payout_org"],':')){
  494.                                 $filteredZone[] = $indexValues;
  495.                             }else{
  496.                                 $totalIndex[] = $indexValues;
  497.                             }
  498.                         }
  499.                         if(!isset($formData["general_deductible"])){
  500.                             $formData["general_deductible"]=0;
  501.                         }
  502.                         if(!isset($value["limit"])){
  503.                             $limit $formData["general_limit"];
  504.                         }else{
  505.                             $limit $value["limit"];
  506.                         }
  507.                         $counterLoop=0;
  508.                         foreach ($totalIndex as $indexkey=>$indexvalue){
  509.                             foreach ($indexvalue as $indexkey2=>$indexvalue2){
  510.                                 if($indexkey2!="date_year"){
  511.                                     if($indexvalue2 $formData["general_deductible"]){
  512.                                         $indexvalue2 0;
  513.                                     }else{
  514.                                         $indexvalue2 $indexvalue2 $formData["general_deductible"];
  515.                                     }
  516.                                     if($indexvalue2>$limit$indexvalue2 $limit;
  517.                                     $totalIndex[$indexkey][$indexkey2]=$indexvalue2;
  518.                                     $payoutMean[$counterLoop]["historic_payout"]=$payoutMean[$counterLoop]["historic_payout"]+$indexvalue2;
  519.                                 }else{
  520.                                     $payoutMean[$counterLoop]=array(
  521.                                         "date_year"=>$totalIndex[$indexkey]["date_year"],
  522.                                         "historic_payout"=>0
  523.                                         
  524.                                     );
  525.                                 }
  526.                             }
  527.                             $payoutMean[$counterLoop]["historic_payout"]=$payoutMean[$counterLoop]["historic_payout"]/(count($indexvalue)-1);
  528.                             $counterLoop=$counterLoop+1;
  529.                         }
  530.                         
  531.                         if(!isset($formData["load_tail"])){
  532.                             $formData["load_tail"]=0.01;
  533.                         }
  534.                         if(!isset($formData["load_fronting"])){
  535.                             $formData["load_fronting"]=0;
  536.                         }
  537.                         if(!isset($formData["load_brokerage"])){
  538.                             $formData["load_brokerage"]=0.325;
  539.                         }
  540.                         if(!isset($formData["load_el"])){
  541.                             $formData["load_el"]=1;
  542.                         }
  543.                         if(!isset($formData["load_std"])){
  544.                             $formData["load_std"]=0.2;
  545.                         }
  546.                         if(!isset($formData["load_min"])){
  547.                             $formData["load_min"]=0.02538462;
  548.                         }
  549.                         if(!isset($formData["load_deduction_cg"])){
  550.                             $formData["load_deduction_cg"]=0.125;
  551.                         }
  552.                         if(!isset($formData["load_factor_uw"])){
  553.                             $formData["load_factor_uw"]=0.15;
  554.                         }
  555.                         
  556.                         if(isset($ExpectedLoss)){
  557.                             unset($ExpectedLoss);
  558.                             unset($Premiums);
  559.                             unset($Iteration);
  560.                         }
  561.                         
  562.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_org')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  563.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_org'))/count(array_column($totalIndex,'historic_payout_org'));
  564.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  565.                         $Iteration[] = "STRICT";
  566.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($payoutMean,'date_year'),"historic_payout"=>array_column($payoutMean,'historic_payout')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  567.                         $ExpectedLoss[] = array_sum(array_column($payoutMean,'historic_payout'))/count(array_column($payoutMean,'historic_payout'));
  568.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  569.                         $Iteration[] = "AVERAGE";
  570.                         
  571.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varcat_minus')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  572.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varcat_minus'))/count(array_column($totalIndex,'historic_payout_varcat_minus'));
  573.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  574.                         $Iteration[] = "SPEED_MINUS10PCT";
  575.                         
  576.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varcat_plus')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  577.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varcat_plus'))/count(array_column($totalIndex,'historic_payout_varcat_plus'));
  578.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  579.                         $Iteration[] = "SPEED_PLUS10PCT";
  580.                         
  581.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varpoint1')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  582.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varpoint1'))/count(array_column($totalIndex,'historic_payout_varpoint1'));
  583.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  584.                         $Iteration[] = "VAR_NORTH";
  585.                         
  586.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varpoint2')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  587.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varpoint2'))/count(array_column($totalIndex,'historic_payout_varpoint2'));
  588.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  589.                         $Iteration[] = "VAR_SOUTH";
  590.                         
  591.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varpoint3')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  592.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varpoint3'))/count(array_column($totalIndex,'historic_payout_varpoint3'));
  593.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  594.                         $Iteration[] = "VAR_EAST";
  595.                         
  596.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varpoint4')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  597.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varpoint4'))/count(array_column($totalIndex,'historic_payout_varpoint4'));
  598.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  599.                         $Iteration[] = "VAR_WEST";
  600.                         
  601.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varpoint5')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  602.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varpoint5'))/count(array_column($totalIndex,'historic_payout_varpoint5'));
  603.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  604.                         $Iteration[] = "VAR_NORTHWEST";
  605.                         
  606.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varpoint6')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  607.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varpoint6'))/count(array_column($totalIndex,'historic_payout_varpoint6'));
  608.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  609.                         $Iteration[] = "VAR_NORTHEAST";
  610.                         
  611.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varpoint7')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  612.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varpoint7'))/count(array_column($totalIndex,'historic_payout_varpoint7'));
  613.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  614.                         $Iteration[] = "VAR_SOUTHWEST";
  615.                         
  616.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_varpoint8')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  617.                         $ExpectedLoss[] = array_sum(array_column($totalIndex,'historic_payout_varpoint8'))/count(array_column($totalIndex,'historic_payout_varpoint8'));
  618.                         $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  619.                         $Iteration[] = "VAR_SOUTHEAST";
  620.                         
  621.                         foreach ($Premiums as $key2 => $value2){
  622.                             $primes[$value["reference"]]["Analysis"][] = array(
  623.                                 "Iteration" => $Iteration[$key2],
  624.                                 "ExpectedLoss"=> $ExpectedLoss[$key2],
  625.                                 "Premiums" => $Premiums[$key2]
  626.                             );
  627.                         }
  628.                         
  629.                         foreach ($totalIndex as $key2 => $value2){
  630.                             $primes[$value["reference"]]["Payouts"][] = array(
  631.                                 "Year" => $value2["date_year"],
  632.                                 "Payout" => $value2["historic_payout_org"]
  633.                             );
  634.                             
  635.                         }
  636.                         if (isset($filteredZone)) {
  637.                             foreach ($filteredZone as $key3=>$value3){
  638.                                 if($value["geteventnames"]=="ALL"){
  639.                                     $primes[$value["reference"]]["Events"][]=array(
  640.                                         "ID"=>$value3["date_year"],
  641.                                         "Name"=>$value3["historic_payout_varpoint1"],
  642.                                         "TIME"=>$value3["historic_payout_org"],
  643.                                         "LAT"=>floatval($value3["historic_payout_varcat_minus"]),
  644.                                         "LON"=>floatval($value3["historic_payout_varcat_plus"]),
  645.                                         "Mg"=>floatval($value3["historic_payout_varpoint2"]),
  646.                                         "MgSec"=>floatval($value3["historic_payout_varpoint3"])
  647.                                     );
  648.                                 }else{
  649.                                     $primes[$value["reference"]]["Events"][]=array(
  650.                                         "ID"=>$value3["date_year"],
  651.                                         "Name"=>$value3["historic_payout_varpoint1"],
  652.                                         "TIME"=>$value3["historic_payout_org"],
  653.                                         "LAT"=>floatval($value3["historic_payout_varcat_minus"]),
  654.                                         "LON"=>floatval($value3["historic_payout_varcat_plus"]),
  655.                                         "Mg"=>floatval($value3["historic_payout_varpoint2"]),
  656.                                         "MgSec"=>floatval($value3["historic_payout_varpoint3"]),
  657.                                         "Circle"=>floatval($value2["historic_payout_varpoint7"]),
  658.                                         "PayOut"=>floatval($value2["historic_payout_varpoint8"])
  659.                                     );
  660.                                 }
  661.                             }
  662.                         }
  663.                     }
  664.                 }
  665.                 
  666.                 $EventDomain $entityManager->getRepository(EventDomain::class)->findOneById(1);
  667.                 $EventLevel $entityManager->getRepository(EventLevel::class)->findOneById(1);
  668.                 $EventType $entityManager->getRepository(EventType::class)->findOneById(1);
  669.                 
  670.                 $Event = new Event();
  671.                 
  672.                 $Event->setDateEvent(new \DateTime('now'));
  673.                 $Event->setDescription('{"entry_point":"'.$request->getPathInfo().'","vivaldi_version":"'.$_ENV["VIVALDI_VERSION"].'","input_json":'.json_encode($formData).',"output_json":'.json_encode($primes).'}');
  674.                 $Event->setUsers($user);
  675.                 $Event->setEventType($EventType);
  676.                 $Event->setEventDomain($EventDomain);
  677.                 $Event->setEventLevel($EventLevel);
  678.                 
  679.                 
  680.                 $entityManager->persist($Event);
  681.                 $entityManager->flush();
  682.                 $primes["Reference"] = $Event->getId();
  683.                 $primes["VivaldiVersion"] = $_ENV["VIVALDI_VERSION"];
  684.                 $primes["Time"] = $Event->getDateEvent();
  685.                 
  686.                 return $this->json($primes);
  687.             }else{
  688.                 $response = new JsonResponse(null401);
  689.                 $response->headers->set('Content-Type''application/json');
  690.                 return $response;
  691.             }
  692.         }else{
  693.             $response = new JsonResponse(null401);
  694.             $response->headers->set('Content-Type''application/json');
  695.             return $response;
  696.         }
  697.     }
  698.     
  699.     #[Route('/api/coverage/cat/getmultipremiumstruc'name'CaMultitPremiumStruc'methods: ['POST'])]
  700.     public function getCatMultiPremiumStruc(Request $request,EntityManagerInterface $entityManagerLoggerInterface $logger): JsonResponse
  701.     {
  702.         $user $this->getUSer();
  703.         if ($user){
  704.             $EventCoumter $entityManager->getRepository(Event::class)->counterTodayByUsers($user);
  705.             $Menulist $entityManager->getRepository(ProfileMenu::class)->findByProfile($user->getProfile()->getId());
  706.             $control FALSE;
  707.             foreach ($Menulist as $value){
  708.                 if(strpos($value->getMenu()->getMenuLink(), $request->getPathInfo()) !== false){
  709.                     $control TRUE;
  710.                 }
  711.             }
  712.             if($control && $EventCoumter<$user->getMaxRequest()){
  713.                 $logger->alert('coverage/getcatpremium as '.$user->getUsername().' alowed');
  714.                 $formData=json_decode($request->getContent(),true);
  715.                 $outStruct["general_limit"]= "general_limit_value";
  716.                 for($x=0;$x<$formData["structures"];$x++){
  717.                     $structuresTemp = array();
  718.                     $structuresTemp["reference"]="reference_value_".$x;
  719.                     $structuresTemp["limit"]="limit_value_".$x;
  720.                     $structuresTemp["product_id"]="product_id_value_".$x;
  721.                     if($formData["form_type"][$x]=="rings"){
  722.                         $structuresTemp["latitude"]="latitude_value_".$x;
  723.                         $structuresTemp["longitude"]="longitude_value_".$x;
  724.                         $rings=array();
  725.                         unset($ringsTemp);
  726.                         for($y=0;$y<$formData["form_type_number"][$x];$y++){
  727.                             $ringsTemp["radius"]="radius_value_".$x."_".$y;
  728.                             $strike=array();
  729.                             unset($strikeTemp);
  730.                             for($z=0;$z<$formData["strikes_number"][$x];$z++){
  731.                                 $strikeTemp["strike"]="strike_value_".$x."_".$y."_".$z;
  732.                                 $strikeTemp["payout"]="payout_value_".$x."_".$y."_".$z;
  733.                                 $strike[]=$strikeTemp;
  734.                             }
  735.                             $ringsTemp["strikes"]=$strike;
  736.                             $rings[]=$ringsTemp;
  737.                         }
  738.                         $structuresTemp["rings"]=$rings;
  739.                     }else{
  740.                         $polygon=array();
  741.                         unset($polygonTemp);
  742.                         for($y=0;$y<$formData["form_type_number"][$x];$y++){
  743.                             $lat=array();
  744.                             $lon=array();
  745.                             for($z=0;$z<$formData["form_type_coord"][$x];$z++){
  746.                                 $lat[]="latitude_value_".$x."_".$y."_".$z;
  747.                                 $lon[]="longitude_value_".$x."_".$y."_".$z;
  748.                             }
  749.                             $polygonTemp["latitude"]=$lat;
  750.                             $polygonTemp["longitude"]=$lon;
  751.                             $strike=array();
  752.                             unset($strikeTemp);
  753.                             for($z=0;$z<$formData["strikes_number"][$x];$z++){
  754.                                 $strikeTemp["strike"]="strike_value_".$x."_".$y."_".$z;
  755.                                 $strikeTemp["payout"]="payout_value_".$x."_".$y."_".$z;
  756.                                 $strike[]=$strikeTemp;
  757.                             }
  758.                             $polygonTemp["strikes"]=$strike;
  759.                             $polygon[]=$polygonTemp;
  760.                         }
  761.                         $structuresTemp["polygons"]=$polygon;
  762.                     }
  763.                     $structuresTemp["period"]=array(
  764.                         "start_date"=>"start_date_value_".$x,
  765.                         "end_date"=>"end_date_value_".$x
  766.                     );
  767.                     $structures[]=$structuresTemp;
  768.                 }
  769.                 $outStruct["structures"]=$structures;
  770.                 return $this->json($outStruct);
  771.             }else{
  772.                 $response = new JsonResponse(null401);
  773.                 $response->headers->set('Content-Type''application/json');
  774.                 return $response;
  775.             }
  776.         }else{
  777.             $response = new JsonResponse(null401);
  778.             $response->headers->set('Content-Type''application/json');
  779.             return $response;
  780.         }
  781.     }
  782.     
  783.     #[Route('/api/coverage/cat/getaggregatedpremium'name'CatAggregatedPremium'methods: ['POST'])]
  784.     public function getCatAggregatedPremium(Request $request,EntityManagerInterface $entityManagerLoggerInterface $logger): JsonResponse
  785.     {
  786.         $user $this->getUSer();
  787.         if ($user){
  788.             $EventCoumter $entityManager->getRepository(Event::class)->counterTodayByUsers($user);
  789.             $Menulist $entityManager->getRepository(ProfileMenu::class)->findByProfile($user->getProfile()->getId());
  790.             $control FALSE;
  791.             foreach ($Menulist as $value){
  792.                 if(strpos($value->getMenu()->getMenuLink(), $request->getPathInfo()) !== false){
  793.                     $control TRUE;
  794.                 }
  795.             }
  796.             if($control && $EventCoumter<$user->getMaxRequest()){
  797.                 $logger->alert('coverage/cat/getpremium as '.$user->getUsername().' alowed');
  798.                 $formData=json_decode($request->getContent(),true);
  799.                 $totalIndex = array();
  800.                 $min_start_date 10000;
  801.                 $max_end_date 0;
  802.                 $strucCount 0;
  803.                 if(!isset($formData["geteventnames"])){
  804.                     $formData["geteventnames"] = "PAYOUT";
  805.                 }
  806.                 if(!isset($formData["dointerpol"])){
  807.                     $formData["dointerpol"] = "YES";
  808.                 }
  809.                 foreach ($formData["structures"] as $key=>$value){
  810.                     $product $entityManager->getRepository(Product::class)->findOneById($value["product_id"]);
  811.                     $portfolio $entityManager->getRepository(Portfolio::class)->findOneById($product->getPortfolio());
  812.                     
  813.                     $strucCount $strucCount +1;
  814.                     $databaseConf $entityManager->getRepository(ProviderDatabaseConfiguration::class)->createQueryBuilder('o')->where('o.providerDatabase = :databaseId')->andWhere('o.configuration = :config')->setParameter('databaseId'$product->getProductDatabase()->getId())->setParameter('config''GetCatIndex')->getQuery()->getResult();
  815.                     
  816.                     if(!isset($value["reference"])){
  817.                         $value["reference"] = "Struc".$strucCount;
  818.                         $formData["structures"][$key]["reference"] = "Struc".$strucCount;
  819.                     }
  820.                     
  821.                     if(!isset($value["geteventnames"])){
  822.                         $value["geteventnames"] = $formData["geteventnames"];
  823.                         $formData["structures"][$key]["geteventnames"] = $formData["geteventnames"];
  824.                     }
  825.                     
  826.                     if(!isset($value["units"])){
  827.                         $value["units"] = "CAT";
  828.                     }
  829.                     
  830.                     if(!isset($value["replica_period"])){
  831.                         $value["replica_period"] = 30;
  832.                     }
  833.                     
  834.                     if(!isset($value["history_length"])){
  835.                         if(is_null($product->getHistoryLength())){
  836.                             $formData["structures"][$key]["history_length"] = 50;
  837.                         }else{
  838.                             $formData["structures"][$key]["history_length"] = $product->getHistoryLength();
  839.                         }
  840.                     }
  841.                     
  842.                     $value["period"]=$formData["period"];
  843.                     $formData["structures"][$key]["period"]=$formData["period"];
  844.                     $value["dointerpol"]=$formData["dointerpol"];
  845.                     
  846.                     $indexTemp = array();
  847.                     $counterLoop=0;
  848.                     while(count($indexTemp)==&& $counterLoop<3){
  849.                         $counterLoop=$counterLoop+1;
  850.                         $indexTemp $entityManager->getRepository(Observation::class)->getDataLakeCatPayOut($product,$databaseConf[0]->getConfigurationValue(),json_encode($value));
  851.                     }
  852.                     if(count($indexTemp)!=0){
  853.                         foreach ($indexTemp as $indexValues){
  854.                             if(str_contains($indexValues["historic_payout_org"],':')){
  855.                                 $filteredZone[$value["reference"]][] = $indexValues;
  856.                             }else{
  857.                                 $totalIndex[] = $indexValues;
  858.                             }
  859.                         }
  860.                     }else{
  861.                         $response = new JsonResponse($value["reference"]." Pricing error"422);
  862.                         $response->headers->set('Content-Type''application/json');
  863.                         return $response;
  864.                     }
  865.                 }
  866.                 $originalPayout=array();
  867.                 foreach ($totalIndex as $value){
  868.                     $originalPayout[] = array(
  869.                         "date_year" => $value["date_year"],
  870.                         "historic_payout_org" => $value["historic_payout_org"]
  871.                     );
  872.                 }
  873.                 $Years array_column($totalIndex,'date_year');
  874.                 $totalPayout = array();
  875.                 for($i=min($Years);$i<=max($Years);$i++){
  876.                     $yearIndex array_keys($Years,$i);
  877.                     $total array_fill(0110);
  878.                     foreach ($yearIndex as $value2){
  879.                         $total[0] = $total[0] + $totalIndex[$value2]["historic_payout_org"];
  880.                         $total[1] = $total[1] + $totalIndex[$value2]["historic_payout_varcat_minus"];
  881.                         $total[2] = $total[2] + $totalIndex[$value2]["historic_payout_varcat_plus"];
  882.                         $total[3] = $total[3] + $totalIndex[$value2]["historic_payout_varpoint1"];
  883.                         $total[4] = $total[4] + $totalIndex[$value2]["historic_payout_varpoint2"];
  884.                         $total[5] = $total[5] + $totalIndex[$value2]["historic_payout_varpoint3"];
  885.                         $total[6] = $total[6] + $totalIndex[$value2]["historic_payout_varpoint4"];
  886.                         $total[7] = $total[7] + $totalIndex[$value2]["historic_payout_varpoint5"];
  887.                         $total[8] = $total[8] + $totalIndex[$value2]["historic_payout_varpoint6"];
  888.                         $total[9] = $total[9] + $totalIndex[$value2]["historic_payout_varpoint7"];
  889.                         $total[10] = $total[10] + $totalIndex[$value2]["historic_payout_varpoint8"];
  890.                     }
  891.                     if(!isset($formData["general_deductible"])){
  892.                         $formData["general_deductible"]=0;
  893.                     }
  894.                     for($j=0;$j<11;$j++){
  895.                         if($total[$j] < $formData["general_deductible"]){
  896.                             $total[$j] = 0;
  897.                         }else{
  898.                             $total[$j] = $total[$j] - $formData["general_deductible"];
  899.                         }
  900.                         if($total[$j]>$formData["general_limit"]) $total[$j] = $formData["general_limit"];
  901.                     }
  902.                     $total_mean array_sum($total)/count($total);
  903.                     if($total_mean>$formData["general_limit"]){
  904.                         $total_mean $formData["general_limit"];
  905.                     }
  906.                     $totalPayout[]=array(
  907.                         "date_year" => $i,
  908.                         "total_mean" => $total_mean,
  909.                         "historic_payout_org" => $total[0],
  910.                         "historic_payout_varcat_minus" => $total[1],
  911.                         "historic_payout_varcat_plus" => $total[2],
  912.                         "historic_payout_varpoint1" => $total[3],
  913.                         "historic_payout_varpoint2" => $total[4],
  914.                         "historic_payout_varpoint3" => $total[5],
  915.                         "historic_payout_varpoint4" => $total[6],
  916.                         "historic_payout_varpoint5" => $total[7],
  917.                         "historic_payout_varpoint6" => $total[8],
  918.                         "historic_payout_varpoint7" => $total[9],
  919.                         "historic_payout_varpoint8" => $total[10]
  920.                     );
  921.                 }
  922.                 
  923.                 $payoutMean array_fill(0120);
  924.                 $payoutMean[0] =  array_sum(array_column($totalPayout,'total_mean'))/(count(array_column($totalPayout,'total_mean')));
  925.                 $payoutMean[1] =  array_sum(array_column($totalPayout,'historic_payout_org'))/(count(array_column($totalPayout,'historic_payout_org')));
  926.                 $payoutMean[2] =  array_sum(array_column($totalPayout,'historic_payout_varcat_minus'))/(count(array_column($totalPayout,'historic_payout_varcat_minus')));
  927.                 $payoutMean[3] =  array_sum(array_column($totalPayout,'historic_payout_varcat_plus'))/(count(array_column($totalPayout,'historic_payout_varcat_plus')));
  928.                 
  929.                 for($j=4;$j<12;$j++){
  930.                     $payoutMean[$j] =  array_sum(array_column($totalPayout,'historic_payout_varpoint'.($j-3)))/(count(array_column($totalPayout,'historic_payout_varpoint'.($j-3))));
  931.                 }
  932.                 
  933.                 if(!isset($formData["load_tail"])){
  934.                     $formData["load_tail"]=0.01;
  935.                 }
  936.                 if(!isset($formData["load_fronting"])){
  937.                     $formData["load_fronting"]=0;
  938.                 }
  939.                 if(!isset($formData["load_brokerage"])){
  940.                     $formData["load_brokerage"]=0.325;
  941.                 }
  942.                 if(!isset($formData["load_el"])){
  943.                     $formData["load_el"]=1;
  944.                 }
  945.                 if(!isset($formData["load_std"])){
  946.                     $formData["load_std"]=0.2;
  947.                 }
  948.                 if(!isset($formData["load_min"])){
  949.                     $formData["load_min"]=0.02538462;
  950.                 }
  951.                 if(!isset($formData["load_deduction_cg"])){
  952.                     $formData["load_deduction_cg"]=0.125;
  953.                 }
  954.                 if(!isset($formData["load_factor_uw"])){
  955.                     $formData["load_factor_uw"]=0.15;
  956.                 }
  957.                 
  958.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_org')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  959.                 $ExpectedLoss[] = $payoutMean[1];
  960.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  961.                 $Iteration[] = "STRICT";
  962.                 
  963.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'total_mean')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  964.                 $ExpectedLoss[] = $payoutMean[0];
  965.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  966.                 $Iteration[] = "AVERAGE";
  967.                 
  968.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varcat_minus')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  969.                 $ExpectedLoss[] = $payoutMean[2];
  970.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  971.                 $Iteration[] = "SPEED_MINUS10PCT";
  972.                 
  973.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varcat_plus')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  974.                 $ExpectedLoss[] = $payoutMean[3];
  975.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  976.                 $Iteration[] = "SPEED_PLUS10PCT";
  977.                 
  978.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint1')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  979.                 $ExpectedLoss[] = $payoutMean[4];
  980.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  981.                 $Iteration[] = "VAR_NORTH";
  982.                 
  983.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint2')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  984.                 $ExpectedLoss[] = $payoutMean[5];
  985.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  986.                 $Iteration[] = "VAR_SOUTH";
  987.                 
  988.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint3')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  989.                 $ExpectedLoss[] = $payoutMean[6];
  990.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  991.                 $Iteration[] = "VAR_EAST";
  992.                 
  993.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint4')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  994.                 $ExpectedLoss[] = $payoutMean[7];
  995.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  996.                 $Iteration[] = "VAR_WEST";
  997.                 
  998.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint5')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  999.                 $ExpectedLoss[] = $payoutMean[8];
  1000.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  1001.                 $Iteration[] = "VAR_NORTHWEST";
  1002.                 
  1003.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint6')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  1004.                 $ExpectedLoss[] = $payoutMean[9];
  1005.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  1006.                 $Iteration[] = "VAR_NORTHEAST";
  1007.                 
  1008.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint7')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  1009.                 $ExpectedLoss[] = $payoutMean[10];
  1010.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  1011.                 $Iteration[] = "VAR_SOUTHWEST";
  1012.                 
  1013.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_varpoint8')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  1014.                 $ExpectedLoss[] = $payoutMean[11];
  1015.                 $Premiums[] = $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  1016.                 $Iteration[] = "VAR_SOUTHEAST";
  1017.                 
  1018.                 $primes=array();
  1019.                 foreach ($Premiums as $key => $value2){
  1020.                     $primes["Analysis"][] = array(
  1021.                         "Iteration" => $Iteration[$key],
  1022.                         "ExpectedLoss"=> $ExpectedLoss[$key],
  1023.                         "Premiums" => $Premiums[$key]
  1024.                     );
  1025.                 }
  1026.                 
  1027.                 $totalyears=max($Years)-min($Years)+1;
  1028.                 for($i=min($Years);$i<=max($Years);$i++){
  1029.                     $yearIndex array_keys($Years,$i);
  1030.                     $strucCount 0;
  1031.                     foreach ($yearIndex as $key=>$value2){
  1032.                         $primes["Payouts"][$formData["structures"][$strucCount]["reference"]][] = array(
  1033.                         //$primes["Payouts"][$formData["structures"][intval($value2/$totalyears)]["reference"]][] = array(
  1034.                             "Year" => $totalIndex[$value2]["date_year"],
  1035.                             "Payout" => $totalIndex[$value2]["historic_payout_org"]
  1036.                         );
  1037.                         $strucCount $strucCount 1;
  1038.                     }
  1039.                 }
  1040.                 if (isset($filteredZone)) {
  1041.                     foreach ($filteredZone as $key=>$value){
  1042.                         foreach ($value as $key2=>$value2){
  1043.                             if($formData["geteventnames"]=="ALL"){
  1044.                                 $primes["Events"][$key][]=array(
  1045.                                     "ID"=>$value2["date_year"],
  1046.                                     "Name"=>$value2["historic_payout_varpoint1"],
  1047.                                     "TIME"=>$value2["historic_payout_org"],
  1048.                                     "LAT"=>floatval($value2["historic_payout_varcat_minus"]),
  1049.                                     "LON"=>floatval($value2["historic_payout_varcat_plus"]),
  1050.                                     "Mg"=>floatval($value2["historic_payout_varpoint2"]),
  1051.                                     "MgSec"=>floatval($value2["historic_payout_varpoint3"])
  1052.                                 );
  1053.                             }else{
  1054.                                 $primes["Events"][$key][]=array(
  1055.                                     "ID"=>$value2["date_year"],
  1056.                                     "Name"=>$value2["historic_payout_varpoint1"],
  1057.                                     "TIME"=>$value2["historic_payout_org"],
  1058.                                     "LAT"=>floatval($value2["historic_payout_varcat_minus"]),
  1059.                                     "LON"=>floatval($value2["historic_payout_varcat_plus"]),
  1060.                                     "Mg"=>floatval($value2["historic_payout_varpoint2"]),
  1061.                                     "MgSec"=>floatval($value2["historic_payout_varpoint3"]),
  1062.                                     "Circle"=>floatval($value2["historic_payout_varpoint7"]),
  1063.                                     "PayOut"=>floatval($value2["historic_payout_varpoint8"])
  1064.                                 );
  1065.                             }
  1066.                         }
  1067.                     }
  1068.                 }
  1069.                 
  1070.                 $EventDomain $entityManager->getRepository(EventDomain::class)->findOneById(1);
  1071.                 $EventLevel $entityManager->getRepository(EventLevel::class)->findOneById(1);
  1072.                 $EventType $entityManager->getRepository(EventType::class)->findOneById(1);
  1073.                 
  1074.                 $Event = new Event();
  1075.                 
  1076.                 $Event->setDateEvent(new \DateTime('now'));
  1077.                 $Event->setDescription('{"entry_point":"'.$request->getPathInfo().'","vivaldi_version":"'.$_ENV["VIVALDI_VERSION"].'","input_json":'.json_encode($formData).',"output_json":'.json_encode($primes).'}');
  1078.                 $Event->setUsers($user);
  1079.                 $Event->setEventType($EventType);
  1080.                 $Event->setEventDomain($EventDomain);
  1081.                 $Event->setEventLevel($EventLevel);
  1082.                 
  1083.                 
  1084.                 $entityManager->persist($Event);
  1085.                 $entityManager->flush();
  1086.                 $primes["Reference"] = $Event->getId();
  1087.                 $primes["VivaldiVersion"] = $_ENV["VIVALDI_VERSION"];
  1088.                 $primes["Time"] = $Event->getDateEvent();
  1089.                 
  1090.                 return $this->json($primes);
  1091.             }else{
  1092.                 $response = new JsonResponse(null401);
  1093.                 $response->headers->set('Content-Type''application/json');
  1094.                 return $response;
  1095.             }
  1096.         }else{
  1097.             $response = new JsonResponse(null401);
  1098.             $response->headers->set('Content-Type''application/json');
  1099.             return $response;
  1100.         }
  1101.     }
  1102.     
  1103.     #[Route('/api/coverage/cat/getaggregatedpremiumstruc'name'CatAggregatedPremiumStruc'methods: ['POST'])]
  1104.     public function getCatAggregatedPremiumStruc(Request $request,EntityManagerInterface $entityManagerLoggerInterface $logger): JsonResponse
  1105.     {
  1106.         $user $this->getUSer();
  1107.         if ($user){
  1108.             $EventCoumter $entityManager->getRepository(Event::class)->counterTodayByUsers($user);
  1109.             $Menulist $entityManager->getRepository(ProfileMenu::class)->findByProfile($user->getProfile()->getId());
  1110.             $control FALSE;
  1111.             foreach ($Menulist as $value){
  1112.                 if(strpos($value->getMenu()->getMenuLink(), $request->getPathInfo()) !== false){
  1113.                     $control TRUE;
  1114.                 }
  1115.             }
  1116.             if($control && $EventCoumter<$user->getMaxRequest()){
  1117.                 $logger->alert('coverage/getcatpremium as '.$user->getUsername().' alowed');
  1118.                 $formData=json_decode($request->getContent(),true);
  1119.                 $outStruct["general_limit"]= "general_limit_value";
  1120.                 $outStruct["period"]=array(
  1121.                     "start_date"=>"start_date_value",
  1122.                     "end_date"=>"end_date_value"
  1123.                 );
  1124.                 for($x=0;$x<$formData["structures"];$x++){
  1125.                     $structuresTemp = array();
  1126.                     $structuresTemp["reference"]="reference_value_".$x;
  1127.                     $structuresTemp["limit"]="limit_value_".$x;
  1128.                     $structuresTemp["product_id"]="product_id_value_".$x;
  1129.                     if($formData["form_type"][$x]=="rings"){
  1130.                         $structuresTemp["latitude"]="latitude_value_".$x;
  1131.                         $structuresTemp["longitude"]="longitude_value_".$x;
  1132.                         $rings=array();
  1133.                         unset($ringsTemp);
  1134.                         for($y=0;$y<$formData["form_type_number"][$x];$y++){
  1135.                             $ringsTemp["radius"]="radius_value_".$x."_".$y;
  1136.                             $strike=array();
  1137.                             unset($strikeTemp);
  1138.                             for($z=0;$z<$formData["strikes_number"][$x];$z++){
  1139.                                 $strikeTemp["strike"]="strike_value_".$x."_".$y."_".$z;
  1140.                                 $strikeTemp["payout"]="payout_value_".$x."_".$y."_".$z;
  1141.                                 $strike[]=$strikeTemp;
  1142.                             }
  1143.                             $ringsTemp["strikes"]=$strike;
  1144.                             $rings[]=$ringsTemp;
  1145.                         }
  1146.                         $structuresTemp["rings"]=$rings;
  1147.                     }else{
  1148.                         $polygon=array();
  1149.                         unset($polygonTemp);
  1150.                         for($y=0;$y<$formData["form_type_number"][$x];$y++){
  1151.                             $lat=array();
  1152.                             $lon=array();
  1153.                             for($z=0;$z<$formData["form_type_coord"][$x];$z++){
  1154.                                 $lat[]="latitude_value_".$x."_".$y."_".$z;
  1155.                                 $lon[]="longitude_value_".$x."_".$y."_".$z;
  1156.                             }
  1157.                             $polygonTemp["latitude"]=$lat;
  1158.                             $polygonTemp["longitude"]=$lon;
  1159.                             $strike=array();
  1160.                             unset($strikeTemp);
  1161.                             for($z=0;$z<$formData["strikes_number"][$x];$z++){
  1162.                                 $strikeTemp["strike"]="strike_value_".$x."_".$y."_".$z;
  1163.                                 $strikeTemp["payout"]="payout_value_".$x."_".$y."_".$z;
  1164.                                 $strike[]=$strikeTemp;
  1165.                             }
  1166.                             $polygonTemp["strikes"]=$strike;
  1167.                             $polygon[]=$polygonTemp;
  1168.                         }
  1169.                         $structuresTemp["polygons"]=$polygon;
  1170.                     }
  1171.                     $structures[]=$structuresTemp;
  1172.                 }
  1173.                 $outStruct["structures"]=$structures;
  1174.                 return $this->json($outStruct);
  1175.             }else{
  1176.                 $response = new JsonResponse(null401);
  1177.                 $response->headers->set('Content-Type''application/json');
  1178.                 return $response;
  1179.             }
  1180.         }else{
  1181.             $response = new JsonResponse(null401);
  1182.             $response->headers->set('Content-Type''application/json');
  1183.             return $response;
  1184.         }
  1185.     }
  1186.     
  1187.     #[Route('/api/external/cat/getpremium'name'ExtCatPremium'methods: ['POST'])]
  1188.     public function getExtCatPremium(Request $request,EntityManagerInterface $entityManagerLoggerInterface $logger): JsonResponse
  1189.     {
  1190.         $user $this->getUSer();
  1191.         if ($user){
  1192.             $EventCoumter $entityManager->getRepository(Event::class)->counterTodayByUsers($user);
  1193.             $Menulist $entityManager->getRepository(ProfileMenu::class)->findByProfile($user->getProfile()->getId());
  1194.             $control FALSE;
  1195.             foreach ($Menulist as $value){
  1196.                 if(strpos($value->getMenu()->getMenuLink(), $request->getPathInfo()) !== false){
  1197.                     $control TRUE;
  1198.                 }
  1199.             }
  1200.             if($control && $EventCoumter<$user->getMaxRequest()){
  1201.                 $logger->alert('coverage/cat/getpremium as '.$user->getUsername().' alowed');
  1202.                 $formData=json_decode($request->getContent(),true);
  1203.                 $totalIndex = array();
  1204.                 $product $entityManager->getRepository(Product::class)->findOneById($formData["product_id"]);
  1205.                 $portfolio $entityManager->getRepository(Portfolio::class)->findOneById($product->getPortfolio());
  1206.                 $min_start_date 10000;
  1207.                 $max_end_date 0;
  1208.                 $strucCount 0;
  1209.                 if(!isset($formData["geteventnames"])){
  1210.                     $formData["geteventnames"] = "PAYOUT";
  1211.                 }
  1212.                 if(!isset($formData["dointerpol"])){
  1213.                     $formData["dointerpol"] = "YES";
  1214.                 }
  1215.                 
  1216.                 $formData["structures"][1]=$formData["structures"][0];
  1217.                 $formData["structures"][0]["period"]["start_date"]="1945-01-01";
  1218.                 $formData["structures"][0]["period"]["end_date"]=(date("Y")-1)."-12-31";
  1219.                 $formData["structures"][1]["period"]["start_date"]="1970-01-01";
  1220.                 $formData["structures"][1]["period"]["end_date"]=(date("Y")-1)."-12-31";
  1221.                 
  1222.                 $key=0;
  1223.                 $value=$formData["structures"][$key];
  1224.                 
  1225.                     $strucCount $strucCount +1;
  1226.                     $databaseConf $entityManager->getRepository(ProviderDatabaseConfiguration::class)->createQueryBuilder('o')->where('o.providerDatabase = :databaseId')->andWhere('o.configuration = :config')->setParameter('databaseId'$product->getProductDatabase()->getId())->setParameter('config''GetCatIndex')->getQuery()->getResult();
  1227.                     
  1228.                     if(!isset($value["reference"])){
  1229.                         $value["reference"] = "Struc".$strucCount;
  1230.                         $formData["structures"][$key]["reference"] = "Struc".$strucCount;
  1231.                     }
  1232.                     
  1233.                     if(!isset($value["geteventnames"])){
  1234.                         $value["geteventnames"] = $formData["geteventnames"];
  1235.                         $formData["structures"][$key]["geteventnames"] = $formData["geteventnames"];
  1236.                     }
  1237.                     
  1238.                     if(!isset($value["units"])){
  1239.                         $value["units"] = "CAT";
  1240.                     }
  1241.                     
  1242.                     if(!isset($value["replica_period"])){
  1243.                         $value["replica_period"] = 30;
  1244.                     }
  1245.                     
  1246.                     $value["dointerpol"]=$formData["dointerpol"];
  1247.                     
  1248.                     $indexTemp = array();
  1249.                     $counterLoop=0;
  1250.                     while(count($indexTemp)==&& $counterLoop<3){
  1251.                         $counterLoop=$counterLoop+1;
  1252.                         $indexTemp $entityManager->getRepository(Observation::class)->getDataLakeCatPayOut($product,$databaseConf[0]->getConfigurationValue(),json_encode($value));
  1253.                     }
  1254.                     if(count($indexTemp)!=0){
  1255.                         foreach ($indexTemp as $indexValues){
  1256.                             if(!str_contains($indexValues["historic_payout_org"],':')){
  1257.                                 $totalIndex[$key][] = $indexValues;
  1258.                             }
  1259.                         }
  1260.                     }else{
  1261.                         $response = new JsonResponse($value["reference"]." Pricing error"422);
  1262.                         $response->headers->set('Content-Type''application/json');
  1263.                         return $response;
  1264.                     }
  1265.                     
  1266.                     $key=$key+1;
  1267.                     $value=$formData["structures"][$key];
  1268.                     
  1269.                     $strucCount $strucCount +1;
  1270.                     $databaseConf $entityManager->getRepository(ProviderDatabaseConfiguration::class)->createQueryBuilder('o')->where('o.providerDatabase = :databaseId')->andWhere('o.configuration = :config')->setParameter('databaseId'$product->getProductDatabase()->getId())->setParameter('config''GetCatIndex')->getQuery()->getResult();
  1271.                     
  1272.                     if(!isset($value["reference"])){
  1273.                         $value["reference"] = "Struc".$strucCount;
  1274.                         $formData["structures"][$key]["reference"] = "Struc".$strucCount;
  1275.                     }
  1276.                     
  1277.                     if(!isset($value["geteventnames"])){
  1278.                         $value["geteventnames"] = $formData["geteventnames"];
  1279.                         $formData["structures"][$key]["geteventnames"] = $formData["geteventnames"];
  1280.                     }
  1281.                     
  1282.                     if(!isset($value["units"])){
  1283.                         $value["units"] = "CAT";
  1284.                     }
  1285.                     
  1286.                     if(!isset($value["replica_period"])){
  1287.                         $value["replica_period"] = 30;
  1288.                     }
  1289.                     
  1290.                     $value["dointerpol"]=$formData["dointerpol"];
  1291.                     
  1292.                     if(count($indexTemp)!=0){
  1293.                         foreach ($indexTemp as $indexValues){
  1294.                             if(!str_contains($indexValues["historic_payout_org"],':')){
  1295.                                 if(intval($indexValues["date_year"])>=1970){
  1296.                                     $totalIndex[$key][] = $indexValues;
  1297.                                 }
  1298.                             }
  1299.                         }
  1300.                     }else{
  1301.                         $response = new JsonResponse($value["reference"]." Pricing error"422);
  1302.                         $response->headers->set('Content-Type''application/json');
  1303.                         return $response;
  1304.                     }
  1305.                     if(!isset($formData["general_deductible"])){
  1306.                         $formData["general_deductible"]=0;
  1307.                     }
  1308.                     
  1309.                     for ($i 0$i <= 1$i++) {
  1310.                         foreach ($totalIndex[$i] as $key=>$value){
  1311.                             if($totalIndex[$i][$key]["historic_payout_org"] < $formData["general_deductible"]){
  1312.                                 $totalIndex[$i][$key]["historic_payout_org"] = 0;
  1313.                             }else{
  1314.                                 $totalIndex[$i][$key]["historic_payout_org"] = $totalIndex[$i][$key]["historic_payout_org"] - $formData["general_deductible"];
  1315.                             }
  1316.                             if($totalIndex[$i][$key]["historic_payout_org"]>$formData["general_limit"]) $totalIndex[$i][$key]["historic_payout_org"] = $formData["general_limit"];
  1317.                         }
  1318.                     }
  1319.                     
  1320.                 if(!isset($formData["load_tail"])){
  1321.                     $formData["load_tail"]=0.01;
  1322.                 }
  1323.                 if(!isset($formData["load_fronting"])){
  1324.                     $formData["load_fronting"]=0;
  1325.                 }
  1326.                 if(!isset($formData["load_brokerage"])){
  1327.                     $formData["load_brokerage"]=0.325;
  1328.                 }
  1329.                 if(!isset($formData["load_el"])){
  1330.                     $formData["load_el"]=1;
  1331.                 }
  1332.                 if(!isset($formData["load_std"])){
  1333.                     $formData["load_std"]=0.2;
  1334.                 }
  1335.                 if(!isset($formData["load_min"])){
  1336.                     $formData["load_min"]=0.02538462;
  1337.                 }
  1338.                 if(!isset($formData["load_deduction_cg"])){
  1339.                     $formData["load_deduction_cg"]=0.125;
  1340.                 }
  1341.                 if(!isset($formData["load_factor_uw"])){
  1342.                     $formData["load_factor_uw"]=0.15;
  1343.                 }
  1344.                 
  1345.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex[0],'date_year'),"historic_payout"=>array_column($totalIndex[0],'historic_payout_org')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  1346.                 $Premium $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  1347.                 
  1348.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex[1],'date_year'),"historic_payout"=>array_column($totalIndex[1],'historic_payout_org')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  1349.                 $Premium = ($Premium $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium)))/2;
  1350.                 
  1351.                 $primes["Analysis"][] = array(
  1352.                     "Premiums" => $Premium
  1353.                 );
  1354.                 
  1355.                 foreach ($totalIndex[1] as $value){
  1356.                     $primes["Payouts"][] = array(
  1357.                         "Year" => $value["date_year"],
  1358.                         "Payout" => $value["historic_payout_org"]
  1359.                     );
  1360.                 }
  1361.                 $EventDomain $entityManager->getRepository(EventDomain::class)->findOneById(1);
  1362.                 $EventLevel $entityManager->getRepository(EventLevel::class)->findOneById(1);
  1363.                 $EventType $entityManager->getRepository(EventType::class)->findOneById(1);
  1364.                 
  1365.                 $Event = new Event();
  1366.                 
  1367.                 $Event->setDateEvent(new \DateTime('now'));
  1368.                 $Event->setDescription('{"entry_point":"'.$request->getPathInfo().'","vivaldi_version":"'.$_ENV["VIVALDI_VERSION"].'","input_json":'.json_encode($formData).',"output_json":'.json_encode($primes).'}');
  1369.                 $Event->setUsers($user);
  1370.                 $Event->setEventType($EventType);
  1371.                 $Event->setEventDomain($EventDomain);
  1372.                 $Event->setEventLevel($EventLevel);
  1373.                 
  1374.                 
  1375.                 $entityManager->persist($Event);
  1376.                 $entityManager->flush();
  1377.                 $primes["Reference"] = $Event->getId();
  1378.                 $primes["VivaldiVersion"] = $_ENV["VIVALDI_VERSION"];
  1379.                 $primes["Time"] = $Event->getDateEvent();
  1380.                 
  1381.                 return $this->json($primes);
  1382.             }else{
  1383.                 $response = new JsonResponse(null401);
  1384.                 $response->headers->set('Content-Type''application/json');
  1385.                 return $response;
  1386.             }
  1387.         }else{
  1388.             $response = new JsonResponse(null401);
  1389.             $response->headers->set('Content-Type''application/json');
  1390.             return $response;
  1391.         }
  1392.     }
  1393.     
  1394.     #[Route('/api/partners/getmultipremium'name'PartnerMultiPremium'methods: ['POST'])]
  1395.     public function getPartnerMultiPremium(Request $request,EntityManagerInterface $entityManagerLoggerInterface $logger): JsonResponse
  1396.     {
  1397.         $user $this->getUSer();
  1398.         if ($user){
  1399.             $EventCoumter $entityManager->getRepository(Event::class)->counterTodayByUsers($user);
  1400.             $Menulist $entityManager->getRepository(ProfileMenu::class)->findByProfile($user->getProfile()->getId());
  1401.             $control FALSE;
  1402.             foreach ($Menulist as $value){
  1403.                 if(strpos($value->getMenu()->getMenuLink(), $request->getPathInfo()) !== false){
  1404.                     $control TRUE;
  1405.                 }
  1406.             }
  1407.             if($control && $EventCoumter<$user->getMaxRequest()){
  1408.                 $logger->alert('partners/getmultipremium as '.$user->getUsername().' alowed');
  1409.                 $formData=json_decode($request->getContent(),true);
  1410.                 $min_start_date 10000;
  1411.                 $max_end_date 0;
  1412.                 $strucCount 0;
  1413.                 $formData["dointerpol"] = "YES";
  1414.                 
  1415.                 foreach ($formData["structures"] as $key=>$value){
  1416.                     $totalIndex = array();
  1417.                     $filteredZone = array();
  1418.                     $strucCount=$strucCount+1;
  1419.                     $product $entityManager->getRepository(Product::class)->findOneById($value["product_id"]);
  1420.                     $portfolio $entityManager->getRepository(Portfolio::class)->findOneById($product->getPortfolio());
  1421.                     $databaseConf $entityManager->getRepository(ProviderDatabaseConfiguration::class)->createQueryBuilder('o')->where('o.providerDatabase = :databaseId')->andWhere('o.configuration = :config')->setParameter('databaseId'$product->getProductDatabase()->getId())->setParameter('config''GetCatIndex')->getQuery()->getResult();
  1422.                     
  1423.                     if(!isset($value["reference"])){
  1424.                         $value["reference"] = "Struc".$strucCount;
  1425.                         $formData["structures"][$key]["reference"] = "Struc".$strucCount;
  1426.                     }
  1427.                     
  1428.                     if(!isset($value["geteventnames"])){
  1429.                         if(!isset($formData["geteventnames"])){
  1430.                             $value["geteventnames"] = "PAYOUT";
  1431.                             $formData["structures"][$key]["geteventnames"] = "PAYOUT";
  1432.                         }else{
  1433.                             $value["geteventnames"] = $formData["geteventnames"];
  1434.                             $formData["structures"][$key]["geteventnames"] = $formData["geteventnames"];
  1435.                         }
  1436.                     }
  1437.                     
  1438.                     
  1439.                     $value["replica_period"] = 30;
  1440.                     $formData["structures"][$key]["replica_period"] = 30;
  1441.                     
  1442.                     if(is_null($product->getHistoryLength())){
  1443.                         $formData["structures"][$key]["history_length"] = 50;
  1444.                     }else{
  1445.                         $formData["structures"][$key]["history_length"] = $product->getHistoryLength();
  1446.                     }
  1447.                     
  1448.                     if($value["product_id"]==|| $value["product_id"]==3){
  1449.                         $value["period"]=array("start_date" => "1970-01-01",
  1450.                             "end_date" => (intval(date("Y"))-1)."-12-31");
  1451.                         $formData["structures"][$key]["period"]=$value["period"];
  1452.                     }elseif ($value["product_id"]==8){
  1453.                         $value["period"]=array("start_date" => "1925-01-01",
  1454.                             "end_date" => (intval(date("Y"))-1)."-12-31");
  1455.                         $formData["structures"][$key]["period"]=$value["period"];
  1456.                     }else{
  1457.                         $response = new JsonResponse("Missing Product"400);
  1458.                         $response->headers->set('Content-Type''application/json');
  1459.                         return $response;
  1460.                     }
  1461.                     
  1462.                     $value["dointerpol"]=$formData["dointerpol"];
  1463.                     
  1464.                     $indexTemp = array();
  1465.                     $counterLoop=0;
  1466.                     while(count($indexTemp)==&& $counterLoop<6){
  1467.                         $counterLoop=$counterLoop+1;
  1468.                         $indexTemp $entityManager->getRepository(Observation::class)->getDataLakeCatPayOut($product,$databaseConf[0]->getConfigurationValue(),json_encode($value));
  1469.                     }
  1470.                     
  1471.                     if(count($indexTemp)==0){
  1472.                         $response = new JsonResponse($value["reference"]." Pricing error"422);
  1473.                         $response->headers->set('Content-Type''application/json');
  1474.                         return $response;
  1475.                     }else{
  1476.                         foreach ($indexTemp as $indexValues){
  1477.                             if(str_contains($indexValues["historic_payout_org"],':')){
  1478.                                 $filteredZone[] = $indexValues;
  1479.                             }else{
  1480.                                 $totalIndex[] = $indexValues;
  1481.                             }
  1482.                         }
  1483.                         if(!isset($formData["general_deductible"])){
  1484.                             $formData["general_deductible"]=0;
  1485.                         }
  1486.                         if(!isset($value["limit"])){
  1487.                             $limit $formData["general_limit"];
  1488.                         }else{
  1489.                             $limit $value["limit"];
  1490.                         }
  1491.                         $counterLoop=0;
  1492.                         foreach ($totalIndex as $indexkey=>$indexvalue){
  1493.                             foreach ($indexvalue as $indexkey2=>$indexvalue2){
  1494.                                 if($indexkey2!="date_year"){
  1495.                                     if($indexvalue2 $formData["general_deductible"]){
  1496.                                         $indexvalue2 0;
  1497.                                     }else{
  1498.                                         $indexvalue2 $indexvalue2 $formData["general_deductible"];
  1499.                                     }
  1500.                                     if($indexvalue2>$limit$indexvalue2 $limit;
  1501.                                     $totalIndex[$indexkey][$indexkey2]=$indexvalue2;
  1502.                                     $payoutMean[$counterLoop]["historic_payout"]=$payoutMean[$counterLoop]["historic_payout"]+$indexvalue2;
  1503.                                 }else{
  1504.                                     $payoutMean[$counterLoop]=array(
  1505.                                         "date_year"=>$totalIndex[$indexkey]["date_year"],
  1506.                                         "historic_payout"=>0
  1507.                                         
  1508.                                     );
  1509.                                 }
  1510.                             }
  1511.                             $payoutMean[$counterLoop]["historic_payout"]=$payoutMean[$counterLoop]["historic_payout"]/(count($indexvalue)-1);
  1512.                             $counterLoop=$counterLoop+1;
  1513.                         }
  1514.                         
  1515.                         $formData["load_tail"]=(+ (sqrt(intval(date("j")))/20))/100;
  1516.                         $formData["load_fronting"]=0;
  1517.                         
  1518.                         $formData["load_brokerage"]=0.325;
  1519.                         $formData["load_el"]=1;
  1520.                         $formData["load_std"]=0.2;
  1521.                         $formData["load_min"]=0.02538462;
  1522.                         $formData["load_deduction_cg"]=0.125;
  1523.                         $formData["load_factor_uw"]=0.15;
  1524.                         
  1525.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($totalIndex,'date_year'),"historic_payout"=>array_column($totalIndex,'historic_payout_org')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  1526.                         $PremiumsStrict $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  1527.                         
  1528.                         $jsonPremium=array("payout"=>array("date_year"=>array_column($payoutMean,'date_year'),"historic_payout"=>array_column($payoutMean,'historic_payout')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  1529.                         $PremiumAVG $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  1530.                         
  1531.                         $primes[$value["reference"]]["Analysis"][] = array(
  1532.                             "Premium" => max($PremiumAVG,$PremiumsStrict
  1533.                         );
  1534.                     }
  1535.                 }
  1536.                 
  1537.                 $EventDomain $entityManager->getRepository(EventDomain::class)->findOneById(1);
  1538.                 $EventLevel $entityManager->getRepository(EventLevel::class)->findOneById(1);
  1539.                 $EventType $entityManager->getRepository(EventType::class)->findOneById(1);
  1540.                 
  1541.                 $Event = new Event();
  1542.                 
  1543.                 $Event->setDateEvent(new \DateTime('now'));
  1544.                 $Event->setDescription('{"entry_point":"'.$request->getPathInfo().'","vivaldi_version":"'.$_ENV["VIVALDI_VERSION"].'","input_json":'.json_encode($formData).',"output_json":'.json_encode($primes).'}');
  1545.                 $Event->setUsers($user);
  1546.                 $Event->setEventType($EventType);
  1547.                 $Event->setEventDomain($EventDomain);
  1548.                 $Event->setEventLevel($EventLevel);
  1549.                 
  1550.                 
  1551.                 $entityManager->persist($Event);
  1552.                 $entityManager->flush();
  1553.                 $primes["Reference"] = $Event->getId();
  1554.                 $primes["VivaldiVersion"] = $_ENV["VIVALDI_VERSION"];
  1555.                 $primes["Time"] = $Event->getDateEvent();
  1556.                 
  1557.                 return $this->json($primes);
  1558.             }else{
  1559.                 $response = new JsonResponse(null401);
  1560.                 $response->headers->set('Content-Type''application/json');
  1561.                 return $response;
  1562.             }
  1563.         }else{
  1564.             $response = new JsonResponse(null401);
  1565.             $response->headers->set('Content-Type''application/json');
  1566.             return $response;
  1567.         }
  1568.     }
  1569.     #[Route('/api/partners/getaggregatedpremium'name'PartnerAggregatedPremium'methods: ['POST'])]
  1570.     public function getPartnerAggregatedPremium(Request $requestEntityManagerInterface $entityManagerLoggerInterface $logger): JsonResponse
  1571.     {
  1572.         $user $this->getUSer();
  1573.         if ($user){
  1574.             $EventCoumter $entityManager->getRepository(Event::class)->counterTodayByUsers($user);
  1575.             $Menulist $entityManager->getRepository(ProfileMenu::class)->findByProfile($user->getProfile()->getId());
  1576.             $control FALSE;
  1577.             foreach ($Menulist as $value){
  1578.                 if(strpos($value->getMenu()->getMenuLink(), $request->getPathInfo()) !== false){
  1579.                     $control TRUE;
  1580.                 }
  1581.             }
  1582.             if($control && $EventCoumter<$user->getMaxRequest()){
  1583.                 $logger->alert('coverage/cat/getpremium as '.$user->getUsername().' alowed');
  1584.                 $formData=json_decode($request->getContent(),true);
  1585.                 $totalIndex = array();
  1586.                 $min_start_date 10000;
  1587.                 $max_end_date 0;
  1588.                 $strucCount 0;
  1589.                 
  1590.                 $formData["geteventnames"] = "PAYOUT";
  1591.                 $formData["dointerpol"] = "YES";
  1592.                 foreach ($formData["structures"] as $key=>$value){
  1593.                     $product $entityManager->getRepository(Product::class)->findOneById($value["product_id"]);
  1594.                     $portfolio $entityManager->getRepository(Portfolio::class)->findOneById($product->getPortfolio());
  1595.                     
  1596.                     if($value["product_id"]==|| $value["product_id"]==3){
  1597.                         $value["period"]=array("start_date" => "1970-01-01",
  1598.                             "end_date" => (intval(date("Y"))-1)."-12-31");
  1599.                         $formData["structures"][$key]["period"]=$value["period"];
  1600.                     }elseif ($value["product_id"]==8){
  1601.                         $value["period"]=array("start_date" => "1925-01-01",
  1602.                             "end_date" => (intval(date("Y"))-1)."-12-31");
  1603.                         $formData["structures"][$key]["period"]=$value["period"];
  1604.                     }else{
  1605.                         $response = new JsonResponse("Missing Product"400);
  1606.                         $response->headers->set('Content-Type''application/json');
  1607.                         return $response;
  1608.                     }
  1609.                     
  1610.                     $strucCount $strucCount +1;
  1611.                     $databaseConf $entityManager->getRepository(ProviderDatabaseConfiguration::class)->createQueryBuilder('o')->where('o.providerDatabase = :databaseId')->andWhere('o.configuration = :config')->setParameter('databaseId'$product->getProductDatabase()->getId())->setParameter('config''GetCatIndex')->getQuery()->getResult();
  1612.                     
  1613.                     if(!isset($value["reference"])){
  1614.                         $value["reference"] = "Struc".$strucCount;
  1615.                         $formData["structures"][$key]["reference"] = "Struc".$strucCount;
  1616.                     }
  1617.                     
  1618.                     $value["geteventnames"] = $formData["geteventnames"];
  1619.                     $formData["structures"][$key]["geteventnames"] = $formData["geteventnames"];
  1620.                     
  1621.                     if(!isset($value["units"])){
  1622.                         $value["units"] = "CAT";
  1623.                     }
  1624.                     
  1625.                     $value["replica_period"] = 30;
  1626.                     $formData["structures"][$key]["replica_period"] = 30;
  1627.                     
  1628.                     if(is_null($product->getHistoryLength())){
  1629.                         $formData["structures"][$key]["history_length"] = 50;
  1630.                         $value["history_length"] = 50;
  1631.                     }else{
  1632.                         $formData["structures"][$key]["history_length"] = $product->getHistoryLength();
  1633.                         $value["history_length"] = $product->getHistoryLength();
  1634.                     }
  1635.                     $value["dointerpol"]=$formData["dointerpol"];
  1636.                     
  1637.                     $indexTemp = array();
  1638.                     $counterLoop=0;
  1639.                     while(count($indexTemp)==&& $counterLoop<3){
  1640.                         $counterLoop=$counterLoop+1;
  1641.                         $indexTemp $entityManager->getRepository(Observation::class)->getDataLakeCatPayOut($product,$databaseConf[0]->getConfigurationValue(),json_encode($value));
  1642.                     }
  1643.                     if(count($indexTemp)!=0){
  1644.                         foreach ($indexTemp as $indexValues){
  1645.                             if(str_contains($indexValues["historic_payout_org"],':')){
  1646.                                 $filteredZone[$value["reference"]][] = $indexValues;
  1647.                             }else{
  1648.                                 $totalIndex[] = $indexValues;
  1649.                             }
  1650.                         }
  1651.                     }else{
  1652.                         $response = new JsonResponse($value["reference"]." Pricing error"422);
  1653.                         $response->headers->set('Content-Type''application/json');
  1654.                         return $response;
  1655.                     }
  1656.                 }
  1657.                 $originalPayout=array();
  1658.                 foreach ($totalIndex as $value){
  1659.                     $originalPayout[] = array(
  1660.                         "date_year" => $value["date_year"],
  1661.                         "historic_payout_org" => $value["historic_payout_org"]
  1662.                     );
  1663.                 }
  1664.                 $Years array_column($totalIndex,'date_year');
  1665.                 $totalPayout = array();
  1666.                 for($i=min($Years);$i<=max($Years);$i++){
  1667.                     $yearIndex array_keys($Years,$i);
  1668.                     $total array_fill(0110);
  1669.                     foreach ($yearIndex as $value2){
  1670.                         $total[0] = $total[0] + $totalIndex[$value2]["historic_payout_org"];
  1671.                         $total[1] = $total[1] + $totalIndex[$value2]["historic_payout_varcat_minus"];
  1672.                         $total[2] = $total[2] + $totalIndex[$value2]["historic_payout_varcat_plus"];
  1673.                         $total[3] = $total[3] + $totalIndex[$value2]["historic_payout_varpoint1"];
  1674.                         $total[4] = $total[4] + $totalIndex[$value2]["historic_payout_varpoint2"];
  1675.                         $total[5] = $total[5] + $totalIndex[$value2]["historic_payout_varpoint3"];
  1676.                         $total[6] = $total[6] + $totalIndex[$value2]["historic_payout_varpoint4"];
  1677.                         $total[7] = $total[7] + $totalIndex[$value2]["historic_payout_varpoint5"];
  1678.                         $total[8] = $total[8] + $totalIndex[$value2]["historic_payout_varpoint6"];
  1679.                         $total[9] = $total[9] + $totalIndex[$value2]["historic_payout_varpoint7"];
  1680.                         $total[10] = $total[10] + $totalIndex[$value2]["historic_payout_varpoint8"];
  1681.                     }
  1682.                     if(!isset($formData["general_deductible"])){
  1683.                         $formData["general_deductible"]=0;
  1684.                     }
  1685.                     for($j=0;$j<11;$j++){
  1686.                         if($total[$j] < $formData["general_deductible"]){
  1687.                             $total[$j] = 0;
  1688.                         }else{
  1689.                             $total[$j] = $total[$j] - $formData["general_deductible"];
  1690.                         }
  1691.                         if($total[$j]>$formData["general_limit"]) $total[$j] = $formData["general_limit"];
  1692.                     }
  1693.                     $total_mean array_sum($total)/count($total);
  1694.                     if($total_mean>$formData["general_limit"]){
  1695.                         $total_mean $formData["general_limit"];
  1696.                     }
  1697.                     $totalPayout[]=array(
  1698.                         "date_year" => $i,
  1699.                         "total_mean" => $total_mean,
  1700.                         "historic_payout_org" => $total[0],
  1701.                         "historic_payout_varcat_minus" => $total[1],
  1702.                         "historic_payout_varcat_plus" => $total[2],
  1703.                         "historic_payout_varpoint1" => $total[3],
  1704.                         "historic_payout_varpoint2" => $total[4],
  1705.                         "historic_payout_varpoint3" => $total[5],
  1706.                         "historic_payout_varpoint4" => $total[6],
  1707.                         "historic_payout_varpoint5" => $total[7],
  1708.                         "historic_payout_varpoint6" => $total[8],
  1709.                         "historic_payout_varpoint7" => $total[9],
  1710.                         "historic_payout_varpoint8" => $total[10]
  1711.                     );
  1712.                 }
  1713.                 
  1714.                 $payoutMean array_fill(0120);
  1715.                 $payoutMean[0] =  array_sum(array_column($totalPayout,'total_mean'))/(count(array_column($totalPayout,'total_mean')));
  1716.                 $payoutMean[1] =  array_sum(array_column($totalPayout,'historic_payout_org'))/(count(array_column($totalPayout,'historic_payout_org')));
  1717.                 $payoutMean[2] =  array_sum(array_column($totalPayout,'historic_payout_varcat_minus'))/(count(array_column($totalPayout,'historic_payout_varcat_minus')));
  1718.                 $payoutMean[3] =  array_sum(array_column($totalPayout,'historic_payout_varcat_plus'))/(count(array_column($totalPayout,'historic_payout_varcat_plus')));
  1719.                 
  1720.                 for($j=4;$j<12;$j++){
  1721.                     $payoutMean[$j] =  array_sum(array_column($totalPayout,'historic_payout_varpoint'.($j-3)))/(count(array_column($totalPayout,'historic_payout_varpoint'.($j-3))));
  1722.                 }
  1723.                 
  1724.                 $formData["load_tail"]=(+ (sqrt(intval(date("j")))/20))/100;
  1725.                 $formData["load_fronting"]=0;
  1726.                 $formData["load_brokerage"]=0.325;
  1727.                 $formData["load_el"]=1;
  1728.                 $formData["load_std"]=0.2;
  1729.                 $formData["load_min"]=0.02538462;
  1730.                 $formData["load_deduction_cg"]=0.125;
  1731.                 $formData["load_factor_uw"]=0.15;
  1732.                 
  1733.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'historic_payout_org')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  1734.                 $PremiumStrict $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  1735.                 
  1736.                 
  1737.                 $jsonPremium=array("payout"=>array("date_year"=>array_column($totalPayout,'date_year'),"historic_payout"=>array_column($totalPayout,'total_mean')),"risk_taker"=>$portfolio->getThirdParty()->getAlgorithm(),"inputjson"=>$formData);
  1738.                 $PremiumAVG $entityManager->getRepository(Coverage::class)->getPremium(json_encode($jsonPremium));
  1739.                 
  1740.                 $primes=array();
  1741.                 $primes["Analysis"][] = array(
  1742.                     "Premium" => max($PremiumAVG,$PremiumStrict
  1743.                 );
  1744.                 
  1745.                 $EventDomain $entityManager->getRepository(EventDomain::class)->findOneById(1);
  1746.                 $EventLevel $entityManager->getRepository(EventLevel::class)->findOneById(1);
  1747.                 $EventType $entityManager->getRepository(EventType::class)->findOneById(1);
  1748.                 
  1749.                 $Event = new Event();
  1750.                 
  1751.                 $Event->setDateEvent(new \DateTime('now'));
  1752.                 $Event->setDescription('{"entry_point":"'.$request->getPathInfo().'","vivaldi_version":"'.$_ENV["VIVALDI_VERSION"].'","input_json":'.json_encode($formData).',"output_json":'.json_encode($primes).'}');
  1753.                 $Event->setUsers($user);
  1754.                 $Event->setEventType($EventType);
  1755.                 $Event->setEventDomain($EventDomain);
  1756.                 $Event->setEventLevel($EventLevel);
  1757.                 
  1758.                 
  1759.                 $entityManager->persist($Event);
  1760.                 $entityManager->flush();
  1761.                 $primes["Reference"] = $Event->getId();
  1762.                 $primes["VivaldiVersion"] = $_ENV["VIVALDI_VERSION"];
  1763.                 $primes["Time"] = $Event->getDateEvent();
  1764.                 
  1765.                 return $this->json($primes);
  1766.             }else{
  1767.                 $response = new JsonResponse(null401);
  1768.                 $response->headers->set('Content-Type''application/json');
  1769.                 return $response;
  1770.             }
  1771.         }else{
  1772.             $response = new JsonResponse(null401);
  1773.             $response->headers->set('Content-Type''application/json');
  1774.             return $response;
  1775.         }
  1776.     }
  1777.     
  1778.     #[Route('/api/coverage'name'app_coverage')]
  1779.     public function index(): JsonResponse
  1780.     {
  1781.         return $this->json([
  1782.             'message' => 'Welcome to your new controller!',
  1783.             'path' => 'src/Controller/CoverageController.php',
  1784.         ]);
  1785.     }
  1786. }