Commit 3a2a1b3f authored by danushka9999's avatar danushka9999

drools dmn rules asset added

parent 2148534c
This source diff could not be displayed because it is too large. You can view the blob instead.
import React, { useState, useEffect } from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Animated } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import Carousel from 'react-native-snap-carousel';
//import Carousel from 'react-native-snap-carousel';
const BlinkingText = () => {
const [isBlinking, setIsBlinking] = useState(true);
......@@ -51,7 +51,7 @@ const NutrientSlider = ({ target_nutrient }) => {
return (
<View style={styles.container}>
<Text style={styles.heading}>Nutrient Select</Text>
<Carousel
{/* <Carousel
data={nutrientOptions}
renderItem={({ item }) => (
<TouchableOpacity
......@@ -70,7 +70,7 @@ const NutrientSlider = ({ target_nutrient }) => {
sliderWidth={300}
itemWidth={200}
loop
/>
/> */}
<BlinkingText />
</View>
);
......
......@@ -12,6 +12,7 @@ import mango from '../../assets/mango.jpeg';
import banana from '../../assets/banana.jpeg';
import blackgram from '../../assets/blackgram.jpeg';
import carrot from '../../assets/carrot.jpeg';
import Carrot from '../../assets/carrot.jpeg';
import chickpeas from '../../assets/chickpeas.jpeg';
import jute from '../../assets/jute.jpeg';
import kidneybeans from '../../assets/kidneybeans.jpeg';
......@@ -23,6 +24,14 @@ import muskmelon from '../../assets/muskmelon.webp';
import papaya from '../../assets/papaya.webp';
import pigeonpeas from '../../assets/pigeonpeas.jpeg';
import watermelon from '../../assets/watermelon.jpeg';
import Beans from '../../assets/Beans.jpg';
import Raddish from '../../assets/Radish.jpg';
import Cabbage from '../../assets/Cabbage.jpg';
import Capsicum from '../../assets/Capsicum.jpg';
import Cucumber from '../../assets/Cucumber.jpg';
import Beet from '../../assets/Beet.jpg';
import Lettuce from '../../assets/Lettuce.jpg'
const cropImages = {
Soybean,
......@@ -49,7 +58,17 @@ const cropImages = {
muskmelon,
papaya,
pigeonpeas,
watermelon
watermelon,
Beans,
Raddish,
Cabbage,
Carrot,
Capsicum,
Cucumber,
Beet,
Lettuce
};
export default cropImages;
......
......@@ -11,7 +11,6 @@ const CreateCropRotaionPlan = ({ navigation }) => {
const [pestAttack, setPestAttack] = useState('');
const [years, setYears] = useState('');
const [selectedCrops, setSelectedCrops] = useState('');
const [iotData, setIotData] = useState('');
const [validationError, setValidationError] = useState('');
const validateFields = () => {
......@@ -23,44 +22,45 @@ const CreateCropRotaionPlan = ({ navigation }) => {
return true;
};
const handleFetchFromIOT = async () => {
try {
const response = await axios.get('http://192.168.227.241');
setIotData(response.data); // Assuming the API response contains NPK values
// Update the state values with the fetched data
setNitrogen(iotData.Nitrogen);
setPhosphorus(iotData.Phosphorus);
setPotassium(iotData.Potassium);
} catch (error) {
console.error('Error fetching data from IOT sensor:', error);
}
};
const handleSubmit = () => {
if (validateFields()) {
// Create a payload object with the user input data
const payload = {
nitrogen,
phosphorus,
potassium,
district,
previousCropFamily,
pestAttack,
years,
selectedCrops,
'model-namespace': 'https://kiegroup.org/dmn/_25F99D3F-9E8D-416E-ACE9-DF17C399813F',
'model-name': 'Crop-Rotation-PlannerDMN',
'dmn-context': {
Data: {
Nitrogen: parseInt(nitrogen),
Potassium: parseInt(potassium),
Phosphorus: parseInt(phosphorus),
District: district,
PreviousCropFamily: previousCropFamily,
PreviousPestAttck: pestAttack,
NoOfYears: parseInt(years),
PreferedCropFamily: selectedCrops,
},
},
};
// Send a POST request to your API with the payload
axios.post('YOUR_API_ENDPOINT_HERE', payload)
axios
.post('http://localhost:8180/kie-server/services/rest/server/containers/crop-rotation-planner/dmn', payload, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
auth: {
username: 'kieserver',
password: 'kieserver1!',
},
})
.then((response) => {
// Handle success, e.g., navigate to the next screen
navigation.navigate('NextScreen', { response });
navigation.navigate('Crop Rotation Plan', { response });
})
.catch((error) => {
console.error('Error submitting data:', error);
});
}
};
return (
<ImageBackground source={require('../../assets/backgroudManualData.jpg')} style={styles.backgroundImage}>
......@@ -90,10 +90,6 @@ const CreateCropRotaionPlan = ({ navigation }) => {
onChangeText={(text) => setPotassium(text)}
/>
<TouchableOpacity onPress={handleFetchFromIOT} style={styles.button}>
<Text style={styles.buttonText}>Fetch from IOT Sensor</Text>
</TouchableOpacity>
<Picker
style={styles.input}
selectedValue={district}
......@@ -109,7 +105,7 @@ const CreateCropRotaionPlan = ({ navigation }) => {
onValueChange={(itemValue) => setPreviousCropFamily(itemValue)}
>
<Picker.Item label="Select Previous Crop Family" value="" />
<Picker.Item label="RootCrops" value="RootsCrops" />
<Picker.Item label="RootCrops" value="Roots Crops" />
<Picker.Item label="Vegetables" value="Vegetables" />
</Picker>
......@@ -138,8 +134,8 @@ const CreateCropRotaionPlan = ({ navigation }) => {
selectedValue={selectedCrops}
onValueChange={(itemValue) => setSelectedCrops(itemValue)}
>
<Picker.Item label="Select Most Preferd Crop Family" value="" />
<Picker.Item label="RootCrops" value="RootCrops" />
<Picker.Item label="Select Most Preferred Crop Family" value="" />
<Picker.Item label="RootCrops" value="Root Crops" />
<Picker.Item label="Vegetables" value="Vegetables" />
</Picker>
......
......@@ -5,45 +5,75 @@ import cropImages from '../common/Images';
const CropRotationResponse = ({ route }) => {
const { response } = route.params;
return (
<View style={styles.container}>
<Text style={styles.heading}>Crop Rotation Plan</Text>
<FlatList
data={response.cropsToGrow}
keyExtractor={(item) => item.cropName}
renderItem={({ item }) => (
<View style={styles.cropItem}>
<Image
style={styles.cropImage}
source={cropImages[item.cropName]}
/>
<Text style={styles.cropName}>{item.cropName}</Text>
<Text style={styles.year}>{item.year}</Text>
<Text style={styles.year}>{item.Sequence}</Text>
</View>
)}
/>
</View>
);
};
if (response.data.result['dmn-evaluation-result']['dmn-context'].IsPossiibleToProceedWithCropRotationPlan !== null) {
let cropList = Object.keys(response.data.result['dmn-evaluation-result']['dmn-context'])
.filter((key) => key.startsWith('Crop'))
.map((key) => response.data.result['dmn-evaluation-result']['dmn-context'][key])
.filter((crop) => crop !== null);
export default CropRotationResponse;
cropList.sort((a, b) => {
if (a.Year === b.Year) {
return a.YearSequence - b.YearSequence;
}
return a.Year - b.Year;
});
return (
<View style={styles.container}>
<Text style={styles.heading}>Crop Rotation Plan</Text>
<FlatList
data={cropList}
keyExtractor={(item) => item.Crop}
renderItem={({ item }) => (
<View style={styles.cropItem}>
<Image style={styles.cropImage} source={cropImages[item.Crop]} />
<View style={styles.cropInfo}>
<Text style={styles.cropName}>{item.Crop}</Text>
<Text style={styles.cropDetail}>Family: {item.CropFamily}</Text>
<Text style={styles.cropDetail}>Growth: {item.GrowthPeriod}</Text>
<Text style={styles.cropDetail}>Sequence: {item.YearSequence}</Text>
</View>
</View>
)}
/>
</View>
);
} else {
return (
<View style={styles.container}>
<Text style={styles.message}>
The N, P, K values are not at the standard level to grow the preferred crop. Please check the crop rotation page for more information.
</Text>
</View>
);
}
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f9f9f9',
padding: 20,
},
heading: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 20,
},
message: {
fontSize: 18,
textAlign: 'center',
margin: 20,
},
cropItem: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#ffffff',
borderRadius: 10,
marginBottom: 10,
padding: 10,
},
cropImage: {
width: 50,
......@@ -51,13 +81,17 @@ const styles = StyleSheet.create({
marginRight: 10,
borderRadius: 5,
},
cropName: {
fontSize: 16,
fontWeight: 'bold',
cropInfo: {
flex: 1,
},
year: {
cropName: {
fontSize: 16,
fontWeight: 'bold',
},
cropDetail: {
fontSize: 14,
color: '#444',
},
});
export default CropRotationResponse;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment