Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMSBIOHUB-451: Recognize 'Species' column in uploaded observation CSV #1196

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
7 changes: 4 additions & 3 deletions api/src/services/observation-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import { DBService } from './db-service';
const defaultLog = getLogger('services/observation-service');

const observationCSVColumnValidator: IXLSXCSVValidator = {
columnNames: ['SPECIES_TAXONOMIC_ID', 'COUNT', 'DATE', 'TIME', 'LATITUDE', 'LONGITUDE'],
columnNames: ['SPECIES', 'COUNT', 'DATE', 'TIME', 'LATITUDE', 'LONGITUDE'],
columnTypes: ['number', 'number', 'date', 'string', 'number', 'number'],
columnAliases: {
LATITUDE: ['LAT'],
LONGITUDE: ['LON', 'LONG', 'LNG']
LONGITUDE: ['LON', 'LONG', 'LNG'],
SPECIES: ['TAXON']
}
};

Expand Down Expand Up @@ -278,7 +279,7 @@ export class ObservationService extends DBService {
// Step 5. Merge all the table rows into an array of ObservationInsert[]
const insertRows: InsertObservation[] = worksheetRowObjects.map((row) => ({
survey_id: surveyId,
wldtaxonomic_units_id: row['SPECIES_TAXONOMIC_ID'],
wldtaxonomic_units_id: row['SPECIES'],
survey_sample_site_id: null,
survey_sample_method_id: null,
survey_sample_period_id: null,
Expand Down
11 changes: 6 additions & 5 deletions api/src/utils/xlsx-utils/worksheet-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ describe('worksheet utils', () => {

it('should validate aliases', () => {
const observationCSVColumnValidator: worksheet_utils.IXLSXCSVValidator = {
columnNames: ['SPECIES_TAXONOMIC_ID', 'COUNT', 'DATE', 'TIME', 'LATITUDE', 'LONGITUDE'],
columnNames: ['SPECIES', 'COUNT', 'DATE', 'TIME', 'LATITUDE', 'LONGITUDE'],
columnTypes: ['number', 'number', 'date', 'string', 'number', 'number'],
columnAliases: {
LATITUDE: ['LAT'],
LONGITUDE: ['LON', 'LONG', 'LNG']
LONGITUDE: ['LON', 'LONG', 'LNG'],
SPECIES: ['TAXON']
}
};

const mockWorksheet = ({} as unknown) as xlsx.WorkSheet;

const getWorksheetHeaderssStub = sinon
.stub(worksheet_utils, 'getWorksheetHeaders')
.callsFake(() => ['SPECIES_TAXONOMIC_ID', 'COUNT', 'DATE', 'TIME', 'LAT', 'LON']);
.callsFake(() => ['TAXON', 'COUNT', 'DATE', 'TIME', 'LAT', 'LON']);

const result = worksheet_utils.validateWorksheetHeaders(mockWorksheet, observationCSVColumnValidator);

Expand All @@ -34,7 +35,7 @@ describe('worksheet utils', () => {

it('should fail for unknown aliases', () => {
const observationCSVColumnValidator: worksheet_utils.IXLSXCSVValidator = {
columnNames: ['SPECIES_TAXONOMIC_ID', 'COUNT', 'DATE', 'TIME', 'LATITUDE', 'LONGITUDE'],
columnNames: ['SPECIES', 'COUNT', 'DATE', 'TIME', 'LATITUDE', 'LONGITUDE'],
columnTypes: ['number', 'number', 'date', 'string', 'number', 'number'],
columnAliases: {
LATITUDE: ['LAT'],
Expand All @@ -46,7 +47,7 @@ describe('worksheet utils', () => {

const getWorksheetHeaderssStub = sinon
.stub(worksheet_utils, 'getWorksheetHeaders')
.callsFake(() => ['SPECIES_TAXONOMIC_ID', 'COUNT', 'DATE', 'TIME', 'SOMETHING_LAT', 'LON']);
.callsFake(() => ['SPECIES', 'COUNT', 'DATE', 'TIME', 'SOMETHING_LAT', 'LON']);

const result = worksheet_utils.validateWorksheetHeaders(mockWorksheet, observationCSVColumnValidator);

Expand Down
Loading