def createTestDB ( project_name, channel_list=['unit_anno'], channel_type=ANNOTATION, channel_datatype=UINT32, public=0, ximagesize=10000, yimagesize=10000, zimagesize=1000, xvoxelres=4.0, yvoxelres=4.0, zvoxelres=3.0, scalingoption=ZSLICES, scalinglevels=5, readonly=READONLY_FALSE, propagate=NOT_PROPAGATED, window=[0,0], time=[0,0], default=False, ocp_version=OCP_VERSION ):
  """Create a unit test data base on the specified sit and name"""
  
  unituser = User.objects.get(username='******')

  ds = Dataset ( dataset_name="unittest", user=unituser, ximagesize=ximagesize, yimagesize=yimagesize, zimagesize=zimagesize,  xoffset=0, yoffset=0, zoffset=1, xvoxelres=xvoxelres, yvoxelres=yvoxelres, zvoxelres=zvoxelres, scalingoption=scalingoption, scalinglevels=scalinglevels, starttime=time[0], endtime=time[1], dataset_description="Unit test" ) 
  ds.save()


  # RBTODO need to add a window and a project

  # make the project entry
  pr = Project (project_name=project_name, project_description='Unit test', user=unituser, dataset=ds, ocp_version=ocp_version, kvengine=kvengine_to_test.kvengine, kvserver=kvengine_to_test.kvserver)
  pr.save()

  # and create the database
  pd = ocpcaproj.OCPCAProjectsDB()

  # create a token
  tk = Token (token_name = project_name, user=unituser, token_description = 'Unit test token', project_id=pr, public=public)
  tk.save()

  pd.newOCPCAProject( pr.project_name )
  try:
    for channel_name in channel_list:
      ch = Channel (channel_name=channel_name, channel_type=channel_type, channel_datatype=channel_datatype, channel_description='Unit test channel', project_id=pr, readonly=readonly, propagate=propagate, resolution=0, exceptions=1,startwindow=window[0], endwindow=window[1], default=default)
      ch.save()
      pd.newOCPCAChannel(pr.project_name, ch.channel_name)
  except Exception, e:
    pass
Esempio n. 2
0
  def importTable(self):
    """Import the datasets from csv format"""

    cursor = self.conn.cursor()
    with open('{}.csv'.format(self.table_name), 'rb') as csv_file:
      csv_reader = csv.DictReader(csv_file, delimiter=',')
      for row in csv_reader:
        
        try:
          if row['openid'] == 'apl':
            user = User.objects.get(username=row['will'])
          else:
            user = User.objects.get(username=row['openid'])
        except Exception, e:
          user = User.objects.get(username='******')
        
        if self.table_name == 'datasets':
          ds = Dataset (dataset_name=row['dataset'], user=user, ximagesize=int(row['ximagesize']), yimagesize=int(row['yimagesize']), zimagesize=int(row['endslice']), zoffset=int(row['startslice']), scalinglevels=int(row['zoomlevels']), starttime=int(row['starttime']), endtime=int(row['endtime']), dataset_description=row['dataset'], zvoxelres=row['zscale'], public=1)
          try:
            ds.save()
          except Exception, e:
            print ds, "Error"
        elif self.table_name == 'projects':
          try:
            ds = Dataset.objects.get(dataset_name=row['dataset'])
            pr = Project.objects.get(project_name=row['project'])
            #pr,pr_status = Project.objects.update_or_create(project_name=row['project'], project_description=row['project'], dataset=ds, user=user, ocp_version='0.0', host=row['host'], kvengine=row['kvengine'], kvserver=row['kvserver'])
            [channel_type, channel_datatype] = DATATYPE[int(row['datatype'])]
            #ch,ch_status = Channel.objects.update_or_create(channel_name=channel_type, channel_description=channel_type, channel_type=channel_type, channel_datatype=channel_datatype, project_id=pr, resolution=row['resolution'], exceptions=row['exceptions'], startwindow=0, endwindow=0, default="1", readonly=row['readonly'], propagate=row['propagate'])
            if int(row['datatype']) in [3,4]:
              # delete the old channel
              Channel.objects.filter(project_id=pr.project_name).delete()
              # iterate over channel names and create channels
              import ast
              for channel_name in ast.literal_eval(row['channel']):
                print channel_name[0]
                ch = Channel (channel_name = channel_name[0], project_id=pr, channel_description=channel_type,channel_type=channel_type, channel_datatype=channel_datatype, resolution=row['resolution'], exceptions=row['exceptions'], startwindow=0, endwindow=0, default=1, readonly=row['readonly'], propagate=row['propagate'])
                ch.save()
            else:
              continue
              #updated_values = { 'channel_description':channel_type, 'channel_type':channel_type, 'channel_datatype':channel_datatype, 'resolution':row['resolution'], 'exceptions':row['exceptions'], 'startwindow':0, 'endwindow':0, 'default':"1", 'readonly':row['readonly'], 'propagate':row['propagate']}
              #ch, ch_status = Channel.objects.update_or_create(channel_name=channel_type, project_id=pr, defaults=updated_values)
            #tk,tk_status = Token.objects.update_or_create(token_name=row['token'], token_description=row['token'], user=user, project_id=pr, public=row['public'])
            #pr.save()
            #ch.save()
            #tk.save()
          except Exception, e:

            raise
