Re: Sort Multidimensional Array by Column 5
Re: Sort Multidimensional Array by Column 5
- Subject: Re: Sort Multidimensional Array by Column 5
- From: KOENIG Yvan <email@hidden>
- Date: Sat, 9 Oct 2010 19:28:46 +0200
Le 9 oct. 2010 à 18:47, Deivy Petrescu a écrit :
>
> Richard,
>
> i did not check the other codes submitted to see if they handled any possible kinds of lists.
> I am submitting a code, based on Emmanuel (of Satimage's fame) sort routine,that handles csv file outputs like the one you sbmitted
>
> I believe I've submitted this code to the list before.
> The advantage, it is fairly fast (although you can make it faster using script's list, and the code is fairly concise.
>
>
>
> Here it is, hope it is self explanatory
>
>
> <script>
>
> set mydata to "\"Customer GUID\",\"Form GUID\",\"Contact GUID\",\"Form Type\",\"Ref No\",\"Account Number\",\"Company Name\",\"Contact Name\",\"Contact Address\",\"Email address\",\"Artwork awaiting Response\",\"Days no Response\",\"Special Pricing\",\"Date\"\r\"17F1098A-482E-4BCB-BC17-B56094FF7CC1\",\"ADB3CC97-0A42-40FF-9C63-10AB043A0F7E\",\"66864065-0256-41E3-AFCF-CC7053DAD196\",\"PF\",\"\",\"S0154C\",\"Synectic Systems Group Ltd\",\"A Name\",\"\",\"email@address\",\"Yes\",\"2\",\"No\",\"\"\r\"43C79C66-2127-41B9-B444-34EAB49DEB68\",\"7AF809BA-10F9-4997-858D-DF3ACE829BC0\",\"ED9FF7CF-ECF0-4D2D-BAB9-687B4AEEF109\",\"QT\",\"2940\",\"M0012C\",\"Manchester Metropolitan University[] The\",\"A Name\",\"An Address[]2nd Line[]3rd Line[]Etc[]\",\"email@address\",\"No\",\"1\",\"No\",\"\"\r\"41A9C623-3E6E-44E1-81D6-FC5B57FCC7D8\",\"4625DC32-B013-42CC-BFD4-73962A3106F4\",\"1D54FDFE-731E-4B85-BD7B-416A7B05AA90\",\"SO\",\"3110\",\"C0250C\",\"Chem-dry (uk) Ltd\",\"A Name\",\"An Address[]2nd Line[]3rd Line[]Etc[]\",\"email@address\",\"Yes\",\"2\",\"No\",\"\""
> tid("\r")
> set mydata to (rest of text items of mydata)
> tid(",")
> set decreasing to true
> set mydata to sort(mydata, 5, ",", decreasing)
>
>
> on sort(lista, item_Number, item_delimiter, decreasing)
> if (count of lista) < 2 then return lista
> tid(item_delimiter)
> set listalow to {}
> set listahigh to {}
> set l1 to contents of item 1 of lista
> set comp to text item item_Number of (l1 as string)
> set lista to rest of lista
> repeat with l in lista
> if text item item_Number of (l as string) < comp then
> set end of listalow to contents of l
> else
> set end of listahigh to contents of l
> end if
> end repeat
> if not decreasing then
> return sort(listalow, itemNumber, itemdelimiter, decreasing) & l1 & sort(listahigh, itemNumber, itemdelimiter, decreasing)
> else
> return sort(listahigh, itemNumber, itemdelimiter, decreasing) & l1 & sort(listalow, itemNumber, itemdelimiter, decreasing)
> end if
> end sort
>
>
>
>
> on tid(x)
> set AppleScript's text item delimiters to x
> end tid
>
> </script>
Using the comma to cut 'paragraphs' in pieces is dangerous.
Quotes are inserted at beg and end of items to take care of possible commas existing in the stored items.
If such comma exists, the paragraph will be slipped in too many items.
This is why, given the fact that the described datas have every items enclosed between quotes, I felt safer to split using the delimiter : quote&",""e
The sort code used is the less efficient one.
It may be valid for short sets of datas but on large ones, it's awful.
In term of increasing speed, we have :
QuickSort
HeapSort
InterSort.
Intersort which is used in my posts is the fastest but it has a drawback, it duplicates the list to work when Heapsort sorts the list upon itself.
So, when memory is short, it may be useful to use HeapSort
Yvan KOENIG (VALLAURIS, France) samedi 9 octobre 2010 19:21:28
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden