-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: soil ID algorithm service (#509)
- Loading branch information
Showing
8 changed files
with
484 additions
and
305 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright © 2024 Technology Matters | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
|
||
export const projectSoilSettings = /* GraphQL */ ` | ||
fragment projectSoilSettings on ProjectSoilSettingsNode { | ||
depthIntervals { | ||
depthInterval { | ||
start | ||
end | ||
} | ||
label | ||
} | ||
depthIntervalPreset | ||
soilPitRequired | ||
slopeRequired | ||
soilTextureRequired | ||
soilColorRequired | ||
verticalCrackingRequired | ||
carbonatesRequired | ||
phRequired | ||
soilOrganicCarbonMatterRequired | ||
electricalConductivityRequired | ||
sodiumAdsorptionRatioRequired | ||
soilStructureRequired | ||
landUseLandCoverRequired | ||
soilLimitationsRequired | ||
photosRequired | ||
notesRequired | ||
} | ||
`; | ||
|
||
export const soilData = /* GraphQL */ ` | ||
fragment soilData on SoilDataNode { | ||
downSlope | ||
crossSlope | ||
bedrock | ||
depthIntervalPreset | ||
slopeLandscapePosition | ||
slopeAspect | ||
slopeSteepnessSelect | ||
slopeSteepnessPercent | ||
slopeSteepnessDegree | ||
surfaceCracksSelect | ||
surfaceSaltSelect | ||
floodingSelect | ||
limeRequirementsSelect | ||
surfaceStoninessSelect | ||
waterTableDepthSelect | ||
soilDepthSelect | ||
landCoverSelect | ||
grazingSelect | ||
depthIntervals { | ||
...soilDataDepthInterval | ||
} | ||
depthDependentData { | ||
...depthDependentSoilData | ||
} | ||
} | ||
`; | ||
|
||
export const soilDataDepthInterval = /* GraphQL */ ` | ||
fragment soilDataDepthInterval on SoilDataDepthIntervalNode { | ||
label | ||
depthInterval { | ||
start | ||
end | ||
} | ||
soilTextureEnabled | ||
soilColorEnabled | ||
carbonatesEnabled | ||
phEnabled | ||
soilOrganicCarbonMatterEnabled | ||
electricalConductivityEnabled | ||
sodiumAdsorptionRatioEnabled | ||
soilStructureEnabled | ||
} | ||
`; | ||
|
||
export const depthDependentSoilData = /* GraphQL */ ` | ||
fragment depthDependentSoilData on DepthDependentSoilDataNode { | ||
depthInterval { | ||
start | ||
end | ||
} | ||
texture | ||
rockFragmentVolume | ||
clayPercent | ||
colorHue | ||
colorValue | ||
colorChroma | ||
colorPhotoUsed | ||
colorPhotoSoilCondition | ||
colorPhotoLightingCondition | ||
conductivity | ||
conductivityTest | ||
conductivityUnit | ||
structure | ||
ph | ||
phTestingSolution | ||
phTestingMethod | ||
soilOrganicCarbon | ||
soilOrganicMatter | ||
soilOrganicCarbonTesting | ||
soilOrganicMatterTesting | ||
sodiumAbsorptionRatio | ||
carbonates | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
/* | ||
* Copyright © 2024 Technology Matters | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
|
||
import { graphql } from 'terraso-client-shared/graphqlSchema'; | ||
import type { | ||
DepthDependentSoilDataUpdateMutationInput, | ||
ProjectSoilSettingsDeleteDepthIntervalMutationInput, | ||
ProjectSoilSettingsUpdateDepthIntervalMutationInput, | ||
ProjectSoilSettingsUpdateMutationInput, | ||
SoilDataDeleteDepthIntervalMutationInput, | ||
SoilDataUpdateDepthIntervalMutationInput, | ||
SoilDataUpdateMutationInput, | ||
} from 'terraso-client-shared/graphqlSchema/graphql'; | ||
import { collapseProjects } from 'terraso-client-shared/project/projectService'; | ||
import { collapseSites } from 'terraso-client-shared/site/siteService'; | ||
import * as terrasoApi from 'terraso-client-shared/terrasoApi/api'; | ||
import { | ||
collapseEdges, | ||
collapseMaps, | ||
} from 'terraso-client-shared/terrasoApi/utils'; | ||
|
||
export const fetchSoilDataForUser = async (userId: string) => { | ||
const query = graphql(` | ||
query userSoilData($id: ID!) { | ||
userSites: sites(owner: $id) { | ||
edges { | ||
node { | ||
...siteData | ||
soilData { | ||
...soilData | ||
} | ||
} | ||
} | ||
} | ||
projects: projects(member: $id) { | ||
edges { | ||
node { | ||
...projectData | ||
siteSet { | ||
edges { | ||
node { | ||
soilData { | ||
...soilData | ||
} | ||
} | ||
} | ||
} | ||
soilSettings { | ||
...projectSoilSettings | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
const { userSites, projects: allProjects } = await terrasoApi.requestGraphQL( | ||
query, | ||
{ id: userId }, | ||
); | ||
|
||
const { | ||
projects, | ||
sites: projectSites, | ||
users, | ||
} = collapseProjects(allProjects); | ||
const allSites = collapseEdges(userSites).concat( | ||
collapseEdges(allProjects).flatMap(({ siteSet }) => collapseEdges(siteSet)), | ||
); | ||
|
||
return { | ||
projects, | ||
users, | ||
projectSoilSettings: Object.fromEntries( | ||
collapseEdges(allProjects).map(({ soilSettings, id }) => [ | ||
id, | ||
soilSettings, | ||
]), | ||
), | ||
sites: collapseMaps(collapseSites(userSites), projectSites), | ||
soilData: Object.fromEntries( | ||
allSites.map(({ soilData, id }) => [id, soilData]), | ||
), | ||
}; | ||
}; | ||
|
||
export const updateSoilData = async (soilData: SoilDataUpdateMutationInput) => { | ||
const query = graphql(` | ||
mutation updateSoilData($input: SoilDataUpdateMutationInput!) { | ||
updateSoilData(input: $input) { | ||
soilData { | ||
...soilData | ||
} | ||
errors | ||
} | ||
} | ||
`); | ||
|
||
const resp = await terrasoApi.requestGraphQL(query, { input: soilData }); | ||
return resp.updateSoilData.soilData!; | ||
}; | ||
|
||
export const updateDepthDependentSoilData = async ( | ||
depthDependentData: DepthDependentSoilDataUpdateMutationInput, | ||
) => { | ||
const query = graphql(` | ||
mutation updateDepthDependentSoilData( | ||
$input: DepthDependentSoilDataUpdateMutationInput! | ||
) { | ||
updateDepthDependentSoilData(input: $input) { | ||
soilData { | ||
...soilData | ||
} | ||
errors | ||
} | ||
} | ||
`); | ||
|
||
const resp = await terrasoApi.requestGraphQL(query, { | ||
input: depthDependentData, | ||
}); | ||
|
||
return resp.updateDepthDependentSoilData.soilData!; | ||
}; | ||
|
||
export const updateSoilDataDepthInterval = async ( | ||
soilData: SoilDataUpdateDepthIntervalMutationInput, | ||
) => { | ||
const query = graphql(` | ||
mutation updateSoilDataDepthInterval( | ||
$input: SoilDataUpdateDepthIntervalMutationInput! | ||
) { | ||
updateSoilDataDepthInterval(input: $input) { | ||
soilData { | ||
...soilData | ||
} | ||
errors | ||
} | ||
} | ||
`); | ||
|
||
const resp = await terrasoApi.requestGraphQL(query, { input: soilData }); | ||
return resp.updateSoilDataDepthInterval.soilData!; | ||
}; | ||
|
||
export const deleteSoilDataDepthInterval = async ( | ||
soilData: SoilDataDeleteDepthIntervalMutationInput, | ||
) => { | ||
const query = graphql(` | ||
mutation deleteSoilDataDepthInterval( | ||
$input: SoilDataDeleteDepthIntervalMutationInput! | ||
) { | ||
deleteSoilDataDepthInterval(input: $input) { | ||
soilData { | ||
...soilData | ||
} | ||
errors | ||
} | ||
} | ||
`); | ||
|
||
const resp = await terrasoApi.requestGraphQL(query, { input: soilData }); | ||
return resp.deleteSoilDataDepthInterval.soilData!; | ||
}; | ||
|
||
export const updateProjectSoilSettings = async ( | ||
soilSettings: ProjectSoilSettingsUpdateMutationInput, | ||
) => { | ||
const query = graphql(` | ||
mutation updateProjectSoilSettings( | ||
$input: ProjectSoilSettingsUpdateMutationInput! | ||
) { | ||
updateProjectSoilSettings(input: $input) { | ||
projectSoilSettings { | ||
...projectSoilSettings | ||
} | ||
errors | ||
} | ||
} | ||
`); | ||
|
||
const resp = await terrasoApi.requestGraphQL(query, { input: soilSettings }); | ||
return resp.updateProjectSoilSettings.projectSoilSettings!; | ||
}; | ||
|
||
export const updateProjectDepthInterval = async ( | ||
depthInterval: ProjectSoilSettingsUpdateDepthIntervalMutationInput, | ||
) => { | ||
const query = graphql(` | ||
mutation updateProjectSoilSettingsDepthInterval( | ||
$input: ProjectSoilSettingsUpdateDepthIntervalMutationInput! | ||
) { | ||
updateProjectSoilSettingsDepthInterval(input: $input) { | ||
projectSoilSettings { | ||
...projectSoilSettings | ||
} | ||
errors | ||
} | ||
} | ||
`); | ||
|
||
const resp = await terrasoApi.requestGraphQL(query, { input: depthInterval }); | ||
return resp.updateProjectSoilSettingsDepthInterval.projectSoilSettings!; | ||
}; | ||
|
||
export const deleteProjectDepthInterval = async ( | ||
depthInterval: ProjectSoilSettingsDeleteDepthIntervalMutationInput, | ||
) => { | ||
const query = graphql(` | ||
mutation deleteProjectSoilSettingsDepthInterval( | ||
$input: ProjectSoilSettingsDeleteDepthIntervalMutationInput! | ||
) { | ||
deleteProjectSoilSettingsDepthInterval(input: $input) { | ||
projectSoilSettings { | ||
...projectSoilSettings | ||
} | ||
errors | ||
} | ||
} | ||
`); | ||
|
||
const resp = await terrasoApi.requestGraphQL(query, { input: depthInterval }); | ||
return resp.deleteProjectSoilSettingsDepthInterval.projectSoilSettings!; | ||
}; |
Oops, something went wrong.