{
  "id": 359700,
  "title": "Intersections of goal lines (A or B)",
  "url": "/competitions/tabular-playground-series-oct-2022/discussion/359700",
  "author_name": "",
  "post_date": "2022-10-13T07:52:55.479452300Z",
  "votes": 3,
  "comment_count": 3,
  "views": 0,
  "content": "<pre><code>def intersection_gates (data,t):\n    data['ball_pos_x_new']=data['ball_pos_x']+t*data['ball_vel_x']             \n</code></pre>\n<p><strong># here we define a new location of the ball with the  speed vector plus the time value.</strong></p>\n<pre><code>data['ball_pos_y_new']=data['ball_pos_y']+t*data['ball_vel_y']\ndata['ball_pos_z_new']=data['ball_pos_z']+t*data['ball_vel_z']\n\ndata['l'] = data['ball_pos_x_new'] - data['ball_pos_x']\ndata['m'] = data['ball_pos_y_new'] - data['ball_pos_y']\ndata['n'] = data['ball_pos_z_new'] - data['ball_pos_z']\n</code></pre>\n<p><strong># here we find a point with y=100 (the location of a  gate).</strong></p>\n<pre><code>data['yA'] = (100 - data['ball_pos_y_new'])/ data['m']                            \ndata['xA'] = data['yA']*data['l']+data['ball_pos_x_new']\ndata['zA'] = data['yA']*data['n']+data['ball_pos_z_new']\n</code></pre>\n<p><strong># here we check that a point belongs to the gate.</strong></p>\n<pre><code>data['x1A'] = data['yA']*data['l']+data['ball_pos_x_new']&gt;-20                 \ndata['x2A'] = data['yA']*data['l']+data['ball_pos_x_new']&lt;20\ndata['z1A'] = data['yA']*data['n']+data['ball_pos_z_new']&gt;0\ndata['z2A'] = data['yA']*data['n']+data['ball_pos_z_new']&lt;20            \n</code></pre>\n<p><strong>#the distance of the covered way.</strong></p>\n<pre><code>data['distance_t']=np.sqrt(                                                                          \n                            (data['ball_pos_x_new']-data['ball_pos_x'])**2+\n                            (data['ball_pos_y_new']-data['ball_pos_y'])**2+\n                            (data['ball_pos_z_new']-data['ball_pos_z'])**2\n                            )\n</code></pre>\n<p><strong>#the distance between ball and the gate</strong></p>\n<pre><code>data['distance_B']=np.sqrt(                                                                             \n                            (data['xA']-data['ball_pos_x'])**2+\n                            (100-data['ball_pos_y'])**2+\n                            (data['zA']-data['ball_pos_z'])**2\n                            )    \n</code></pre>\n<p><strong>#check the that the ball is moving towards the   right gate</strong></p>\n<pre><code>data['ball_vel_y_dirB'] = data['ball_vel_y'] &gt; 0         \n</code></pre>\n<p><strong>#the distance between the ball and the gate must be less than the distance between  ball and the new position of the ball.</strong>                                      </p>\n<pre><code>data['distance_B'] = data['distance_B'] &lt;= data['distance_t']                       \n\n\ndata['intersection_team_A'] = (data.loc[:,['x1A','x2A','z1A','z2A','ball_vel_y_dirB','distance_B']]).sum(axis=1) == 6\n</code></pre>\n<p><strong>#If 6 out of 6 are true, it means that there is a high probability that the ball will cross the goal in one or two second.</strong></p>\n<pre><code>#________________________The same story about another gate._________________________________________\n\ndata['yB'] = (-100 - data['ball_pos_y_new'])/ data['m']\ndata['xB'] = data['yB']*data['l']+data['ball_pos_x_new']\ndata['zB'] = data['yB']*data['n']+data['ball_pos_z_new']\n\n\ndata['x1B'] = data['yB']*data['l']+data['ball_pos_x_new']&gt;-20\ndata['x2B'] = data['yB']*data['l']+data['ball_pos_x_new']&lt;20\ndata['z1B'] = data['yB']*data['n']+data['ball_pos_z_new']&gt;0\ndata['z2B'] = data['yB']*data['n']+data['ball_pos_z_new']&lt;20\n\ndata['distance_A']=np.sqrt(\n                            (data['xB']-data['ball_pos_x'])**2+\n                            (-100-data['ball_pos_y'])**2+\n                            (data['zB']-data['ball_pos_z'])**2\n                            )   \ndata['ball_vel_y_dirA'] = data['ball_vel_y']&lt; 0\ndata['distance_A'] = data['distance_A'] &lt;= data['distance_t']\n\ndata['intersection_team_B'] =  (data.loc[:,['x1B','x2B','z1B','z2B','ball_vel_y_dirA','distance_A']]).sum(axis=1) == 6\n\ndata = data.drop(columns=['distance_B','distance_A','distance_t',\n                          'ball_pos_x_new','ball_pos_y_new','ball_pos_z_new',\n                          'l','m','n','yA','xA','zA','yB','zB','xB',\n                          'x1A','x2A','z1A','z2A','x1B','x2B','z1B','z2B'],axis=1)\n\nreturn data\n</code></pre>",
  "messages": [
    {
      "id": "1985261",
      "postDate": "10/13/2022 07:52:55",
      "content": "<pre><code>def intersection_gates (data,t):\n    data['ball_pos_x_new']=data['ball_pos_x']+t*data['ball_vel_x']             \n</code></pre>\n<p><strong># here we define a new location of the ball with the  speed vector plus the time value.</strong></p>\n<pre><code>data['ball_pos_y_new']=data['ball_pos_y']+t*data['ball_vel_y']\ndata['ball_pos_z_new']=data['ball_pos_z']+t*data['ball_vel_z']\n\ndata['l'] = data['ball_pos_x_new'] - data['ball_pos_x']\ndata['m'] = data['ball_pos_y_new'] - data['ball_pos_y']\ndata['n'] = data['ball_pos_z_new'] - data['ball_pos_z']\n</code></pre>\n<p><strong># here we find a point with y=100 (the location of a  gate).</strong></p>\n<pre><code>data['yA'] = (100 - data['ball_pos_y_new'])/ data['m']                            \ndata['xA'] = data['yA']*data['l']+data['ball_pos_x_new']\ndata['zA'] = data['yA']*data['n']+data['ball_pos_z_new']\n</code></pre>\n<p><strong># here we check that a point belongs to the gate.</strong></p>\n<pre><code>data['x1A'] = data['yA']*data['l']+data['ball_pos_x_new']&gt;-20                 \ndata['x2A'] = data['yA']*data['l']+data['ball_pos_x_new']&lt;20\ndata['z1A'] = data['yA']*data['n']+data['ball_pos_z_new']&gt;0\ndata['z2A'] = data['yA']*data['n']+data['ball_pos_z_new']&lt;20            \n</code></pre>\n<p><strong>#the distance of the covered way.</strong></p>\n<pre><code>data['distance_t']=np.sqrt(                                                                          \n                            (data['ball_pos_x_new']-data['ball_pos_x'])**2+\n                            (data['ball_pos_y_new']-data['ball_pos_y'])**2+\n                            (data['ball_pos_z_new']-data['ball_pos_z'])**2\n                            )\n</code></pre>\n<p><strong>#the distance between ball and the gate</strong></p>\n<pre><code>data['distance_B']=np.sqrt(                                                                             \n                            (data['xA']-data['ball_pos_x'])**2+\n                            (100-data['ball_pos_y'])**2+\n                            (data['zA']-data['ball_pos_z'])**2\n                            )    \n</code></pre>\n<p><strong>#check the that the ball is moving towards the   right gate</strong></p>\n<pre><code>data['ball_vel_y_dirB'] = data['ball_vel_y'] &gt; 0         \n</code></pre>\n<p><strong>#the distance between the ball and the gate must be less than the distance between  ball and the new position of the ball.</strong>                                      </p>\n<pre><code>data['distance_B'] = data['distance_B'] &lt;= data['distance_t']                       \n\n\ndata['intersection_team_A'] = (data.loc[:,['x1A','x2A','z1A','z2A','ball_vel_y_dirB','distance_B']]).sum(axis=1) == 6\n</code></pre>\n<p><strong>#If 6 out of 6 are true, it means that there is a high probability that the ball will cross the goal in one or two second.</strong></p>\n<pre><code>#________________________The same story about another gate._________________________________________\n\ndata['yB'] = (-100 - data['ball_pos_y_new'])/ data['m']\ndata['xB'] = data['yB']*data['l']+data['ball_pos_x_new']\ndata['zB'] = data['yB']*data['n']+data['ball_pos_z_new']\n\n\ndata['x1B'] = data['yB']*data['l']+data['ball_pos_x_new']&gt;-20\ndata['x2B'] = data['yB']*data['l']+data['ball_pos_x_new']&lt;20\ndata['z1B'] = data['yB']*data['n']+data['ball_pos_z_new']&gt;0\ndata['z2B'] = data['yB']*data['n']+data['ball_pos_z_new']&lt;20\n\ndata['distance_A']=np.sqrt(\n                            (data['xB']-data['ball_pos_x'])**2+\n                            (-100-data['ball_pos_y'])**2+\n                            (data['zB']-data['ball_pos_z'])**2\n                            )   \ndata['ball_vel_y_dirA'] = data['ball_vel_y']&lt; 0\ndata['distance_A'] = data['distance_A'] &lt;= data['distance_t']\n\ndata['intersection_team_B'] =  (data.loc[:,['x1B','x2B','z1B','z2B','ball_vel_y_dirA','distance_A']]).sum(axis=1) == 6\n\ndata = data.drop(columns=['distance_B','distance_A','distance_t',\n                          'ball_pos_x_new','ball_pos_y_new','ball_pos_z_new',\n                          'l','m','n','yA','xA','zA','yB','zB','xB',\n                          'x1A','x2A','z1A','z2A','x1B','x2B','z1B','z2B'],axis=1)\n\nreturn data\n</code></pre>",
      "rawMarkdown": "```\ndef intersection_gates (data,t):\n    data['ball_pos_x_new']=data['ball_pos_x']+t*data['ball_vel_x']             \n```   \n\n**# here we define a new location of the ball with the  speed vector plus the time value.**\n    \n    data['ball_pos_y_new']=data['ball_pos_y']+t*data['ball_vel_y']\n    data['ball_pos_z_new']=data['ball_pos_z']+t*data['ball_vel_z']\n\n    data['l'] = data['ball_pos_x_new'] - data['ball_pos_x']\n    data['m'] = data['ball_pos_y_new'] - data['ball_pos_y']\n    data['n'] = data['ball_pos_z_new'] - data['ball_pos_z']\n\n**# here we find a point with y=100 (the location of a  gate).**\n\n    data['yA'] = (100 - data['ball_pos_y_new'])/ data['m']                            \n    data['xA'] = data['yA']*data['l']+data['ball_pos_x_new']\n    data['zA'] = data['yA']*data['n']+data['ball_pos_z_new']\n \n**# here we check that a point belongs to the gate.**\n\n    data['x1A'] = data['yA']*data['l']+data['ball_pos_x_new']>-20                 \n    data['x2A'] = data['yA']*data['l']+data['ball_pos_x_new']<20\n    data['z1A'] = data['yA']*data['n']+data['ball_pos_z_new']>0\n    data['z2A'] = data['yA']*data['n']+data['ball_pos_z_new']<20            \n\n **#the distance of the covered way.**\n\n    data['distance_t']=np.sqrt(                                                                          \n                                (data['ball_pos_x_new']-data['ball_pos_x'])**2+\n                                (data['ball_pos_y_new']-data['ball_pos_y'])**2+\n                                (data['ball_pos_z_new']-data['ball_pos_z'])**2\n                                )\n**#the distance between ball and the gate**\n\n    data['distance_B']=np.sqrt(                                                                             \n                                (data['xA']-data['ball_pos_x'])**2+\n                                (100-data['ball_pos_y'])**2+\n                                (data['zA']-data['ball_pos_z'])**2\n                                )    \n\n **#check the that the ball is moving towards the   right gate**\n\n    data['ball_vel_y_dirB'] = data['ball_vel_y'] > 0         \n\n**#the distance between the ball and the gate must be less than the distance between  ball and the new position of the ball.**                                      \n\n    data['distance_B'] = data['distance_B'] <= data['distance_t']                       \n\n\n    data['intersection_team_A'] = (data.loc[:,['x1A','x2A','z1A','z2A','ball_vel_y_dirB','distance_B']]).sum(axis=1) == 6\n\n**#If 6 out of 6 are true, it means that there is a high probability that the ball will cross the goal in one or two second.**\n\n    #________________________The same story about another gate._________________________________________\n\n    data['yB'] = (-100 - data['ball_pos_y_new'])/ data['m']\n    data['xB'] = data['yB']*data['l']+data['ball_pos_x_new']\n    data['zB'] = data['yB']*data['n']+data['ball_pos_z_new']\n\n\n    data['x1B'] = data['yB']*data['l']+data['ball_pos_x_new']>-20\n    data['x2B'] = data['yB']*data['l']+data['ball_pos_x_new']<20\n    data['z1B'] = data['yB']*data['n']+data['ball_pos_z_new']>0\n    data['z2B'] = data['yB']*data['n']+data['ball_pos_z_new']<20\n\n    data['distance_A']=np.sqrt(\n                                (data['xB']-data['ball_pos_x'])**2+\n                                (-100-data['ball_pos_y'])**2+\n                                (data['zB']-data['ball_pos_z'])**2\n                                )   \n    data['ball_vel_y_dirA'] = data['ball_vel_y']< 0\n    data['distance_A'] = data['distance_A'] <= data['distance_t']\n\n    data['intersection_team_B'] =  (data.loc[:,['x1B','x2B','z1B','z2B','ball_vel_y_dirA','distance_A']]).sum(axis=1) == 6\n\n    data = data.drop(columns=['distance_B','distance_A','distance_t',\n                              'ball_pos_x_new','ball_pos_y_new','ball_pos_z_new',\n                              'l','m','n','yA','xA','zA','yB','zB','xB',\n                              'x1A','x2A','z1A','z2A','x1B','x2B','z1B','z2B'],axis=1)\n\n    return data",
      "votes": null
    },
    {
      "id": "1985265",
      "postDate": "10/13/2022 07:54:08",
      "content": "<p>The first version was with lambda function. But it took much time to process data. It takes around 3 sec for one train set.</p>",
      "rawMarkdown": "The first version was with lambda function. But it took much time to process data. It takes around 3 sec for one train set.",
      "votes": null
    },
    {
      "id": "1985350",
      "postDate": "10/13/2022 09:09:30",
      "content": "<p>Im not sure I follow the logic of what you are stating here. Can you summarise your process? </p>",
      "rawMarkdown": "Im not sure I follow the logic of what you are stating here. Can you summarise your process?",
      "votes": null
    },
    {
      "id": "1988175",
      "postDate": "10/15/2022 05:54:01",
      "content": "<p>hihihihihihihihihihi</p>",
      "rawMarkdown": "hihihihihihihihihihi",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1985265,
      "author_name": "viktortaran",
      "author_url": "",
      "post_date": "10/13/2022 07:54:08",
      "content": "<p>The first version was with lambda function. But it took much time to process data. It takes around 3 sec for one train set.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1985350,
      "author_name": "slythe",
      "author_url": "",
      "post_date": "10/13/2022 09:09:30",
      "content": "<p>Im not sure I follow the logic of what you are stating here. Can you summarise your process? </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1988175,
      "author_name": "apical",
      "author_url": "",
      "post_date": "10/15/2022 05:54:01",
      "content": "<p>hihihihihihihihihihi</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1985261": "```\ndef intersection_gates (data,t):\n    data['ball_pos_x_new']=data['ball_pos_x']+t*data['ball_vel_x']             \n```   \n\n**# here we define a new location of the ball with the  speed vector plus the time value.**\n    \n    data['ball_pos_y_new']=data['ball_pos_y']+t*data['ball_vel_y']\n    data['ball_pos_z_new']=data['ball_pos_z']+t*data['ball_vel_z']\n\n    data['l'] = data['ball_pos_x_new'] - data['ball_pos_x']\n    data['m'] = data['ball_pos_y_new'] - data['ball_pos_y']\n    data['n'] = data['ball_pos_z_new'] - data['ball_pos_z']\n\n**# here we find a point with y=100 (the location of a  gate).**\n\n    data['yA'] = (100 - data['ball_pos_y_new'])/ data['m']                            \n    data['xA'] = data['yA']*data['l']+data['ball_pos_x_new']\n    data['zA'] = data['yA']*data['n']+data['ball_pos_z_new']\n \n**# here we check that a point belongs to the gate.**\n\n    data['x1A'] = data['yA']*data['l']+data['ball_pos_x_new']>-20                 \n    data['x2A'] = data['yA']*data['l']+data['ball_pos_x_new']<20\n    data['z1A'] = data['yA']*data['n']+data['ball_pos_z_new']>0\n    data['z2A'] = data['yA']*data['n']+data['ball_pos_z_new']<20            \n\n **#the distance of the covered way.**\n\n    data['distance_t']=np.sqrt(                                                                          \n                                (data['ball_pos_x_new']-data['ball_pos_x'])**2+\n                                (data['ball_pos_y_new']-data['ball_pos_y'])**2+\n                                (data['ball_pos_z_new']-data['ball_pos_z'])**2\n                                )\n**#the distance between ball and the gate**\n\n    data['distance_B']=np.sqrt(                                                                             \n                                (data['xA']-data['ball_pos_x'])**2+\n                                (100-data['ball_pos_y'])**2+\n                                (data['zA']-data['ball_pos_z'])**2\n                                )    \n\n **#check the that the ball is moving towards the   right gate**\n\n    data['ball_vel_y_dirB'] = data['ball_vel_y'] > 0         \n\n**#the distance between the ball and the gate must be less than the distance between  ball and the new position of the ball.**                                      \n\n    data['distance_B'] = data['distance_B'] <= data['distance_t']                       \n\n\n    data['intersection_team_A'] = (data.loc[:,['x1A','x2A','z1A','z2A','ball_vel_y_dirB','distance_B']]).sum(axis=1) == 6\n\n**#If 6 out of 6 are true, it means that there is a high probability that the ball will cross the goal in one or two second.**\n\n    #________________________The same story about another gate._________________________________________\n\n    data['yB'] = (-100 - data['ball_pos_y_new'])/ data['m']\n    data['xB'] = data['yB']*data['l']+data['ball_pos_x_new']\n    data['zB'] = data['yB']*data['n']+data['ball_pos_z_new']\n\n\n    data['x1B'] = data['yB']*data['l']+data['ball_pos_x_new']>-20\n    data['x2B'] = data['yB']*data['l']+data['ball_pos_x_new']<20\n    data['z1B'] = data['yB']*data['n']+data['ball_pos_z_new']>0\n    data['z2B'] = data['yB']*data['n']+data['ball_pos_z_new']<20\n\n    data['distance_A']=np.sqrt(\n                                (data['xB']-data['ball_pos_x'])**2+\n                                (-100-data['ball_pos_y'])**2+\n                                (data['zB']-data['ball_pos_z'])**2\n                                )   \n    data['ball_vel_y_dirA'] = data['ball_vel_y']< 0\n    data['distance_A'] = data['distance_A'] <= data['distance_t']\n\n    data['intersection_team_B'] =  (data.loc[:,['x1B','x2B','z1B','z2B','ball_vel_y_dirA','distance_A']]).sum(axis=1) == 6\n\n    data = data.drop(columns=['distance_B','distance_A','distance_t',\n                              'ball_pos_x_new','ball_pos_y_new','ball_pos_z_new',\n                              'l','m','n','yA','xA','zA','yB','zB','xB',\n                              'x1A','x2A','z1A','z2A','x1B','x2B','z1B','z2B'],axis=1)\n\n    return data",
    "1985265": "The first version was with lambda function. But it took much time to process data. It takes around 3 sec for one train set.",
    "1985350": "Im not sure I follow the logic of what you are stating here. Can you summarise your process?",
    "1988175": "hihihihihihihihihihi"
  },
  "source": "meta"
}