Exemplo n.º 1
0
 def createNestedTable(self):
     """
 Table
   A
   B
   Subtable
     C
     D
 :return dict: name, object pairs
 """
     if IGNORE_TEST:
         return
     table = UITable("Table")
     result = {"Table": table}
     result["A"] = Column("A")
     table.addColumn(result["A"])
     result["B"] = Column("B")
     table.addColumn(result["B"])
     subtable = UITable("Subtable")
     result["Subtable"] = subtable
     table.addChild(subtable)
     result["C"] = Column("C")
     subtable.addColumn(result["C"])
     result["D"] = Column("D")
     subtable.addColumn(result["D"])
     return result
Exemplo n.º 2
0
 def createRandomTable(cls, name, nrow, ncol, ncolstr=0,
       low_int=0, hi_int=100):
   """
   Creates a table with random integers as values
   Input: name - name of the table
          nrow - number of rows
          ncol - number of columns
          ncolstr - number of columns with strings
          low_int - smallest integer
          hi_int - largest integer
   """
   ncol = int(ncol)
   nrow = int(nrow)
   table = cls(name)
   ncolstr = min(ncol, ncolstr)
   ncolint = ncol - ncolstr
   c_list = range(ncol)
   random.shuffle(c_list)
   for n in range(ncol):
     column = Column("Col_" + str(n))
     if c_list[n] <= ncolint - 1:
       values = np.random.randint(low_int, hi_int, nrow)
       values_ext = values.tolist()
     else:
       values_ext = ut.randomWords(nrow)
     #values_ext.append(None)
     column.addCells(np.array(values_ext))
     table.addColumn(column)
   versioned_file = VersionedFile(
       settings.SCISHEETS_DEFAULT_TABLEFILE,
       st.SCISHEETS_USER_TBLDIR_BACKUP,
       st.SCISHEETS_MAX_TABLE_VERSIONS)
   table.setVersionedFile(versioned_file)
   return table
 def setUp(self):
   self.table = ht.createTable("TEST",
       column_name=[ht.COLUMN1, ht.COLUMN2])
   new_column = Column(FORMULA_COLUMN_NAME)
   new_column.setFormula("np.sin(%s)" % ht.COLUMN1)
   self.table.addColumn(new_column)
   self.table.evaluate()
   columns = self.table.getColumns()
   self.column_variables =  \
       [ColumnVariable(c) for c in columns] 
Exemplo n.º 4
0
 def setUp(self):
   self.table = ht.createTable("TEST",
       column_name=[ht.COLUMN1, ht.COLUMN2])
   new_column = Column(FORMULA_COLUMN_NAME)
   new_column.setFormula("np.sin(%s)" % ht.COLUMN1)
   self.table.addColumn(new_column)
   self.table.evaluate()
   columns = self.table.getColumns()
   self.column_variables =  \
       [ColumnVariable(c) for c in columns] 
Exemplo n.º 5
0
 def _commandAppendAndInsert(self, node, target, command, name):
     """
 Processes Append and Insert commands for targets of Column and Table.
 :param NamedTree node:
 :param str target:
 :param str command:
 :param str name: name for new Column
 :return str error:
 """
     versioned = self.getVersionedFile()
     UITable._versionCheckpoint(versioned, target, command)
     error = Column.isPermittedName(name)
     if self._isDuplicateInGlobalScope(name):
         error = "%s conflics with existing names" % proposed_name
     if error is None:
         new_column = Column(name)
         increment = 0
         if command == "Append":
             increment = 1
         parent = node.getParent()
         column_index = node.getPosition()
         new_column_index = column_index + increment
         parent.addChild(new_column, new_column_index)
     return error
Exemplo n.º 6
0
 def _columnCommand(self, cmd_dict):
   # Processes a UI request for a Column
   # Input: cmd_dict - dictionary with the keys
   # Output: response - response to user
   error = None
   target = "Column"
   command = cmd_dict["command"]
   column = self.visibleColumnFromIndex(cmd_dict["column_index"])
   versioned = self.getVersionedFile()
   if (command == "Append") or (command == "Insert"):
     versioned.checkpoint(id="%s/%s" % (target, command))
     name = cmd_dict["args"][0]
     error = Column.isPermittedName(name)
     if error is None:
       new_column = Column(name)
       increment = 0
       if command == "Append":
         increment = 1
       column_index = self.indexFromColumn(column)
       new_column_index = column_index + increment
       self.addColumn(new_column, new_column_index)
   elif command == "Delete":
     versioned.checkpoint(id="%s/%s" % (target, command))
     self.deleteColumn(column)
   elif command == "Formula":
     versioned.checkpoint(id="%s/%s" % (target, command))
     formula = cmd_dict["args"][0]
     if len(formula.strip()) == 0:
       error = column.setFormula(None)
     else:
       error = column.setFormula(formula)
   elif command == "Move":
     versioned.checkpoint(id="%s/%s" % (target, command))
     dest_column_name = cmd_dict["args"][0]
     try:
       if dest_column_name == "LAST":
         new_column_index = self.numColumns() - 1
       else:
         dest_column = self.columnFromName(dest_column_name)
         new_column_index = self.indexFromColumn(dest_column)
       cur_column = self.visibleColumnFromIndex(cmd_dict["column_index"])
       self.moveColumn(cur_column, new_column_index)
     except Exception:
       error = "Column %s does not exists." % dest_column_name
   elif command == "Refactor":
     versioned.checkpoint(id="%s/%s" % (target, command))
     proposed_name = cmd_dict["args"][0]
     try:
       self.refactorColumn(column.getName(), proposed_name)
     except Exception as err:
       error = str(err)
   elif command == "Rename":
     versioned.checkpoint(id="%s/%s" % (target, command))
     proposed_name = cmd_dict["args"][0]
     if not self.renameColumn(column, proposed_name):
       error = "%s is a duplicate column name." % proposed_name
   else:
     msg = "Unimplemented %s command: %s." % (target, command)
     raise NotYetImplemented(msg)
   response = self._createResponse(error)
   return response