database

The Week of 4-14-14

Since Last Time

Since last week I'm not sure if I've actually accomplished a lot or if it only feels that way. The major milestone is that the app seems to be working reliably. Since I fixed some goofy code I've only had one or two crashes, and only on the simulator, never on an actual device. Furthermore, I feel good about the current design direction of the UI. I also versed my self in some of the details of Info.plist because it is now the home of the database's state information and that information will be the basis for future database update logic. 

My next steps actually involved revisiting how to retrieve the JSPointsLists associated with an instance of JSAthlete from the Core Data store. I actually spent a fair amount of time on this looking into NSOrderedSet and the 'Arrangement Ordered' checkbox in the Core Data model for to-many relationships. As it turns out it was all for not; I was hoping that this would be an easy and efficient way to ensure that the JSPointsLists were ordered the way I wanted when I retrieved them from the Core Data store, but the only way to order them using this feature appears to be based on the order in which those items were added to the store. As it turns out, it's just easier to create a NSSortDescriptor and return a NSArray using sortedArrayUsingDescriptors:. 

I also took a few days this week to pimp out Xcode with a few plug-ins (again, at the suggestion of Matt Thompson at NSHipster). The long of short of it is that Alcatraz makes it super easy to install Xcode plug-ins. There are loads of interesting plug-ins that you can use to accomplish tons of neat stuff that I hadn't really thought about before, but can make Xcode more enjoyable to use. The list of plug-ins I chose to install is listed at the bottom. I also eventually used Alcatraz to install CocoaPods which I used to include ios-linechart in the app. I'm hoping that LineChart will fit with what I need for basic plotting in the form of graphing FIS points and world rank over time. 

Up Next

My immediate next step is to work on implementing the ios-linechart code to create the plots I want. It doesn't look incredibly hard, but those are famous last words. Once I have that code written I'm hoping to move on to what needs to be implemented to store user created lists. Somewhere in there I also need to dig into the FIS CSV file because I'm getting inconsistent results when I look at the SQLite store and sort by a particular event's points vs. sorting that event's world rank. Yikes.


The week of 4-7-2014

The Idea

I'm staring to think I need to post about what I'm working on both to inform users about the work I do, but also to keep a record for my own review in the future. So, seeing as this is my first post I'm not sure what future posts will include, but I figure weekly-ish log of my activity could be helpful. 

So Far...

The Database

The foundation of the app (at least in it's current incarnation) is the database that will back the athlete table-view and the athlete detail-view. I considered building the database using sqlite and the Gus Mueller's highly recommended FMDB and Marco Arment's accompanying FCModel, but after considering my dearth of SQL and iOS knowledge I thought it best to let Apple's documentation and templates lead the way. So, I decided to use Apple's Core Data to build the athlete and points database. 

Inside the Core Data model I have two entities, Athlete and PointsList, with a to-many relationship between Athletes and PointsLists. The attributes associated with each entity are meant to mirror the columns included in the downloadable .csv files published by FIS.  For the time being I have elected to keep all the available information the CoreData database for completeness, plus I'm not currently concerned about the size of the database since additions are relatively infrequent. If size does become an issue I can always migrate to a new database that excludes less-important information such as an athlete's National ID, Club and World Rankings, but for the time being I think those will be useful. 

I haven't completely decided how I want to get the updated FIS data into the app, but following the objc.io suggestions on Importing Large Data Sets I currently plan on including a seed database in the app bundle and updating it via a web server. To create the Core Data seed database I wrote a command-line tool, similar to objc.io's Core Data importer, that reads from the various FIS .csv files to create the Athletes and PointsList SQLite databases using the app's Core Data model. This import utility should also be useful for creating updated SQLite databases on the web server. 

What I haven't decided on yet is how I want to store user generated collections of athletes. At first, I thought I would just add a UserList entity with a to-many relationship for Athletes, but if I plan on replacing that entire database for updates I need to come up with an alternative method. I'm currently thinking that a .plist that holds the names of lists and then the FIS IDs of the athletes included each list should do the trick. An alternative method would be to setup a second Core Data stack for holding just user generated list data. 

The App

The basics of the app seem solid. I started by reading up on Core Data using Tim Isted and Tom Harrington's Core Data for iOS and then built on top of Apple's iOS template 'Master-Detail Application' and so far so good. The template came preconfigured with a table-view and a detail-view that cover the basics of what I need for views and implementing search with fetch requests and fetched results controllers was relatively straight forward. 

I've done some minimal customization of the table-view cells and the detail view at this point, but I think that will be a major focus in the upcoming weeks. I want to provide coaches, athletes and parents with an in-depth detail view that shows not only the current details on an athlete, but also a synopsis of their points history with a graph or trend line. 

Today's Challenges

Today I've been looking into two challenges: where to store database state information (I'm thinking a .plist, but I don't currently know anything about them) and how to create plots for the detail view (I'm thinking of using ios-linechart that's part of CocoaPods).