Skip to content

Commit

Permalink
Merge branch 'development' into forestgeo-app-development
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshraze committed Nov 26, 2024
2 parents 73e5017 + d234406 commit b6d3a47
Show file tree
Hide file tree
Showing 24 changed files with 1,188 additions and 925 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ permissions:
pages: write

env:
INSTANCE: 'Writerside/fad' # Use the Writerside instance ID as specified in your writerside.cfg
ARTIFACT: 'webHelpFAD-all.zip' # Update artifact name if needed
INSTANCE: 'documentation/fad'
ARTIFACT: 'webHelpFAD2-all.zip'
DOCKER_VERSION: '243.21565' # Writerside's recommended Docker version

jobs:
Expand All @@ -34,8 +34,13 @@ jobs:
instance: ${{ env.INSTANCE }}
artifact: ${{ env.ARTIFACT }}
docker-version: ${{ env.DOCKER_VERSION }}
args: --verbose

# Step 3: Save build results
# Debug: List artifacts directory
- name: List artifacts directory
run: ls -la artifacts/

# Step 3: Save artifact with build results
- name: Save artifact with build results
uses: actions/upload-artifact@v4
with:
Expand Down
94 changes: 11 additions & 83 deletions frontend/app/api/fixeddata/[dataType]/[[...slugs]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ export async function GET(
}
): Promise<NextResponse<{ output: any[]; deprecated?: any[]; totalCount: number; finishedQuery: string }>> {
if (!params.slugs || params.slugs.length < 5) throw new Error('slugs not received.');
const [schema, pageParam, pageSizeParam, plotIDParam, plotCensusNumberParam, quadratIDParam, speciesIDParam] = params.slugs;
const [schema, pageParam, pageSizeParam, plotIDParam, plotCensusNumberParam, speciesIDParam] = params.slugs;
if (!schema || schema === 'undefined' || !pageParam || pageParam === 'undefined' || !pageSizeParam || pageSizeParam === 'undefined')
throw new Error('core slugs schema/page/pageSize not correctly received');
const page = parseInt(pageParam);
const pageSize = parseInt(pageSizeParam);
const plotID = plotIDParam ? parseInt(plotIDParam) : undefined;
const plotCensusNumber = plotCensusNumberParam ? parseInt(plotCensusNumberParam) : undefined;
const quadratID = quadratIDParam ? parseInt(quadratIDParam) : undefined;
const speciesID = speciesIDParam ? parseInt(speciesIDParam) : undefined;

const connectionManager = new ConnectionManager();
let updatedMeasurementsExist = false;
let censusIDs;
let pastCensusIDs: string | any[];

try {
let paginatedQuery = ``;
Expand Down Expand Up @@ -92,63 +89,13 @@ export async function GET(
WHERE c.PlotID = ? AND c.PlotCensusNumber = ? LIMIT ?, ?;`;
queryParams.push(plotID, plotCensusNumber, page * pageSize, pageSize);
break;
case 'measurementssummary':
case 'measurementssummary_staging':
case 'measurementssummaryview':
case 'viewfulltable':
case 'viewfulltableview':
paginatedQuery = `
SELECT SQL_CALC_FOUND_ROWS vft.*
FROM ${schema}.${params.dataType} vft
JOIN ${schema}.census c ON vft.PlotID = c.PlotID AND vft.CensusID = c.CensusID
WHERE vft.PlotID = ?
AND c.PlotID = ?
AND c.PlotCensusNumber = ?
ORDER BY vft.MeasurementDate ASC LIMIT ?, ?;`;
queryParams.push(plotID, plotID, plotCensusNumber, page * pageSize, pageSize);
break;
case 'census':
paginatedQuery = `
SELECT SQL_CALC_FOUND_ROWS *
FROM ${schema}.census
WHERE PlotID = ? LIMIT ?, ?`;
queryParams.push(plotID, page * pageSize, pageSize);
break;
case 'coremeasurements':
// Retrieve multiple past CensusID for the given PlotCensusNumber
const censusQuery = `
SELECT CensusID
FROM ${schema}.census
WHERE PlotID = ?
AND PlotCensusNumber = ?
ORDER BY StartDate DESC LIMIT 30
`;
const censusResults = await connectionManager.executeQuery(format(censusQuery, [plotID, plotCensusNumber]));
if (censusResults.length < 2) {
paginatedQuery = `
SELECT SQL_CALC_FOUND_ROWS pdt.*
FROM ${schema}.${params.dataType} pdt
JOIN ${schema}.census c ON pdt.CensusID = c.CensusID
WHERE c.PlotID = ?
AND c.PlotCensusNumber = ?
ORDER BY pdt.MeasurementDate LIMIT ?, ?`;
queryParams.push(plotID, plotCensusNumber, page * pageSize, pageSize);
break;
} else {
updatedMeasurementsExist = true;
censusIDs = censusResults.map((c: any) => c.CensusID);
pastCensusIDs = censusIDs.slice(1);
// Query to fetch paginated measurements from measurementssummaryview
paginatedQuery = `
SELECT SQL_CALC_FOUND_ROWS pdt.*
FROM ${schema}.${params.dataType} pdt
JOIN ${schema}.census c ON sp.CensusID = c.CensusID
WHERE c.PlotID = ?
AND c.CensusID IN (${censusIDs.map(() => '?').join(', ')})
ORDER BY pdt.MeasurementDate ASC LIMIT ?, ?`;
queryParams.push(plotID, ...censusIDs, page * pageSize, pageSize);
break;
}
default:
throw new Error(`Unknown dataType: ${params.dataType}`);
}
Expand All @@ -163,34 +110,15 @@ export async function GET(
const totalRowsResult = await connectionManager.executeQuery(totalRowsQuery);
const totalRows = totalRowsResult[0].totalRows;

if (updatedMeasurementsExist) {
// Separate deprecated and non-deprecated rows
const deprecated = paginatedResults.filter((row: any) => pastCensusIDs.includes(row.CensusID));

// Ensure deprecated measurements are duplicates
const uniqueKeys = ['PlotID', 'QuadratID', 'TreeID', 'StemID']; // Define unique keys that should match
const outputKeys = paginatedResults.map((row: any) => uniqueKeys.map(key => row[key]).join('|'));
const filteredDeprecated = deprecated.filter((row: any) => outputKeys.includes(uniqueKeys.map(key => row[key]).join('|')));
return new NextResponse(
JSON.stringify({
output: MapperFactory.getMapper<any, any>(params.dataType).mapData(paginatedResults),
deprecated: MapperFactory.getMapper<any, any>(params.dataType).mapData(filteredDeprecated),
totalCount: totalRows,
finishedQuery: format(paginatedQuery, queryParams)
}),
{ status: HTTPResponses.OK }
);
} else {
return new NextResponse(
JSON.stringify({
output: MapperFactory.getMapper<any, any>(params.dataType).mapData(paginatedResults),
deprecated: undefined,
totalCount: totalRows,
finishedQuery: format(paginatedQuery, queryParams)
}),
{ status: HTTPResponses.OK }
);
}
return new NextResponse(
JSON.stringify({
output: MapperFactory.getMapper<any, any>(params.dataType).mapData(paginatedResults),
deprecated: undefined,
totalCount: totalRows,
finishedQuery: format(paginatedQuery, queryParams)
}),
{ status: HTTPResponses.OK }
);
} catch (error: any) {
throw new Error(error);
} finally {
Expand Down
Loading

0 comments on commit b6d3a47

Please sign in to comment.