Avatar of Jagadeesh M
Jagadeesh M
Flag for United States of America asked on

Java Objects and Data aggregation and Indicators

I posted the same question earlier in StackExchange and it was eventually closed saying it was    ambiguous, vague, incomplete, overly broad, or rhetorical. If this is the case, please let me know I can update the question accordingly.

Here is my scenario -

Let us say I have events going round the year at least one each day. I have an RSVP system that keeps track of responses. Response are categorized as Definite and Tentative. The granularity of the system goes like this for each date -

All Guests
   + Definite
           + Country [0 - N]
                  + States [0 - N]
                        + Family [0-N]
   + Tentative
           + Country [0 - N]
                  + States [0 - N]
                        + Family [0-N]

Under each category i have count for number of adults and children.

So my example grid on the User Interface would look something like in the attached text file.

And this data in the file is for single data. So in the User Interface, first column is all the descriptive fields and rest of the columns are several dates with corresponding numbers.

I guess the complex part is I have a System table that stores the numbers at the lowest granular level viz children / adults in certain family/state/country/definite. Family / State / Country and Definite/Tentative are all ids pointing to look-up tables.
So in order for us to show the data to the user, we get the data from the database which is at the lower level [child/adult level count] and perform aggregation and return the data to the User Interface.

Similarly User can change adult/children count at any level and it should be distributed down based on the percentage increase.

I need to store at what level certain value is changed - this is where I need indicators at each level.

All the user overridden values will go into a different table which can store the level it was changed and updated values go into a new table.

What I want to know -

1 - What is the best way to layout my Java Objects [may be we call them as DTO because client would obviously be consuming it from the server and display them on the UI] ?
2 - Can we apply any patterns? Any example / pseudo code ?
3 - What is the best way to maintain the rules?
4 - How to maintain the indicators and achieve aggregation


Avatar of undefined
Last Comment
Jagadeesh M

8/22/2022 - Mon

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jagadeesh M

One other important information I forgot to add was the distribution aspect. If I change my Adults count at Tentative level, based the percentage that its children had, it would redistribute it.

If you want to redistribute it you will have to manually loop through it and change all dependent values.
Jagadeesh M

I visualize this as a dynamic tree with different levels (N - children), how about using some tree traversal technique ? There are any in-memory graph / tree traversal apis that I can use out of box?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

It depends on how you will represent the information. For instance if you have an XML schema and you could represent it as XML you could traverse the DOM tree. If you save it as a bean (this is what I suggested) you will have to manually traverse it (you will have a list of states and a list of countries) and find the node you want. There is no tree traversal solution that fits everything.
Jagadeesh M

Information is represented like the way it was shown in the attached text file. It is just that data in the database is stored at the lowest level and rest of the parent level is just a mere aggregation of the data.

But on the UI User has the ability to change at any level with the condition that distribution honors changes made the lower level.

Any someone body a pseudo code on how the structure be maintained? Would it be a map of maps with several indicators at each level. Also levels are dynamic and this is what is making it more complex.