Page 258 -
P. 258

build a model


           Model your data


          Your web server needs to store a single copy of your data, which in this case is
           Coach Kelly’s timing values (which start out in his text files).

           When your webapp starts, the data in the text files needs to be converted
           to AthleteList object instances, stored within a dictionary (indexed by
           athlete name), and then saved as a pickle file. Let’s put this functionality in a
           new function called put_to_store().

           While your webapp runs, the data in the pickle needs to be available to your
           webapp as a dictionary. Let’s put this functionality in another new function
           called get_from_store().


           When your webapp starts:                     While your webapp runs:

                    julie.txt                                             The single pickle
      james.txt                                                            with all of the

                                                                                            [‘Is this the right room
                                                                                            for an argument?’, “No
                                                                                            you haven’t!”, ‘When?’,
                           mikey.txt                                       coach’s data    “No you didn’t!”, “You
                                                                                            didn’t!”, ‘You did not!’,
                                                                           stored in a
                                                                                           ‘Ah! (taking out his wallet
                                                                                            and paying) Just the five
                                                                                            minutes.’, ‘You most
                                                                                            certainly did not!’, “Oh
                                                                                            no you didn’t!”, “Oh no
                                                                                            you didn’t!”, “Oh look,
                                                                           dictionary      “No it isn’t!”, “It’s
                                                                                            this isn’t an argument!”,
                                                                                            just contradiction!”,
                                                                                           ‘It IS!’, ‘You just
                                                                                            contradicted me!’, ‘You
                                                                                            DID!’, ‘You did just
                                                                                            then!’, ‘(exasperated)
                                                                                            Oh, this is futile!!’,
                                                                                           ‘Yes it is!’]
         sarah.txt
                                                                                     The
                                                                               get_from_store()
                       The                                                         function
                   put_to_store()
                     function
                                                           {'Sarah': AthleteList... ,
                                         [‘Is this the right room
                                         for an argument?’, “No
                                         you haven’t!”, ‘When?’,
                                         “No you didn’t!”, “You
                                         didn’t!”, ‘You did not!’,
                                        ‘Ah! (taking out his wallet
                                         and paying) Just the five     'James': AthleteList... ,
                                         minutes.’, ‘You most
                                         certainly did not!’, “Oh
                                         no you didn’t!”, “Oh no
                                         you didn’t!”, “Oh look,
                                         this isn’t an argument!”,
                                         “No it isn’t!”, “It’s
                                         just contradiction!”,
                                        ‘It IS!’, ‘You just
                                         contradicted me!’, ‘You     'Julie': AthleteList... ,
                                         DID!’, ‘You did just
                                         then!’, ‘(exasperated)
                                         Oh, this is futile!!’,
                                        ‘Yes it is!’]
                                                            'Mikey': AthleteList... }
                        The single pickle with
                        all of the data stored                        A dictionary of AthleteLists returned
                        in a dictionary
                                                                      from the “get_from_store()” function
           222    Chapter 7
   253   254   255   256   257   258   259   260   261   262   263