Jump to content
UBot Underground

Finding The Highest Value In A List


Recommended Posts

Hi there :)

I'm new to uBot. Excited to be part of the community :)

 

 

There is a table in a web page. For this example let's say that there are two columns: "Name" and "Value"

From this table, I need to compare (difference) between two values - the highest value, and the 2nd highest value.

Then, I need to know which name is assigned with the highest value.  

 

 

My (textual) algorithm is as follows: 

 

1. Scrape required column value for each row 

2. Scrape the name of each row 

3. Add the two above to a table

4. Compare between the highest and 2nd highest value

5. Determine the name of the highest value. 

 

(if you have a better idea for an algorithm please share ^^ ) 

 

Now I have a table with 'name' and 'value'. 

The value has a $ sign which needs to be removed, because uBot (apparently) can't perform math with $ sign. 

I was able to remove the $ sign for specific rows, but I can't seem to do it for all rows via a loop or via regEx while scraping. 

 

Questions:

1. How can the $ be removed for all items in the list \ table? (I assume that it's best to remove unwanted chars when scraping instead of afterwards via 'replace')

2. How can the highest and 2nd highest values in the list\table be determined?

3. How can we determine which row has the highest value?

 

 

Thanks in advance guys ^^

Edited by shloogy
Link to post
Share on other sites

Well for the $ problem there is a function called $replace, here you can see how to use it while you add your text to a table or when you pull the text out you can replace that sign:

set(#text,"$10.07","Global")
set table cell(&data,0,0,$replace(#text,"$",$nothing))

As for the highest value problem, there are a couple of ways to do it. But if you ever want to multithread the program then its probably best to do the comparison after you have all the data already. So here is an example of that but keep in mind that if you have more than 2 of the same numbers this will only record the last two in that case and not all of them:

clear table(&data)
set(#row,0,"Global")
comment("Create dummy data")
loop(25) {
    set table cell(&data,#row,0,$random text($rand(10,20)))
    set table cell(&data,#row,1,$rand(1,1000))
    increment(#row)
}
divider
comment("Find the largest numbers")
set(#largestNumber,0,"Global")
set(#largestName,$nothing,"Global")
set(#secondLargestNumber,0,"Global")
set(#secondLargestName,$nothing,"Global")
set(#row,0,"Global")
loop($table total rows(&data)) {
    if($comparison($table cell(&data,#row,1),">= Greater than or equal to",#largestNumber)) {
        then {
            set(#secondLargestNumber,#largestNumber,"Global")
            set(#secondLargestName,#largestName,"Global")
            set(#largestNumber,$table cell(&data,#row,1),"Global")
            set(#largestName,$table cell(&data,#row,0),"Global")
        }
        else {
        }
    }
    increment(#row)
}
Link to post
Share on other sites

Hey,

Your best bet all around is JavaScript if you have it in Standard edition or upgrade or do some fancy coding as far as I know.

 

as for the table you can use replace on you %table

clear list(%table)
add list to list(%table,$list from text("$100.00,$75.00,$71.95
$95.00,$32.44,$88.26",$new line),"Delete","Global")
clear table(&table)
clear table(&table1)
create table from text(&table,%table)
create table from text(&table2,$replace(%table,"$",$nothing))
comment("you can do this into a list as well
just put replace in the text field")
set(#table,$replace(%table,"$",$nothing),"Global")
alert(#table)
alert(&table2)

since you cant copy this I attached a file for you

 

Regards,

Nick

replace dollar sign.ubot

Link to post
Share on other sites

 

Well for the $ problem there is a function called $replace, here you can see how to use it while you add your text to a table or when you pull the text out you can replace that sign:

set(#text,"$10.07","Global")
set table cell(&data,0,0,$replace(#text,"$",$nothing))

As for the highest value problem, there are a couple of ways to do it. But if you ever want to multithread the program then its probably best to do the comparison after you have all the data already. So here is an example of that but keep in mind that if you have more than 2 of the same numbers this will only record the last two in that case and not all of them:

clear table(&data)
set(#row,0,"Global")
comment("Create dummy data")
loop(25) {
    set table cell(&data,#row,0,$random text($rand(10,20)))
    set table cell(&data,#row,1,$rand(1,1000))
    increment(#row)
}
divider
comment("Find the largest numbers")
set(#largestNumber,0,"Global")
set(#largestName,$nothing,"Global")
set(#secondLargestNumber,0,"Global")
set(#secondLargestName,$nothing,"Global")
set(#row,0,"Global")
loop($table total rows(&data)) {
    if($comparison($table cell(&data,#row,1),">= Greater than or equal to",#largestNumber)) {
        then {
            set(#secondLargestNumber,#largestNumber,"Global")
            set(#secondLargestName,#largestName,"Global")
            set(#largestNumber,$table cell(&data,#row,1),"Global")
            set(#largestName,$table cell(&data,#row,0),"Global")
        }
        else {
        }
    }
    increment(#row)
}

I keep forgetting to refresh, lol

Link to post
Share on other sites

Thanks for the reply guys, highly appreciated!

 

On some situations, the algorithm provided doesn't return values for #secondLargestName at all. When it happens, #secondLargestNumber returns 0. 

Those two missing values are required for future usage. 

 

Attached a GIF (mouse hover gives you video controls such as pause): 

 

https://i.gyazo.com/ab7d77185cbadf97a2fd0d1ea0adece6.mp4

 

 

I tried to come up with a solution but couldn't figure it out, still new at this. 

Edited by shloogy
Link to post
Share on other sites

Thanks for the reply guys, highly appreciated!

 

On some situations, the algorithm provided doesn't return values for #secondLargestName at all. When it happens, #secondLargestNumber returns 0. 

Those two missing values are required for future usage. 

 

Attached a GIF (mouse hover gives you video controls such as pause): 

 

https://i.gyazo.com/ab7d77185cbadf97a2fd0d1ea0adece6.mp4

 

 

I tried to come up with a solution but couldn't figure it out, still new at this. 

 

Yes good catch. It was not setting the second number when the first was the largest already, this should fix that.

clear table(&data)
set(#row,0,"Global")
comment("Create dummy data")
loop(3) {
    set table cell(&data,#row,0,$random text($rand(10,20)))
    set table cell(&data,#row,1,$rand(1,1000))
    increment(#row)
}
divider
comment("Find the largest numbers")
set(#largestNumber,0,"Global")
set(#largestName,$nothing,"Global")
set(#secondLargestNumber,0,"Global")
set(#secondLargestName,$nothing,"Global")
set(#row,0,"Global")
loop($table total rows(&data)) {
    if($comparison($table cell(&data,#row,1),">= Greater than or equal to",#largestNumber)) {
        then {
            set(#secondLargestNumber,#largestNumber,"Global")
            set(#secondLargestName,#largestName,"Global")
            set(#largestNumber,$table cell(&data,#row,1),"Global")
            set(#largestName,$table cell(&data,#row,0),"Global")
        }
        else if($comparison($table cell(&data,#row,1),">= Greater than or equal to",#secondLargestNumber)) {
            set(#secondLargestNumber,$table cell(&data,#row,1),"Global")
            set(#secondLargestName,$table cell(&data,#row,0),"Global")
        }
        else {
        }
    }
    increment(#row)
}
Link to post
Share on other sites
  • 3 weeks later...

Not able to read through the whole thread.. but this gave me the idea for my next tutorial :)

 

Here's a simple way to get the highest and lowest values from a list. Hope it helps someone..

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...