diff options
| author | adamhrv <adam@ahprojects.com> | 2019-03-28 20:01:11 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2019-03-28 20:01:11 +0100 |
| commit | 21fd4284ac0f14ec860ccda1032ef380ccfa7b2f (patch) | |
| tree | 6751b86621a1ad76ebab1ffe9f0d1a6ab053bacc /scraper/client/paper | |
| parent | b2c61d7ebc142b41f8cb15b00764319801d1bf5d (diff) | |
| parent | 5309b381e64f59b8f57014ad41e55d7f87ca0628 (diff) | |
Merge branch 'master' of github.com:adamhrv/megapixels_dev
Diffstat (limited to 'scraper/client/paper')
| -rw-r--r-- | scraper/client/paper/citationList.component.js | 111 | ||||
| -rw-r--r-- | scraper/client/paper/paper.citations.js | 86 | ||||
| -rw-r--r-- | scraper/client/paper/paper.css | 9 | ||||
| -rw-r--r-- | scraper/client/paper/paper.info.js | 4 | ||||
| -rw-r--r-- | scraper/client/paper/paper.unknown.js | 48 | ||||
| -rw-r--r-- | scraper/client/paper/paper.verify.js | 142 |
6 files changed, 268 insertions, 132 deletions
diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js new file mode 100644 index 00000000..10e3ba9a --- /dev/null +++ b/scraper/client/paper/citationList.component.js @@ -0,0 +1,111 @@ +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 { + 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, sortedCitations } = api + const { dataset } = paperInfo + if (!dataset || !citations || !verifications[dataset.key]) return <Loader /> + let verifiedLookup = verifications[dataset.key] || {} + // console.log(verifications) + return ( + <div className='citations'> + <h2>{title}</h2> + <ul> + {(sortedCitations || []).map((citation, i) => { + let cite = { ...citation } + cite.id = { + _raw: true, + value: <Link to={'/paper/' + dataset.key + '/verify/' + citation.id}>{citation.id}</Link> + } + cite.pdf = { + _raw: true, + value: (cite.pdf && cite.pdf.length) + ? cite.pdf.map((pdf, i) => <a key={'pdf_' + i} href={pdf} rel='noopener noreferrer' target="_blank">[pdf]</a>) + : "no pdf" + } + cite.s2 = { + _raw: true, + value: <a + href={'https://www.semanticscholar.org/paper/' + citation.id} + target="_blank" + rel="noopener noreferrer" + className={'pdfLink'} + >{'[semantic scholar]'}</a> + } + cite.addresses = { + _raw: true, + value: (cite.addresses || []).map((address, j) => ( + <div key={j}>{address.name}{', '}<span className='type'>{address.type}</span></div> + )) + } + if (citation.id in verifiedLookup) { + const verification = verifiedLookup[citation.id] + cite.verified = { + _raw: true, + value: verification.uses_dataset === USES_DATASET.YES + ? <span className='verified'>uses dataset</span> + : verification.uses_dataset === USES_DATASET.NO + ? <span className='unverified'>{"doesn't use dataset"}</span> + : <span className='not_enough_info'>{"not enough information"}</span> + } + } + else { + cite.verified = { + _raw: true, + value: <span className='unknown'>unknown</span> + } + } + return ( + <li key={i}> + <TableObject + summary + object={cite} + tag={cite.title} + order={['id', 'pdf', 's2', 'year', 'addresses', 'verified']} + /> + </li> + ) + })} + </ul> + </div> + ) + } +} + +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 5c8e0e0c..f0e9ea26 100644 --- a/scraper/client/paper/paper.citations.js +++ b/scraper/client/paper/paper.citations.js @@ -5,84 +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 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 <Loader /> + return ( - <div className='citations'> - <h2>{dataset.name_full}: Citations</h2> - <ul> - {citations.map((citation, i) => { - let cite = { ...citation } - cite.id = { - _raw: true, - value: <Link to={'/paper/' + dataset.key + '/verify/' + citation.id}>{citation.id}</Link> - } - cite.pdf = { - _raw: true, - value: (cite.pdf && cite.pdf.length) ? <a href={cite.pdf[0]} rel='noopener noreferrer' target="_blank">[pdf]</a> : "no pdf" - } - cite.s2 = { - _raw: true, - value: <a - href={'https://www.semanticscholar.org/paper/' + citation.id} - target="_blank" - rel="noopener noreferrer" - className={'pdfLink'} - >{'[semantic scholar]'}</a> - } - cite.addresses = { - _raw: true, - value: cite.addresses.map((address, j) => ( - <div key={j}>{address.name}{', '}<span className='type'>{address.type}</span></div> - )) - } - if (citation.id in verifications && verifications[citation.id].dataset === dataset.key) { - const verification = verifications[citation.id] - cite.verified = { - _raw: true, - value: verification.uses_dataset === USES_DATASET.YES - ? <span className='verified'>uses dataset</span> - : verification.uses_dataset === USES_DATASET.NO - ? <span className='unverified'>{"doesn't use dataset"}</span> - : verification.uses_dataset === 'TRUE' - ? <span className='verified'>uses dataset</span> - : verification.uses_dataset === 'FALSE' - ? <span className='unverified'>{"doesn't use dataset"}</span> - : <span className='unknown'>{"not enough information"}</span> - } - } - else { - cite.verified = { - _raw: true, - value: <span className='unknown'>unknown</span> - } - } - return ( - <li key={i}> - <TableObject - summary - object={cite} - tag={cite.title} - order={['id', 'pdf', 's2', 'year', 'addresses', 'verified']} - /> - </li> - ) - })} - </ul> - </div> + <CitationList + title={dataset.name_full + ': Citations'} + citations={citations.concat(unknownCitations.citations)} + /> ) } } diff --git a/scraper/client/paper/paper.css b/scraper/client/paper/paper.css index ac711559..9bb684ff 100644 --- a/scraper/client/paper/paper.css +++ b/scraper/client/paper/paper.css @@ -62,6 +62,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.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 ( <div className='paperInfo'> @@ -21,7 +21,7 @@ class PaperInfo extends Component { /> <TableObject summary tag="Statistics" - object={statistics} + object={dataset} order={['year_published', 'purpose_short', 'wild', 'indoor', 'outdoor', 'cyberspace', 'names', 'downloaded', diff --git a/scraper/client/paper/paper.unknown.js b/scraper/client/paper/paper.unknown.js index 0cb7d2da..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 <Loader /> + return ( - <div className='citations'> - <h2>{dataset.name_full}: Unknown Citations</h2> - <ul> - {citations.map((citation, i) => { - let cite = { ...citation } - cite.id = { - _raw: true, - value: <Link to={'/paper/' + dataset.key + '/address/' + citation.id}>{citation.id}</Link> - } - cite.pdf = { - _raw: true, - value: cite.pdf ? <a href={cite.pdf} rel='noopener noreferrer' target="_blank">[pdf]</a> : "no pdf" - } - return ( - <li key={i}> - <TableObject - summary - object={cite} - tag={cite.title} - /> - </li> - ) - })} - </ul> - </div> + <CitationList + title={dataset.name_full + ': Unknown Citations'} + citations={unknownCitations.citations} + /> ) } } diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 65342adf..f5dbc13c 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -4,18 +4,27 @@ 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 = { 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, + institution_1: '', + institution_2: '', + institution_3: '', + validate_1: false, + validate_2: false, + validate_3: false, } class PaperVerify extends Component { @@ -26,6 +35,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 +44,67 @@ 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, - uses_dataset: paper.uses_dataset === "TRUE", - images_in_paper: paper.images_in_paper === "TRUE", + ...address.paper, + uses_dataset: paper.uses_dataset, + images_in_paper: paper.images_in_paper, verified_by: paper.verified_by, reference: paper.reference, notes: paper.notes, - }) + } + this.setState(newState) } } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { + console.log('loaded unknown citations') 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 } @@ -107,15 +132,23 @@ 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) + 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 { @@ -123,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) } } @@ -131,24 +164,25 @@ 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) } } } render() { - let { paperInfo } = this.props.api + const { paperInfo, unknownCitations } = this.props.api if (paperInfo.loading) return <Loader /> // console.log(this.state) const { citation } = this.state @@ -185,6 +219,8 @@ class PaperVerify extends Component { </a> </div> + {this.renderLocationForm()} + <div className='row vettingRow'> <div className='rowHeading'> {'Uses dataset'} @@ -194,7 +230,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={String(this.state.uses_dataset) === USES_DATASET.YES} onChange={e => this.setState({ uses_dataset: USES_DATASET.YES, })} @@ -207,7 +243,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={String(this.state.uses_dataset) === USES_DATASET.NO} onChange={e => this.setState({ uses_dataset: USES_DATASET.NO, })} @@ -220,7 +256,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={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, })} @@ -230,8 +266,8 @@ class PaperVerify extends Component { </div> <div - className={this.state.uses_dataset === USES_DATASET.YES ? 'row vettingRow' : 'row vettingRow disabled'} - disabled={this.state.uses_dataset === USES_DATASET.YES ? false : true} + className={String(this.state.uses_dataset) === USES_DATASET.YES ? 'row vettingRow' : 'row vettingRow disabled'} + disabled={String(this.state.uses_dataset) === USES_DATASET.YES ? false : true} > <div className='rowHeading'> {'Paper shows images'} @@ -355,6 +391,54 @@ class PaperVerify extends Component { </div> ) } + renderLocationForm() { + if (!this.state.citation.isUnknown) return + return ( + <div> + <div className='param'> + <label>Institution #1</label> + <Autocomplete + placeholder='Institution #1' + value={this.state.institution_1} + onSelect={(institution_1, validate_1) => { + this.setState({ institution_1, validate_1 }) + }} + onCancel={value => { + this.setState({ institution_1: '', validate_1: false }) + }} + /> + </div> + + <div className='param'> + <label>Institution #2</label> + <Autocomplete + placeholder='Institution #2' + value={this.state.institution_2} + onSelect={(institution_2, validate_2) => { + this.setState({ institution_2, validate_2 }) + }} + onCancel={value => { + this.setState({ institution_2: '', validate_2: false }) + }} + /> + </div> + + <div className='param'> + <label>Institution #3</label> + <Autocomplete + placeholder='Institution #3' + value={this.state.institution_3} + onSelect={(institution_3, validate_3) => { + this.setState({ institution_3, validate_3 }) + }} + onCancel={value => { + this.setState({ institution_3: '', validate_3: false }) + }} + /> + </div> + </div> + ) + } } /* |
