From ad6284a2040837e7373b4d89644a01306f181dd5 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 14:45:07 +0100 Subject: fetch papers by single dataset --- scraper/client/actions.js | 7 +++- scraper/client/paper/paper.citations.js | 42 +++++++++++--------- scraper/client/paper/paper.verify.js | 68 +++++++++++++++++++++++++-------- 3 files changed, 81 insertions(+), 36 deletions(-) (limited to 'scraper/client') diff --git a/scraper/client/actions.js b/scraper/client/actions.js index 734a8cbd..1b5152ea 100644 --- a/scraper/client/actions.js +++ b/scraper/client/actions.js @@ -1,9 +1,10 @@ import { get, post } from './util' import * as types from './types' -export const api = (dispatch, method, tag, url, params) => { +export const api = (dispatch, method, tag, url, params, after) => { dispatch({ type: types.api.loading, tag }) return method(url, params).then(data => { + if (after) data = after(data) dispatch({ type: types.api.loaded, tag, data }) return data }).catch(err => { @@ -36,6 +37,10 @@ export const getVerifications = () => dispatch => ( api(dispatch, get, 'verifications', '/api/verifications', {}) ) +export const getVerificationsDataset = dataset => dispatch => ( + api(dispatch, get, 'verifications', '/api/verifications/' + dataset, {}) +) + export const getVerification = sha256 => dispatch => ( api(dispatch, get, 'verify', '/api/verify/' + sha256, {}) ) diff --git a/scraper/client/paper/paper.citations.js b/scraper/client/paper/paper.citations.js index 5c8e0e0c..c55599e0 100644 --- a/scraper/client/paper/paper.citations.js +++ b/scraper/client/paper/paper.citations.js @@ -5,26 +5,32 @@ import { Link } from 'react-router-dom' import * as actions from '../actions' -import { TableObject } from '../common' +import { TableObject, Loader } from '../common' import { USES_DATASET } from '../types' class PaperCitations extends Component { - componentDidMount() { - this.props.actions.getVerifications() + componentDidUpdate(prevProps) { + if (this.props.api.paperInfo.dataset !== prevProps.api.paperInfo.dataset) { + this.props.actions.getVerificationsDataset(this.props.api.paperInfo.dataset.key) + } } render() { - const { dataset, citations } = this.props.api.paperInfo - let { verifications } = this.props.api.verifications - verifications = verifications || {} - if (!dataset || !citations) return null - console.log('rendering citations...') - // console.log(citations) + const { paperInfo, unknownCitations, verifications } = this.props.api + const { dataset, citations } = paperInfo + if (!dataset || !citations || !verifications[dataset.key]) return + let verifiedLookup = verifications[dataset.key] || {} + // console.log(verifications) + return (

{dataset.name_full}: Citations

    - {citations.map((citation, i) => { + {citations.concat(unknownCitations.citations) + .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.UNKNOWN, citation]) + .sort((a,b) => (b[1] - a[1] || (a[0].localeCompare(b[0])))) + .map((pair, i) => { + const [ title, uses_dataset, citation ] = pair let cite = { ...citation } cite.id = { _raw: true, @@ -32,7 +38,9 @@ class PaperCitations extends Component { } cite.pdf = { _raw: true, - value: (cite.pdf && cite.pdf.length) ? [pdf] : "no pdf" + value: (cite.pdf && cite.pdf.length) + ? cite.pdf.map((pdf, i) => [pdf]) + : "no pdf" } cite.s2 = { _raw: true, @@ -45,23 +53,19 @@ class PaperCitations extends Component { } cite.addresses = { _raw: true, - value: cite.addresses.map((address, j) => ( + value: (cite.addresses || []).map((address, j) => (
    {address.name}{', '}{address.type}
    )) } - if (citation.id in verifications && verifications[citation.id].dataset === dataset.key) { - const verification = verifications[citation.id] + if (citation.id in verifiedLookup) { + const verification = verifiedLookup[citation.id] cite.verified = { _raw: true, value: verification.uses_dataset === USES_DATASET.YES ? uses dataset : verification.uses_dataset === USES_DATASET.NO ? {"doesn't use dataset"} - : verification.uses_dataset === 'TRUE' - ? uses dataset - : verification.uses_dataset === 'FALSE' - ? {"doesn't use dataset"} - : {"not enough information"} + : {"not enough information"} } } else { diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 65342adf..1b55186a 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -9,13 +9,16 @@ import { USES_DATASET } from '../types' const initialState = { citation: null, + address: {}, uses_dataset: USES_DATASET.UNKNOWN, images_in_paper: "FALSE", used_as_model: "FALSE", verified_by: localStorage.getItem('verify.username') || '', reference: '', notes: '', + location: '', pdf_index: 0, + isUnknown: false, } class PaperVerify extends Component { @@ -26,6 +29,7 @@ class PaperVerify extends Component { componentDidMount() { const { sha256 } = this.props.match.params this.props.actions.getInstitutions() + this.props.actions.getAddress(sha256) this.props.actions.getVerification(sha256) const citationState = this.getCitationState(sha256) console.log('DID MOUNT') @@ -34,52 +38,66 @@ class PaperVerify extends Component { componentDidUpdate(oldProps) { const { sha256 } = this.props.match.params - const { verify } = this.props.api + const { address, verify } = this.props.api const { sha256: oldSha256 } = oldProps.match.params - const { verify: oldVerify } = oldProps.api + const { verify: oldVerify, address: oldAddress } = oldProps.api const oldPaper = oldVerify ? oldVerify.paper : null const paper = verify ? verify.paper : null + let newState = {} if (oldSha256 && sha256 !== oldSha256) { console.log('update verification') + this.props.actions.getAddress(sha256) this.props.actions.getVerification(sha256) const citationState = this.getCitationState(sha256) - this.setState({ + newState = { ...initialState, ...citationState, - }) + ...address.paper, + } + this.setState(newState) } else if (verify && !verify.loading && verify.paper && (!oldPaper || oldPaper !== verify.paper)) { if (paper.error) { console.log('USING PAPER VERIFICATION') const citationState = this.getCitationState(sha256) - this.setState({ + newState = { ...initialState, ...citationState, - }) + ...address.paper, + } + this.setState(newState) } else { // console.log(paper) console.log('GOT CUSTOM CITATION STATE', paper) const citationState = this.getCitationState(sha256) - this.setState({ + newState = { ...citationState, + ...address.paper, uses_dataset: paper.uses_dataset === "TRUE", images_in_paper: paper.images_in_paper === "TRUE", verified_by: paper.verified_by, reference: paper.reference, notes: paper.notes, - }) + } + this.setState(newState) } } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { const citationState = this.getCitationState(sha256) - this.setState(citationState) + newState = citationState + this.setState(newState) } } getCitationState(sha256) { const { paperInfo, unknownCitations } = this.props.api let citation = (unknownCitations.citations || []).find(f => f.id === sha256) - if (!citation) { + if (citation) { + citation.isUnknown = true + } else { citation = (paperInfo.citations || []).find(f => f.id === sha256) + if (citation) { + citation.isUnknown = false + } } // console.log(sha256, citation) let state = { citation } @@ -148,7 +166,7 @@ class PaperVerify extends Component { } render() { - let { paperInfo } = this.props.api + const { paperInfo, unknownCitations } = this.props.api if (paperInfo.loading) return // console.log(this.state) const { citation } = this.state @@ -185,6 +203,8 @@ class PaperVerify extends Component {
+ {this.renderLocationForm()} +
{'Uses dataset'} @@ -194,7 +214,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={this.state.uses_dataset === USES_DATASET.YES || this.state.uses_dataset === "FALSE"} + checked={parseInt(this.state.uses_dataset) === USES_DATASET.YES || this.state.uses_dataset === "FALSE"} onChange={e => this.setState({ uses_dataset: USES_DATASET.YES, })} @@ -207,7 +227,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={this.state.uses_dataset === USES_DATASET.NO || this.state.uses_dataset === "FALSE"} + checked={parseInt(this.state.uses_dataset) === USES_DATASET.NO || this.state.uses_dataset === "FALSE"} onChange={e => this.setState({ uses_dataset: USES_DATASET.NO, })} @@ -220,7 +240,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={this.state.uses_dataset === USES_DATASET.UNKNOWN || this.state.uses_dataset === "FALSE"} + checked={parseInt(this.state.uses_dataset) === USES_DATASET.UNKNOWN || this.state.uses_dataset === "FALSE"} onChange={e => this.setState({ uses_dataset: USES_DATASET.UNKNOWN, })} @@ -230,8 +250,8 @@ class PaperVerify extends Component {
{'Paper shows images'} @@ -355,6 +375,22 @@ class PaperVerify extends Component {
) } + renderLocationForm() { + if (!this.state.citation.isUnknown) return + return ( +
+
+ + this.setState({ institution_1: e.target.value })} + /> +
+
+ ) + } } /* -- cgit v1.2.3-70-g09d2 From 3bad596c05c8305d327955225d3d10aacce78da1 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 15:27:56 +0100 Subject: add paper addresses to unverified papers --- scraper/client/common/autocomplete.component.js | 7 +++ scraper/client/paper/paper.verify.js | 74 ++++++++++++++++++++----- scraper/s2-geocode-server.py | 17 +----- scraper/util.py | 15 +++++ 4 files changed, 85 insertions(+), 28 deletions(-) (limited to 'scraper/client') diff --git a/scraper/client/common/autocomplete.component.js b/scraper/client/common/autocomplete.component.js index e2908cd1..a619e2c8 100644 --- a/scraper/client/common/autocomplete.component.js +++ b/scraper/client/common/autocomplete.component.js @@ -49,6 +49,10 @@ class Autocomplete extends Component { componentDidMount() { // build index based on what's in the hierarchy + if (!this.props.institutions.loading) this.buildIndex() + } + + buildIndex() { const { entities, lookup } = this.props.institutions let index = [] this.index = index @@ -69,6 +73,9 @@ class Autocomplete extends Component { } componentDidUpdate(oldProps) { + if (oldProps.institutions.loading && !this.props.institutions.loading) { + this.buildIndex() + } if (this.props.vetting !== oldProps.vetting) { this.handleChange({ target: { value: this.props.vetting } }) } else if (this.props.value !== oldProps.value) { diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 1b55186a..fe752c37 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -4,7 +4,7 @@ import { connect } from 'react-redux' import * as actions from '../actions' import { history } from '../store' -import { Loader } from '../common' +import { Loader, Autocomplete } from '../common' import { USES_DATASET } from '../types' const initialState = { @@ -19,6 +19,12 @@ const initialState = { location: '', pdf_index: 0, isUnknown: false, + institution_1: '', + institution_2: '', + institution_3: '', + validate_1: false, + validate_2: false, + validate_3: false, } class PaperVerify extends Component { @@ -73,8 +79,8 @@ class PaperVerify extends Component { newState = { ...citationState, ...address.paper, - uses_dataset: paper.uses_dataset === "TRUE", - images_in_paper: paper.images_in_paper === "TRUE", + uses_dataset: paper.uses_dataset, + images_in_paper: paper.images_in_paper, verified_by: paper.verified_by, reference: paper.reference, notes: paper.notes, @@ -82,6 +88,7 @@ class PaperVerify extends Component { this.setState(newState) } } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { + console.log('loaded unknown citations') const citationState = this.getCitationState(sha256) newState = citationState this.setState(newState) @@ -125,6 +132,13 @@ class PaperVerify extends Component { reference: this.state.reference, notes: this.state.notes, date: dateString, + isUnknown: this.state.citation.isUnknown, + institution_1: this.state.institution_1, + validate_1: this.state.validate_1, + institution_2: this.state.institution_2, + validate_2: this.state.validate_2, + institution_3: this.state.institution_3, + validate_3: this.state.validate_3, }) this.next(false) } @@ -214,7 +228,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={parseInt(this.state.uses_dataset) === USES_DATASET.YES || this.state.uses_dataset === "FALSE"} + checked={String(this.state.uses_dataset) === USES_DATASET.YES} onChange={e => this.setState({ uses_dataset: USES_DATASET.YES, })} @@ -227,7 +241,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={parseInt(this.state.uses_dataset) === USES_DATASET.NO || this.state.uses_dataset === "FALSE"} + checked={String(this.state.uses_dataset) === USES_DATASET.NO} onChange={e => this.setState({ uses_dataset: USES_DATASET.NO, })} @@ -240,7 +254,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={parseInt(this.state.uses_dataset) === USES_DATASET.UNKNOWN || this.state.uses_dataset === "FALSE"} + checked={String(this.state.uses_dataset) !== USES_DATASET.YES && String(this.state.uses_dataset) !== USES_DATASET.NO} onChange={e => this.setState({ uses_dataset: USES_DATASET.UNKNOWN, })} @@ -250,8 +264,8 @@ class PaperVerify extends Component {
{'Paper shows images'} @@ -380,12 +394,44 @@ class PaperVerify extends Component { return (
- - this.setState({ institution_1: e.target.value })} + + { + this.setState({ institution_1: value, validate_1: true }) + }} + onCancel={value => { + this.setState({ institution_1: '', validate_2: false }) + }} + /> +
+ +
+ + { + this.setState({ institution_2: value, validate_2: true }) + }} + onCancel={value => { + this.setState({ institution_2: '', validate_2: false }) + }} + /> +
+ +
+ + { + this.setState({ institution_3: value, validate_3: true }) + }} + onCancel={value => { + this.setState({ institution_3: '', validate_3: false }) + }} />
diff --git a/scraper/s2-geocode-server.py b/scraper/s2-geocode-server.py index f5dc04c9..3aeda881 100644 --- a/scraper/s2-geocode-server.py +++ b/scraper/s2-geocode-server.py @@ -131,22 +131,11 @@ def find_verification(sha256): @app.route('/api/verify/add', methods=['POST']) def add_verification(): - worksheet = fetch_worksheet('verifications') form = request.get_json() print(form) - keys = worksheet.row_values(1) - row = [ form[key] if key in form else '' for key in keys ] - try: - cell = worksheet.find(form['paper_id']) - except: - cell = None - - if cell: - for item, i in enumerate(row): - worksheet.update_cell(cell.row, i+1, item) - else: - worksheet.append_row(row) - + update_or_append_worksheet('verifications', form) + if form['isUnknown']: + update_or_append_worksheet('paper_locations', form) return jsonify({ 'status': 'ok' }) diff --git a/scraper/util.py b/scraper/util.py index 1ee2ad52..96ced430 100644 --- a/scraper/util.py +++ b/scraper/util.py @@ -452,6 +452,21 @@ def fetch_google_lookup(name, item_key='key'): lookup[rec[item_key]] = rec return lookup +def update_or_append_worksheet(name, form): + worksheet = fetch_worksheet(name) + keys = worksheet.row_values(1) + row = [ form[key] if key in form else '' for key in keys ] + try: + cell = worksheet.find(form['paper_id']) + except: + cell = None + + if cell: + for i, item in enumerate(row): + worksheet.update_cell(cell.row, i+1, item) + else: + worksheet.append_row(row) + def load_countries(): countries = read_json('countries.json') lookup = {} -- cgit v1.2.3-70-g09d2 From 6b4ec476c22dda8b2e96044883b749fceed293b2 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 15:29:47 +0100 Subject: add paper addresses to unverified papers --- scraper/client/paper/paper.unknown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scraper/client') diff --git a/scraper/client/paper/paper.unknown.js b/scraper/client/paper/paper.unknown.js index 0cb7d2da..7f1e053a 100644 --- a/scraper/client/paper/paper.unknown.js +++ b/scraper/client/paper/paper.unknown.js @@ -21,7 +21,7 @@ class PaperUnknown extends Component { let cite = { ...citation } cite.id = { _raw: true, - value: {citation.id} + value: {citation.id} } cite.pdf = { _raw: true, -- cgit v1.2.3-70-g09d2 From eb79e2827ad0ca03f410b7beef77bcaffb28daea Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 15:57:26 +0100 Subject: fixie wixie --- scraper/client/paper/paper.verify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scraper/client') diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index fe752c37..1b7e5364 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -402,7 +402,7 @@ class PaperVerify extends Component { this.setState({ institution_1: value, validate_1: true }) }} onCancel={value => { - this.setState({ institution_1: '', validate_2: false }) + this.setState({ institution_1: '', validate_1: false }) }} />
-- cgit v1.2.3-70-g09d2 From b94cad3271d8269b5965d0096ce5564abed9ad53 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 16:04:43 +0100 Subject: better autocomplete --- scraper/client/common/autocomplete.component.js | 20 ++++++++++++-------- scraper/client/paper/paper.verify.js | 12 ++++++------ 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'scraper/client') diff --git a/scraper/client/common/autocomplete.component.js b/scraper/client/common/autocomplete.component.js index a619e2c8..e6c638eb 100644 --- a/scraper/client/common/autocomplete.component.js +++ b/scraper/client/common/autocomplete.component.js @@ -84,7 +84,8 @@ class Autocomplete extends Component { } handleKeyDown(e) { - let id + let name + console.log(e.keyCode) switch (e.keyCode) { case 27: // escape e.preventDefault() @@ -104,10 +105,13 @@ class Autocomplete extends Component { selected: (this.state.selected + 1) % this.state.matches.length }) return false - case 13: // enter - id = this.state.matches[this.state.selected] + case 13: // enter - select from the list + name = this.state.matches[this.state.selected] e.preventDefault() - this.handleSelect(id) + this.handleSelect(name, true) + return false + case 9: // tab - keep the unverified text + this.handleSelect(this.state.q, false) return false default: break @@ -161,9 +165,9 @@ class Autocomplete extends Component { }) } - handleSelect(name) { - console.log('select', name) - if (this.props.onSelect) this.props.onSelect(name) + handleSelect(name, valid) { + console.log('select', name, valid) + if (this.props.onSelect) this.props.onSelect(name, valid) this.setState({ q: name, selected: 0, matches: [] }) } @@ -180,7 +184,7 @@ class Autocomplete extends Component {
this.handleSelect(match)} + onClick={() => this.handleSelect(match, true)} onMouseEnter={() => this.setState({ selected: i })} > {label} diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 1b7e5364..61faa24a 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -398,8 +398,8 @@ class PaperVerify extends Component { { - this.setState({ institution_1: value, validate_1: true }) + onSelect={(institution_1, validate_1) => { + this.setState({ institution_1, validate_1 }) }} onCancel={value => { this.setState({ institution_1: '', validate_1: false }) @@ -412,8 +412,8 @@ class PaperVerify extends Component { { - this.setState({ institution_2: value, validate_2: true }) + onSelect={(institution_2, validate_2) => { + this.setState({ institution_2, validate_2 }) }} onCancel={value => { this.setState({ institution_2: '', validate_2: false }) @@ -426,8 +426,8 @@ class PaperVerify extends Component { { - this.setState({ institution_3: value, validate_3: true }) + onSelect={(institution_3, validate_3) => { + this.setState({ institution_3, validate_3 }) }} onCancel={value => { this.setState({ institution_3: '', validate_3: false }) -- cgit v1.2.3-70-g09d2 From a8cfefc602a43753353940816633daae3e1692aa Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 16:25:23 +0100 Subject: abstract into citationList component --- scraper/client/common/autocomplete.component.js | 24 ++++--- scraper/client/paper/citationList.component.js | 96 +++++++++++++++++++++++++ scraper/client/paper/paper.citations.js | 74 ++----------------- scraper/client/paper/paper.css | 9 +++ scraper/client/paper/paper.unknown.js | 48 +++++-------- 5 files changed, 143 insertions(+), 108 deletions(-) create mode 100644 scraper/client/paper/citationList.component.js (limited to 'scraper/client') diff --git a/scraper/client/common/autocomplete.component.js b/scraper/client/common/autocomplete.component.js index e6c638eb..67dc78c9 100644 --- a/scraper/client/common/autocomplete.component.js +++ b/scraper/client/common/autocomplete.component.js @@ -91,14 +91,12 @@ class Autocomplete extends Component { e.preventDefault() this.handleCancel() break - case 37: // left case 38: // up e.preventDefault() this.setState({ selected: (this.state.matches.length + this.state.selected - 1) % this.state.matches.length }) return false - case 39: // right case 40: // down e.preventDefault() this.setState({ @@ -111,7 +109,12 @@ class Autocomplete extends Component { this.handleSelect(name, true) return false case 9: // tab - keep the unverified text - this.handleSelect(this.state.q, false) + name = this.state.matches[this.state.selected] + if (name === this.state.q) { + this.handleSelect(this.state.q, true) + } else { + this.handleSelect(this.state.q, false) + } return false default: break @@ -132,7 +135,6 @@ class Autocomplete extends Component { return } let seen = {} - let matches = [] value.split(' ').forEach(word => { const re = new RegExp(word) this.index.forEach(([synonym, term]) => { @@ -150,14 +152,14 @@ class Autocomplete extends Component { } } }) - matches = Object.keys(seen) - .map(term => [seen[term], term]) - .sort((a, b) => { - return b[0] - a[0] - }) - .slice(0, 100) - .map(pair => pair[1]) }) + let matches = Object.keys(seen) + .map(term => [seen[term], term]) + .sort((a, b) => { + return b[0] - a[0] + }) + .slice(0, 100) + .map(pair => pair[1]) this.setState({ q, selected: 0, diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js new file mode 100644 index 00000000..435dfde2 --- /dev/null +++ b/scraper/client/paper/citationList.component.js @@ -0,0 +1,96 @@ +import React, { Component } from 'react' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' +import { Link } from 'react-router-dom' + +import * as actions from '../actions' + +import { TableObject, Loader } from '../common' +import { USES_DATASET } from '../types' + +class CitationList extends Component { + render() { + const { citations, title, api } = this.props + const { paperInfo, unknownCitations, verifications } = api + const { dataset } = paperInfo + if (!dataset || !citations || !verifications[dataset.key]) return + let verifiedLookup = verifications[dataset.key] || {} + // console.log(verifications) + + return ( +
+

{title}

+
    + {citations + .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.UNKNOWN, citation]) + .sort((a,b) => (b[1] - a[1] || (a[0].localeCompare(b[0])))) + .map((pair, i) => { + const [ title, uses_dataset, citation ] = pair + let cite = { ...citation } + cite.id = { + _raw: true, + value: {citation.id} + } + cite.pdf = { + _raw: true, + value: (cite.pdf && cite.pdf.length) + ? cite.pdf.map((pdf, i) => [pdf]) + : "no pdf" + } + cite.s2 = { + _raw: true, + value: {'[semantic scholar]'} + } + cite.addresses = { + _raw: true, + value: (cite.addresses || []).map((address, j) => ( +
    {address.name}{', '}{address.type}
    + )) + } + if (citation.id in verifiedLookup) { + const verification = verifiedLookup[citation.id] + cite.verified = { + _raw: true, + value: verification.uses_dataset === USES_DATASET.YES + ? uses dataset + : verification.uses_dataset === USES_DATASET.NO + ? {"doesn't use dataset"} + : {"not enough information"} + } + } + else { + cite.verified = { + _raw: true, + value: unknown + } + } + return ( +
  • + +
  • + ) + })} +
+
+ ) + } +} + +const mapStateToProps = state => ({ + api: state.api +}) +const mapDispatchToProps = dispatch => ({ + actions: bindActionCreators({ ...actions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(CitationList) diff --git a/scraper/client/paper/paper.citations.js b/scraper/client/paper/paper.citations.js index c55599e0..f0e9ea26 100644 --- a/scraper/client/paper/paper.citations.js +++ b/scraper/client/paper/paper.citations.js @@ -5,9 +5,11 @@ import { Link } from 'react-router-dom' import * as actions from '../actions' -import { TableObject, Loader } from '../common' +import { Loader } from '../common' import { USES_DATASET } from '../types' +import CitationList from './citationList.component' + class PaperCitations extends Component { componentDidUpdate(prevProps) { if (this.props.api.paperInfo.dataset !== prevProps.api.paperInfo.dataset) { @@ -19,74 +21,12 @@ class PaperCitations extends Component { const { paperInfo, unknownCitations, verifications } = this.props.api const { dataset, citations } = paperInfo if (!dataset || !citations || !verifications[dataset.key]) return - let verifiedLookup = verifications[dataset.key] || {} - // console.log(verifications) return ( -
-

{dataset.name_full}: Citations

-
    - {citations.concat(unknownCitations.citations) - .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.UNKNOWN, citation]) - .sort((a,b) => (b[1] - a[1] || (a[0].localeCompare(b[0])))) - .map((pair, i) => { - const [ title, uses_dataset, citation ] = pair - let cite = { ...citation } - cite.id = { - _raw: true, - value: {citation.id} - } - cite.pdf = { - _raw: true, - value: (cite.pdf && cite.pdf.length) - ? cite.pdf.map((pdf, i) => [pdf]) - : "no pdf" - } - cite.s2 = { - _raw: true, - value: {'[semantic scholar]'} - } - cite.addresses = { - _raw: true, - value: (cite.addresses || []).map((address, j) => ( -
    {address.name}{', '}{address.type}
    - )) - } - if (citation.id in verifiedLookup) { - const verification = verifiedLookup[citation.id] - cite.verified = { - _raw: true, - value: verification.uses_dataset === USES_DATASET.YES - ? uses dataset - : verification.uses_dataset === USES_DATASET.NO - ? {"doesn't use dataset"} - : {"not enough information"} - } - } - else { - cite.verified = { - _raw: true, - value: unknown - } - } - return ( -
  • - -
  • - ) - })} -
-
+ ) } } diff --git a/scraper/client/paper/paper.css b/scraper/client/paper/paper.css index 025d6b8a..302eceb0 100644 --- a/scraper/client/paper/paper.css +++ b/scraper/client/paper/paper.css @@ -61,6 +61,15 @@ padding:4px; font-size:12px; } +.not_enough_info { + font-weight: bold; + color: white; + font-weight: bold; + display: inline-block; + background: #e0c200; + padding:4px; + font-size:12px; +} .unknown { font-weight: bold; color: white; diff --git a/scraper/client/paper/paper.unknown.js b/scraper/client/paper/paper.unknown.js index 7f1e053a..876ac144 100644 --- a/scraper/client/paper/paper.unknown.js +++ b/scraper/client/paper/paper.unknown.js @@ -5,40 +5,28 @@ import { Link } from 'react-router-dom' import * as actions from '../actions' -import { TableObject } from '../common' +import { Loader } from '../common' +import { USES_DATASET } from '../types' + +import CitationList from './citationList.component' class PaperUnknown extends Component { + componentDidUpdate(prevProps) { + if (this.props.api.paperInfo.dataset !== prevProps.api.paperInfo.dataset) { + this.props.actions.getVerificationsDataset(this.props.api.paperInfo.dataset.key) + } + } + render() { - const { dataset } = this.props.api.paperInfo - const { citations } = this.props.api.unknownCitations - if (!dataset || !citations) return null - console.log('rendering unknown citations...') + const { paperInfo, unknownCitations, verifications } = this.props.api + const { dataset, citations } = paperInfo + if (!dataset || !citations || !verifications[dataset.key]) return + return ( -
-

{dataset.name_full}: Unknown Citations

-
    - {citations.map((citation, i) => { - let cite = { ...citation } - cite.id = { - _raw: true, - value: {citation.id} - } - cite.pdf = { - _raw: true, - value: cite.pdf ? [pdf] : "no pdf" - } - return ( -
  • - -
  • - ) - })} -
-
+ ) } } -- cgit v1.2.3-70-g09d2 From b6a9e2c382ac5e1f6c67040c74077ac03674c549 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 16:28:27 +0100 Subject: better sorting / style --- scraper/client/paper/citationList.component.js | 2 +- scraper/client/types.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'scraper/client') diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js index 435dfde2..09060375 100644 --- a/scraper/client/paper/citationList.component.js +++ b/scraper/client/paper/citationList.component.js @@ -22,7 +22,7 @@ class CitationList extends Component {

{title}

    {citations - .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.UNKNOWN, citation]) + .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, citation]) .sort((a,b) => (b[1] - a[1] || (a[0].localeCompare(b[0])))) .map((pair, i) => { const [ title, uses_dataset, citation ] = pair diff --git a/scraper/client/types.js b/scraper/client/types.js index 95b7a4e3..e6b4142c 100644 --- a/scraper/client/types.js +++ b/scraper/client/types.js @@ -16,4 +16,5 @@ export const USES_DATASET = { YES: "1", NO: "-1", UNKNOWN: "0", + NO_DATA: "-2", } -- cgit v1.2.3-70-g09d2 From 85976cd08452c546fe3565d6b3ff5ceea220e35c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 16:47:15 +0100 Subject: fix stats --- scraper/client/paper/paper.info.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scraper/client') diff --git a/scraper/client/paper/paper.info.js b/scraper/client/paper/paper.info.js index a8553c9b..35234617 100644 --- a/scraper/client/paper/paper.info.js +++ b/scraper/client/paper/paper.info.js @@ -9,7 +9,7 @@ import { TableObject } from '../common' class PaperInfo extends Component { render() { const { paperInfo, unknownCitations } = this.props.api - const { dataset, statistics, address } = paperInfo + const { dataset, address } = paperInfo if (!dataset) return null return (
    @@ -21,7 +21,7 @@ class PaperInfo extends Component { /> Date: Thu, 28 Mar 2019 16:50:57 +0100 Subject: add pdf length search --- scraper/client/paper/citationList.component.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'scraper/client') diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js index 09060375..1443b24c 100644 --- a/scraper/client/paper/citationList.component.js +++ b/scraper/client/paper/citationList.component.js @@ -22,8 +22,13 @@ class CitationList extends Component {

    {title}

      {citations - .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, citation]) - .sort((a,b) => (b[1] - a[1] || (a[0].localeCompare(b[0])))) + .map(citation => [ + citation.title, + verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, + citation.pdf.length, + citation + ]) + .sort((a,b) => (b[2] - a[2] || b[1] - a[1] || (a[0].localeCompare(b[0])))) .map((pair, i) => { const [ title, uses_dataset, citation ] = pair let cite = { ...citation } -- cgit v1.2.3-70-g09d2 From 36a44fe10d2501312d16aa5f70b31fd3585fb996 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 16:52:54 +0100 Subject: add pdf length search --- scraper/client/paper/citationList.component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scraper/client') diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js index 1443b24c..ca4d2482 100644 --- a/scraper/client/paper/citationList.component.js +++ b/scraper/client/paper/citationList.component.js @@ -28,7 +28,7 @@ class CitationList extends Component { citation.pdf.length, citation ]) - .sort((a,b) => (b[2] - a[2] || b[1] - a[1] || (a[0].localeCompare(b[0])))) + .sort((a,b) => (b[1] - a[1] || b[2] - a[2] || (a[0].localeCompare(b[0])))) .map((pair, i) => { const [ title, uses_dataset, citation ] = pair let cite = { ...citation } -- cgit v1.2.3-70-g09d2 From 27a557b5c5af1fee23c8be1ffae668b5ed6ba28d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 17:10:40 +0100 Subject: fix sorting --- scraper/client/actions.js | 2 +- scraper/client/paper/citationList.component.js | 36 ++++++++++++++++---------- scraper/client/paper/paper.verify.js | 22 +++++++++------- scraper/client/store.js | 10 ++++++- scraper/client/types.js | 4 +++ 5 files changed, 49 insertions(+), 25 deletions(-) (limited to 'scraper/client') diff --git a/scraper/client/actions.js b/scraper/client/actions.js index 1b5152ea..b5c477f6 100644 --- a/scraper/client/actions.js +++ b/scraper/client/actions.js @@ -49,5 +49,5 @@ export const postVerification = data => dispatch => ( api(dispatch, post, 'verify', '/api/verify/add', data) ) - +export const setSortedCitations = sortedCitations => dispatch => dispatch({ type: types.system.set_sorted_citations, sortedCitations }) diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js index ca4d2482..10e3ba9a 100644 --- a/scraper/client/paper/citationList.component.js +++ b/scraper/client/paper/citationList.component.js @@ -9,28 +9,38 @@ import { TableObject, Loader } from '../common' import { USES_DATASET } from '../types' class CitationList extends Component { + componentDidMount() { + const { citations, api } = this.props + const { paperInfo, unknownCitations, verifications } = api + const { dataset } = paperInfo + if (!dataset || !citations || !verifications[dataset.key]) { + this.props.actions.setSortedCitations([]) + return + } + let verifiedLookup = verifications[dataset.key] || {} + const sortedCitations = citations.map(citation => [ + citation.title, + verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, + citation.pdf.length, + citation + ]) + .sort((a,b) => (b[1] - a[1] || b[2] - a[2] || (a[0].localeCompare(b[0])))) + .map(tup => tup[3]) + this.props.actions.setSortedCitations(sortedCitations) + } + render() { const { citations, title, api } = this.props - const { paperInfo, unknownCitations, verifications } = api + const { paperInfo, unknownCitations, verifications, sortedCitations } = api const { dataset } = paperInfo if (!dataset || !citations || !verifications[dataset.key]) return let verifiedLookup = verifications[dataset.key] || {} // console.log(verifications) - return (

      {title}

        - {citations - .map(citation => [ - citation.title, - verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, - citation.pdf.length, - citation - ]) - .sort((a,b) => (b[1] - a[1] || b[2] - a[2] || (a[0].localeCompare(b[0])))) - .map((pair, i) => { - const [ title, uses_dataset, citation ] = pair + {(sortedCitations || []).map((citation, i) => { let cite = { ...citation } cite.id = { _raw: true, @@ -92,7 +102,7 @@ class CitationList extends Component { } const mapStateToProps = state => ({ - api: state.api + api: state.api, }) const mapDispatchToProps = dispatch => ({ actions: bindActionCreators({ ...actions }, dispatch), diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 61faa24a..f5dbc13c 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -140,14 +140,15 @@ class PaperVerify extends Component { institution_3: this.state.institution_3, validate_3: this.state.validate_3, }) - this.next(false) + this.next() } prev() { const { key } = this.props.api.paperInfo.dataset - const { paperInfo } = this.props.api - let citationIndex = (paperInfo.citations || []) - .findIndex(f => f.id === this.state.citation.id) + const { paperInfo, sortedCitations } = this.props.api + const citations = sortedCitations || paperInfo.citations || [] + let citationIndex = citations.findIndex(f => f.id === this.state.citation.id) + if (citationIndex === -1) { history.push('/paper/' + key + '/info/') } else { @@ -155,7 +156,7 @@ class PaperVerify extends Component { if (citationIndex < 0) { history.push('/paper/' + key + '/info/') } else { - let nextId = paperInfo.citations[citationIndex].id + let nextId = citations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } @@ -163,17 +164,18 @@ class PaperVerify extends Component { next() { const { key } = this.props.api.paperInfo.dataset - const { paperInfo } = this.props.api - let citationIndex = (paperInfo.citations || []) - .findIndex(f => f.id === this.state.citation.id) + const { paperInfo, sortedCitations } = this.props.api + const citations = sortedCitations || paperInfo.citations || [] + let citationIndex = citations.findIndex(f => f.id === this.state.citation.id) + if (citationIndex === -1) { history.push('/paper/' + key + '/info/') } else { citationIndex += 1 - if (citationIndex >= paperInfo.citations.length) { + if (citationIndex >= citations.length) { history.push('/paper/' + key + '/info/') } else { - let nextId = paperInfo.citations[citationIndex].id + let nextId = citations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } diff --git a/scraper/client/store.js b/scraper/client/store.js index b199ae29..6da60cbe 100644 --- a/scraper/client/store.js +++ b/scraper/client/store.js @@ -15,7 +15,8 @@ const initialState = () => ({ unknownCitations: {}, verify: {}, verifications: {}, - options: {} + options: {}, + sortedCitations: [], }) export default function apiReducer(state = initialState(), action) { @@ -45,6 +46,13 @@ export default function apiReducer(state = initialState(), action) { paperKey: action.paperKey } + case types.system.set_sorted_citations: + console.log(action.sortedCitations || []) + return { + ...state, + sortedCitations: action.sortedCitations || [], + } + default: return state } diff --git a/scraper/client/types.js b/scraper/client/types.js index e6b4142c..22c93a89 100644 --- a/scraper/client/types.js +++ b/scraper/client/types.js @@ -10,6 +10,10 @@ export const api = tagAsType('api', [ 'loading', 'loaded', 'error', 'set_paper_key', ]) +export const system = tagAsType('system', [ + 'set_sorted_citations', +]) + export const init = '@@INIT' export const USES_DATASET = { -- cgit v1.2.3-70-g09d2