Esempio n. 3
0
def extractChannelDict(ch_dict, channel_only=False):
  """Generate a channel object from the JSON flle"""

  ch = Channel()
  try:
    #ch.pk = ch_dict['channel_name']
    ch.channel_name = ch_dict['channel_name']
    ch.channel_datatype =  ch_dict['datatype']
    ch.channel_type = ch_dict['channel_type']
    if not channel_only:
      data_url = ch_dict['data_url']
      file_format = ch_dict['file_format']
      file_type = ch_dict['file_type']
  except Exception, e:
    print "Missing requried fields"
    raise
Esempio n. 4
0
def extractChannelDict(ch_dict, channel_only=False):
  """Generate a channel object from the JSON flle"""

  ch = Channel()
  try:
    #ch.pk = ch_dict['channel_name']
    ch.channel_name = ch_dict['channel_name']
    ch.channel_datatype =  ch_dict['datatype']
    ch.channel_type = ch_dict['channel_type']
    if not channel_only:
      data_url = ch_dict['data_url']
      file_format = ch_dict['file_format']
      file_type = ch_dict['file_type']
  except Exception, e:
    print "Missing requried fields"
    raise
    def importTable(self):
        """Import the datasets from csv format"""

        cursor = self.conn.cursor()
        with open('{}.csv'.format(self.table_name), 'rb') as csv_file:
            csv_reader = csv.DictReader(csv_file, delimiter=',')
            for row in csv_reader:

                try:
                    if row['openid'] == 'apl':
                        user = User.objects.get(username=row['will'])
                    else:
                        user = User.objects.get(username=row['openid'])
                except Exception, e:
                    user = User.objects.get(username='******')

                if self.table_name == 'datasets':
                    ds = Dataset(dataset_name=row['dataset'],
                                 user=user,
                                 ximagesize=int(row['ximagesize']),
                                 yimagesize=int(row['yimagesize']),
                                 zimagesize=int(row['endslice']),
                                 zoffset=int(row['startslice']),
                                 scalinglevels=int(row['zoomlevels']),
                                 starttime=int(row['starttime']),
                                 endtime=int(row['endtime']),
                                 dataset_description=row['dataset'],
                                 zvoxelres=row['zscale'],
                                 public=1)
                    try:
                        ds.save()
                    except Exception, e:
                        print ds, "Error"
                elif self.table_name == 'projects':
                    try:
                        ds = Dataset.objects.get(dataset_name=row['dataset'])
                        pr = Project.objects.get(project_name=row['project'])
                        #pr,pr_status = Project.objects.update_or_create(project_name=row['project'], project_description=row['project'], dataset=ds, user=user, ocp_version='0.0', host=row['host'], kvengine=row['kvengine'], kvserver=row['kvserver'])
                        [channel_type,
                         channel_datatype] = DATATYPE[int(row['datatype'])]
                        #ch,ch_status = Channel.objects.update_or_create(channel_name=channel_type, channel_description=channel_type, channel_type=channel_type, channel_datatype=channel_datatype, project_id=pr, resolution=row['resolution'], exceptions=row['exceptions'], startwindow=0, endwindow=0, default="1", readonly=row['readonly'], propagate=row['propagate'])
                        if int(row['datatype']) in [3, 4]:
                            # delete the old channel
                            Channel.objects.filter(
                                project_id=pr.project_name).delete()
                            # iterate over channel names and create channels
                            import ast
                            for channel_name in ast.literal_eval(
                                    row['channel']):
                                print channel_name[0]
                                ch = Channel(channel_name=channel_name[0],
                                             project_id=pr,
                                             channel_description=channel_type,
                                             channel_type=channel_type,
                                             channel_datatype=channel_datatype,
                                             resolution=row['resolution'],
                                             exceptions=row['exceptions'],
                                             startwindow=0,
                                             endwindow=0,
                                             default=1,
                                             readonly=row['readonly'],
                                             propagate=row['propagate'])
                                ch.save()
                        else:
                            continue
                            #updated_values = { 'channel_description':channel_type, 'channel_type':channel_type, 'channel_datatype':channel_datatype, 'resolution':row['resolution'], 'exceptions':row['exceptions'], 'startwindow':0, 'endwindow':0, 'default':"1", 'readonly':row['readonly'], 'propagate':row['propagate']}
                            #ch, ch_status = Channel.objects.update_or_create(channel_name=channel_type, project_id=pr, defaults=updated_values)
                        #tk,tk_status = Token.objects.update_or_create(token_name=row['token'], token_description=row['token'], user=user, project_id=pr, public=row['public'])
                        #pr.save()
                        #ch.save()
                        #tk.save()
                    except Exception, e:
                        import pdb
                        pdb.set_trace()
                        raise
