Example #1
0
def get_analysis_data_for_queryset_or_sound_ids(view, queryset=None, sound_ids=[]):
    # Get analysis data for all requested sounds and save it to a class variable so the serializer can access it and
    # we only need one request to the similarity service

    analysis_data_required = 'analysis' in view.request.QUERY_PARAMS.get('fields', '').split(',')
    if analysis_data_required:
        # Get ids of the particular sounds we need
        if queryset:
            paginated_queryset = view.paginate_queryset(queryset)
            ids = [int(sound.id) for sound in paginated_queryset.object_list]
        else:
            ids = [int(sid) for sid in sound_ids]

        # Get descriptor values for the required ids
        # Required descriptors are indicated with the parameter 'descriptors'. If 'descriptors' is empty, we return nothing
        descriptors = view.request.QUERY_PARAMS.get('descriptors', [])
        view.sound_analysis_data = {}
        if descriptors:
            try:
                view.sound_analysis_data = get_sounds_descriptors(ids,
                                                                  descriptors.split(','),
                                                                  view.request.QUERY_PARAMS.get('normalized', '0') == '1',
                                                                  only_leaf_descriptors=True)
            except:
                pass
        else:
            for id in ids:
                view.sound_analysis_data[str(id)] = 'No descriptors specified. You should indicate which descriptors you want with the \'descriptors\' request parameter.'
Example #2
0
def get_analysis_data_for_queryset_or_sound_ids(view, queryset=None, sound_ids=[]):
    # Get analysis data for all requested sounds and save it to a class variable so the serializer can access it and
    # we only need one request to the similarity service

    analysis_data_required = 'analysis' in view.request.QUERY_PARAMS.get('fields', '').split(',')
    if analysis_data_required:
        # Get ids of the particular sounds we need
        if queryset:
            paginated_queryset = view.paginate_queryset(queryset)
            ids = [int(sound.id) for sound in paginated_queryset.object_list]
        else:
            ids = [int(sid) for sid in sound_ids]

        # Get descriptor values for the required ids
        # Required descriptors are indicated with the parameter 'descriptors'. If 'descriptors' is empty, we return nothing
        descriptors = view.request.QUERY_PARAMS.get('descriptors', [])
        view.sound_analysis_data = {}
        if descriptors:
            try:
                view.sound_analysis_data = get_sounds_descriptors(ids,
                                                                  descriptors.split(','),
                                                                  view.request.QUERY_PARAMS.get('normalized', '0') == '1',
                                                                  only_leaf_descriptors=True)
            except:
                pass
        else:
            for id in ids:
                view.sound_analysis_data[str(id)] = 'No descriptors specified. You should indicate which descriptors you want with the \'descriptors\' request parameter.'
Example #3
0
def prepare_single_sound_analysis(sound,request,filter):

    try:
        # Load file from disk
        #analysis = yaml.load(file(sound.locations('analysis.statistics.path')))

        # Get data from gaia
        analysis = get_sounds_descriptors([sound.id], [], normalization=False, only_leaf_descriptors=False)[str(sound.id)]
    except Exception, e:
        raise e
        raise Exception('Could not load analysis data.')
Example #4
0
 def get_analysis(self, obj):
     # Get the sound descriptors from gaia
     try:
         descriptors = self.context['request'].GET.get('descriptors', [])
         if descriptors:
             return get_sounds_descriptors([obj.id],
                                           descriptors.split(','),
                                           self.context['request'].GET.get('normalized', '0') == '1',
                                           only_leaf_descriptors=True)[str(obj.id)]
         else:
             return 'No descriptors specified. You should indicate which descriptors you want with the \'descriptors\' request parameter.'
     except Exception, e:
         return None
Example #5
0
 def get_analysis(self, obj):
     # Get the sound descriptors from gaia
     try:
         descriptors = self.context['request'].GET.get('descriptors', [])
         if descriptors:
             return get_sounds_descriptors(
                 [obj.id],
                 descriptors.split(','),
                 self.context['request'].GET.get('normalized', '0') == '1',
                 only_leaf_descriptors=True)[str(obj.id)]
         else:
             return 'No descriptors specified. You should indicate which descriptors you want with the \'descriptors\' request parameter.'
     except Exception, e:
         return None