# Relating F1 Position with Points Gone Wrong

**URL:** <https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979>\
**Category:** Ask for Help\
**Created:** [November 17, 2024, 8:31pm UTC](https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979 "2024-11-17T20:31:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterkota](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@peterkota](https://community.glideapps.com/u/peterkota)\
**Post date:** [November 17, 2024, 8:31pm UTC](https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979/1 "2024-11-17T20:31:38Z")

</div>

Hi all,  
Im building a little app for my wife who is having an F1 watch party whereby everyone who attends can add their race predictions in from 1st-10th.

Each position they get correct they should receive the certain amount of points relative to that position, but I cant seem to make this work.

As a test, i have entered my predictions and some fake race results.

The problem is even if a driver is selected but doesnt finish in the same position as my prediction, i still get points for it.

eg I Selected Alexander Albon to finish 2nd, but he finished Last, yet i still get 5 points when i get 0 as my prediction was wrong.

See screenshots attached!

 ![Screenshot 2024-11-18 at 7.24.39 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/c/ec40129bac622cd4498af408a9b7a31872cfa0ae.png)

 ![Screenshot 2024-11-18 at 7.24.55 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/b/3bb489d2fe10e93c1ec573d0275e901d5591d11d.png)

---

<div class="post-metadata">

**Author:** ![Atom](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/atom/32/82126_2.png) [@Atom](https://community.glideapps.com/u/Atom)\
**Post date:** [November 17, 2024, 8:57pm UTC](https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979/2 "2024-11-17T20:57:44Z")

</div>

You’re on the right track! You really just need to add a couple more columns in the Predictions table.

1. Add a Lookup for the Driver name for each of the Relations. Do 1st\_Driver, 2nd\_Driver etc.

2. Add an If → Then → Else column where: "IF 1st is 1st\_Driver, then 1st\_LOOK, Else 0 "

3. You can then add a math column to sum up all the IF THEN ELSE columns for a total points Column.

Let me know if you have any questions!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [November 18, 2024, 12:05am UTC](https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979/3 "2024-11-18T00:05:43Z")

</div>

You might also want to bake in a column for a “Race ID”, in case you want ot have more of these watch parties later and reuse the app.

---

<div class="post-metadata">

**Author:** ![peterkota](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@peterkota](https://community.glideapps.com/u/peterkota)\
**Post date:** [November 20, 2024, 9:16pm UTC](https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979/4 "2024-11-20T21:16:05Z")

</div>

Thanks so much for the help, it makes sense, but i dont know what im doing wrong! See attached.

 ![Screenshot 2024-11-21 at 8.15.35 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/1/01eb0d0f117c0a07cfcf32668a85fe40e3c1d56a.png)

---

<div class="post-metadata">

**Author:** ![peterkota](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@peterkota](https://community.glideapps.com/u/peterkota)\
**Post date:** [November 20, 2024, 9:18pm UTC](https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979/5 "2024-11-20T21:18:08Z")

</div>

That would be awesome!

Would i add RaceID into the Predictions AND Race Results? Where should it live?

---

<div class="post-metadata">

**Author:** ![Atom](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/atom/32/82126_2.png) [@Atom](https://community.glideapps.com/u/Atom)\
**Post date:** [November 20, 2024, 11:38pm UTC](https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979/6 "2024-11-20T23:38:00Z")

</div>

You need to do the following:

1. Add a Row ID column to the Race Results table

2. Add another Lookup column in the Prediction table, that looks up the Row ID column of the Race Results. Call it ID for reference:

3. Change the If → Then → Else to “IF ID = [MANUAL], THEN 1st\_LOOK, ELSE 0”

Where [MANUAL] is the Row ID that corresponds to that position. For example, the 1st\_IF value for [MANUAL] should be the ROW ID of “1st Position” in the Race Results table.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [November 20, 2024, 11:54pm UTC](https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979/7 "2024-11-20T23:54:33Z")

</div>

I would do it like this:

Races: Add a table for Races, with RowID, Race Names.

Predictions: Add a column for RaceID (RowID) coming from Races, I assume people will be able to predict 1st, 2nd, 3rd etc. Craft a JSON column to have a centralized “string” for all predictions from a player.

E.g:

```auto
{
"1st": "John Doe",
"2nd": "James Doe"
}

```

Race Results: Add a column for RaceID, and then a JSON like this.

```auto
{
"Position": "{POS}",
"Driver": "{DRI}",
"Points": {PTS}
}

```

In Predictions, use a multiple relation with the RaceID to the Race Resuls table, then a Joined List column to get all the templates back, separate by a comma and a new line character.

Add a template column with the template being:

[  
R  
]

With R being the Joined List above (formatted to true JSON).

Then, with a JSON for the player’s prediction, and a JSON array for the race results, you would use JavaScript to get the final points.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [November 20, 2024, 11:57pm UTC](https://community.glideapps.com/t/relating-f1-position-with-points-gone-wrong/77979/8 "2024-11-20T23:57:19Z")

</div>

Based on your data, sample JSONs would look like this:

Player Prediction JSON:

```auto
{
  "1st": "Carlos Sainz",
  "2nd": "Alexander Albon",
  "3rd": "Lando Norris"
}

```

Race Results JSON:

```auto
[
  {"Position": "1st", "Driver": "Carlos Sainz", "Points": 25},
  {"Position": "2nd", "Driver": "Lando Norris", "Points": 18},
  {"Position": "3rd", "Driver": "Oscar Piastri", "Points": 15},
  {"Position": "Last Place", "Driver": "Alexander Albon", "Points": 5}
]

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/3/d33ff66f0e4f72aea27bffaede5013c0978fc511.jpeg)

The JS function:

```auto
function calculatePoints(predictionsJSON, raceResultsJSON) {
  // Parse the input JSON strings
  const predictions = JSON.parse(predictionsJSON);
  const raceResults = JSON.parse(raceResultsJSON);

  // Create a mapping of positions to drivers from the race results
  const resultsMap = {};
  raceResults.forEach(result => {
    resultsMap[result.Position] = { driver: result.Driver, points: result.Points };
  });

  // Initialize total score
  let totalPoints = 0;

  // Compare predictions with actual results and calculate points
  for (const [position, predictedDriver] of Object.entries(predictions)) {
    if (resultsMap[position] && resultsMap[position].driver === predictedDriver) {
      totalPoints += resultsMap[position].points;
    }
  }

  return totalPoints;
}

return calculatePoints(p1, p2)

```

I got 25 for predicting the 1st position right.
