source: main/waeup.sirp/trunk/src/waeup/sirp/jambtables/README.txt @ 5645

Last change on this file since 5645 was 5328, checked in by uli, 14 years ago

Merge changes from ulif-fasttables back into trunk.

File size: 3.7 KB
Line 
1JAMB registration numbers
2*************************
3
4.. :doctest:
5
6JAMB data is stored in a JAMBDataTable.
7
8Creating JAMB Tables
9====================
10
11We 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
21JAMB CSV tables have to provide the following header fields in the
22first 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
31Now 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
42Accessing JAMB Data
43===================
44
45Getting Entries
46---------------
47
48We can get the entries from the table as an iterator:
49
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     {...}]
69
70Also a :meth:`keys` and :meth:`items` method are available. They both
71return an iterator.
72
73The :meth:`keys` method in action:
74
75     >>> pprint(list(table.keys()))
76     [u'91100546DD', u'91111834CC', u'91109351AC']
77
78The :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
101A ``values()``-like behaviour cen be archieved by simply using the
102iterator.
103
104Getting JAMB Table Meta Data
105----------------------------
106
107We can also get a datetime stamp, that tells, when the table was
108imported. This could help with maintaining old tables:
109
110    >>> table.import_datetime
111    datetime.datetime(..., ..., ..., ..., ..., ..., ...)
112   
113
114We can delete the table:
115
116    >>> del JAMBDataTable
117
118Clean up:
119
120    >>> import os
121    >>> os.unlink(datafile)
Note: See TracBrowser for help on using the repository browser.