Re: can I use fetch spec to filter an array?
Re: can I use fetch spec to filter an array?
- Subject: Re: can I use fetch spec to filter an array?
- From: Chuck Hill <email@hidden>
- Date: Tue, 30 Dec 2003 13:43:41 -0800
- Organization: Global Village Consulting, Inc.
Summary reporting is always a problem due to the constraints of
processing speed and memory usage. One thing you might want to
consider is ReportMill (http://www.reportmill.com/). It is free to
use if all you need are HTML reports. It is fairly easy to use and,
in my limited experience, fairly efficient too. It might be worth
cobbling together your report to see what the processing time is like.
Barring that, I'd fetch all the bookings in the time frame with a
fetch spec set to prefetch all the agents. This should give you all
the data that you need in two fetches (one for bookings, one for
agents). If there are a lot of bookings this can chew up a lot of
memory (e.g. when your client suddenly decides to see what happens
when they run the weekly summary over a whole year :-). You could
start fetching daily sets of data and getting aggressive with EOF
memory management to control this.
Once you have all the bookings, you can get all the agents from:
NSArray agents = new
NSSet((NSArray)bookings.valueForKey("agent")).allObjects();
Then run a loop over all the bookings, tell the agent to calculate
stats for them:
thisBooking.agent().accumulateStatsFor(thisBooking);
You will probably also want a resetStats() method to zero these out.
You will need to add instance variables to Agent to hold the 11
totals. Don't put these in the EOModel, they are just transient
values for reporting. The code to determine which booking affects
which stat goes in Agent. This keeps the functionality fairly well
partitioned and keeps processing time down as you have a minimal
number of fetches and touch each booking once in one loop.
Following this, sort the list of agents and report away!
HTH
Chuck
Denis Stanton wrote:
I thought I knew this, but now I can't find any mention in the API
Can I use a fetch specification to filter an array in memory, as opposed
to an entity in a database?
I have written an application for a travel company. They need a report
showing the total value of bookings received from each agent over a data
range. Actually there are about 11 totals per agent and say 300 agents.
For my first attempt I used a fetch spec inside a loop. For each agent
I defined a fetch spec with agent name, start date and end date and then
fetched all the matching records from the bookings file into an array
named bookings. Then I used bookings.valueForKey("@sum.nettprice") to
accumulate the total of booking.netprice(), and so on through all 11 sub
totals.
Too slow.
I wondered if there was any need to re-read the database. Since there
is a one-to-many relationship between agent and booking, the bookings
for an agent are already in agent.bookings(), except that they have not
been selected by date range. So can I apply a filter to the
agent.bookings() array in memory instead of reading the Booking entity
from the database using:
fetchspec = new EOFetchSpecification("Booking", qualifier, null);
MSMutableArray bookings = new
NSMutableArray(editingContext.objectsWithFetchSpecification(fetchspec)
I have also tried filtering the agent.bookings() array by means of a for
loop to select and copy each of the the bookings within range to a new
array, but that is also slow and seems crude.
Is there a proper way to do this?
Denis
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
Progress is the mother of all problems.
- G. K. Chesterton
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.