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: Denis Stanton <email@hidden>
- Date: Wed, 31 Dec 2003 13:22:47 +1300
Hi Chuck
On Wednesday, December 31, 2003, at 10:43 AM, Chuck Hill wrote:
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.
Well that's new to me. I had the impression that ReportMill was fairly
expensive, or at least priced high enough to make it uneconomic for my
needs.
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 :-).
They are likely to run this report to cover either a six month or one
year period. The speed problem only becomes apparent for the one-year
report. That means a lot of bookings in memory so I was attempting to
process one agent at a time.
You could start fetching daily sets of data and getting aggressive
with EOF memory management to control this.
Any hints about getting aggressive with EOF memory management would be
of interest.
My report uses a simple repetition to work through the agent array.
DisplayList: WORepetition { list = agentArray; item = agent;}
Then I have a setAgent method that is implicitly called by the
repetition.
protected void setAgent(Agent inValue) {
bookings() = new NSMutableArray(
EOQualifier.filteredArrayWithQualifier(agent.bookings(), qualifier) )
}
The repetition encloses lines with values mapped to @sum calculations
on the bookings array
String1: WOString { value = email@hiddenrice; }
I am assuming that since the setAgent() method recreates the bookings
array for each agent then Java will take care of the memory management,
keeping just one agent's bookings in memory at a time.
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!
Do you see an advantage in accumulating into instance variables in each
Agent, then sorting and printing, as opposed to sorting the agents
first (I specify the sort in the fetch) and then calculating and
printing one line at a time by defining the display as for String1
above?
"Extract - (calculate) - Sort and Print" seems more like the way I used
to work in the pre-OO days (I was a Cobol programmer for 15 years). I
have been trying to avoid storing calculated values when the
calculation itself can be defined as an instance method.
HTH
BTW. What is HTH? Happy "T" Holiday?
Denis
Denis Stanton
email@hidden
Home: +64 9 533 0391
mobile: +64 21 1433622
_______________________________________________
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.