Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
Updated ranker
Browse files Browse the repository at this point in the history
- uses descending values
- uses (1/time)*const for better accuracy like @dowhep  suggested
- Jack in the bot got score as expected (highest), so algo is working lol
  • Loading branch information
shreystechtips committed Mar 7, 2019
1 parent 7358752 commit 4634735
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
14 changes: 7 additions & 7 deletions NRGScoutingApp/Helper Classes/ConstantVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ public class ConstantVars {
// This is just examples of multiplier, should be changed soon
public static readonly double TIME_NERF = 10000;
public static readonly double OVERALL_MULT = 10;
public static readonly double CARGO_MULTIPLIER = 3 / TIME_NERF;
public static readonly double HATCHER_MULTIPLIER = 2 / TIME_NERF;
public static readonly double CLIMB_MULTIPLIER = 1;
public static readonly double DROP_1_MULTIPLIER = 1 / TIME_NERF;
public static readonly double DROP_2_MULTIPLIER = 2 / TIME_NERF;
public static readonly double DROP_3_MULTIPLIER = 3 / TIME_NERF;
public static readonly double DROP_4_MULTIPLIER = 3 / TIME_NERF;
public static readonly double CARGO_MULTIPLIER = 3 * MATCH_SPAN_MS;
public static readonly double HATCHER_MULTIPLIER = 2 * MATCH_SPAN_MS;
public static readonly double CLIMB_MULTIPLIER = 5;
public static readonly double DROP_1_MULTIPLIER = 1 * MATCH_SPAN_MS;
public static readonly double DROP_2_MULTIPLIER = 2 * MATCH_SPAN_MS;
public static readonly double DROP_3_MULTIPLIER = 3 * MATCH_SPAN_MS;
public static readonly double DROP_4_MULTIPLIER = 3 * MATCH_SPAN_MS;

//Climb
public static readonly double PTS_NEED_HELP_LVL_2 = 1;
Expand Down
49 changes: 29 additions & 20 deletions NRGScoutingApp/Helper Classes/Ranker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Newtonsoft.Json.Linq;
using Xamarin.Essentials;
using Xamarin.Forms;
using System.Linq;

namespace NRGScoutingApp {
public class Ranker {
Expand Down Expand Up @@ -63,7 +64,7 @@ public String[] returnTeamTimes (string team) {
retValues[3] = ConstantVars.noVal;
}
if (drop1Data.ContainsKey (team)) {
retValues[4] = timeAdaptiveString ((int) drop1Data[team]); //timeAdaptiveString
retValues[4] = timeAdaptiveString ((int) drop1Data[team]);
} else {
retValues[4] = ConstantVars.noVal;
}
Expand Down Expand Up @@ -120,15 +121,15 @@ public Dictionary<String, double> getRank (MatchFormat.CHOOSE_RANK_TYPE x) {
refresh ();
switch (x) {
case MatchFormat.CHOOSE_RANK_TYPE.pick1: //hatch
return hatchData;
return timeFixer(hatchData);
case MatchFormat.CHOOSE_RANK_TYPE.pick2: //cargo
return cargoData;
return timeFixer(cargoData);
case MatchFormat.CHOOSE_RANK_TYPE.drop1:
return drop1_4Data;
return timeFixer(drop1_4Data);
case MatchFormat.CHOOSE_RANK_TYPE.drop2:
return drop2Data;
return timeFixer(drop2Data);
case MatchFormat.CHOOSE_RANK_TYPE.drop3:
return drop3Data;
return timeFixer(drop3Data);
case MatchFormat.CHOOSE_RANK_TYPE.climb:
return climbData;
case MatchFormat.CHOOSE_RANK_TYPE.overallRank:
Expand All @@ -139,6 +140,14 @@ public Dictionary<String, double> getRank (MatchFormat.CHOOSE_RANK_TYPE x) {
}
}

public Dictionary<String,double> timeFixer(Dictionary<string, double> input) {
Dictionary<String, double> temp = new Dictionary<string, double>(input);
foreach(var s in input.ToList()) {
temp[s.Key] = Math.Round(ConstantVars.MATCH_SPAN_MS / input[s.Key],2);
}
return temp;
}

public Dictionary<string, string> returnDataAsTime (Dictionary<string, double> input) {
Dictionary<string, string> result = new Dictionary<string, string> ();
foreach (var x in input) {
Expand Down Expand Up @@ -220,26 +229,26 @@ public Dictionary<string, double> getOverallData () {
Dictionary<string, double> climbData = getClimbData ();
foreach (KeyValuePair<string, double> entry in climbData) {
double point = 0;
if (dropData1.ContainsKey (entry.Key)) {
point += dropData1[entry.Key] * ConstantVars.DROP_1_MULTIPLIER;
if (dropData1.ContainsKey (entry.Key) && drop1Data[entry.Key] > 0) {
point += ConstantVars.DROP_1_MULTIPLIER / dropData1[entry.Key];
}
if (dropData2.ContainsKey (entry.Key)) {
point += dropData2[entry.Key] * ConstantVars.DROP_2_MULTIPLIER;
if (dropData2.ContainsKey (entry.Key) && drop2Data[entry.Key] > 0) {
point += ConstantVars.DROP_2_MULTIPLIER/ dropData2[entry.Key];
}
if (dropData3.ContainsKey (entry.Key)) {
point += dropData3[entry.Key] * ConstantVars.DROP_3_MULTIPLIER;
if (dropData3.ContainsKey (entry.Key) && drop3Data[entry.Key] > 0) {
point += ConstantVars.DROP_3_MULTIPLIER/ dropData3[entry.Key];
}
if (dropData4.ContainsKey (entry.Key)) {
point += dropData4[entry.Key] * ConstantVars.DROP_4_MULTIPLIER;
if (dropData4.ContainsKey (entry.Key) && drop4Data[entry.Key] > 0) {
point += ConstantVars.DROP_4_MULTIPLIER/ dropData4[entry.Key];
}
if (cargoData.ContainsKey (entry.Key)) {
point += cargoData[entry.Key] * ConstantVars.CARGO_MULTIPLIER;
if (cargoData.ContainsKey (entry.Key) && cargoData[entry.Key] > 0) {
point += ConstantVars.CARGO_MULTIPLIER/ cargoData[entry.Key];
}
if (hatcherData.ContainsKey (entry.Key)) {
point += hatcherData[entry.Key] * ConstantVars.HATCHER_MULTIPLIER;
if (hatcherData.ContainsKey (entry.Key) && hatcherData[entry.Key] > 0) {
point += ConstantVars.HATCHER_MULTIPLIER/ hatcherData[entry.Key];
}
point -= (climbData[entry.Key] * ConstantVars.CLIMB_MULTIPLIER);
data.Add (entry.Key, Math.Round(point * ConstantVars.OVERALL_MULT,2));
point += (climbData[entry.Key] * ConstantVars.CLIMB_MULTIPLIER);
data.Add (entry.Key, Math.Round(point,2)); //* ConstantVars.OVERALL_MULT
}
return data;
}
Expand Down
2 changes: 1 addition & 1 deletion NRGScoutingApp/Pages/Main Landing/Rankings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void updateEvents () {
//Gets all data and sets it into ascending order based on each team's average time
Dictionary<string, double> x = mainRank.getRank (rankChoice);
var y = from pair in x
orderby pair.Value ascending
orderby pair.Value descending
select pair;
setListVisibility (y.Count ());
List<RankStruct> ranks = new List<RankStruct> ();
Expand Down
2 changes: 1 addition & 1 deletion NRGScoutingApp/Pages/Pit Scouting/PitEntry.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void cacheCheck () {
}
catch (NullReferenceException e)
{

Console.WriteLine(e.StackTrace);
}
}
updateAllBoxes();
Expand Down

0 comments on commit 4634735

Please sign in to comment.