Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 7e8f2046 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add RecordHepConf and test_07_RecordHepConf

parent abd23540
......@@ -17,6 +17,7 @@ from .exception import CdsException, RecordException
from .inveniostore import InvenioStore
from .inspirehepstore import InspirehepStore, SHELFS
from .recordconf import RecordConf
from .recordhepconf import RecordHepConf
from .recordheppubli import RecordHepPubli
from .recordinst import RecordInst
from .recordpubli import RecordPubli
......@@ -205,16 +206,12 @@ def build_record(recjson, shelf=None):
else:
if is_conference(recjson) and shelf == "literature":
pass
# add_conference_data(recjson)
# upcast_record = RecordHepConf(recjson)
upcast_record = RecordHepConf(recjson)
elif shelf == "institutions":
pass
# elif shelf == "institutions":
# upcast_record = RecordHepInst(recjson)
elif is_thesis(recjson) and shelf == "literature":
pass
# elif is_thesis(recjson) and shelf == "literature":
# upcast_record = RecordHepThesis(recjson)
elif shelf == "literature":
......
""" store_tools.recordhepconf
"""
import requests
from datetime import datetime
from plugin_dbui import CLEAN_SPACES
from .recordheppubli import RecordHepPubli
class RecordHepConf(RecordHepPubli):
"""Conference proceeding from inspirehep.net version 2.
"""
def __init__(self, recjson):
super().__init__(recjson)
self.conference = None
# get the URL of the conference record in inspirehep.net
publication_info = self.get("publication_info", None)
if publication_info is None:
return
urlins = None
for elt in publication_info:
if "cnum" in elt:
urlins = elt.get("conference_record", {}).get("$ref", None)
if urlins is None:
return
# get conference metadata
try:
r = requests.get(urlins, timeout=30)
r.raise_for_status()
obj = r.json()
except(requests.RequestException, ValueError):
return
self.conference = obj.get("metadata", None)
def conference_country(self):
"""The country where the conference took place.
Returns:
str:
* the filter *CLEAN_SPACES* is applied.
* empty when the country is not defined.
"""
conference = self.conference
if conference is None:
return ""
val = (conference
.get("addresses", [{}])[0]
.get("country", ""))
return CLEAN_SPACES(val)
def conference_dates(self):
"""The dates of the conference.
Returns:
str:
* usual pattern are ``6-5 March 2012``
or ``30 March - 5 April 2012``
* empty string when not defined
"""
conference = self.conference
if conference is None:
return ""
opening = conference.get("opening_date", None)
closing = conference.get("closing_date", None)
if opening is None or closing is None:
return ""
ds = datetime.strptime(opening, "%Y-%m-%d")
de = datetime.strptime(closing, "%Y-%m-%d")
val = de.strftime("%d %B %Y")
if ds.month == de.month:
val = f"{ds.day}-{val}"
else:
val = f"{ds.strftime('%d %b')} - {val}"
return val
def conference_id(self):
"""The conference identifier used in the store.
Returns:
int or None
"""
conference = self.conference
if conference is None:
return ""
return conference.get("control_number", None)
def conference_key(self):
"""The conference key used in the store.
Returns:
str:
* empty string when it is not defined
"""
for elt in self["publication_info"]:
if "cnum" in elt:
return elt["cnum"]
return ""
def conference_location(self):
"""The conference location.
Returns:
str:
- the pattern is ``town, country``
- empty string when town or country is missing
- empty string when it is not defined
"""
conference = self.conference
if conference is None:
return ""
addresses = conference.get("addresses", [{}])[0]
city = addresses.get("cities", [None])[0]
country = addresses.get("country", None)
if city is None or country is None:
return ""
return f"{city}, {country}"
def conference_title(self):
"""The title of the conference.
Returns:
str:
* empty string when it is not defined
* first title is selected is there is more than one
"""
conference = self.conference
if conference is None:
return ""
val = (conference
.get("titles", [{}])[0]
.get("title", ""))
return val
def conference_town(self):
"""The town where the conference took place.
Returns:
str:
* empty string when it is not defined.
"""
conference = self.conference
if conference is None:
return ""
val = (conference
.get("addresses", [{}])[0]
.get("cities", [""])[0])
return val
def conference_url(self):
"""The URL of the conference home page.
Returns:
str:
* select the first URL when there is more than one
* empty string when it is not defined
"""
conference = self.conference
if conference is None:
return ""
val = (conference
.get("urls", [{}])[0]
.get("value", ""))
return val
def conference_year(self):
"""The year of the conference.
Returns:
str:
* empty string when it is not defined.
"""
conference = self.conference
if conference is None:
return ""
opening = conference.get("opening_date", None)
return ("" if opening is None else opening[:4])
......@@ -129,8 +129,7 @@ class RecordHepPubli(RecordHep, PluginAuthors, PluginPublicationInfo):
"year",
"pagination"]
self["publication_info"] = \
DataFrame([[""] * len(cols)], columns=cols)
self["df_info"] = DataFrame([[""] * len(cols)], columns=cols)
return
......@@ -150,7 +149,7 @@ class RecordHepPubli(RecordHep, PluginAuthors, PluginPublicationInfo):
df = df.sort_values("year")
# replace
self["publication_info"] = df
self["df_info"] = df
def collaboration(self):
"""The collaboration(s) signing the publication.
......
"""test_07_RecordHepConf
Test specific methods of the RecordConf class for ::
https://inspirehep.net/api/literature/1089237
(same as https://cds.cern.ch/record/1411352)
Prospects for CP violation in B0s --> J/psiphi from first LHCb data
O. Leroy, Symposium on Prospects in the Physics of Discrete Symmetries,
Rome, Italy, 6 - 11 Dec 2010
J. Phys.: Conf. Ser. 335 (2011) 012042
No correction are applied to the record.
Allow to test the brute force decoding with its mistakes.
Note:
* Only the first authors is defined
* The submitted date is 05 Jan 2012
* conference date 6 - 11 Dec 2010
"""
import pytest
from store_tools import load_record
from store_tools.recordhepconf import RecordHepConf
@pytest.fixture(scope="module")
def record():
return load_record("inspirehep.net", 1089237, shelf="literature")
def test_upcast_ins_07001(record):
assert isinstance(record, RecordHepConf)
def test_conference_location_ins_07002(record):
assert record.conference_location() == "Rome, Italy"
def test_conference_country_ins_07004(record):
assert record.conference_country() == "Italy"
def test_conference_dates_ins_07006(record):
assert record.conference_dates() == "6-11 December 2010"
def test_conference_id_ins_07008(record):
assert record.conference_id() == 980401
def test_conference_key_ins_07010(record):
assert record.conference_key() == "C10-12-06"
def test_conference_title_ins_07012(record):
assert record.conference_title() == \
"2nd Symposium on Prospects in the Physics of Discrete Symmetries"
def test_conference_town_ins_07014(record):
assert record.conference_town() == "Rome"
def test_conference_url_ins_07016(record):
assert record.conference_url() == "http://www.roma1.infn.it/discrete10"
def test_conference_year_ins_07018(record):
assert record.conference_year() == "2010"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment