diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 15:27:56 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 15:27:56 +0100 |
| commit | 3bad596c05c8305d327955225d3d10aacce78da1 (patch) | |
| tree | bfc7788a60d13fbcdcea71313aeebdc6ea69a05f /scraper | |
| parent | ad6284a2040837e7373b4d89644a01306f181dd5 (diff) | |
add paper addresses to unverified papers
Diffstat (limited to 'scraper')
| -rw-r--r-- | scraper/client/common/autocomplete.component.js | 7 | ||||
| -rw-r--r-- | scraper/client/paper/paper.verify.js | 74 | ||||
| -rw-r--r-- | scraper/s2-geocode-server.py | 17 | ||||
| -rw-r--r-- | scraper/util.py | 15 |
4 files changed, 85 insertions, 28 deletions
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 { </div> <div - className={parseInt(this.state.uses_dataset) === USES_DATASET.YES ? 'row vettingRow' : 'row vettingRow disabled'} - disabled={parseInt(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'} @@ -380,12 +394,44 @@ class PaperVerify extends Component { return ( <div> <div className='param'> - <label>Institution</label> - <input - type='text' - value={this.state.address.institution_1} - placeholder='Institution' - onChange={e => this.setState({ institution_1: e.target.value })} + <label>Institution #1</label> + <Autocomplete + placeholder='Institution #1' + value={this.state.institution_1} + onSelect={value => { + this.setState({ institution_1: value, validate_1: true }) + }} + onCancel={value => { + this.setState({ institution_1: '', validate_2: false }) + }} + /> + </div> + + <div className='param'> + <label>Institution #2</label> + <Autocomplete + placeholder='Institution #2' + value={this.state.institution_2} + onSelect={value => { + this.setState({ institution_2: value, validate_2: true }) + }} + 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={value => { + this.setState({ institution_3: value, validate_3: true }) + }} + onCancel={value => { + this.setState({ institution_3: '', validate_3: false }) + }} /> </div> </div> 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 = {} |
