/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Public Attributes
RollingGainAuto::Table::Table Class Reference

List of all members.

Public Member Functions

def __init__
def reset
def read
def dump
def compare

Public Attributes

 filename
 comments
 headerLine
 fieldNames
 columns
 nRows

Detailed Description

Definition at line 6 of file Table.py.


Constructor & Destructor Documentation

def RollingGainAuto::Table::Table::__init__ (   self)

Definition at line 7 of file Table.py.

00008                       :
00009         self.reset()


Member Function Documentation

def RollingGainAuto::Table::Table::reset (   self)

Definition at line 10 of file Table.py.

00011                    :
00012         self.filename = None     # The table file
00013         
00014         self.comments = []       # All lines start with '#'        
00015         self.headerLine = None   # The line with  '# [name1]  [name2] ...'
00016         self.fieldNames = []     # Column names
00017         self.columns = {}        # Column name indexed value list
00018         self.nRows = 0           # Number of rows    

def RollingGainAuto::Table::Table::read (   self,
  filename 
)

Definition at line 19 of file Table.py.

00020                            :
00021         self.filename = filename
00022         tableLines = open(self.filename).readlines()
00023         for line in tableLines:
00024             data = line.strip()
00025             # Catch comments / header
00026             if len(data)>0 and data[0]=='#':
00027                 comment = data[1:].strip()
00028                 if len(comment)>0 and comment[0] =='[':
00029                     # Found header
00030                     if len(self.fieldNames) > 0:
00031                         print "Warning Headers already defined by line \"",data,"\"",self.filename
00032                         print "Following lines are skipped."
00033                         return None
00034                     tokens = comment.split(']')
00035                     if len(tokens[-1].strip())==0: tokens = tokens[:-1]
00036                     for token in tokens:
00037                         fieldStart = token.rfind('[')
00038                         if fieldStart<0:
00039                             print "Invalid token \"",token,"\" in line \"",line,"\""
00040                             return None
00041                         fieldName = token[fieldStart+1:].strip()
00042                         self.fieldNames.append(fieldName)
00043                         self.columns[fieldName] = []
00044                         self.headerLine = line
00045                 else:
00046                     self.comments.append(line)
00047                 continue
00048             # Data line
00049             fields = data.split()
00050             if len(fields)==0: continue  # Empty line
00051             if len(fields) != len(self.columns):
00052                 print "Invalid number of fields in line \"",line,"\""
00053                 return None
00054             for fieldIdx in range(len(fields)):
00055                 self.columns[ self.fieldNames[fieldIdx] ].append( fields[fieldIdx] )
00056             self.nRows += 1

def RollingGainAuto::Table::Table::dump (   self)

Definition at line 57 of file Table.py.

00058                   :
00059         print self.fieldNames
00060         for rowIdx in range(self.nRows):
00061             for fieldIdx in range(len(self.fieldNames)):
00062                 print self.columns[self.fieldNames[fieldIdx]][rowIdx]

def RollingGainAuto::Table::Table::compare (   self)

Definition at line 63 of file Table.py.

00064                      :
00065         name1 = self.columns['name'][0]
00066 
00067         print "Start to compare"
00068         for rowIdx in range(self.nRows):
00069             print rowIdx, self.columns['name'][rowIdx]
00070             if name1 == self.columns['name'][rowIdx]:
00071                 print "The same name with id ", self.columns['id'][rowIdx]


Member Data Documentation

Definition at line 10 of file Table.py.

Definition at line 10 of file Table.py.

Definition at line 10 of file Table.py.

Definition at line 10 of file Table.py.

Definition at line 10 of file Table.py.

Definition at line 10 of file Table.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:59:50 for RollingGainAuto by doxygen 1.7.4