Skip to content

Commit

Permalink
style: automatic reformat
Browse files Browse the repository at this point in the history
auto reformat with ruff/docformatter/prettier after config changes
  • Loading branch information
alycejenni committed Oct 30, 2024
1 parent dc2e8d0 commit b78bfec
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ckanext/statistics/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ckan.plugins import toolkit
from tqdm import tqdm

from .model.gbif_download import gbif_downloads_table, GBIFDownload
from .model.gbif_download import GBIFDownload, gbif_downloads_table


def get_commands():
Expand Down Expand Up @@ -79,7 +79,7 @@ def get_gbif_stats(dataset_uuid, limit=100):
:param dataset_uuid: the dataset uuid to get stats records for
:param limit: the number of records to retrieve at once (default: 100)
:return: yields dicts
:returns: yields dicts
"""
offset = 0
url = f'https://api.gbif.org/v1/occurrence/download/dataset/{dataset_uuid}'
Expand Down
1 change: 1 addition & 0 deletions ckanext/statistics/lib/dataset_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


import logging

from ckan.lib.search import SearchIndexError
from ckan.plugins import toolkit

Expand Down
15 changes: 8 additions & 7 deletions ckanext/statistics/lib/download_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import json
from collections import OrderedDict, defaultdict

import ckan.model as model
from ckan.plugins import toolkit
from importlib_resources import files
from sqlalchemy import sql

import ckan.model as model
from ckan.plugins import toolkit
from ckanext.ckanpackager.model.stat import CKANPackagerStat
from ckanext.versioned_datastore.model.downloads import DownloadRequest

from ..lib.statistics import Statistics
from ..logic.schema import statistics_downloads_schema
from ..model.gbif_download import GBIFDownload
Expand All @@ -28,11 +29,11 @@ class MonthlyStats(object):
"""

def __init__(self, month=None, year=None, resource_id=None):
'''
"""
:param month: if passed, only this month will be counted (defaults to None)
:param year: if passed, only this year will be counted (defaults to None)
:param resource_id: if passed, only this resource will be counted (defaults to None)
'''
"""
self.month = int(month) if month is not None else None
self.year = int(year) if year is not None else None
self.resource_id = resource_id
Expand Down Expand Up @@ -117,8 +118,8 @@ def update_from_backfill(self, month, year, stats):
:param month: the month
:param year: the year
:param stats: the stats in a dict, the format of this dict must match a month/year entry in
the self.stats dict
:param stats: the stats in a dict, the format of this dict must match a
month/year entry in the self.stats dict
"""
if self.month is not None and self.month != int(month):
return
Expand Down Expand Up @@ -158,7 +159,7 @@ def as_dict(self):
"""
Return an OrderedDict of count stats in ascending chronological order.
:return: an OrderedDict
:returns: an OrderedDict
"""
return OrderedDict(
sorted(
Expand Down
4 changes: 2 additions & 2 deletions ckanext/statistics/model/gbif_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Created by the Natural History Museum in London, UK


from ckan.model import meta, DomainObject
from sqlalchemy import Column, DateTime, Integer, func, Table, UnicodeText
from ckan.model import DomainObject, meta
from sqlalchemy import Column, DateTime, Integer, Table, UnicodeText, func

gbif_downloads_table = Table(
'gbif_downloads',
Expand Down
1 change: 1 addition & 0 deletions ckanext/statistics/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ckan.plugins import SingletonPlugin, implements, interfaces

from ckanext.statistics.logic.action import dataset_statistics, download_statistics

from . import cli


Expand Down
1 change: 0 additions & 1 deletion docs/_scripts/gen_api_pages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# !/usr/bin/env python
# encoding: utf-8

"""
Generate the code reference pages and navigation.
Expand Down
15 changes: 7 additions & 8 deletions tests/test_download_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

from collections import OrderedDict
from datetime import datetime
from unittest.mock import MagicMock, call

import pytest

from ckanext.ckanpackager.model.stat import CKANPackagerStat, ckanpackager_stats_table
from ckanext.statistics.lib.download_statistics import DownloadStatistics, MonthlyStats
from ckanext.statistics.model.gbif_download import GBIFDownload, gbif_downloads_table
from ckanext.versioned_datastore.model import stats, slugs, details, downloads
from ckanext.versioned_datastore.model import details, downloads, slugs, stats
from ckanext.versioned_datastore.model.downloads import (
DownloadRequest,
CoreFileRecord,
DerivativeFileRecord,
DownloadRequest,
)
from unittest.mock import MagicMock, call


class TestMonthlyStats(object):
Expand Down Expand Up @@ -409,7 +409,6 @@ def test_add_ckanpackager_stats(self):
assert call(datetime(2011, 12, 1), 'blarp', 0) in calls

def test_add_versioned_datastore_download_stats(self):

core_record_kwargs = {
'query': {},
'query_version': 'v12.4.9',
Expand All @@ -423,7 +422,7 @@ def test_add_versioned_datastore_download_stats(self):
resource_hash='abcd',
modified=datetime(2019, 1, 1),
resource_totals={'resource1': 100, 'resource2': 32},
**core_record_kwargs
**core_record_kwargs,
)
core_record_1.save()

Expand All @@ -433,7 +432,7 @@ def test_add_versioned_datastore_download_stats(self):
resource_hash='efgh',
modified=datetime(2018, 5, 10),
resource_totals={'resource1': 4},
**core_record_kwargs
**core_record_kwargs,
)
core_record_2.save()

Expand All @@ -443,7 +442,7 @@ def test_add_versioned_datastore_download_stats(self):
resource_hash='ijkl',
modified=datetime(2018, 4, 14),
resource_totals={'resource3': 189},
**core_record_kwargs
**core_record_kwargs,
)
core_record_3.save()

Expand Down

0 comments on commit b78bfec

Please sign in to comment.