Z
zydjohn
Guest
Hello:
I have a group of people take part in an e-game, and each one played the same gaem twice and have 2 records. I have the results of such game performance saved in an array of struct. Now, my target is to create a few groups, each group will have the people with the similar average records for their previous performance, but the average records are not important, I need only the people’s ID.
Here is the code I have now:
const double deviation = 2.5;
public class ManByRecords
{
public string ID { get; set; }
public double BestRecord { get; set; }
public double WorstRecord { get; set; }
}
public class ManByGroup
{
public List<string> ID_IN_Group { get; set; }
}
var man1 = new ManByRecords() { ID = "#1", WorstRecord = 10.0, BestRecord = 16.0 };
var man2 = new ManByRecords() { ID = "#2", WorstRecord = 20.0, BestRecord = 26.0 };
var man3 = new ManByRecords() { ID = "#3", WorstRecord = 21.0, BestRecord = 27.0 };
var man4 = new ManByRecords() { ID = "#4", WorstRecord = 30.0, BestRecord = 36.0 };
var group1 = new ManByGroup() { ID_IN_Group = new List<string> { "#1" } };
var group2 = new ManByGroup() { ID_IN_Group = new List<string> { "#2", "#3"} };
var group3 = new ManByGroup() { ID_IN_Group = new List<string> { "#4" } };
The rules to put different people into one group is like this: if their average record is within the range of deviation, then they are in the same group; otherwise, they are the only member in their respective group.
For example: for man1, as his average record is: 13(=10+16/2), and no other people’s average record are within the range of deviation of 13 (which is from 10.5 to 15.5, from 13-2.5 to 13+2.5), therefore, man1’s ID is in one group with his ID#.
For man2 and man3: man2’s average record is: 23(=20+26/2); man3’s average record is: 24(21+27/2). The man2’s average record are in the range of deviation from 20.5 to 25.5; and man3’s average record are in the range of deviation from 21.5 to 26.5; the both average records have the overlap range of values, therefore, the both people’s IDs are now in the same group: group2.
The same for man4.
I want to use LINQ to do this, but it seems not straight forward. I don’t need to use different group names like group1, group2 or group3. You can put all the group in a list of struct/class, but I can access them easily, it is OK.
Any idea is welcome!
Continue reading...
I have a group of people take part in an e-game, and each one played the same gaem twice and have 2 records. I have the results of such game performance saved in an array of struct. Now, my target is to create a few groups, each group will have the people with the similar average records for their previous performance, but the average records are not important, I need only the people’s ID.
Here is the code I have now:
const double deviation = 2.5;
public class ManByRecords
{
public string ID { get; set; }
public double BestRecord { get; set; }
public double WorstRecord { get; set; }
}
public class ManByGroup
{
public List<string> ID_IN_Group { get; set; }
}
var man1 = new ManByRecords() { ID = "#1", WorstRecord = 10.0, BestRecord = 16.0 };
var man2 = new ManByRecords() { ID = "#2", WorstRecord = 20.0, BestRecord = 26.0 };
var man3 = new ManByRecords() { ID = "#3", WorstRecord = 21.0, BestRecord = 27.0 };
var man4 = new ManByRecords() { ID = "#4", WorstRecord = 30.0, BestRecord = 36.0 };
var group1 = new ManByGroup() { ID_IN_Group = new List<string> { "#1" } };
var group2 = new ManByGroup() { ID_IN_Group = new List<string> { "#2", "#3"} };
var group3 = new ManByGroup() { ID_IN_Group = new List<string> { "#4" } };
The rules to put different people into one group is like this: if their average record is within the range of deviation, then they are in the same group; otherwise, they are the only member in their respective group.
For example: for man1, as his average record is: 13(=10+16/2), and no other people’s average record are within the range of deviation of 13 (which is from 10.5 to 15.5, from 13-2.5 to 13+2.5), therefore, man1’s ID is in one group with his ID#.
For man2 and man3: man2’s average record is: 23(=20+26/2); man3’s average record is: 24(21+27/2). The man2’s average record are in the range of deviation from 20.5 to 25.5; and man3’s average record are in the range of deviation from 21.5 to 26.5; the both average records have the overlap range of values, therefore, the both people’s IDs are now in the same group: group2.
The same for man4.
I want to use LINQ to do this, but it seems not straight forward. I don’t need to use different group names like group1, group2 or group3. You can put all the group in a list of struct/class, but I can access them easily, it is OK.
Any idea is welcome!
Continue reading...