-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add user map of institutions (WIP) #773
Open
CharlesSheelam
wants to merge
6
commits into
comses:main
Choose a base branch
from
CharlesSheelam:fix-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d5ad10
refactor: says models instead of codebases
CharlesSheelam af3f7ce
fix: add section for model releases
CharlesSheelam 7baaa03
fix: move sub bullets to model releases
CharlesSheelam 427def6
set up backend for institution data
CharlesSheelam aebc7c1
fix: map displays correct data
CharlesSheelam e53a3e9
fix: fix styling and package.json
CharlesSheelam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
django/core/management/commands/delete_ror_affiliations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.core.management.base import BaseCommand | ||
from core.models import MemberProfile | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
class Command(BaseCommand): | ||
help = """Remove coordinates from each affiliation in all member profiles""" | ||
|
||
def handle(self, *args, **options): | ||
all_member_profiles = MemberProfile.objects.all() | ||
|
||
for profile in all_member_profiles: | ||
updated = False | ||
affiliations = profile.affiliations | ||
|
||
|
||
for affiliation in affiliations: | ||
|
||
if "coordinates" in affiliation: | ||
del affiliation["coordinates"] | ||
#del affiliation["links"] | ||
#del affiliation["types"] | ||
updated = True | ||
|
||
if updated: | ||
profile.affiliations = affiliations | ||
profile.save() | ||
|
||
|
||
|
72 changes: 72 additions & 0 deletions
72
django/core/management/commands/update_ror_affiliations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from django.core.management.base import BaseCommand | ||
from core.models import MemberProfile | ||
import requests | ||
import time | ||
import logging | ||
from pathlib import Path | ||
import concurrent.futures | ||
import json | ||
import http.server | ||
import socketserver | ||
import argparse | ||
|
||
|
||
from core.models import MemberProfile | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """something""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.session = requests.Session() | ||
|
||
def lookup_ror_id(self, ror_id): | ||
api_url = f"https://api.ror.org/organizations/{ror_id}" | ||
try: | ||
response = self.session.get(api_url, timeout=10) | ||
response.raise_for_status() | ||
data = response.json() | ||
print(".", end="", flush=True) | ||
return data["name"], data["addresses"][0]["lat"], data["addresses"][0]["lng"], data["links"][0], data["types"][0] | ||
except requests.RequestException as e: | ||
print("E", end="", flush=True) | ||
return None, None, None, None, None | ||
|
||
|
||
|
||
def handle(self, *args, **options): | ||
# TODO: look up every memberprofile.affiliations that has a ror_id and add the lat, lon to each json record | ||
#add sessions to make faster | ||
#get links and types as well | ||
#make metrics.py function to get list of institution data | ||
all_member_profiles = MemberProfile.objects.all() | ||
|
||
for profile in all_member_profiles: | ||
|
||
updated = False | ||
affiliations = profile.affiliations | ||
|
||
|
||
for affiliation in affiliations: | ||
if "ror_id" not in affiliation: | ||
continue | ||
|
||
if "coordinates" not in affiliation: | ||
name, lat, lon, links, types = self.lookup_ror_id(affiliation["ror_id"]) | ||
if lat is not None and lon is not None: | ||
affiliation["name"] = name | ||
affiliation["coordinates"] = {"lat": lat, "lon": lon} | ||
affiliation["link"] = links | ||
affiliation["type"] = types | ||
updated = True | ||
|
||
if updated: | ||
profile.affiliations = affiliations | ||
profile.save() | ||
|
||
self.session.close() | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just for testing, right? I'd leave this untracked since it won't get used in production