Re: Sorting arrays nightmare
Re: Sorting arrays nightmare
- Subject: Re: Sorting arrays nightmare
- From: Louis Demers <email@hidden>
- Date: Sun, 20 Feb 2011 17:37:36 -0500
On 2011-02-20, at 16:45 , Miguel Arroz wrote:
> Hi,
>
> Are you sure the NSTimestamp values are exactly the same, down to milliseconds? If your users are just copying date and time (without milliseconds), you are most probably getting different millisecond values for each row.
It happens because they copy and paste date/time in the date form field , so I do not understand how the parser would generate different dates from that... It should be deterministic. Furthermore, I now have forms for batch creation of transactions which simply programmatically copy the NSTimestamp to each transactions record ....
As I said earlier, the sort on the date seems OK, it's the secondary sort on the primary key that does not stick... (when sorting descending...)
>
> Regards,
>
> Miguel Arroz
>
> On 2011/02/20, at 20:01, Louis Demers wrote:
>
>> Hi, i'v been banging my head for hours on this strange behavior...
>>
>> Background: My inventory transaction system allows people to make transaction on exactly the same date (they use cut and paste to put exactly the same date/time in a bunch of transactions). But I need to process them chronologically and those transactions EO contain some data such as cumulated values, average costs cumulated quantities....
>>
>> Fetching EO sorted by date will not guarantee the same order each time its executed, so I taught I would additionally sort by primary keys to fix the order once and for all.
>>
>> Part 1) I use a fetchspec named "updateTransactionCost" that is defined in EOModeler and in the tab "Sort Orderings", my first item is "dateEnd" ascending and the second line is "id" ascending. That technique seems to work.
>> <Screen shot 2011-02-20 at 14.51.48 .png>
>>
>> Part 2) I need a support method to find the latest transaction before a specific date. To do so I use a fetchspec also defined in EOModeler define the Qualifier as "dateEnd < $beforeDate and part = $part and part.spec = $spec" and the sort ordering tab as "dateEnd" descending and the second line is "id" descending. I set the mac rows in the option's tab to 1 as I'm interested only in the latest transaction before the date.
>>
>> <Screen shot 2011-02-20 at 14.46.00 .png>
>>
>> I then use the Wonder generated Transaction.fetchTransactionBefore() to get the array, but it is not sorted properly by id. It seems that only the first sort order key (date) is being used...
>>
>> Here is sample debug output when enumerating in chronological order <> are primary keys
>>
>> <35474> 2011-01-10 19:07:36 Etc/GMT Q: 1/1
>> <35475> 2011-01-10 19:07:36 Etc/GMT Q: 1/2
>> <35472> 2011-01-20 19:07:36 Etc/GMT Q: 1/3
>> <35473> 2011-01-20 19:07:36 Etc/GMT Q: 1/4
>> <35478> 2011-01-20 19:07:36 Etc/GMT Q: 1/5
>> <35476> 2011-01-30 19:07:36 Etc/GMT Q: 1/6
>> <35477> 2011-01-30 19:07:36 Etc/GMT Q: 1/7
>>
>> and if I print the latest
>>
>> latest before 2011-01-25 19:07:36 Etc/GMT <35472>2011-01-20 19:07:36 Etc/GMT Q: 1/3
>>
>> Any clues ? or alternative algorithm to find my latest transaction method ?
>>
>> Thanks in advance...
>>
>> PS: using latest of everything...
>>
>>
>>
>> Louis Demers eng.
>> www.obzerv.com
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
>
Louis Demers eng.
www.obzerv.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden