Skip to content
Open

V2.1 #24

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
806bba1
update djoser version
bdrumheller Feb 19, 2018
b8779a3
update submodule on parent
bdrumheller Feb 19, 2018
9941b6c
upgrade to drf 1.11 LTS
bdrumheller Feb 19, 2018
e442758
remove valid password check for password reset
bdrumheller Feb 19, 2018
811c862
add images to samples, subsamples, chemical analysis
bdrumheller Feb 20, 2018
6bda95f
added var for sitename for new email template
Mar 13, 2018
4476084
updated djoser submodule locaiton
Mar 13, 2018
dc0d585
Merge branch 'v2.1' into master
bdrumheller Apr 10, 2018
f2917b4
make chemical analysis query orderable
IreLynn Jul 14, 2018
b18425e
added csv renderer for chemical analyses & updated serializer and view
IreLynn Aug 10, 2018
e6cf15e
cleaned up some methods in sample serializer
IreLynn Aug 10, 2018
e4f5404
chemical analysis CSV renderer works, and adapts to fields argument
IreLynn Aug 22, 2018
2ec37ad
added missing call to handle_meta_regions & added functionality to ad…
IreLynn Aug 22, 2018
0e740aa
add support for bulk image upload via image container list; update im…
bdrumheller Aug 27, 2018
62fb064
Merge branch 'master' of https://github.com/bdrumheller/api_v2
bdrumheller Aug 27, 2018
a778fac
remove print
bdrumheller Aug 27, 2018
7859f60
resolved conflicts on @bdrumheller master & csv_fixes branch to merge…
IreLynn Sep 1, 2018
bc9ff1e
added missing comma
IreLynn Sep 3, 2018
39f9b6c
updated url routing to match newest version of djoser
IreLynn Sep 3, 2018
7f1a328
Merge branch 'v2.1' of https://github.com/metpetdb/api_v2 into bulkup…
IreLynn Sep 4, 2018
72e4e05
added images to fields so it stops breaking (hopefully....)
IreLynn Sep 4, 2018
b46bfcf
merged v2.1 branch with master version on prod server
Sep 4, 2018
866683f
Merge pull request #20 from metpetdb/bulkupload_fix
IreLynn Sep 4, 2018
67a6861
updated formatting of provided 'DOMAIN' & 'SITE_NAME' vars to work wi…
IreLynn Sep 4, 2018
dc8b149
Merge branch 'v2.1' of https://github.com/metpetdb/api_v2 into bulkup…
IreLynn Sep 4, 2018
cec2fdf
debugged image migration & chemical analysis migration w/ images
IreLynn Oct 18, 2018
5db7105
attempt to fix png save issue
IreLynn Oct 18, 2018
a88fded
added sample_id field
IreLynn Dec 12, 2018
bad0df9
added ordering to users and countries; added location_coords back to …
IreLynn Dec 23, 2018
b95d803
modified label: 'Sample'-->'Sample Number'
IreLynn Dec 27, 2018
f51907f
reworking expected fields for sample template
IreLynn Dec 27, 2018
d82e489
bulk upload for samples mostly works (but frontend table rendering is…
IreLynn Dec 28, 2018
c681cdd
removed unnecessary time from sample collection date field
IreLynn Jan 3, 2019
9fa3332
sample bulk upload appears to be fully functional (in backend)
IreLynn Jan 4, 2019
62789d9
updated sample serializer to automatically handle lat/long geometry
IreLynn Feb 6, 2019
de2f28c
slight modifications to make chemical analyses play nice with frontend
IreLynn Feb 7, 2019
951ffe2
modified views to look for & assign filenames when csv requested
IreLynn Mar 6, 2019
4aa4c56
added ordering on number of associated images & chemical analyses
IreLynn Mar 7, 2019
962b65e
added ordering on number of subsamples
IreLynn Mar 7, 2019
ed24e88
increased max page length for region retrieval in frontend (for searc…
IreLynn Mar 7, 2019
d98553a
updated default sorting for elements and oxides
IreLynn Mar 12, 2019
86af47d
fixed some default orderings
IreLynn Mar 13, 2019
f34a553
chem bulk upload parsing correctly
IreLynn Mar 20, 2019
89ee9ea
chem analysis bulk upload (mostly?) working
IreLynn Mar 20, 2019
cf92fde
commented out error prints (oops)
IreLynn Apr 10, 2019
a63455e
made sample number & owner id a unique pair
IreLynn May 2, 2019
79aaa09
cleaned up views file & added public_data to serializer so field can …
IreLynn May 2, 2019
64e58ed
fixed lat/long bug
IreLynn Jun 13, 2019
718f3d5
quick n dirty handling of single image file upload
IreLynn Jun 13, 2019
bfd0ebf
playing w single image upload
IreLynn Jun 14, 2019
3c3d393
merged stuff
Jun 14, 2019
3fa1d67
merged again
Jun 14, 2019
c561596
added association with sample/subsample on image direct upload
IreLynn Jun 20, 2019
f49a713
Merge branch 'v2.1' of https://github.com/metpetdb/api_v2 into v2.1
Jun 20, 2019
3b3fe65
fixed permissions issue with users being allowed to add images to sam…
IreLynn Jun 20, 2019
38be5f7
added image_types endpoint
IreLynn Jun 20, 2019
c35801c
Merge branch 'v2.1' of https://github.com/metpetdb/api_v2 into v2.1
Jun 20, 2019
c24997e
fixed checking of owner ID
IreLynn Jun 20, 2019
3f9939e
Merge branch 'v2.1' of https://github.com/metpetdb/api_v2 into v2.1
Jun 20, 2019
fcfeb95
added element attribute to image model'
IreLynn Jul 1, 2019
9c4e4f9
added user ID back to sample serializer so that frontend can properly…
Jul 8, 2019
6d1c546
Merge branch 'v2.1' of https://github.com/metpetdb/api_v2 into v2.1
Sep 4, 2019
a86e880
partial query search and modified model for xray images
Sep 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "metpetdb_api/vendor/djoser"]
path = metpetdb_api/vendor/djoser
url = https://github.com/IreLynn/djoser.git
url = https://github.com/bdrumheller/djoser.git
Empty file added metpetdb_api/__init__.py
Empty file.
6 changes: 2 additions & 4 deletions metpetdb_api/api/bulk_upload/v1/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
Subsample
)

