[英]Compare values for the previous rows on leaderboard table, simple query
I am trying to compare the pick status of each previous row to ensure the pick status is higher than the previous. 我正在尝试比较每个前一行的选择状态,以确保选择状态高于上一个。 The user makes 4 picks and if the pick status is 1 or 2 its added to the pick status total. 用户进行4个选择,如果选择状态为1或2,则将其添加到选择状态总计中。
The user with the highest total of won_and_looking_good tops the table, but if the user has the same total then their points_player is taken into consideration. 拥有won_and_looking_good总数最高的用户位于表的顶部,但是如果用户具有相同的总数,则考虑其points_player。
I am basically trying to compare the total_of_won_and_looking_good with the total_of_won_and_looking_good from the previous row, i can seem to figure out how to to do this. 我基本上是想将上一行的total_of_won_and_looking_good与total_of_won_and_looking_good进行比较,我似乎可以弄清楚该如何做。 This is my code: 这是我的代码:
test_player_leaderboard_entry() { test_player_leaderboard_entry(){
int previous_total = 0;
int size = playerRows.size();
for (int i = 0; i < size; i++) {
//Position
String position_first_player = Drivers.getDriver().findElement(By.cssSelector("[data-qa-position-value='" + i + "']")).getText();
//Points
String points_player = Drivers.getDriver().findElement(By.cssSelector("[data-qa-points-value='" + i + "']")).getText();
//Username
String username_player = Drivers.getDriver().findElement(By.cssSelector("[data-qa-player-value='" + i + "']")).getText();
//Row Number
Integer row = i + 1;
Integer total_of_won_and_looking_good = 0;
//PICKS
for (int pick_number = 1; pick_number < 5; pick_number++) {
String pick_status = Drivers.getDriver().findElement(By.xpath("//*[@id='root']/div/main/section[2]/section/div/ol/a[" + row + "]/li/div[3]/div[" + pick_number + "]/div")).getAttribute("data-qa-pick-state");
//System.out.println(pick_status);
if (Integer.parseInt(pick_status) == 2 || Integer.parseInt(pick_status) == 1) {
total_of_won_and_looking_good = total_of_won_and_looking_good + 1;
}
}if (i > 0 && total_of_won_and_looking_good >= previous_total) {
System.out.println("Pick amounts are the same");
}
System.out.println("On row number " + row + " we find " + username_player + " in position " + position_first_player + " with " + total_of_won_and_looking_good + " correct picks and " + points_player + " points!");
}
}
So you want to test that total_of_won_and_looking_good
decreases monotonically. 因此,您要测试total_of_won_and_looking_good
单调减少。
You will need to record the previous value, and if you are not on the first row, compare the new value with the previous value. 您将需要记录先前的值,如果不在第一行,则将新值与先前的值进行比较。
You'll need a new local variable: int previous_total;
您将需要一个新的局部变量: int previous_total;
which is declared on the first line of the body of test_player_leaderboard_entry
. 在test_player_leaderboard_entry
正文的第一行声明。 And after you've calculated the new value, something like: 计算完新值后,类似:
if (i > 0 && total_of_won_and_looking_good > previous_total) {
// report the error
}
previous_total = total_of_won_and_looking_good;
which goes just before your current System.out.println
. 它在您当前的System.out.println
之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.