コード例 #1
0
ファイル: api_view_datasets.py プロジェクト: IQSS/miniverse
    def get_stats_result(self, request):
        """Return the StatsResult object for this statistic"""

        dv_id = self.kwargs.get('ds_id', None)
        if dv_id is None:
            return StatsResult.build_error_result("No Dataset id specified", 400)

        # Get the latest version
        dataset_version = get_latest_dataset_version(dv_id)

        if dataset_version is None:
            return StatsResult.build_error_result('No published Dataset with id: %s' % dv_id, 404)

        dataset_as_json = DatasetSerializer(dataset_version).as_json()

        return StatsResult.build_success_result(dataset_as_json)
コード例 #2
0
    def get_stats_result(self, request):
        """Return the StatsResult object for this statistic"""

        #dv_id = request.GET.get('id', None)
        alias = self.kwargs.get('alias', None)
        if alias is None:
            return StatsResult.build_error_result("No Dataverse 'alias' specified", 400)

        try:
            selected_dv = Dataverse.objects.select_related('dvobject').get(\
                alias=alias,\
                dvobject__publicationdate__isnull=False)
        except Dataverse.DoesNotExist:
            return StatsResult.build_error_result('No published Dataverse with alias: %s' % alias, 404)

        dataverse_as_json = DataverseSerializer(selected_dv).as_json()

        return StatsResult.build_success_result(dataverse_as_json)
コード例 #3
0
    def get_stats_result(self, request):
        """Return the StatsResult object for this statistic"""

        dv_id = self.kwargs.get('ds_id', None)
        if dv_id is None:
            return StatsResult.build_error_result("No Dataset id specified",
                                                  400)

        # Get the latest version
        dataset_version = get_latest_dataset_version(dv_id)

        if dataset_version is None:
            return StatsResult.build_error_result(
                'No published Dataset with id: %s' % dv_id, 404)

        dataset_as_json = DatasetSerializer(dataset_version).as_json()

        return StatsResult.build_success_result(dataset_as_json)
コード例 #4
0
ファイル: stats_util_files.py プロジェクト: ekoi/miniverse
    def get_easy_file_downloads_by_month(self, **extra_filters):

        file_counts_by_month = self.get_easy_file_downloads_counts(
            **extra_filters)
        running_total = self.get_easy_file_downloads_running_total(
            **extra_filters)
        noncumulative = self.noncumulative

        formatted_records = []  # move from a queryset to a []

        for d in file_counts_by_month:

            year_month = d['yyyy_mm'][:7]
            year = int(d['yyyy_mm'][:4])
            try:
                month = int(d['yyyy_mm'][5:7])
            except:
                return StatsResult.build_error_result(
                    "in converting %s (month) into an integer (in get_easy_dataset_count_by_month)"
                    % d['yyyy_mm'][5:7])

            fmt_rec = OrderedDict()
            fmt_rec['yyyy_mm'] = year_month
            fmt_rec['count'] = d['count']

            # running total
            running_total += d['count']
            if noncumulative:
                fmt_rec['running_total'] = d['count']
            else:
                fmt_rec['running_total'] = running_total

            # Add year and month numbers
            fmt_rec['year_num'] = year
            fmt_rec['month_num'] = month

            # Add month name
            month_name_found, month_name_short = get_month_name_abbreviation(
                month)
            if month_name_found:
                assume_month_name_found, fmt_rec[
                    'month_name'] = get_month_name(month)
                fmt_rec['month_name_short'] = month_name_short
            else:
                logging.warning(
                    "no month name found for month %d (get_easy_file_downloads_by_month)"
                    % month)

            formatted_records.append(fmt_rec)

        data_dict = OrderedDict()
        data_dict['total_downloads'] = running_total
        data_dict['record_count'] = len(formatted_records)
        data_dict['records'] = formatted_records

        return StatsResult.build_success_result(data_dict, None)
コード例 #5
0
ファイル: stats_util_files.py プロジェクト: ekoi/miniverse
    def get_easy_counts_by_month(self, ds_counts_by_month, running_total,
                                 noncumulative):

        formatted_records = []

        for d in ds_counts_by_month:
            year_month = d['yyyy_mm'][:7]
            year = int(d['yyyy_mm'][:4])
            try:
                month = int(d['yyyy_mm'][5:7])
            except:
                return StatsResult.build_error_result(
                    "in converting %s (month) into an integer (in get_easy_dataset_count_by_month)"
                    % d['yyyy_mm'][5:7])

            fmt_dict = OrderedDict()
            fmt_dict['yyyy_mm'] = year_month
            fmt_dict['count'] = d['count']

            # running total
            running_total += d['count']
            if noncumulative:
                fmt_dict['running_total'] = d['count']
            else:
                fmt_dict['running_total'] = running_total

            # Add year and month numbers
            fmt_dict['year_num'] = year
            fmt_dict['month_num'] = month

            # Add month name
            month_name_found, month_name_short = get_month_name_abbreviation(
                month)

            if month_name_found:
                assume_month_name_found, fmt_dict[
                    'month_name'] = get_month_name(month)
                fmt_dict['month_name_short'] = month_name_short
            else:
                logging.warning(
                    "no month name found for month %d (get_easy_dataset_count_by_month)"
                    % month)

            # Add formatted record
            formatted_records.append(fmt_dict)

        data_dict = OrderedDict()
        data_dict['record_count'] = len(formatted_records)
        data_dict['records'] = formatted_records

        return StatsResult.build_success_result(data_dict, None)
コード例 #6
0
ファイル: api_view_datasets.py プロジェクト: IQSS/miniverse
    def get_stats_result(self, request):
        """Return the StatsResult object for this statistic"""
        persistent_id = request.GET.get('persistentId', None)
        if persistent_id is None:
            return StatsResult.build_error_result("No Dataset persistent id specified", 400)

        ds = Dataset.get_dataset_by_persistent_id(persistent_id)

        err_404 = 'No published dataset found for persistentId: %s' % persistent_id

        if ds is None or not ds.dvobject.publicationdate:
            return StatsResult.build_error_result(err_404, 404)


        # Get the latest version
        dataset_version = get_latest_dataset_version(ds.dvobject.id)

        if dataset_version is None:
            return StatsResult.build_error_result(err_404, 404)

        dataset_as_json = DatasetSerializer(dataset_version).as_json()

        return StatsResult.build_success_result(dataset_as_json)
コード例 #7
0
    def get_stats_result(self, request):
        """Return the StatsResult object for this statistic"""
        persistent_id = request.GET.get('persistentId', None)
        if persistent_id is None:
            return StatsResult.build_error_result(
                "No Dataset persistent id specified", 400)

        ds = Dataset.get_dataset_by_persistent_id(persistent_id)

        err_404 = 'No published dataset found for persistentId: %s' % persistent_id

        if ds is None or not ds.dvobject.publicationdate:
            return StatsResult.build_error_result(err_404, 404)

        # Get the latest version
        dataset_version = get_latest_dataset_version(ds.dvobject.id)

        if dataset_version is None:
            return StatsResult.build_error_result(err_404, 404)

        dataset_as_json = DatasetSerializer(dataset_version).as_json()

        return StatsResult.build_success_result(dataset_as_json)
コード例 #8
0
    def get_error_msg_return(self):
        if not self.was_error_found():
            raise AttributeError("Only call this if was_error_found() is true")

        return StatsResult.build_error_result(self.error_message,\
            self.bad_http_status_code)