csv-import (was:Re: [Thuban-devel] Re: Lots of interesting code in precision farming application)

Ole Rahn O.Rahn at fh-osnabrueck.de
Tue Nov 30 10:25:02 CET 2004


Hi Moritz,

as far as I remember, you're right: The CSV Reader should be quite 
independent of the rest of the Precision Farming Extension, BUT the 
MemoryShape isn't ... anymore.

In order to allow deletion of shapes from a MemoryShapeStore, I had to 
alter the MemoryTable (Thuban/Model/table.py). The reason for that is 
the sequential order of attribute data inside this table. If you remove 
random shapes, you have to keep track of which rows were deleted or else 
all data will get deranged...

In order to prevent you from having to search for missing methods there 
are two ways to proceed:
1) I can send you a version of the MemoryShapeStore without deletion 
functions -> no dependency of an altered table.py
2) Here is a diff between a mostly (except for maybe some console 
print-outs) unchanged Thuban 1.0.0 version of table.py and the PIROL one 
- in case you want to use the MemoryShapeStore with its "extended" 
functions... :

Index: table.py
===================================================================
RCS file: /CVS/cvsrepo/thuban/Thuban/Model/table.py,v
retrieving revision 1.4
retrieving revision 1.9
diff -r1.4 -r1.9
14c14
< __version__ = "$Revision: 1.4 $"
---
 > __version__ = "$Revision: 1.9 $"
271a272,295
 >            
 >         self.deletedRows = []
 >        
 >     def removeRow( self, index, row_is_ordinal = 0):
 >         oldIndex = index
 >         if ( not row_is_ordinal ):
 >             index = self.RowIdToOrdinal( index )
 >
 >         #print "removeRow():", index, self.NumRows()
 >         if ( index < self.NumRows() and index > -1):
 >             self.data.remove( self.data[index] )
 >             self.deletedRows.append( oldIndex )
 >             #print "removed:", index
 >             return True
 >            
 >         return False
 >        
 >     def appendRow( self, data, id=-1 ):
 > #        if ( id == -1 ):
 > #            id = self.NumRows()
 >            
 >         self.data.append( data )
 >        
 >        
300a325,333
 >     def _getDeletedBelow( self, gid ):
 >         differenz = 0
 >         for deleted in self.deletedRows:
 >             if ( deleted < gid ):
 >                 #print "-",deleted
 >                 differenz += 1
 >                
 >         return differenz
 >        
307c340,341
<         return gid
---
 >         #print "RowIdToOrdinal():", gid, gid - self._getDeletedBelow(gid)
 >         return gid - self._getDeletedBelow(gid)
315c349
<         return num
---
 >         return num + self._getDeletedBelow(num) +1
325c359,363
<         return self.data[row][self.column_map[col].index]
---
 >         if ( not row_is_ordinal ):
 >             #print "row", row, "col", col, "value", 
self.data[self.RowIdToOrdinal(row)][self.column_map[col].index]
 >             return 
self.data[self.RowIdToOrdinal(row)][self.column_map[col].index]
 >         else:
 >             return self.data[row][self.column_map[col].index]
333c371,375
<         return dict([(col.name, self.data[index][col.index])
---
 >         if ( not row_is_ordinal ):
 >             return dict([(col.name, 
self.data[self.RowIdToOrdinal(index)][col.index])
 >                       for col in self.columns])
 >         else:
 >             return dict([(col.name, self.data[index][col.index])


I hope this helps!
Also, if there is anything I can help you with while trying to decrypt 
our code, let me know. I'll be happy to help.


Best regards

Ole




More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)