from apps.chemical_analyses.models import(
Element,
Oxide,
)
from apps.chemical_analyses.shared_models import Element, Oxide


class BulkUploadTests(APITransactionTestCase):
"""
Expand Down
101 changes: 68 additions & 33 deletions metpetdb_api/api/bulk_upload/v1/upload_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,45 @@
"""
import copy

# labels are case insensitive!
sample_label_mappings = {
'sample number':'number',
'rock type':'rock_type_name',
'latitude':'latitude',
'longitude':'longitude',
'location error':'location_error',
'collector':'collector_name',
'date of collection':'collection_date',
'present sample location':'location_name',
'country':'country',
# multi-fields
'comment':'description',
'reference':'references',
'region':'regions',
'metamorphic region':'metamorphic_regions',
'metamorphic grade':'metamorphic_grades'
}

chem_analysis_label_mappings = {
'sample':'sample',
'subsample':'subsample',
'mineral':'mineral',
'method':'analysis_method',
'subsample type':'subsample_type',
'reference':'reference',
'point':'spot_id',
'analytical facility':'where_done',
'analysis date':'analysis_date',
'analyst':'analyst',
'reference x':'reference_x',
'reference y':'reference_y',
'stage x':'stage_x',
'stage y':'stage_y',
'total':'total',
'comment':'description'
}


class Template:
def __init__(self, c_types = [], required = [], db_types = [], types = {}):
self.complex_types = c_types
Expand All @@ -45,12 +84,13 @@ def check_line_len(self):
raise Exception("inconsistent line length. Expected {0}, but was {1}".format(len(data[i-1]), len(data[i])))

def check_required(self, row):
header = row[0]
header = [x for x in row[0]]
for i in range(0,len(header)):
header[i] = header[i].lower()
missing ={}
for i in range(0, len(header)):
if self.is_required(header[i]):
if row[1][i] == '':
missing[header[i]] = 'missing'
for i in range(0, len(self.required)):
if self.required[i] not in header:
missing[self.required[i]] = 'missing'
return missing

