Ejemplo n.º 1
0
    def fromYAML(self, domain_type, primary_key, filename):
        """Load a table from a yaml file. The domain type provides the context for
       this data, the key idicates the name used for the context in the
       file.
       Parameters:
         domain_type    a SubDomain type or corresponding to the primary key
                        of this table
         primary_key    the string key used in the file for the primary domain
         filename       the name of the yaml file
    """

        import YamlLoader as yl

        self._domainType = domain_type
        self._key = primary_key

        self._data = yl.load_yaml(filename)
Ejemplo n.º 2
0
  def fromYAML(self,domain_type,primary_key, filename):
    """Load a table from a yaml file. The domain type provides the context for
       this data, the key idicates the name used for the context in the
       file.
       Parameters:
         domain_type    a SubDomain type or corresponding to the primary key
                        of this table
         primary_key    the string key used in the file for the primary domain
         filename       the name of the yaml file
    """

    import YamlLoader as yl

    self._domainType = domain_type
    self._key = primary_key

    self._data = yl.load_yaml(filename)
Ejemplo n.º 3
0
    def insertRun(self, filename, position = -1, rows = 1):
        """Insert a run with all of its child tables and projections
           into the data datatree/data store. The input filename should
           refer to the meta file denoting the run.
        """
        parentItem = self._rootItem
        metadata, filelist = yl.load_meta(filename)
        if position == -1:
            position = parentItem.childCount()

        # Create RunItem
        self.beginInsertRows(QModelIndex(), position, position + rows - 1)
        runItem = RunItem(os.path.basename(filename), metadata, parentItem)
        self.endInsertRows()

        # Create groups for Tables and Projections
        self.beginInsertRows(self.createIndex(position, 0, runItem), 0, 2)
        tablesItem = GroupItem("tables", parent = runItem)
        projectionsItem = GroupItem("projections", parent = runItem)
        self.endInsertRows()

        # Create TableItems and ProjectionItems
        for filedict in filelist:
            if filedict['filetype'].upper() == "TABLE":
                type_string = filedict['domain'] + "_" + filedict['type']
                data_type = SubDomain.instantiate(type_string)
                if data_type is None:
                    print "No matching type found for", filedict['type'], \
                        "! Skipping table..."
                    continue

                filepath = os.path.join(os.path.dirname(filename),
                    filedict['filename'])
                metadata, data = yl.load_table(filepath)
                if metadata:
                    combined_meta = dict(metadata.items() + filedict.items())
                else:
                    combined_meta = filedict
                atable = Table()
                atable.fromRecArray(data_type, filedict['field'], data)
                self.insertTable(filedict['filename'], atable, combined_meta, \
                    parent = self.createIndex(position, 0, tablesItem))
            elif filedict['filetype'].upper() == "PROJECTION":
                domainlist = filedict['subdomain']
                mydomains = list()
                mykeys = list()
                for subdomaindict in domainlist:
                    type_string = subdomaindict['domain'] + "_" \
                        + subdomaindict['type']
                    data_type = SubDomain.instantiate(type_string)
                    if data_type is None:
                        print "No matching type found for", \
                            subdomaindict['type'], "! Skipping projection..."
                        continue
                    else:
                        mydomains.append(data_type)
                        mykeys.append(subdomaindict['field'])

                if len(mydomains) != 2:
                    print "Not enough domains for projection. Skipping..."
                    continue

                # Different projections created here per type. Again, probably
                # should be moved to different class.
                if filedict['type'].upper() == "FILE":
                    filepath = os.path.join(os.path.dirname(filename),
                        filedict['filename'])
                    metadata, data = yl.load_table(filepath)
                    if metadata:
                        combined_meta = dict(metadata.items() + filedict.items())
                    else:
                        combined_meta = filedict
                    atable = Table()
                    atable.fromRecArray(mydomains[0], mykeys[0], data)
                    aprojection = TableProjection(mydomains[0], mydomains[1],
                        source_key = mykeys[0], destination_key = mykeys[1],
                        table = atable)
                    self.insertProjection(mydomains[0].typename() + "<->"
                        + mydomains[1].typename(), aprojection, combined_meta,
                        parent = self.createIndex(position, 0, projectionsItem))
                else:
                    aprojection = Projection.instantiate(filedict['type'],
                        mydomains[0], mydomains[1], run = runItem, **filedict)
                    self.insertProjection(mydomains[0].typename() + "<->"
                        + mydomains[1].typename(), aprojection, filedict,
                        parent = self.createIndex(position, 0, projectionsItem))


        runItem.refreshSubdomains()
        self.createSubDomainTables(runItem, projectionsItem, tablesItem)
        return True