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

App update 2.0.2 #856

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
07aff18
sample tree project id added
shyambhongle Oct 24, 2024
d96fb06
Edit option on Intervention Preview
shyambhongle Oct 24, 2024
7582caa
minor
shyambhongle Oct 24, 2024
35dcd7e
Icons updated
shyambhongle Oct 28, 2024
495db85
Merge pull request #855 from Plant-for-the-Planet-org/feature/edit
shyambhongle Oct 30, 2024
8e70768
build number upgraded
shyambhongle Dec 19, 2024
483fda5
validation and minor bug fixes
shyambhongle Dec 20, 2024
28315d6
Adaptive icon upgraded android
shyambhongle Dec 20, 2024
1be77b3
Zip package upgraded to latest
shyambhongle Dec 24, 2024
bcaebf8
Metadata changes
shyambhongle Dec 26, 2024
404fd76
Meta data key issue fix
shyambhongle Dec 26, 2024
91a89f9
Dropdown condition handled
shyambhongle Dec 26, 2024
abff22f
Merge branch 'bugfix/xcode-build-fix' into feature/translation
shyambhongle Dec 29, 2024
2920706
maplibre ios build fix
shyambhongle Dec 29, 2024
a51c797
patch removed(maplibre old version)
shyambhongle Dec 29, 2024
d19ab92
app.json updated for ios deployement target
shyambhongle Dec 30, 2024
d3de20f
Merge pull request #864 from Plant-for-the-Planet-org/bugfix/xcode-bu…
shyambhongle Dec 30, 2024
d3c65dc
Merge pull request #861 from Plant-for-the-Planet-org/hotfix/validation
shyambhongle Dec 30, 2024
0568d87
Missing Translations added
shyambhongle Dec 30, 2024
0a9f41e
Removed Unwanted GPS call
shyambhongle Dec 30, 2024
20a08d8
better error handling
shyambhongle Dec 30, 2024
d83223e
minor fix
shyambhongle Dec 31, 2024
d4164f3
Merge branch 'develop' into feature/translation
shyambhongle Dec 31, 2024
7c6faa2
build version incremeated
shyambhongle Dec 31, 2024
1f5a469
Image caching implemented
shyambhongle Dec 31, 2024
876e86e
Merge pull request #866 from Plant-for-the-Planet-org/feature/transla…
shyambhongle Jan 7, 2025
87a9b62
Point filters added in polygon layer's
shyambhongle Feb 1, 2025
dd28623
build version incremented
shyambhongle Feb 2, 2025
e95cb21
Merge pull request #880 from Plant-for-the-Planet-org/hotfix/maplibre…
shyambhongle Feb 26, 2025
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
Prev Previous commit
Next Next commit
validation and minor bug fixes
shyambhongle committed Dec 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 483fda54179528c2147ce74ec202af9eb34b7f6e
2 changes: 1 addition & 1 deletion src/components/home/ProjectModal.tsx
Original file line number Diff line number Diff line change
@@ -181,7 +181,7 @@ const ProjectModal = (props: Props) => {
)
try {
const parsedGeometry = JSON.parse(currentSiteData[0].geometry)
const newCoords = getRandomPointInPolygon(parsedGeometry.coordinates[0], 1)
const newCoords = getRandomPointInPolygon(parsedGeometry.coordinates[0])
const { geoJSON } = makeInterventionGeoJson('Point', [newCoords], 'sd')
const bounds = bbox(geoJSON)
dispatch(updateMapBounds({ bounds: bounds, key: 'DISPLAY_MAP' }))
2 changes: 1 addition & 1 deletion src/components/intervention/InterventionHeaderList.tsx
Original file line number Diff line number Diff line change
@@ -92,6 +92,6 @@ const styles = StyleSheet.create({
borderColor: Colors.GRAY_LIGHT,
borderRadius: 20,
borderWidth: 0.5,
marginRight:'1%'
marginRight:10
}
})
16 changes: 11 additions & 5 deletions src/screens/AddMeasurementView.tsx
Original file line number Diff line number Diff line change
@@ -66,7 +66,8 @@ const AddMeasurement = () => {
const handleHeightChange = (text: string) => {
setHeightErrorMessage('');
const regex = /^(?!0*(\.0+)?$)(\d+(\.\d+)?|\.\d+)$/;
const isValid = regex.test(text)
const finalText = text.replace(/,/g, '.');
const isValid = regex.test(finalText)
// Ensure there is at most one decimal point
if (isValid) {
setHeight(text);
@@ -84,7 +85,8 @@ const AddMeasurement = () => {
const handleDiameterChange = (text: string) => {
setWidthErrorMessage('');
const regex = /^(?!0*(\.0+)?$)(\d+(\.\d+)?|\.\d+)$/;
const isValid = regex.test(text)
const finalText = text.replace(/,/g, '.');
const isValid = regex.test(finalText)
if (isValid) {
setWidth(text);
} else {
@@ -97,7 +99,9 @@ const AddMeasurement = () => {


const onSubmit = () => {
const validationObject = measurementValidation(height, width, isNonISUCountry);
const updatedHeight = height.replace(/,/g, '.');
const updatedWidth = width.replace(/,/g, '.');
const validationObject = measurementValidation(updatedHeight, updatedWidth, isNonISUCountry);
const { diameterErrorMessage, heightErrorMessage, isRatioCorrect } = validationObject;
setHeightErrorMessage(heightErrorMessage)
setWidthErrorMessage(diameterErrorMessage)
@@ -141,6 +145,8 @@ const AddMeasurement = () => {
}

const submitDetails = async () => {
const updatedHeight = height.replace(/,/g, '.');
const updatedWidth = width.replace(/,/g, '.');
const { lat, long, accuracy } = getUserLocation()
const treeDetails: SampleTree = {
tree_id: id,
@@ -156,11 +162,11 @@ const AddMeasurement = () => {
cdn_image_url: '',
specie_name: SampleTreeData.current_species.scientificName,
specie_diameter: getConvertedDiameter(
width,
updatedWidth,
isNonISUCountry
),
specie_height: getConvertedHeight(
height,
updatedHeight,
isNonISUCountry
),
tag_id: tagId,
2 changes: 1 addition & 1 deletion src/screens/InterventionFormView.tsx
Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ const InterventionFormView = () => {
el => el.id === registerForm.site_id,
)
const parsedGeometry = JSON.parse(currentSiteData[0].geometry)
const newCoords = getRandomPointInPolygon(parsedGeometry.coordinates[0], 1)
const newCoords = getRandomPointInPolygon(parsedGeometry.coordinates[0])
return [newCoords]
}

14 changes: 8 additions & 6 deletions src/screens/ReviewTreeDetails.tsx
Original file line number Diff line number Diff line change
@@ -162,11 +162,12 @@ const ReviewTreeDetails = () => {
let hasError = false;

const handleHeightValidation = () => {
const updatedHeight = openEditModal.value.replace(/,/g, '.');
const regex = /^(?!0*(\.0+)?$)(\d+(\.\d+)?|\.\d+)$/;
const isValid = regex.test(openEditModal.value)
const isValid = regex.test(updatedHeight)
if (isValid) {
const validationObject = measurementValidation(
openEditModal.value,
updatedHeight,
treeDetails.specie_diameter,
isNonISUCountry,
);
@@ -179,7 +180,7 @@ const ReviewTreeDetails = () => {
hasError = true
} else {
finalDetails.specie_height = getConvertedHeight(
Number(openEditModal.value),
Number(updatedHeight),
isNonISUCountry
)
}
@@ -192,12 +193,13 @@ const ReviewTreeDetails = () => {
};

const handleDiameterValidation = () => {
const updatedWidth = openEditModal.value.replace(/,/g, '.');
const regex = /^(?!0*(\.0+)?$)(\d+(\.\d+)?|\.\d+)$/;
const isValid = regex.test(openEditModal.value)
const isValid = regex.test(updatedWidth)
if (isValid) {
const validationObject = measurementValidation(
treeDetails.specie_height,
openEditModal.value,
updatedWidth,
isNonISUCountry,
);
setInputErrorMessage(validationObject.diameterErrorMessage);
@@ -209,7 +211,7 @@ const ReviewTreeDetails = () => {
hasError = true
} else {
finalDetails.specie_diameter = getConvertedDiameter(
Number(openEditModal.value),
Number(updatedWidth),
isNonISUCountry
)
}
23 changes: 15 additions & 8 deletions src/screens/TreeRemeasurementView.tsx
Original file line number Diff line number Diff line change
@@ -134,6 +134,8 @@ const TreeRemeasurementView = () => {

const handleSkip = async () => {
setShowSkipModal(false)
const updatedHeight = height.replace(/,/g, '.');
const updatedWidth = width.replace(/,/g, '.');
const { lat, long } = getUserLocation()
const isWithin20m = isWithinRange(lat, long, treeDetails.latitude, treeDetails.longitude)
const param: History = {
@@ -143,11 +145,11 @@ const TreeRemeasurementView = () => {
imageUrl: imageUri,
cdnImageUrl: '',
diameter: isAlive ? getConvertedDiameter(
width,
updatedWidth,
isNonISUCountry,
) : treeDetails.specie_diameter,
height: isAlive ? getConvertedHeight(
height,
updatedHeight,
isNonISUCountry,
) : treeDetails.specie_height,
appMetadata: '',
@@ -193,11 +195,12 @@ const TreeRemeasurementView = () => {
const handleHeightChange = (text: string) => {
setHeightErrorMessage('');
const regex = /^(?!0*(\.0+)?$)(\d+(\.\d+)?|\.\d+)$/;
const isValid = regex.test(text)
const updatedHeight = text.replace(/,/g, '.');
const isValid = regex.test(updatedHeight)
// Ensure there is at most one decimal point
if (isValid) {
setHeight(text);
const convertedHeight = height ? getConvertedHeight(text, isNonISUCountry) : 0;
const convertedHeight = height ? getConvertedHeight(updatedHeight, isNonISUCountry) : 0;
if (convertedHeight < DBHInMeter) {
setDiameterLabel(i18next.t('label.measurement_basal_diameter'));
} else {
@@ -211,9 +214,10 @@ const TreeRemeasurementView = () => {
const handleDiameterChange = (text: string) => {
setWidthErrorMessage('');
const regex = /^(?!0*(\.0+)?$)(\d+(\.\d+)?|\.\d+)$/;
const isValid = regex.test(text)
const updatedWidth = text.replace(/,/g, '.');
const isValid = regex.test(updatedWidth)
if (isValid) {
setWidth(text);
setWidth(updatedWidth);
} else {
setWidthErrorMessage('Please provide the correct diameter.')
}
@@ -273,8 +277,11 @@ const TreeRemeasurementView = () => {
}

const submitHandler = async (gpsValidated?: boolean) => {
const finalHeight = height || treeDetails.specie_height
const finalWidth = width || treeDetails.specie_diameter
const updatedHeight = height.replace(/,/g, '.');
const updatedWidth = width.replace(/,/g, '.');

const finalHeight = updatedHeight || treeDetails.specie_height
const finalWidth = updatedWidth || treeDetails.specie_diameter
const { lat, long } = getUserLocation()
const isWithin20m = isWithinRange(lat, long, treeDetails.latitude, treeDetails.longitude)

79 changes: 35 additions & 44 deletions src/utils/helpers/generatePointInPolygon.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import seedrandom from 'seedrandom';


/**
* Generates a random point coordinate within a given polygon.
*
* @param {Array} polygon - An array of coordinate arrays representing the polygon.
* @param {number} index - An index to differentiate points for polygons with similar coordinates.
* @returns {Array} The random point coordinate [longitude, latitude].
*/
export const getRandomPointInPolygon = (polygon, index) => {
export const getRandomPointInPolygon = (polygon) => {
// Calculate the bounding box of the polygon
const bounds = polygon.reduce(
(prev, curr) => {
@@ -23,45 +20,39 @@ export const getRandomPointInPolygon = (polygon, index) => {
{ minLon: Infinity, maxLon: -Infinity, minLat: Infinity, maxLat: -Infinity }
);

// Create a seed based on the polygon's coordinates and the index
const seed = JSON.stringify(polygon) + index;
const rng = seedrandom(seed);

// Generate a random point within the bounding box
let randomPoint;
let isInPolygon = false;
while (!isInPolygon) {
const lon = bounds.minLon + rng() * (bounds.maxLon - bounds.minLon);
const lat = bounds.minLat + rng() * (bounds.maxLat - bounds.minLat);
randomPoint = [lon, lat];

// Check if the random point is within the polygon
isInPolygon = isPointInPolygon(randomPoint, polygon);
// Helper function to check if a point is inside the polygon
const isPointInPolygon = (point, polygon) => {
let inside = false;
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
const xi = polygon[i][0], yi = polygon[i][1];
const xj = polygon[j][0], yj = polygon[j][1];

const intersect = ((yi > point[1]) !== (yj > point[1]))
&& (point[0] < (xj - xi) * (point[1] - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}
return inside;
};

// Generate random points until we find one inside the polygon
let attempts = 0;
const maxAttempts = 1000; // Prevent infinite loop

while (attempts < maxAttempts) {
const randomLon = bounds.minLon + Math.random() * (bounds.maxLon - bounds.minLon);
const randomLat = bounds.minLat + Math.random() * (bounds.maxLat - bounds.minLat);

if (isPointInPolygon([randomLon, randomLat], polygon)) {
return [randomLon, randomLat, 0]; // Adding 0 for elevation to match input format
}

attempts++;
}

return randomPoint;

// If we couldn't find a point after max attempts, return center of bounding box
return [
(bounds.minLon + bounds.maxLon) / 2,
(bounds.minLat + bounds.maxLat) / 2,
0
];
};

/**
* Checks if a point is within a given polygon.
*
* @param {Array} point - The point coordinate [longitude, latitude].
* @param {Array} polygon - An array of coordinate arrays representing the polygon.
* @returns {boolean} True if the point is within the polygon, false otherwise.
*/
function isPointInPolygon(point, polygon) {
const [x, y] = point;
let isInside = false;

for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
const [x1, y1] = polygon[i];
const [x2, y2] = polygon[j];

const intersect =
y1 > y !== y2 > y && x < ((x2 - x1) * (y - y1)) / (y2 - y1) + x1;

if (intersect) isInside = !isInside;
}

return isInside;
}
Original file line number Diff line number Diff line change
@@ -200,6 +200,9 @@ const getEntireSiteCheck = (data: any) => {
if (typeof publicData === 'object' && publicData !== null && !Array.isArray(publicData)) {
for (const key in publicData) {
if (key == 'isEntireSite') { // optional: ensure the property is not inherited
if (publicData[key] === 'false' || publicData[key] === false) {
return false
}
return true
}
}