def check_type(self, curr_row):
Expand Down Expand Up @@ -104,7 +144,7 @@ def parse(self, data):
for heading in header:
if self.is_complex(heading): result_template[heading] = []
else: result_template[heading] = ''
result_template['errors'] = '';
result_template['errors'] = ''

for i in range(1, len(data)):
tmp_result = self.TemplateResult(copy.deepcopy(result_template))
Expand All @@ -114,17 +154,8 @@ def parse(self, data):
for j in range(0,len(data[i])):
heading = header[j]

if heading in self.amounts:
name = data[i][j]
amount = self.get_amount(data,i,j)
tmp_result.set_field_complex(heading, {"name": name, "amount": amount})
continue

if heading == 'mineral' and heading not in self.amounts:
tmp_result.set_field_complex(heading, {"name": data[i][j]})
continue

field = data[i][j]
# print("{}: {}".format(heading,data[i][j]))
if self.is_complex(heading):
tmp_result.set_field_complex(heading,field)
else: tmp_result.set_field_simple(heading, field)
Expand All @@ -133,14 +164,14 @@ def parse(self, data):
result.append(tmp_result.get_rep())
return result, meta_header

def is_complex(self, name): return name in self.complex_types
def is_required(self, name): return name in self.required
def is_complex(self, name): return name.lower() in self.complex_types
def is_required(self, name): return name.lower() in self.required
def is_db_type(self, name): return name in self.db_types

class ChemicalAnalysesTemplate(Template):
def __init__(self):
complex_types = ["comment", "element", "oxide","mineral"]
required = ["subsample_id", "spot_id", "mineral", "analysis_method"]
complex_types = ["comment","element","oxide"]
required = ["sample","subsample","point","mineral","method","subsample type"]
db_types = ["element", "oxide"]
types = {"comment": str, "stage_x" : float, "stage_y" : float, "reference_x": float, "reference_y": float}
Template.__init__(self, complex_types, required, db_types, types)
Expand Down Expand Up @@ -168,19 +199,19 @@ def get_meta_header(self,header):
meta_header.append((heading, mappings[heading]))
added.add(heading)
else:
meta_header.append((heading, heading))
meta_header.append((heading, heading))
added.add(heading)
return meta_header

class SampleTemplate(Template):

def __init__(self):
complex_types = ["comment", "references", "mineral", "metamorphic_region_id", "metamorphic_grade"]
required = ["number", "latitude", "longitude", "rock_type_name"]
complex_types = ["comment", "reference", "region", "metamorphic region", "metamorphic grade"]
required = ["sample number", "latitude", "longitude", "rock type"]
types = {"comment": str, "latitude": float, 'longitude': float}
db_types = ["minerals"]
#selected_types = {'minerals': ['el1', 'el2', 'el3']}
Template.__init__(self, complex_types, required, db_types, types)
self.amounts.add('mineral')

def check_amounts(self,header):
pass
Expand All @@ -189,18 +220,22 @@ def get_amount(self,data=[],i=0,j=0):
return 0

def get_meta_header(self,header):
mappings = {'mineral' : 'minerals'}
added = set()
mappings = {}
added = set()
meta_header = []
itr = iter(header)
for heading in itr:
if heading == 'latitude':
for i in range (0,2): heading = next(itr)
meta_header.append((('latitude','longitude'),'location_coords'))
elif heading not in added:
if heading in mappings.keys():
meta_header.append((heading, mappings[heading]))
# if heading.lower() == 'latitude':
# for i in range (0,2): heading = next(itr)
# meta_header.append((('latitude','longitude'),'Location'))
if heading not in added:
if heading.lower() in mappings.keys():
meta_header.append((heading.lower(),heading))
added.add(heading)
else:
meta_header.append((heading, heading))
meta_header.append((heading, heading))
added.add(heading)
# print("\nMETA-HEADER:")
# print(meta_header)
# print("\n\n")
return meta_header
Loading