[5235] | 1 | JAMB registration numbers |
---|
| 2 | ************************* |
---|
| 3 | |
---|
[5263] | 4 | .. :doctest: |
---|
[5235] | 5 | |
---|
| 6 | JAMB data is stored in a JAMBDataTable. |
---|
| 7 | |
---|
[5243] | 8 | Creating JAMB Tables |
---|
| 9 | ==================== |
---|
| 10 | |
---|
[5235] | 11 | We can import JAMB registration data from a regular CSV file: |
---|
| 12 | |
---|
| 13 | >>> datafile = 'jambsample.csv' |
---|
| 14 | >>> open(datafile, 'wb').write( |
---|
| 15 | ... '''reg_no,fst_sit_fname,lastname,firstname,middlenames,sex,date_of_birth,jamb_state,jamb_lga,course1,screening_date,screening_venue,entry_session,screening_type |
---|
| 16 | ... 91100546DD,ISUOSUO MOSES ODOMERO,ISUOSUO,MOSES,ODOMERO,M,25/5/1982,DEL,ISO-S,BSCPOL,2009/09/25 09:00:00 GMT+1,REPRINT SLIP AS FROM WED 23/09/2009,9,pde |
---|
| 17 | ... 91111834CC,DURUIHEOMA AUGUSTINA ADANNA,DURUIHEOMA,AUGUSTINA,ADANNA,F,15/4/1986,IMO,MBAIT,BSCPOL,2009/09/25 09:00:00 GMT+1,REPRINT SLIP AS FROM WED 23/09/2009,9,pde |
---|
| 18 | ... 91109351AC,ARISERE EBIKEBUNA COMFORT,ARISERE,EBIKEBUNA,COMFORT,F,6/1/1984,EDO,OV-SW,BSCPOL,2009/09/25 09:00:00 GMT+1,REPRINT SLIP AS FROM WED 23/09/2009,9,pde |
---|
| 19 | ... ''') |
---|
| 20 | |
---|
[5244] | 21 | JAMB CSV tables have to provide the following header fields in the |
---|
| 22 | first line: |
---|
| 23 | |
---|
| 24 | >>> from pprint import pprint |
---|
| 25 | >>> from waeup.sirp.jambtables.jambtables import JAMB_DATA_HEADERS |
---|
| 26 | >>> JAMB_DATA_HEADERS |
---|
| 27 | ['firstname', 'lastname', 'middlenames', 'screening_type', |
---|
| 28 | 'screening_venue', 'reg_no', 'sex', 'course1', 'jamb_state', |
---|
| 29 | 'screening_date', 'jamb_lga', 'fst_sit_fname', 'date_of_birth'] |
---|
| 30 | |
---|
[5235] | 31 | Now we create a JAMBDataTable and import the data: |
---|
| 32 | |
---|
| 33 | >>> from waeup.sirp.jambtables import JAMBDataTable |
---|
| 34 | >>> table = JAMBDataTable() |
---|
| 35 | >>> len(list(table)) |
---|
| 36 | 0 |
---|
| 37 | |
---|
| 38 | >>> table.importFromCSV(datafile) |
---|
| 39 | >>> len(list(table)) |
---|
| 40 | 3 |
---|
| 41 | |
---|
[5243] | 42 | Accessing JAMB Data |
---|
| 43 | =================== |
---|
| 44 | |
---|
| 45 | Getting Entries |
---|
| 46 | --------------- |
---|
| 47 | |
---|
[5235] | 48 | We can get the entries from the table as an iterator: |
---|
| 49 | |
---|
[5239] | 50 | >>> from pprint import pprint |
---|
| 51 | >>> entries = [x for x in table] |
---|
| 52 | >>> pprint(entries) |
---|
| 53 | [{'course1': u'BSCPOL', |
---|
| 54 | 'date_of_birth': datetime.date(1982, 5, 25), |
---|
| 55 | 'entry_session': '9', |
---|
| 56 | 'firstname': u'MOSES', |
---|
| 57 | 'fst_sit_fname': u'ISUOSUO MOSES ODOMERO', |
---|
| 58 | 'jamb_lga': u'ISO-S', |
---|
| 59 | 'jamb_state': u'DEL', |
---|
| 60 | 'lastname': u'ISUOSUO', |
---|
| 61 | 'middlenames': u'ODOMERO', |
---|
| 62 | 'reg_no': u'91100546DD', |
---|
| 63 | 'screening_date': u'2009/09/25 09:00:00 GMT+1', |
---|
| 64 | 'screening_type': u'pde', |
---|
| 65 | 'screening_venue': u'REPRINT SLIP AS FROM WED 23/09/2009', |
---|
| 66 | 'sex': u'M'}, |
---|
| 67 | {...}, |
---|
| 68 | {...}] |
---|
[5235] | 69 | |
---|
[5243] | 70 | Also a :meth:`keys` and :meth:`items` method are available. They both |
---|
| 71 | return an iterator. |
---|
| 72 | |
---|
| 73 | The :meth:`keys` method in action: |
---|
| 74 | |
---|
| 75 | >>> pprint(list(table.keys())) |
---|
| 76 | [u'91100546DD', u'91111834CC', u'91109351AC'] |
---|
| 77 | |
---|
| 78 | The :meth:`items` method in action: |
---|
| 79 | |
---|
| 80 | >>> pprint(list(table.items())) |
---|
| 81 | [(u'91100546DD', |
---|
| 82 | {'course1': u'BSCPOL', |
---|
| 83 | 'date_of_birth': datetime.date(1982, 5, 25), |
---|
| 84 | 'entry_session': '9', |
---|
| 85 | 'firstname': u'MOSES', |
---|
| 86 | 'fst_sit_fname': u'ISUOSUO MOSES ODOMERO', |
---|
| 87 | 'jamb_lga': u'ISO-S', |
---|
| 88 | 'jamb_state': u'DEL', |
---|
| 89 | 'lastname': u'ISUOSUO', |
---|
| 90 | 'middlenames': u'ODOMERO', |
---|
| 91 | 'reg_no': u'91100546DD', |
---|
| 92 | 'screening_date': u'2009/09/25 09:00:00 GMT+1', |
---|
| 93 | 'screening_type': u'pde', |
---|
| 94 | 'screening_venue': u'REPRINT SLIP AS FROM WED 23/09/2009', |
---|
| 95 | 'sex': u'M'}), |
---|
| 96 | (u'91111834CC', |
---|
| 97 | {...}), |
---|
| 98 | (u'91109351AC', |
---|
| 99 | {...})] |
---|
| 100 | |
---|
| 101 | A ``values()``-like behaviour cen be archieved by simply using the |
---|
| 102 | iterator. |
---|
| 103 | |
---|
| 104 | Getting JAMB Table Meta Data |
---|
| 105 | ---------------------------- |
---|
| 106 | |
---|
[5239] | 107 | We can also get a datetime stamp, that tells, when the table was |
---|
| 108 | imported. This could help with maintaining old tables: |
---|
[5235] | 109 | |
---|
[5239] | 110 | >>> table.import_datetime |
---|
| 111 | datetime.datetime(..., ..., ..., ..., ..., ..., ...) |
---|
| 112 | |
---|
| 113 | |
---|
[5235] | 114 | We can delete the table: |
---|
| 115 | |
---|
| 116 | >>> del JAMBDataTable |
---|
| 117 | |
---|
| 118 | Clean up: |
---|
| 119 | |
---|
| 120 | >>> import os |
---|
| 121 | >>> os.unlink(datafile) |
---|