Skip to content

Commit

Permalink
[Author] Adding open access percentage field to endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yattias committed May 28, 2024
1 parent 953f344 commit 8faf872
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/researchhub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ def before_send(event, hint):
WEB3_PROVIDER_URL = os.environ.get("WEB3_PROVIDER_URL", keys.WEB3_PROVIDER_URL)
http_provider = Web3.HTTPProvider(WEB3_PROVIDER_URL)
# If test then use mock provider
# if TESTING:
# http_provider = Web3.EthereumTesterProvider()
if TESTING:
http_provider = Web3.EthereumTesterProvider()

try:
w3 = Web3(http_provider)
Expand Down
8 changes: 8 additions & 0 deletions src/user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ class DynamicAuthorProfileSerializer(DynamicModelFieldSerializer):
works_count = SerializerMethodField()
citation_count = SerializerMethodField()
summary_stats = SerializerMethodField()
open_access_pct = SerializerMethodField()

class Meta:
model = Author
Expand Down Expand Up @@ -1084,6 +1085,13 @@ def get_activity_by_year(self, author):
)
return serializer.data

def get_open_access_pct(self, author):
total_paper_count = author.authored_papers.count()
return (
author.authored_papers.filter(is_open_access=True).count()
/ total_paper_count
)

def get_institutions(self, author):
context = self.context
_context_fields = context.get("author_profile::get_institutions", {})
Expand Down
1 change: 1 addition & 0 deletions src/user/views/author_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def profile(self, request, pk=None):
"coauthors",
"summary_stats",
"activity_by_year",
"open_access_pct",
),
)
return Response(serializer.data, status=200)
Expand Down

0 comments on commit 8faf872

Please sign in to comment.