AutoIt Searching values to get class variable - autoit

I have a problem with searching and displaying only the values that I need. So basically I need to get a class name stored in a variable which depends on the selected item.
Every [section] of items has key 1 ( item name ), 78 ( race ), 80 ( class ).
78=1 ; human - race
80=1 ; knight - class
80=2 ; archer - class
80=8 ; mage - class
78=2 ; orc - race
80=1 ; berskerer - class
80=2 ; hunter - class
80=8 ; sorc - class
78=4 ; elf - race
80=1 ; swashbuckler - class
80=2 ; ranger - class
80=8 ; elementalist - class
78=8 ; dragonscion - race
80=15 ; scion - class
Here is my code: http://pastebin.com/DUwhVAxY
Here is zip file with 2 images and .ini file http://uploaded.net/file/eleih11o.
In the 1st image is my code that works, and in the 2nd image is an example of what I need; just a variable with class name.
Here is one more image with all the stuff:

This is the closest I could get but still it will fail since you have no standard seperators and/or items.
Case $hFinddAllButton
GUICtrlSetData($hList, '')
Redim $afound[0][3]
Local $sCout = 0
Local $sCounterText[0]
Local $sCounterNum[0]
For $i = 0 To UBound($matches)-1
If StringInStr($matches[$i][2], GUICtrlRead($hSearchInput)) Then
_ArrayAdd($afound, $matches[$i][0] &'|'& $matches[$i][1] &'|'& $matches[$i][2])
ReDim $sCounterText[UBound($sCounterText) +1]
ReDim $sCounterNum[UBound($sCounterNum) +1]
$sCounterText[$sCout] = $matches[$i][2]
$sCounterNum[$sCout] = $matches[$i][0]
$sCout += 1
EndIf
Next
For $s = 0 To UBound($sCounterText) -1
;~ ConsoleWrite($sCounterText[$s] & #LF)
;~ _ArrayAdd($afound, $matches[$i][0] &'|'& $matches[$i][1] &'|'& $matches[$i][2])
Local $sSplit = StringSplit($sCounterText[0], " ", 2)
Local $sSplit2 = StringSplit($sCounterText[$s], " ", 2)
GUICtrlSetData($hList, '[' & $sCounterNum[$s] &'] ' & $sSplit[0] & " Biltz (" & GUICtrlRead($hSearchInput) & ") - " & $sCounterText[$s])
Next

Related

Fetching specific text from a dialog box using autoit

I want to get text from a dialog box. I am getting the title from the dialog box using winGetTitle() function.
My code in autoit is as follows:
$pId = Run("C:/foldername/Dialogbox.exe")
Local $hWnd = WinWait("[CLASS:#32770]", "", 10)
Local $sTitle = WinGetTitle("[ACTIVE]")
; Display the window title.
ConsoleWrite($sTitle & #CRLF)
; changing control from the class containg title to the class containing the text.
Local $hSysTray_Handle = ControlGetHandle('[Class:#32770]', '', '[Class:SysListView32;Instance:1]')
Local $sText = WinGetText("[ACTIVE]")
Local $sTextnew = ControlGetText($hSysTray_Handle, "", $sText)
ConsoleWrite($sTextnew & #CRLF)
This returns only the title and not the text in the dialog box. #32770 is the main class of dialog box and title, text are in the different classes in basic control info in autoit.
I am new to autoit and don't know how to fetch the text from dialog box. Or should I use sikuli for this?
; Start Mp3tag if not running.
If Not ProcessExists('Mp3tag.exe') Then
Run('"C:\Program Files (x86)\Mp3tag\Mp3tag.exe"')
If #error Then Exit 1
EndIf
; Scans working directory for Mp3 files.
WinWaitClose('Reading directory', '', 5)
; Main window.
$hWnd = WinWait('Mp3tag')
; Get item count of 1st column from the listview.
For $i1 = 1 To 5
$iCount = ControlListView($hWnd, '', 'SysListView321', 'GetItemCount')
If $iCount Then
ConsoleWrite('Found ' & $iCount & ' items.' & #CRLF)
ExitLoop
EndIf
Sleep(1000)
Next
If Not $iCount Then
MsgBox(0x40000, #ScriptName, 'Count is 0')
Exit 1
EndIf
; Get text of each listview item in the 1st column.
For $i1 = 0 To $iCount -1
$sText = ControlListView($hWnd, '', 'SysListView321', 'GetText', $i1)
ConsoleWrite(StringFormat('%3d Text: %s', $i1, $sText) & #CRLF)
Next
I do not have "C:/foldername/Dialogbox.exe" to test with.
I do have Mp3tag which has a SysListView32 control.
ControlListView() can get text etc. from a ListView control.
The parameter GetItemCount will get the count of list items
and GetText will get text from each list item.
This is test output:
Found 15 items.
0 Text: 01 - Lively Up Yourself.mp3
1 Text: 02 - Soul Rebel.mp3
2 Text: 03 - Treat Yourself Right.mp3
3 Text: 04 - Rebels Hop.mp3
4 Text: 05 - Soul Almighty.mp3
5 Text: 06 - Kaya.mp3
6 Text: 07 - Trenchtown Rock.mp3
7 Text: 08 - Soul Shakedown Party.mp3
8 Text: 09 - Natural Mystic.mp3
9 Text: 10 - Fussing And Fighting.mp3
10 Text: 11 - African Herbsman.mp3
11 Text: 12 - Keep On Moving.mp3
12 Text: 13 - Go Tell It On The Mountain.mp3
13 Text: 14 - How Many Times.mp3
14 Text: 15 - Bonus Track.mp3
The list item number is on the left
and the list item text is on the right,
following Text:.
At a guess, the code to test your Dialogbox.exe with:
Run("C:\foldername\Dialogbox.exe")
$hWnd = WinWait("[CLASS:#32770]", "", 10)
; Allow time for SysListView321 to fully load.
Sleep(1000)
; Get the window title.
$sTitle = WinGetTitle("[ACTIVE]")
ConsoleWrite($sTitle & #CRLF)
; Changing control from the class containing title to the class containing the text.
$hLView = ControlGetHandle($hWnd, '', 'SysListView321')
; Get item count of 1st column from the listview.
$iCount = ControlListView($hWnd, '', $hLView, 'GetItemCount')
; Get text of each listview item in the 1st column.
For $i1 = 0 To $iCount -1
$sText = ControlListView($hWnd, '', $hLView, 'GetText', $i1)
ConsoleWrite(StringFormat('%3d Text: %s', $i1, $sText) & #CRLF)
Next
It could use some improvement even if it works.

calculate the percentage of not null recs in a file in unix

How do i figure out the percentage of not null records in my file in UNIX?
My file like this: I wanted to know the amount of records & the percentage of not null rec's. Tried whole lot of grep n cut commands but nothing seems to be working out. Can anyone help me here please...
"name","country","age","place"
"sam","US","30","CA"
"","","",""
"joe","UK","34","BRIS"
,,,,
"jake","US","66","Ohio"
Perl solution:
#!/usr/bin/perl
use warnings;
use strict;
use 5.012; # say, keys #arr
use Text::CSV_XS qw{ csv };
my ($count_all, #count_nonempty);
csv(in => shift,
out => \ 'skip',
headers => 'skip',
on_in => sub {
my (undef, $columns) = #_;
++$count_all;
length $columns->[$_] and $count_nonempty[$_]++
for 0 .. $#$columns;
},
);
for my $column (keys #count_nonempty) {
say "Column ", 1 + $column, ": ",
100 * $count_nonempty[$column] / $count_all, '%';
}
It uses Text::CSV_XS to read the CSV file. It skips the header line, and for each subsequent line, it calls the callback specified in on_in, which increments the count of all lines and also the count of empty fields per column if the length of a field is zero.
Along with choroba, I would normally recommend using a CSV parser on CSV data.
But in this case, all we want to look for is that a record contains any character that is not a comma or quote: if a record contains only commas and/or quotes, it is a "null" record.
awk '
/[^",]/ {nonnull++}
END {printf "%d / %d = %.2f\n", nonnull, NR, nonnull/NR}
' file
To handle leading/trailing whitespace
awk '
{sub(/^[[:blank:]]+/,""); sub(/[[:blank:]]+$/,"")}
/[^",]/ {nonnull++}
END {printf "%d / %d = %.2f\n", nonnull, NR, nonnull/NR}
' file
If allowing fields containing only whitespace, such as
" ","",,," "
is also a null record, we can simple ignore all whitespace
awk '
/[^",[:blank:]]/ {nonnull++}
END {printf "%d / %d = %.2f\n", nonnull, NR, nonnull/NR}
' file

How to know end of PDF File on Auto IT

I have an AutoIT script to open and scroll to end of PDF file by mouse action. By the number of times for scrolling is depended on the zoom percent and the number of pages. How do I determine the end of PDF file for configure the number of times for scrolling?
Below is the sample script. I fixed the number of times for scrolling is 15
Func OpenAllPDFFile($vardirectory)
If #error = 1 Then
MsgBox($MB_SYSTEMMODAL, "", "Path is invalid.", 2)
ElseIf #error = 4 Then
MsgBox($MB_SYSTEMMODAL, "", "No report(s) found.", 2)
ElseIf #error Then
MsgBox($MB_SYSTEMMODAL, "", "Fail to open report", 2)
Else
$FileArray = _FileListToArray($vardirectory, "*.pdf",1)
$NewFileArray = SortPDFFile($FileArray)
For $i = 0 To UBound($NewFileArray)-1
ShellExecute($vardirectory & "\" & $NewFileArray[$i])
ConsoleWrite("Opening pdf file: " & $NewFileArray[$i] & #CRLF)
if WinWaitActive($NewFileArray[$i]) Then
ConsoleWrite("Pdf file " & $NewFileArray[$i] & " is opened" & #CRLF)
WinSetState($NewFileArray[$i], "", #SW_MAXIMIZE)
Sleep($varSleep)
ControlClick($NewFileArray[$i], "", $varZoomPercent)
ControlSend($NewFileArray[$i], "", $varZoomPercent, $vPercent)
Send("{ENTER}")
Sleep($varSleep)
For $y = 0 To 15
If WinExists("[CLASS:AcrobatSDIWindow]") Then
MouseWheel($MOUSE_WHEEL_DOWN, 12)
Sleep($varSleepRead)
Else
ExitLoop
EndIf
Next
Else
ConsoleWrite("Could not find pdf file: " & #CRLF)
EndIf
WinClose("[CLASS:AcrobatSDIWindow]")
Next
EndIf
WinClose($varDUTPlot,"")
EndFunc
If you really just need to go to the end of the PDF I would use Page Down like this:
Send("{PGDN down}") # hold key down
Sleep(10000) # hold it for 10 sec
Send("{PGDN up}") # stop holding it
You can increase or lower the time just by editing the sleep time(in ms).
I don't know how to scale it with the PDF size.
If you know the pagecount it would be easy. ;)
$c = PAGES_IN_PDF
$t = $c * 200 # plan enough time for slow PCs
Sleep($t)

Append two columns adding a specific integer at each value in Unix

I have two files like this:
# step distance
0 4.48595407961296e+01
2500 4.50383737781376e+01
5000 4.53506757198727e+01
7500 4.51682465277482e+01
10000 4.53410353656445e+01
# step distance
0 4.58854106214881e+01
2500 4.58639266431320e+01
5000 4.60620560167519e+01
7500 4.58990075106227e+01
10000 4.59371359946124e+01
So I want to join the two files together, while maintaining the spacing.
Especially, the second file needs to remember the ending values of the first one and start counting from that one.
output:
# step distance
0 4.48595407961296e+01
2500 4.50383737781376e+01
5000 4.53506757198727e+01
7500 4.51682465277482e+01
10000 4.53410353656445e+01
12500 4.58854106214881e+01
15000 4.58639266431320e+01
17500 4.60620560167519e+01
20000 4.58990075106227e+01
22500 4.59371359946124e+01
With calc it was easy to do the problem is that the spacing needs to be in order to work and in that case calc makes a complete mess.
# start awk and set the *Step* between file to 2500
awk -v 'Step=2500' '
# 1st line of 1 file (NR count every line, from each file) init and print header
NR == 1 {LastFile = FILENAME; OFS = "\t"; print}
# when file change (new filename compare to previous line read)
# Set a new index (for incremental absolute step from relative one) and new filename reference
FILENAME != LastFile { StartIndex = LastIndex + Step; LastFile = FILENAME}
# after first line and for every line stating witha digit (+ space if any)
# calculate absolute step and replace relative one, print the new content
NR > 1 && /^[[:blank:]]*[0-9]/ { $1 += StartIndex; LastIndex = $1;print }
' YourFiles*
Result will depend of files order
output separator is set by OFS value (tab here)
Perl to the rescue!
#!/usr/bin/perl
use warnings;
use strict;
open my $F1, '<', 'file1' or die $!;
my ($before, $after, $diff);
my $max = 0;
while (<$F1>) {
print;
my ($space1, $num, $space2) = /^(\s*) ([0-9]+) (\s*)/x or next;
($before, $after) = ($space1, $space2);
$diff = $num - $max;
$max = $num;
}
$before = length "$before$max"; # We'll need it to format the computed numbers.
open my $F2, '<', 'file2' or die $!;
<$F2>; # Skip the header.
while (<$F2>) {
my ($step, $distance) = split;
$step += $max + $diff;
printf "% ${before}d%s%s\n", $step, $after, $distance;
}
The program remembers the last number in $max. It also keeps the length of the leading whitespace plus $max in $before to format all future numbers to take up the same space (using printf).
You didn't show how the distance column is aligned, i.e.
20000 4.58990075106227e+01
22500 11.59371359946124e+01 # dot aligned?
22500 11.34572478912301e+01 # left aligned?
The program would align it the latter way. If you want the former, use a similar trick as for the step column.

How to check if the variable value in AWK script is null or empty?

I am using AWK script to process some logs.
At one place I need to check if the variable value is null or empty to make some decision.
Any Idea how to achieve the same?
awk '
{
{
split($i, keyVal, "#")
key=keyVal[1];
val=keyVal[2];
if(val ~ /^ *$/)
val="Y";
}
}
' File
I have tried with
1) if(val == "")
2) if(val ~ /^ *$/)
not working in both cases.
The comparison with "" should have worked, so that's a bit odd
As one more alternative, you could use the length() function, if zero, your variable is null/empty. E.g.,
if (length(val) == 0)
Also, perhaps the built-in variable NF (number of fields) could come in handy? Since we don't have access to your input data it's hard to say though, but another possibility.
You can directly use the variable without comparison, an empty/null/zero value is considered false, everything else is true.
See here :
# setting default tag if not provided
if (! tag) {
tag="default-tag"
}
So this script will have the variable tag with the value default-tag except if the user call it like this :
$ awk -v tag=custom-tag -f script.awk targetFile
This is true as of :
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)
It works just fine for me
$ awk 'BEGIN{if(val==""){print "null or empty"}}'
null or empty
You can't differentiate between variable being empty and null, when you access "unset" variable, awk just initializes it with default value(here it is "" - empty string). You can use some sort of workaround, for example, setting val_accessed variable to 0 and then to 1 when you access it. Or more simple approach(somewhat "hackish") setting val to "unitialized"(or to some other value which can't appear when running your program).
PS: your script looks strange for me, what are the nested brackets for?
I accidentally discovered this less-used function specific in gawk that could help differentiate :
****** gawk-only ******
BEGIN {
$0 = "abc"
print NF, $0
test_function()
test_function($(NF + 1))
test_function("")
test_function($0)
}
function test_function(_) { print typeof(_) }
1 abc
untyped
unassigned
string
string
So it seems, for non-numeric-like data :
absolutely no input to function at all : untyped
non-existent or empty field, including $0 : unassigned
any non-numeric-appearing string, including "" : string
Here's the chaotic part - numeric data :
strangely enough, for absolutely identical input, only differing between using $0 vs. $1 in function call, you frequently get a different value for typeof()
even a combination of both leading and trailing spaces doesn't prevent gawk from identifying it as strnum
[123]:NF:1
$0 = number:123 $1 = strnum:123 +$1 = number:123
[ 456.33]:NF:1
$0 = string: 456.33 $1 = strnum:456.33 +$1 = number:456.33000
[ 19683 ]:NF:1
$0 = string: 19683 $1 = strnum:19683 +$1 = number:19683
[-20.08554]:NF:1
$0 = number:-20.08554 $1 = strnum:-20.08554 +$1 = number:-20.08554
+/- inf/nan (same for all 4):
[-nan]:NF:1
$0 = string:-nan $1 = strnum:-nan +$1 = number:-nan
this one is a string because it was made from sprintf() :
[0x10FFFF]:NF:1
$0 = string:0x10FFFF $1 = string:0x10FFFF +$1 = number:0
using -n / --non-decimal-data flag, all stays same except
[0x10FFFF]:NF:1
$0 = string:0x10FFFF $1 = strnum:0x10FFFF +$1 = number:1114111
Long story short, if you want your gawk function to be able to differentiate between
empty-string input (""), versus
actually no input at all
e.g. when original intention is to directly apply changes to $0
then typeof(x) == "untyped" seems to be the most reliable indicator.
It gets worse when null-string padding versus a non-empty string of all zeros ::
function __(_) { return (!_) ":" (!+_) }
function ___(_) { return (_ == "") }
function ____(_) { return (!_) ":" (!""_) }
$0--->[ "000" ] | __(""$0)-->{ !(""$0) : !+(""$0) }-->[ 0:1 ]
___($0)-->{ $0=="" }-->[ 0 ] | ____($0)-->{ ! $0 : (!""$0) }-->[ 1:1000 ]
$0--->[ "" ] | __(""$0)-->{ !(""$0) : !+(""$0) }-->[ 1:1 ]
___($0)-->{ $0=="" }-->[ 1 ] | ____($0)-->{ ! $0 : (!""$0) }-->[ 1:1 ]
$0--->[ " -0.0 -0" ] | __(""$0)-->{ !(""$0) : !+(""$0) }-->[ 0:1 ]
___($0)-->{ $0=="" }-->[ 0 ] | ____($0)-->{ ! $0 : (!""$0) }-->[ 0:1 -0.0 -0 ]
$0--->[ " 0x5" ] | __(""$0)-->{ !(""$0) : !+(""$0) }-->[ 0:1 ]
___($0)-->{ $0=="" }-->[ 0 ] | ____($0)-->{ ! $0 : (!""$0) }-->[ 0:1 0x5 ]

Resources