settecplus Posted March 26, 2014 Posted March 26, 2014 Hi, I'm fairly new to autoit and I'm trying to find my way through a little problem... I have to analyze some csv files (log files). They come splitted in many files, with the first row containing the name of the columns. So the first task is combining them, keeping just the first row of the first file, and removing the first row of each subsequent file, which I easily managed to do (with the help of some example here and there). At this point I usually import the single file into excel and perform some calculations. This lends to quite large excel files, and it's overkill, because once the calculations are done I no longer need the source raw data. So it would be best to perform the basic calculations in autoit and import just the results into Excel to complete the remaining tasks. I guess the best way would be loading the data into a multidimensional array, and then manipulate them like if it was a spreadsheet table. And here's my problem, I'm not too acquainted with arrays... The calculations I need to perform are these: 1) find the total number of cells (the max size of the array, really). This should be easy 2) find how many times the value in Column(A) is greater than 1000 3) for each row where Column(A) is greater than 1000, I need to calculate the difference between the same row on another column and its preceding row (for instance in Excel it is : IF(A143>1000; B144-B143; "") ) The point is... from were do I start in performing math operations on multidimensional arrays? Any help is greatly appreciated. Luc
Moderators Melba23 Posted March 26, 2014 Moderators Posted March 26, 2014 settecplus,2D arrays are in fact just like an Excel spreadsheet - you can think of the first dimension as the row and the second the column. I suggest loading one of these CSV files into an array (if you have the Beta version you can use _FileReadToArray - if not there are plenty of CSV2Array type examples out there) and then using _ArrayDisplay to check how the data is presented. That should allow you to determine how you need to structure the formulae for your calculations. If you get stuck, I suggest posting a small sample of one of these log files and explaining which elements need to be used in the various calculations you want to make. 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
settecplus Posted March 26, 2014 Author Posted March 26, 2014 (edited) M23,thank you for your help. I've already done what you suggested, and I have used _ArrayDisplay to take a look at my data. I'm really stuck at math calculations with arrays I have attached a (very) stripped down csv file.I need to calculate:- the number of rows of column A (in this case 14)- how many times column I is greater than 1000 (in this case 9)- this is more complicate: whenever row x of column I is > 1000, I need to calculate the sum of all of the results of row x (column B ) = [row x (column B )] - [row x-1 (column B )]. To be more clear, in Excel I perform this task by creating a new temporary column (Z), which is populated by a IF((I5>1000;B6-B5;"")), and I then do a SUM(Z1:Z1000000). Luctest_array.txt Edited March 26, 2014 by Melba23 Removed inadvertant emoticons
Moderators Melba23 Posted March 26, 2014 Moderators Posted March 26, 2014 settecplus,This works for me - do the results match what you want? #include <File.au3> #include <Array.au3> $aArray = _FileReadToArray("test_array.txt", $FRTA_NOCOUNT, ";") _ArrayDisplay($aArray, "", Default, 8, Default, "A|B|C|D|E|F|G|H|I|J|K") ; Number of rows MsgBox($MB_SYSTEMMODAL, "Rows", UBound($aArray)) ; Rows where Col I > 1000 $iCount = 0 ; Loop through the array For $i = 0 To UBound($aArray) - 1 ; Because the array starts at 0 we need to reduce the count by 1 ; Note we use numeric, not alpha, indices If $aArray[$i][8] > 1000 Then $iCount += 1 Next MsgBox($MB_SYSTEMMODAL, "Rows where Col I > 1000", $iCount) ; Complicated bit $nTotal = 0 For $i = 0 To UBound($aArray) - 2 ; Because the calculation accesses a line greater the current one we need to reduce the count by 2 ; Is Col I > 1000 If $aArray[$i][8] > 1000 Then ; Calculate value and add to total - replace commas with decimal points $nTotal += StringReplace($aArray[$i + 1][1], ",", ".") - StringReplace($aArray[$i][1], ",", ".") EndIf Next MsgBox($MB_SYSTEMMODAL, "Complicated total", StringReplace($nTotal, ".", ",")) ; replace decimal point with commaM23 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
settecplus Posted March 26, 2014 Author Posted March 26, 2014 I'm amazed... Thank you for the help, and for showing me the light It took me a while to understand the complicated bit (call me stupid)! Luc
Moderators Melba23 Posted March 26, 2014 Moderators Posted March 26, 2014 settecplus,Glad I could help. 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
settecplus Posted March 27, 2014 Author Posted March 27, 2014 M23, I guess I may need some more help... Your script works perfectly with new Autoit beta, but on latest stable version I get the error: "warning: $FRTA_NOCOUNT: possibly used before declaration" At the same time, the other part of my script (the one which deals with csv merging and manipulating) works on latest stable but not on newer beta. In this case it doesn't even show any error, so I'm having troubles debugging the error... Long story short, one part of the script works only on newer alpha, the other part works just with the older stable. Quite uncomfortable Luc
Moderators Melba23 Posted March 27, 2014 Moderators Posted March 27, 2014 settecplus,You can replace $FRTA_NOCOUNT with the integer 0 - and give guinness indigestion, but that is not your problem. If you want to post the script you are using that fails with the Beta (or send it to me via PM) I will take a look at it and see if I can spot the problem. 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
settecplus Posted March 31, 2014 Author Posted March 31, 2014 Thank you again for your help. Replacing $FRTA_NOCOUNT with 0 doesn't seem to work, though: "error: _FileReadToArray() called with Const or expression on ByRef-param(s)." Will be back to you via PM. Luc
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