Jump to content

Assistance thinking this through.


SiteNotWorking
Go to solution Solved by Barand,

Recommended Posts

Screenshot-20231128-151846-Chrome.jpg

 

I have this table I created. What I am trying to do is sum the probability based on a lineup, however I am not sure the best way to go through each position and I am struggling on wrapping my brain around the best method.

I.E say I have a lineup that is QB(mvp),WR,WR,RB,K

There is one MVP position per Lineup and the rest are flex. In my table, you will notice 1,2,3 which correspond to the occurrences of that position. After each number there is a probability column. That is what I need to try and add. So for my lineup example I need to look at the MVP column, find QB, then follow the WR from the flex column, all the way to the probab 2 column (because there is 2 WR) which would give me a probability of 8.67%. Next up there is one RB. So I need to go to mvp column, look at QB, then flex column RB, then probab 1 column which gives 11.22%. Lastly there is 1 K, so do the same thing which gives me 3.81%.

 

8.67+11.22+3.81 = 23.7

 

One way I am thinking is having variables for each such as 

$qbrb1,$qbrb2,$qbrb3

$qbwr1,$qbwr2,$qbwr3 etc.

Then I would do something like

$qbrb1 = 11.22

If (mvpPosition == 'QB' && rbCounts = 1) {

Sum1 = $qbrb1

}

 

This could get a little tedious going through each case though, so I am looking for ideas and would appreciate any feedback.

Link to comment
Share on other sites

       $qbrb1 = 11.22;
       $qbrb2 = 3.91;
       $qbrb3 = .15;
       
       $qbte1 = 5.17;
       $qbte2 = .80;
       $qbte3  = 0;
       
       $Sum1 = 0;
       $Sum2 = 0;
       $Sum3 = 0;
       $Sum4 = 0;
       $Sum5 = 0;
       $Sum6 = 0;
       
      if ($index === 0 && $player["position"] === 'QB' && $position_counts['RB']  == 1) {
          $Sum1 = $qbrb1;
      }
      if ($index === 0 && $player["position"] === 'QB' && $position_counts['RB']  == 2) {
      $Sum2 = $qbrb2;
      }
      if ($index === 0 && $player["position"] === 'QB' && $position_counts['RB']  == 3) {
      $Sum3 = $qbrb3;
      }
       if ($index === 0 && $player["position"] === 'QB' && $position_counts['TE']  == 1) {
      $Sum4 = $qbte1;
      }
       if ($index === 0 && $player["position"] === 'QB' && $position_counts['TE']  == 2) {
      $Sum5 = $qbte2;
      }
       if ($index === 0 && $player["position"] === 'QB' && $position_counts['TE']  == 3) {
      $Sum6 = $qbte3;
      }

That would be 2 out of 36 for example

Link to comment
Share on other sites

I'm not entirely sure what you are asking here, but PHP has arrays that are extremely flexible.  An array element can contain a nested array, and you can also have multi-dimensional arrays.  You can also mix arrays and class objects together, as in having a class, creating an object of that class and assigning it to an array, such that you have an array of objects.  Either of these ideas could help you represent the data you have in your table.

Arrays can be easily traversed using for loops or foreach. 

  • Thanks 1
Link to comment
Share on other sites

  • Solution

I agree with Gizmola^.

Using a multidimensional array ...

    $probs = [ 'QB' =>   [  'RB' => [ 1 => 11.22,
                                      2 => 3.91,
                                      3 => 0.15
                                    ],
                           'TE' =>  [ 1 => 5.17,
                                      2 => 0.80,
                                      3 => 0.00
                                    ],       
                           'QB' =>  [ 1 => 9.44,
                                      2 => 0.00,
                                      3 => 0.00
                                    ],       
                           'WR' =>  [ 1 => 10.46,
                                      2 => 8.67,
                                      3 => 4.53
                                    ],       
                           'K' =>   [ 1 => 3.81,
                                      2 => 0.19,
                                      3 => 0.00
                                    ],       
                           'D' =>   [ 1 => 2.85,
                                      2 => 0.07,
                                      3 => 0.00
                                    ]       
                         ]
                        
                // rinse and repeat with the other MVPs and FLEXs       
            ];
            
    $lineup = 'QB, WR, WR, RB, K';
                   
    $arr = array_map('trim', explode(',', $lineup));
    $mvp = array_shift($arr);
    $counts = array_count_values($arr);

    $probability = 0;
    foreach ($counts as $p => $n)  {
        $probability += $probs[$mvp][$p][$n];
    }
    
    echo '<br>'.$probability;             // 23.7

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.