myspacee Posted March 7, 2019 Share Posted March 7, 2019 (edited) Hello, I try to automate ranking sort. Usually my classifications have votes at the end of line, eg: Bat - 0 Bear - 3 Red Fox - 2 Fox - 1 Lion - 4 Cat - 1 Armadillo - 3 Monkey - 10 my users want to order it and obtain Monkey - 10 Lion - 4 Armadillo - 3 Bear - 3 Red Fox - 2 Cat - 1 Fox - 1 Bat - 0 You can notice, that list is double sorted :- before numeric column - then rows with same vote (eg: cat -> fox) I assemble some code : #include <Array.au3> #include<array.au3> #include<file.au3> Local $aArray_Base[0][2] $file = FileOpen(@DesktopDir & '\animals.txt', 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $line_number = StringRegExp($line, '\d+', 1) if @error then $sFill = "" & "|" & $line _ArrayAdd($aArray_Base, $sFill) else $sFill = Number($line_number[0]) & "|" & $line _ArrayAdd($aArray_Base, $sFill) endif WEnd FileClose($file) _ArrayDisplay($aArray_Base, "$avArray BEFORE _ArraySort()") _ArraySort($aArray_Base, 0, 0, 0, 0) _ArrayDisplay($aArray_Base, "$avArray AFTER _ArraySort() ascending column 0") _ArraySort($aArray_Base, 0, 0, 0, 1) _ArrayDisplay($aArray_Base, "$avArray AFTER _ArraySort() ascending column 1") _ArraySort($aArray_Base, 0, 0, 0, 2) _ArrayDisplay($aArray_Base, "$avArray AFTER _ArraySort() ascending column 2") But I can't understand how use _arraysort... Can you help me, please ? thank you, m. Edited March 7, 2019 by myspacee Link to comment Share on other sites More sharing options...
Nine Posted March 7, 2019 Share Posted March 7, 2019 (edited) Try this : #include <File.au3> #include <Array.au3> Opt ("MustDeclareVars", 1) Local $array _FileReadToArray ("animals.txt", $array, $FRTA_ENTIRESPLIT, " - ") For $i = 0 to UBound ($array)-1 $array[$i][1]=Number($array[$i][1]) Next _ArraySort ($array, 0, 0, 0, 1) Local $value = $array[0][1], $start = 0 For $i = 1 to UBound ($array)-1 if $value = $array[$i][1] then ContinueLoop $value = $array[$i][1] if $i - $start > 1 then _ArraySort ($array, 0, $start, $i-1, 0) $start = $i Next if UBound ($array) - $start > 1 then _ArraySort ($array, 0, $start, Ubound($array)-1, 0) _ArrayDisplay ($array) Edited March 7, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
myspacee Posted March 7, 2019 Author Share Posted March 7, 2019 Adapt to my case : expandcollapse popup#include <Array.au3> #include<file.au3> Local $Array[0][2] $file = FileOpen(@DesktopDir & '\animals.txt', 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $line_number = StringRegExp($line, '\d+', 1) if @error then $sFill = $line & "|" & "" _ArrayAdd($Array, $sFill) else $sFill = $line & "|" & Number(StringRegExpReplace($line_number[0], "[^0-9]", "")) _ArrayAdd($Array, $sFill) endif WEnd FileClose($file) For $i = 0 to UBound ($array)-1 $array[$i][1]=Number($array[$i][1]) Next _ArraySort ($array, 1, 0, 0, 1) Local $value = $array[0][1], $start = 0 For $i = 1 to UBound ($array)-1 if $value = $array[$i][1] then ContinueLoop $value = $array[$i][1] if $i - $start > 1 then _ArraySort ($array, 0, $start, $i-1, 0) $start = $i Next if UBound ($array) - $start > 1 then _ArraySort ($array, 1, $start, Ubound($array)-1, 0) _ArraySort ($array, 1, $start, Ubound($array)-1, 0) _ArrayDisplay ($array) Thank you! m. Link to comment Share on other sites More sharing options...
Nine Posted March 7, 2019 Share Posted March 7, 2019 (edited) @myspacee Why are you not using FileReadToArray ? And why are sorting 2 times at the end ? Edited March 7, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
myspacee Posted March 7, 2019 Author Share Posted March 7, 2019 (edited) hello, I need this script as part of onother one. Bigger and with its 'structure'. My fault double sort at end. Thank you again, your solution is more simple than others i try. m. Edited March 7, 2019 by myspacee Link to comment Share on other sites More sharing options...
iamtheky Posted March 7, 2019 Share Posted March 7, 2019 yall are wild #include<array.au3> local $a[8][2] = [['Bat' , 0],['Bear' , 3],['Red Fox' , 2],['Fox' , 1],['Lion' , 4],['Cat' , 1],['Armadillo' , 3],['Monkey' , 10]] _ArraySort($a , 0 , 0 , 0 , 0 , 1) _ArraySort($a , 1 , 0 , 0 , 1) _ArrayDisplay($a) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Nine Posted March 7, 2019 Share Posted March 7, 2019 1 hour ago, iamtheky said: yall are wild Have you even test your code ? -1 if I could... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
iamtheky Posted March 8, 2019 Share Posted March 8, 2019 (edited) Edited March 8, 2019 by iamtheky ..i., ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 8, 2019 Moderators Share Posted March 8, 2019 myspacee, You could also use my ArrayMultiColSort UDF (the link is in my sig): #include<ArrayMultiColSort.au3> Local $aList[8][2] = [['Bat' , 0],['Bear' , 3],['Red Fox' , 2],['Fox' , 1],['Lion' , 4],['Cat' , 1],['Armadillo' , 3],['Monkey' , 10]] ; Set sort order = First col 1 descending, second col 0 ascending Local $aSortData[2][2] = [[1, 1], [0, 0]] _ArrayMultiColSort($aList, $aSortData) _ArrayDisplay($aList, "", Default, 8) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now