Skip to content

Commit

Permalink
Merge pull request #271 from AuScope/dev-sample
Browse files Browse the repository at this point in the history
Merging Dev sample in master
  • Loading branch information
bmotevalli authored Aug 22, 2024
2 parents 9083ccd + 8cd8b84 commit c337a7d
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def process_author_emails(sample, authors_df):

def prepare_samples_data(samples_df, authors_df, related_resources_df, funding_df, org_id):
samples_data = []
existing_names = set()
errors = []
for _, row in samples_df.iterrows():
sample = row.to_dict()
sample["author"] = process_author_emails(sample, authors_df)
Expand All @@ -75,6 +77,10 @@ def prepare_samples_data(samples_df, authors_df, related_resources_df, funding_d
sample['notes'] = sample['description']
sample['location_choice'] = 'noLocation'
sample['parent_sample'] = sample['parent_sample']
sample['parent'] = ''

sample['acquisition_start_date'] = row['acquisition_start_date'].strftime('%Y-%m-%d') if pd.notnull(row['acquisition_start_date']) else None
sample['acquisition_end_date'] = row['acquisition_end_date'].strftime('%Y-%m-%d') if pd.notnull(row['acquisition_end_date']) else None

org = toolkit.get_action('organization_show')({}, {'id': org_id})
sample['owner_org'] = org_id
Expand All @@ -98,10 +104,23 @@ def prepare_samples_data(samples_df, authors_df, related_resources_df, funding_d

sample["name"] = generate_sample_name(org_id, sample['sample_type'], sample['sample_number'])
sample["title"] = generate_sample_title(org_id, sample['sample_type'], sample['sample_number'])
# Check for uniqueness
if sample["name"] in existing_names:
errors.append(f"Duplicate sample name: {sample['name']}")
else:
existing_names.add(sample["name"])

samples_data.append(sample)

return samples_data
try:
package_list = toolkit.get_action('package_list')({}, {})
for package in package_list:
package_data = toolkit.get_action('package_show')({}, {'id': package})
existing_name = package_data.get('name')
if existing_name in existing_names:
errors.append(f"Sample name {existing_name} already exists in CKAN")
except Exception as e:
errors.append(f"Error fetching CKAN data: {str(e)}")
return samples_data, errors

def process_related_resources(sample, related_resources_df):
related_resources_urls = sample.get("related_resources_urls")
Expand Down
194 changes: 128 additions & 66 deletions ckan/src/ckanext-igsn-theme/ckanext/igsn_theme/logic/batch_validation.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<h1>Upload batch sample metadata</h1>
</div>
<div class="col-sm-3 float-right">
<a href="/base/files/auscope-sample-template.xlsx" class="btn btn-link" download>
<a href="/base/files/auscope-sample-template-v3.xlsx" class="btn btn-link" download>
<i class="fas fa-upload"></i> Download Template
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
{% trans %}
<p>AuScope focuses on delivering data, services, and tools to support future research in the Australian geoscience research community. As a component of the “Data Lens” of the AuScope Downward-Looking Telescope, the AuScope Discovery Portal harvests metadata from affiliated data catalogues to support more comprehensive access. Over time, it has become apparent that the data repositories, and more specifically sample data repositories, offered by the AuScope partners and universities need to be improved for curating sample data from the AuScope projects. </p>

<p>AuScope is committed to providing a trusted digital repository for its communities (e.g., NCRIS-funded data projects and Australian Geoscience research communities) to curate and publish their sample data following the FAIR Data Guiding Principles. Sample metadata and links to related datasets will be available openly through the repository with appropriate attributions to promote open science. The repository is essential for geoscience research innovation in support of the AuScope 5-Year Investment Plan and Australian Academy of Science Decadal plan for Australian Geoscience: Our Planet, Australia's Future.</p>
<p> The AuScope Virtual Research Environment (AVRE) is an AuScope program that focuses on delivering data, services, and tools to support the future research of the Australian geoscience research community. AVRE provides a rich ecosystem of Findable, Accessible, Interoperable and Reusable (FAIR) data and tools to a diverse range of Australian research organisations, government geological surveys and the international community. The AVRE program has contributed to the development and spearheaded the adoption of the International Generic Sample Numbers (IGSN) system in Australia in collaboration with the IGSN e.V. Organisation, DataCite, and the Australian Research Data Commons (ARDC).</p>
<p>
The AuScope Sample Repository aims to offer a digital repository for the AuScope community to register persistent identifiers for specimen data and publish specimen metadata following the
<a href="https://www.go-fair.org/fair-principles/" class="custom-link" target="_blank"> FAIR Data Guiding Principles.</a>
The AuScope communities comprise NCRIS-funded data projects and Australian geoscience research communities. The AuScope Sample Repository is operated as a self-service facility for the storage, dissemination, and publication of metadata from AuScope-funded projects and instruments.
</p>
{% endtrans %}

<p>This work is supported by AuScope and funded by the Australian Government through the National Collaborative Research Infrastructure Strategy, NCRIS.</p>
<style>

.custom-link {
color: var(--color-aus-royal-blue);
text-decoration: none;
font-weight: bold;
}

{% endtrans %}
.custom-link:hover {
text-decoration: underline;
color: var(--color-aus-royal-blue);
font-weight: bold;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1 class="page-heading">{{ _("Quick Start") }}</h1>
<li>
<span class="badge">Start Batch Upload</span>
(register multiple samples by uploading a
<a href="/base/files/auscope-sample-template.xlsx" class="custom-link">spreadsheet</a>
<a href="/base/files/auscope-sample-template-v3.xlsx" class="custom-link">spreadsheet</a>
)
</li>
</ul>
Expand All @@ -34,7 +34,7 @@ <h1 class="page-heading">{{ _("Quick Start") }}</h1>
<li>
<span class="badge">Start Batch Upload</span>
(register multiple samples by uploading a
<a href="/base/files/auscope-sample-template.xlsx" class="custom-link">spreadsheet</a>
<a href="/base/files/auscope-sample-template-v3.xlsx" class="custom-link">spreadsheet</a>
)
</li>
</ul>
Expand Down
8 changes: 5 additions & 3 deletions ckan/src/ckanext-igsn-theme/ckanext/igsn_theme/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ def process_excel(self, uploaded_file, org_id):
all_errors.extend(validate_related_resources(related_resources_df))
all_errors.extend(validate_parent_samples(samples_df))



samples_data, errors = prepare_samples_data(samples_df, authors_df, related_resources_df, funding_df, org_id)
all_errors.extend(errors)

if all_errors:
error_list = "\n".join(f"Error {i+1}. {error}. " for i, error in enumerate(all_errors))
# format the error list to be displayed in human readable format
formatted_errors = f"<pre style='white-space: pre-wrap;'>{error_list}</pre>"
raise ValueError(f"""The following errors were found:
{formatted_errors}""")

samples_data = prepare_samples_data(samples_df, authors_df, related_resources_df, funding_df, org_id)


return_value = {
"samples": samples_data,
"authors": authors_df.to_dict("records"),
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit c337a7d

Please sign in to comment.