示例#1
0
def create_collection(request, SI_glitches):

    # Verify the links_subjects column before adding them to collection
    SI_glitches = SI_glitches.loc[SI_glitches.links_subjects != 1e20]
    SI_glitches.links_subjects = SI_glitches.links_subjects.apply(int)
    subject_id_requested = int(SI_glitches['searchedzooID'].iloc[0])

    # merge relevantDBs into one DB
    collection_url = 'https://www.zooniverse.org/projects/zooniverse/gravity-spy/collections/'

    request = check_token(request)

    with panoptes_client.Panoptes() as client:
        client.bearer_token = request.session['access_token']
        client.bearer_expires = (
            datetime.now() + timedelta(seconds=request.session['expires_in']))
        client.logged_in = True

        collection = panoptes_client.Collection()
        collection.links.project = '1104'
        random_hash = id_generator()
        collection.display_name = 'Collection Similar to {0} ID {1}'.format(
            subject_id_requested, random_hash)
        collection.private = False
        urltmp = collection.save()
        collection_url = collection_url + urltmp['collections'][0]['slug']
        collection.add(SI_glitches.links_subjects.tolist())
        collection.set_default_subject(subject_id_requested)

    return collection_url
示例#2
0
    def create_collection(self, name=None, private=True,
                          default_subject=None):
        """Obtain omicron triggers to run gravityspy on

        Parameters:
            name (str, optional):
                name of collection
            private (bool, optional):
                would you like this collection to be private or public
            default_subject (int, optional):
                subject id to be the cover image of collection

        Returns:
            `str` url link to the created collection
        """
        if name is None:
            # will name it after the label of event table
            name = self['Label'][0]

        if default_subject is None:
            default_subject = self['links_subjects'][0]

        collection_url = ('https://www.zooniverse.org/'
                          'projects/zooniverse/gravity-spy/collections/')

        with panoptes_client.Panoptes() as client:
            client.connect()

            collection = panoptes_client.Collection()
            collection.links.project = '1104'
            collection.display_name = '{0}'.format(name)
            collection.private = private
            urltmp = collection.save()
            collection_url = collection_url + urltmp['collections'][0]['slug']
            collection.add(list(self['links_subjects']))
            collection.set_default_subject(default_subject)

        return collection_url
    def __init__(self):
        logger.info('Authenticating with Caesar...')
        config = Config.instance()
        kwargs = {
            'endpoint': config.login_endpoint(),
        }

        if config.auth_mode == 'api_key':
            kwargs.update({
                'client_id': config.client_id,
                'client_secret': config.client_secret,
            })
        elif config.auth_mode == 'interactive':
            kwargs.update({
                'login': '******',
            })
        elif config.auth_mode == 'environment':
            # panoptes client will handle getting environment variables
            # for authentication.
            # keeping this here for clarity
            pass

        self.pan = pan.Panoptes(**kwargs)
示例#4
0
def main():
    client = pan.Panoptes(login='******')

    c = load({})
    d = load({'created_at':'2018-01-29T04:38:00.014Z'})
    code.interact(local={**globals(), **locals()})
def make_subjectset_from_collection(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':

        # create a form instance and populate it with data from the request:
        form = SearchForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            username = str(form.cleaned_data['username'])
            collection_display_name = str(
                form.cleaned_data['collection_display_name'])
            workflow_name = str(form.cleaned_data['workflow_name'])

            client = panoptes_client.Panoptes()
            client.connect(username=os.environ.get('PANOPTES_USERNAME'),
                           password=os.environ.get('PANOPTES_PASSWORD'))

            subjects_in_collection, collection_display_url = retrieve_subjects_from_collection(
                username, collection_display_name)
            subject_set = panoptes_client.SubjectSet()

            subject_set.links.project = '6040'
            subject_set.display_name = '{0}'.format(collection_display_name)

            subject_set.save()
            subject_set.add(subjects_in_collection)

            workflow = panoptes_client.Workflow()
            workflow.display_name = '{0}'.format(workflow_name)
            workflow.links.project = '6040'
            workflow.primary_language = 'en'
            image_location_str = "![Example Alt Text]({0} =400x275)".format(
                collection_display_url)
            workflow.tasks = {
                u'T0': {
                    u'answers': [{
                        u'label': u'Yes'
                    }, {
                        u'label': u'No'
                    }],
                    u'help':
                    u'',
                    u'question':
                    u'Does this image look like \n{0}'.format(
                        image_location_str),
                    u'required':
                    True,
                    u'type':
                    u'single'
                }
            }
            workflow.first_task = "T0"
            workflow.save()
            workflow.mobile_friendly = True
            workflow.retirement = {
                u'criteria': u'classification_count',
                u'options': {
                    u'count': 5
                }
            }
            workflow.save()

            workflow.add_subject_sets(subject_set)

            return redirect(
                "https://www.zooniverse.org/projects/sbc538/vet-new-classes/")
        else:
            return render(request, 'subjectset_from_collection_form.html',
                          {'form': form})