/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/classgen.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/classgen.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 886 by jonathan, Fri May 9 16:36:56 2003 UTC revision 891 by jonathan, Fri May 9 18:08:46 2003 UTC
# Line 156  class ClassGenerator: Line 156  class ClassGenerator:
156          adjusted = False          adjusted = False
157          if len(percents) != 0:          if len(percents) != 0:
158                                                                                                                                                                
             #print "list:", list  
             #print "percents:", percents  
             #print "numGroups:", numGroups  
       
159              #              #
160              # find what part of the list range covers              # find what part of the list range covers
161              #              #
# Line 176  class ClassGenerator: Line 172  class ClassGenerator:
172                      break;                      break;
173    
174              numValues = maxIndex - minIndex + 1              numValues = maxIndex - minIndex + 1
             #print "minIndex:", minIndex, "maxIndex:", maxIndex  
175              if minIndex <= maxIndex:              if minIndex <= maxIndex:
176    
177                  #                  #
178                  # build a list of unique indices into list of where each                  # build a list of unique indices into list of where each
179                  # quantile should be                  # quantile *should* be. set adjusted if the resulting
180                    # indices are different
181                  #                  #
182                  quantiles = {}                  quantiles = {}
183                  for p in percents:                  for p in percents:
# Line 189  class ClassGenerator: Line 185  class ClassGenerator:
185    
186                      adjusted = adjusted \                      adjusted = adjusted \
187                          or quantiles.has_key(index) \                          or quantiles.has_key(index) \
188                          or ((index+1) / float(numValues)) != p                          or ((index - minIndex + 1) / float(numValues)) != p
189    
190                      quantiles[index] = 0                      quantiles[index] = 0
191    
192                  quantiles = quantiles.keys()                  quantiles = quantiles.keys()
193                  quantiles.sort()                  quantiles.sort()
194    
                 #print "quantiles:", quantiles  
       
195                  #                  #
196                  # the current quantile index must be strictly greater than                  # the current quantile index must be strictly greater than
197                  # the lowerBound                  # the lowerBound
# Line 212  class ClassGenerator: Line 206  class ClassGenerator:
206            
207                      # lowerBound + 1 is always a valid index                      # lowerBound + 1 is always a valid index
208            
       
209                      #                      #
210                      # bump up the current quantile index to be a usable index                      # bump up the current quantile index to be a usable index
211                      # if it currently falls below the lowerBound                      # if it currently falls below the lowerBound
# Line 223  class ClassGenerator: Line 216  class ClassGenerator:
216                      listIndex = quantiles[qindex]                      listIndex = quantiles[qindex]
217                      value = list[quantiles[qindex]]                      value = list[quantiles[qindex]]
218            
                     #print "-----------------------------------"  
                     #print "listIndex:", listIndex  
                     #print "value:", value  
       
219                      #                      #
220                      # look for similar values around the quantile index                      # look for similar values around the quantile index
221                      #                      #
                   
                     #print "lowerBound:", lowerBound  
222                      lindex = listIndex - 1                      lindex = listIndex - 1
223                      lcount = 0                      lcount = 0
224                      while lindex > lowerBound:                      while lindex > lowerBound:
# Line 246  class ClassGenerator: Line 233  class ClassGenerator:
233                          rcount += 1                          rcount += 1
234                          rindex += 1                          rindex += 1
235            
                     #print lcount, "(lcount)", rcount, "(rcount)"  
                     #print lindex, "(lindex)", rindex, "(rindex)"  
       
236                      #                      #
237                      # adjust the current quantile index based on how many                      # adjust the current quantile index based on how many
238                      # numbers in the list are the same as the current value                      # numbers in the list are the same as the current value
# Line 263  class ClassGenerator: Line 247  class ClassGenerator:
247                              #                              #
248                              if lindex != lowerBound:                              if lindex != lowerBound:
249                                  newIndex = lindex                                  newIndex = lindex
                                 #quantiles[qindex] = lindex  
250                              else:                              else:
251                                  newIndex = rindex - 1                                  newIndex = rindex - 1
                                 #quantiles[qindex] = rindex - 1  
252            
253                      elif lcount < rcount:                      elif lcount < rcount:
254                          # there are fewer items to the left, so                          # there are fewer items to the left, so
# Line 274  class ClassGenerator: Line 256  class ClassGenerator:
256                          # doing so creates an empty quantile.                          # doing so creates an empty quantile.
257                          if lindex != lowerBound:                          if lindex != lowerBound:
258                              newIndex = lindex                              newIndex = lindex
                             #quantiles[qindex] = lindex  
259                          else:                          else:
260                              newIndex = rindex - 1                              newIndex = rindex - 1
                             #quantiles[qindex] = rindex - 1  
261            
262                      elif rcount < lcount:                      elif rcount < lcount:
263                          # there are fewer items to the right, so go to the right                          # there are fewer items to the right, so go to the right
                         #quantiles[qindex] = rindex - 1  
264                          newIndex = rindex - 1                          newIndex = rindex - 1
265            
266                      quantiles[qindex] = newIndex                      quantiles[qindex] = newIndex
267                      lowerBound = quantiles[qindex]                      lowerBound = quantiles[qindex]
268            
269                      #print "quantiles:", quantiles          #
270                      #print "lowerBound:", lowerBound          # since quantiles is only set if the code is at least a little
271                    # successful, an empty list will be generated in the case that
272                  #print "================================="          # we fail to get to the real body of the algorithm
273                  #print "quantiles:", quantiles          #
274                  #print "qindex:", qindex          return (adjusted,
275                        [(q, (q - minIndex+1) / float(numValues)) for q in quantiles])
         return (adjusted, [(q, (q+1) / float(numValues)) for q in quantiles])  
276    
277  CLR  = 0  CLR  = 0
278  STEP = 1  STEP = 1

Legend:
Removed from v.886  
changed lines
  Added in v.891

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26