85 |
|
|
86 |
return None |
return None |
87 |
|
|
88 |
|
def field_range(self, fieldName): |
89 |
|
"""Finds the first occurences of the minimum and maximum values |
90 |
|
in the table for the given field. |
91 |
|
|
92 |
|
This assumes that the standard comparison operators (<, >, etc.) |
93 |
|
will work for the given data. |
94 |
|
|
95 |
|
Returns a tuple ((min, rec), (max, rec)) where: |
96 |
|
min is the minimum value |
97 |
|
max is the maximum value |
98 |
|
rec is the record number where the value was found. One |
99 |
|
should check that the record number of min is not |
100 |
|
the same as the record number of max. |
101 |
|
|
102 |
|
Returns None if there are no records |
103 |
|
|
104 |
|
""" |
105 |
|
|
106 |
|
|
107 |
|
count = self.record_count() |
108 |
|
|
109 |
|
if count == 0: |
110 |
|
return None |
111 |
|
|
112 |
|
rec = self.read_record(0) |
113 |
|
|
114 |
|
min = rec[fieldName] |
115 |
|
min_rec = 0 |
116 |
|
|
117 |
|
max = rec[fieldName] |
118 |
|
max_rec = 0 |
119 |
|
|
120 |
|
for i in range(1, count): |
121 |
|
rec = self.read_record(i) |
122 |
|
data = rec[fieldName] |
123 |
|
|
124 |
|
if data < min: |
125 |
|
min = data |
126 |
|
min_rec = rec |
127 |
|
elif data > max: |
128 |
|
max = data |
129 |
|
max_rec = rec |
130 |
|
|
131 |
|
return ((min, min_rec), (max, max_rec)) |
132 |
|
|
133 |
|
def GetUniqueValues(self, fieldName): |
134 |
|
"""Return a list of all unique entries in the table for the given |
135 |
|
field name. |
136 |
|
""" |
137 |
|
|
138 |
|
dict = {} |
139 |
|
|
140 |
|
for i in range(0, self.record_count()): |
141 |
|
rec = self.read_record(i) |
142 |
|
data = rec[fieldName] |
143 |
|
|
144 |
|
if not dict.has_key(data): |
145 |
|
dict[data] = 0 |
146 |
|
|
147 |
|
return dict.keys() |
148 |
|
|
149 |
def read_record(self, record): |
def read_record(self, record): |
150 |
"""Return the record no. record as a dict mapping field names to values |
"""Return the record no. record as a dict mapping field names to values |
151 |
""" |
""" |