Ive gained a lot previously here posting questions about core data. A lot of things cleared. Since my object model has potential uncertainties, i run into a lot of challenges and end up questioning the whole approach.
Oh well, heres the problem. Im gonna write a little more detail than required to explain this,
I have 2 entities:
These objects are listed in a tableView. And theres an "Add" button in the navigationItem.
User selects an parent in the list, and taps "Add", a modelView appears and the user inputs the Value and an EntryObject is created for that Parent.
Example, i select Height then tap "Add" and enter the height, and the app records the date added. The date could be manually switched.
Same procedure for "Weight" Parent.
Now If BMI is selected, the modalView shows two textfields, one for height and one for Weight. After the values are entered, an NSNumber is returned by calculating the BMI = [Wt/(Ht*Ht)]. The difference here is that NO Entry Object is created with this value, and simply the number is returned.
Up until now, things work just fine and as desired.
If I fetch Entries (object) of each Parent Object, I'd get:
Parent-BMI = { NO Entry Objects } Instead it pulls in the EntryObjects of height and Weight and parses it and presents the array at runtime. The way i do that is actually create a dictionary with keys as timeStamp (date of entry) and their objects as the entries taken at that timeStamp.
After parsing, the only nsnumber returned is for the 24thApril as both values are present.
I wanted to develop it so that even if "ONE" parent of BMI is missing, in this case, Weight was missing on 10thApril, i'd pull the Weight entry from another date and calculate BMI.
The idea is to step back in time and grab the nearest Weight entry and present that.
Why am i doing so you ask? why not just say hey, no weight entered on 10th hence no BMI then... well, thats cuz
1- some leniency can be granted in health matters, BMI doesn't change suddenly.
2- I wouldn't want to show "N/A", that would just be not fair.. to the user to always enter
This would not apply in every case, but I'm concerned about bmi only.
Any advise on structuring the model or something that makes this more efficient would be great.
I'd really like advice to show BMI in the desired way would be great.
Im Fetching all entries for bmi by creating a NSPredicate and a SortDiscriptor.
And SO i'd get the entries in a sorted like this:
equal number of entries: of height and weight, BUT some dates may have single entries and since i sort with dates first into a dict, i comes like this:
When I build and parse the BMI,
For example when I get 10April Object: i have ONly Ht in it, i would like to get the next /nearest Weight Object to return a non NIL value.
Ive taken a lot of space to write in detail, and granted, most of you got the point repeatedly, but this is just so critical to the app I'm working on...
Oh well, heres the problem. Im gonna write a little more detail than required to explain this,
I have 2 entities:
Code:
Parent Object <-->> Entry object. Parent has a to-many relationship with Entry Object.
Parent 1:
Name: Height
Tag: Ht
Parent 2:
Name: Weight
Tag: Wt
Parent 3:
Name: Body Mass Index
Tag: BMI
Entry Object:{
NSNumber: Value
NSDate: timeStamp
ForParent: -->Parent Object
These objects are listed in a tableView. And theres an "Add" button in the navigationItem.
User selects an parent in the list, and taps "Add", a modelView appears and the user inputs the Value and an EntryObject is created for that Parent.
Example, i select Height then tap "Add" and enter the height, and the app records the date added. The date could be manually switched.
Same procedure for "Weight" Parent.
Now If BMI is selected, the modalView shows two textfields, one for height and one for Weight. After the values are entered, an NSNumber is returned by calculating the BMI = [Wt/(Ht*Ht)]. The difference here is that NO Entry Object is created with this value, and simply the number is returned.
Up until now, things work just fine and as desired.
If I fetch Entries (object) of each Parent Object, I'd get:
Code:
Parent-Height = { Entry(178cm, 10thApril,
Entry(187cm, 24thApril,
}
Parent-Weight = { Entry(167lbs, 24thApril,
}
Code:
The dictionary is { 10thApril {
Height=1.78
}
24thApril {
Height=1.87
Weight=167lbs
}
}
After parsing, the only nsnumber returned is for the 24thApril as both values are present.
Code:
So the resultant Array becomes: { 167/(1.87*1.87), 24thApril }
I wanted to develop it so that even if "ONE" parent of BMI is missing, in this case, Weight was missing on 10thApril, i'd pull the Weight entry from another date and calculate BMI.
The idea is to step back in time and grab the nearest Weight entry and present that.
Why am i doing so you ask? why not just say hey, no weight entered on 10th hence no BMI then... well, thats cuz
1- some leniency can be granted in health matters, BMI doesn't change suddenly.
2- I wouldn't want to show "N/A", that would just be not fair.. to the user to always enter
This would not apply in every case, but I'm concerned about bmi only.
Any advise on structuring the model or something that makes this more efficient would be great.
I'd really like advice to show BMI in the desired way would be great.
Im Fetching all entries for bmi by creating a NSPredicate and a SortDiscriptor.
Code:
Sorting is via the timeStamp.
Predicate = "self.ForParent IN parentArray", [NSArray of HeightParent, WeightParent].
Code:
Entries: {
EntryWeight - 24April, ***
EntryHeight - 24April, ---
EntryHeight - 10April, ---
EntryWeight - 1stApril, ***
EntryHeight - 1stApril, ---
EntryWeight - 20March, ***
}
Code:
Key-24April: [Array= Wt, Ht]
key 10APRIL: [Array= Ht ]
Key 1stApril: [Array = Wt, Ht]
Key 20March: [Array= Wt ]
When I build and parse the BMI,
For example when I get 10April Object: i have ONly Ht in it, i would like to get the next /nearest Weight Object to return a non NIL value.
Ive taken a lot of space to write in detail, and granted, most of you got the point repeatedly, but this is just so critical to the app I'm working on...