Esempio n. 6
0
def createTestDB(project_name,
                 channel_list=['unit_anno'],
                 channel_type=ANNOTATION,
                 channel_datatype=UINT32,
                 public=0,
                 ximagesize=10000,
                 yimagesize=10000,
                 zimagesize=1000,
                 xvoxelres=4.0,
                 yvoxelres=4.0,
                 zvoxelres=3.0,
                 scalingoption=ZSLICES,
                 scalinglevels=5,
                 readonly=READONLY_FALSE,
                 propagate=NOT_PROPAGATED,
                 window=[0, 0],
                 time=[0, 0],
                 default=False,
                 ocp_version=OCP_VERSION):
    """Create a unit test data base on the specified sit and name"""

    unituser = User.objects.get(username='******')

    ds = Dataset(dataset_name="unittest",
                 user=unituser,
                 ximagesize=ximagesize,
                 yimagesize=yimagesize,
                 zimagesize=zimagesize,
                 xoffset=0,
                 yoffset=0,
                 zoffset=1,
                 xvoxelres=xvoxelres,
                 yvoxelres=yvoxelres,
                 zvoxelres=zvoxelres,
                 scalingoption=scalingoption,
                 scalinglevels=scalinglevels,
                 starttime=time[0],
                 endtime=time[1],
                 dataset_description="Unit test")
    ds.save()

    # RBTODO need to add a window and a project

    # make the project entry
    pr = Project(project_name=project_name,
                 project_description='Unit test',
                 user=unituser,
                 dataset=ds,
                 ocp_version=ocp_version,
                 kvengine=kvengine_to_test.kvengine,
                 kvserver=kvengine_to_test.kvserver)
    pr.save()

    # and create the database
    pd = ocpcaproj.OCPCAProjectsDB()

    # create a token
    tk = Token(token_name=project_name,
               user=unituser,
               token_description='Unit test token',
               project_id=pr,
               public=public)
    tk.save()

    pd.newOCPCAProject(pr.project_name)
    try:
        for channel_name in channel_list:
            ch = Channel(channel_name=channel_name,
                         channel_type=channel_type,
                         channel_datatype=channel_datatype,
                         channel_description='Unit test channel',
                         project_id=pr,
                         readonly=readonly,
                         propagate=propagate,
                         resolution=0,
                         exceptions=1,
                         startwindow=window[0],
                         endwindow=window[1],
                         default=default)
            ch.save()
            pd.newOCPCAChannel(pr.project_name, ch.channel_name)
    except Exception, e:
        pass
Esempio n. 7
0
    def importChannels(self):
        """ Import channels from the old project to the new project. """

        # make sure the ocp project exists
        pr = Project.objects.get(project_name=self.newproject_name)

        for channel in self.oldchannels.keys():
            ch = Channel()
            ch.project = pr
            ch.channel_name = channel
            ch.channel_description = 'Imported from oldchannel schema.'
            ch.channel_type = 'image'
            ch.resolution = 0
            ch.propagate = self.propagate
            ch.channel_datatype = self.datatype
            ch.readonly = self.readonly
            ch.exceptions = 0
            ch.startwindow = 0
            ch.endwindow = 0
            ch.default = False

            try:
                ch.save()
                pd = ocpcaproj.OCPCAProjectsDB()
                pd.newOCPCAChannel(pr.project_name, ch.channel_name)
                print "Created channel {}".format(channel)
            except Exception, e:
                print "[ERROR]: {}".format(e)
                exit()
Esempio n. 8
0
  def importChannels(self):
    """ Import channels from the old project to the new project. """
      
    # make sure the ocp project exists 
    pr = Project.objects.get(project_name=self.newproject_name)

    for channel in self.oldchannels.keys():
      ch = Channel()
      ch.project = pr
      ch.channel_name = channel
      ch.channel_description = 'Imported from oldchannel schema.'
      ch.channel_type = 'image'
      ch.resolution = 0 
      ch.propagate = self.propagate
      ch.channel_datatype = self.datatype 
      ch.readonly = self.readonly
      ch.exceptions = 0
      ch.startwindow = 0
      ch.endwindow = 0
      ch.default = False

      try:
        ch.save()
        pd = ocpcaproj.OCPCAProjectsDB()
        pd.newOCPCAChannel( pr.project_name, ch.channel_name )
        print "Created channel {}".format(channel)
      except Exception, e:
        print "[ERROR]: {}".format(e)
        exit()