11 Replies Latest reply on Nov 8, 2012 12:47 PM by 814889

# Design a module

I am having problem designing a module.Can anybody help me

Requirement:

This is basically an agricultural project (web application).I need to design module where some calcuation takes place.
There are differnt crops invovled like maize,tomato,okra etc.Now each of these crops have different traits.
Each trait has a mesurament scale which lies in integer like 200-1000.now let say i have planted the crop and
done measurement noted down the traits.Now i want to do some sort of measurement.Some measurements are simple and some are
complex.

Lets take an example of crop maize.I have recored observations for 15 trait.(trait1.. trait15 are just alias the acutal name can be like plt_ht,yld)
trait1 trait2 trait3 trait4 trait5 trait6..... trait15

i have recorded 5 observations for each traits
trait1 trait2 trait3 trait5 trait6..... trait15
01,02,03,04 01,02,03,04 01,02,03,04

User logs into system and selects his crops and enters data for these observation i either have to calculate average of those data entered for each or sum of those.
This is simple but complexity comes when for some of the tratis i have some different formulas. Like lets take an example let say a trait YLD has a formula based on which i have to caluate its value which may also depends on some other traits .This way all differnet crops have different traits.All this i am able to do whenever user selects crop i will check for those specific traits and do calculations if it is not special trait then i eaither avg it or sum it based on db entery but there is lot of hard coding .I want to have some suggestion from you people if u can think of an better way of handling this.
• ###### 1. Re: Design a modul
So the real question is that you have a lot of formula. And for a given set of traits you need to map to a specific formula?

I suspect that that depends on exactly how you want to map. If you need to do a priority mapping scheme then that is what you need to design. So if traits X,Y and Z would be used before X, Y, then you map must present a search look up that finds X, Y, Z first and only then falls back to X, Y.

I think you might be able to do this with a b-tree (data structure). If you need more priority then you could add weights to each node.

But really it depends on how you prioritize.

If there are a lot of these then, once I had the data structure down, I would load the tree from a text file (or some other manual source) - including the formulas. There is a complexity cost to doing that but probably worth it if there are a lot of them.
• ###### 2. Re: Design a module
It sounds like a job for something like Excel to me.
• ###### 3. Re: Design a module
Perhaps "linear regression" is the technique you were looking for? (It's quite possible that Excel supports that, or has a plugin for it.)
• ###### 4. Re: Design a module
My code has to behave like excel but it is not excel .I have to write java programme which reads data enetred in excel sheet and does calcuation like excel.Each trait is mapped to columns in the sheet. And each crop can be defined as worksheets. The formulas are equivalent to the excel formulas.

Now my code has calcuate simple calcuation and complex calculations.Simple calucation are easy i have take average of vavlue enterd for trait, but problem comes when i have complex calcuation,since each crop have differnt traits which have complex calculations , i have to check for crop then for complex trait and then calculate .So i have to hardcode the trait name of complex traits .can any tell me how can i design usign java oops so that i make generic.
• ###### 5. Re: Design a module
Vicky wrote:
.So i have to hardcode the trait name of complex traits .can any tell me how can i design usign java oops so that i make generic.
What part of my previous response did you not understand?
• ###### 6. Re: Design a module
can please elaborate usign btree and loading formula from text file. let say one of the formula for trait y is x*y/1000 how can i do this.
• ###### 7. Re: Design a module
I didn't understand what a B-tree had to do with either. You're not alone.
• ###### 8. Re: Design a module
EJP wrote:
I didn't understand what a B-tree had to do with either. You're not alone.
It appears that the need exists to find a "formula" which "matches" as specific set of "traits". And it appears that the possibility exists that any given set(A) might have a subset(B) which also has a formula. However set A, being more specific, should take precedence (presumably) over the formula for B.

Thus one needs to find a match for the elements in A and failing that then find the match for B.

Feel free to suggest an alternative solution to the above.
• ###### 9. Re: Design a module
can you please elaborate more on b-treee(if possible code wise) and also about loading f0rmula from a file like i said in my earlier response.

I am alreading those things via HashMap, let for trait z formula i need trait x,y values.I will calcuate the values of x,y before z and keep them in hash map and when i need x,y value for z i will use HashMap lookup
• ###### 10. Re: Design a module
It appears that the need exists to find a "formula" which "matches" as specific set of "traits". And it appears that the possibility exists that any given set(A) might have a subset(B) which also has a formula. However set A, being more specific, should take precedence (presumably) over the formula for B.
I don't understand why you think a B-tree provides a solution to any of that. B-trees don't solve formulas or more/less specific bindings.
Thus one needs to find a match for the elements in A and failing that then find the match for B.
You've been asked twice how B-trees solve any of that, and you haven't answered, other than by reiterating the terms of the problem.

A B-tree might be an appropriate data structure for the problem, although I don't see why, and none of your handwaving tells me. But then so would the HashMap the OP is already using, and many others. And most of the OP's problem is still sitting there waiting for it to be solved. Or else you're attributing magical properties to B-trees that they do not have. And there are no B-tree implementations in the JDK.
Feel free to suggest an alternative solution to the above