Skip to content
Snippets Groups Projects
Commit bcb61efa authored by David, Sebastian's avatar David, Sebastian
Browse files

Created the first running programm with almost ful

parent caeb7d20
No related branches found
No related tags found
1 merge request!8UI Hinzufügen
This diff is collapsed.
import unittest
from input.get.journal_fetcher import JournalFetcher
from input.interface import InputInterface
from input.publication import Publication
"""
Testing the Publication fetcher
Publication 1: 'https://doi.org/10.1021/acs.jcim.1c00203'
Publication 2: 'doi.org/10.1021/acs.jcim.1c00917'
Publication 3: '10.1038/nchem.1781'
Publication 4: '11.12/jaj'
Publication 5: '11.12/'
Publication 6: 'https://doi.org/10.1021/acs.jmedchem.0c01332' # Paper is a PDF
"""
# TODO: Testcases for:
# - Specific Journals: Inherit from FetcherTestCase
# - interface module-importer (test case)
# - Error detection
# - wrong/no Journal_fetchers
# - wrong urls
# - correct Types in publication
# - Edgecases (i.e. paper as pdf, no connection, etc)
class InterfaceTestCase(unittest.TestCase):
def setUp(self):
self.assertEqual(InputInterface.instance, None)
self.interface = InputInterface()
def test_singleton(self):
# interface should already be made in setUp()
self.assertNotEqual(self.interface.instance, None)
new_interface = InputInterface()
self.assertEqual(self.interface, new_interface)
# def test_imported_modules(self):
# fetchers = self.interface.get_supported_fetchers
class FetcherTestCase(unittest.TestCase):
def can_use_url_test(self, fetcher : JournalFetcher, test_url: str, expected_res: bool):
# Tests the 'can_use_url'-method
self.assertEqual(fetcher.can_use_url(test_url), expected_res)
def get_publication_test(self, fetcher : JournalFetcher, test_url: str, expected_res: Publication):
"""
this test asserts that every variable is equals to the expected result
"""
actual_res = fetcher.get_publication(test_url)
self.assertEqual(actual_res.doi_url, expected_res.doi_url)
self.assertEqual(actual_res.title, expected_res.title)
self.assertEqual(actual_res.contributors, expected_res.contributors)
self.assertEqual(actual_res.journal, expected_res.journal)
self.assertEqual(actual_res.publication_date, expected_res.publication_date)
self.assertEqual(actual_res.subjects, expected_res.subjects)
# Checking for all references
self.assertEqual(len(actual_res.references), len(expected_res.references))
num_references = len(expected_res.references)
for i in range(num_references):
self.assertEqual(actual_res.references[i].doi_url, expected_res.references[i].doi_url)
self.assertEqual(actual_res.references[i].journal, expected_res.references[i].journal)
self.assertEqual(actual_res.references[i].contributors, expected_res.references[i].contributors)
self.assertEqual(actual_res.references[i].cit_type, expected_res.references[i].cit_type)
# Checking for all citations
self.assertEqual(len(actual_res.citations), len(expected_res.citations))
num_citations = len(expected_res.citations)
for i in range(num_citations):
self.assertEqual(actual_res.citations[i].doi_url, expected_res.citations[i].doi_url)
self.assertEqual(actual_res.citations[i].journal, expected_res.citations[i].journal)
self.assertEqual(actual_res.citations[i].contributors, expected_res.citations[i].contributors)
self.assertEqual(actual_res.citations[i].cit_type, expected_res.citations[i].cit_type)
def get_publication_exception_test(self, fetcher: JournalFetcher, test_url: str):
# Ckecks
with self.assertRaises(ValueError):
fetcher.get_publication(test_url)
\ No newline at end of file
......@@ -4,6 +4,8 @@ from dash import html
from dash import callback_context
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from input.interface import InputInterface
import input.publication
app = dash.Dash(__name__)
......@@ -22,9 +24,10 @@ app.layout = html.Div([
dcc.Input(id='forward-depth',value='1',type='number',min='1',max='10'),
dcc.Input(id='backward-depth',value='1',type='number',min='1',max='10')
]),
# Layer 2: For the checklist and Remove-/Start-Buttons
# Layer 2: For the checklist, Remove-/Start-Buttons and input-error-message
html.Div([
dcc.Checklist(id='input-checklist',options=[],labelStyle = dict(display='block'),value=[]),
html.Div(id='input-err',style={'color':'red'}),
html.Button(id='clear-all-button',children='Clear All'),
html.Button(id='clear-selected-button',children='Clear Selected'),
html.Button(id='start-button',children='Generate Graph')
......@@ -50,6 +53,7 @@ input-string is required as Output to clear the input box after each input
Output('input-checklist','options'),
Output('input-checklist','value'),
Output('input-string','value'),
Output('input-err','children'),
Input('input-string','value'),
Input('clear-all-button','n_clicks'),
Input('clear-selected-button','n_clicks'),
......@@ -71,21 +75,28 @@ def update_input_checklist(input_value,btn1,btn2,all_inputs,selected_inputs):
changed_id = [p['prop_id'] for p in callback_context.triggered][0]
# if clear-all-button was pressed:
if 'clear-all-button' in changed_id:
return list(),list(),''
return list(),list(),'',''
# if clear-selected-button was pressed:
if 'clear-selected-button' in changed_id:
all_inputs = [i for i in all_inputs if i['value'] not in selected_inputs]
return all_inputs,list(),''
return all_inputs,list(),'',''
# when the programm is first started:
if input_value == '':
app.layout['input-checklist'].options.clear()
return list(),list(),''
return list(),list(),'',''
# when a new element is added via dcc.Input
if 'input-string' in changed_id:
options = all_inputs
currValues = [x['value'] for x in options]
if input_value not in currValues:
options.append({'label':input_value, 'value':input_value})
return options,selected_inputs,''
try:
i = InputInterface()
pub = i.get_pub_light(input_value)
except Exception as err:
return options,selected_inputs,'','{}'.format(err)
rep_str = pub.contributors[0] + ',' + pub.journal + ',' + pub.publication_date
options.append({'label':rep_str, 'value':input_value})
return options,selected_inputs,'',''
'''
This callback shows and hides the (first) help-box
......
import dash
from dash import dcc
from dash import html
from dash.dependencies import Input, Output
from dash.dependencies import Input, Output, State
import base64
import re
app = dash.Dash(__name__)
......@@ -15,6 +17,7 @@ app.layout = html.Div([
children=html.Div(
["Drag and drop or click to select a file to upload."]
),
style={
"width": "30%",
"height": "60px",
......@@ -25,27 +28,51 @@ app.layout = html.Div([
"textAlign": "center",
"margin": "10px",
}),
dcc.Checklist(id='list-of-inputs',labelStyle = dict(display='block'))
]),
dcc.Checklist(id='input-checklist',options=list(),labelStyle = dict(display='block'),value=[]),
])
@app.callback(
Output('list-of-inputs','options'),
Input('upload-data','filenames'),
Input('upload-data','contents')
Output('input-checklist','options'),
Input('upload-data','filename'),
Input('upload-data','contents'),
State('input-checklist','options')
)
def update_input_list(uploaded_filenames,uploaded_file_contents):
for line in uploaded_file_contents:
line = line.rstrip()
list_of_inputs[line] = line
try:
stream = open(uploaded_filenames,'r') # this statement may throw an exception
except IOError as err: # exception stores error message in err
# now comes the code reacting on the exception
sys.stderr.write('{}: {}\n'.format(sys.argv[0], err))
exit(1)
return [{'label': i, 'value': i} for i in list_of_inputs], ''
def update_input_list(uploaded_filenames,uploaded_file_contents,all_inputs):
if uploaded_file_contents is not None:
string = uploaded_file_contents
#cutting the first part of the String away to decode
found = base64.b64decode(re.search(',(.+?)$', string).group(1))
print(found.decode('utf-8'))
uploaded_file_contents = found.decode('utf-8')
list_of_inputs = (uploaded_file_contents.split())
#das hier sollte es untereinander anzeigen, bekomme ich allerdings nicht auf die Seite...
#return (*list_of_inputs, sep="\n")
options = all_inputs
if not options:
options = list()
CurrValues = [x['value'] for x in options]
# würde auch funktionieren
# return (found.decode('utf-8'))
for i in list_of_inputs:
if i not in CurrValues:
options.append({'label':i, 'value':i})
return options
if __name__ == '__main__':
app.run_server(debug=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment