Commit 2baa12cb authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

Merge branch 'master' of http://gitlab.sliit.lk/21_22-j-38/21_22j-38 into it18218640

parents 32e5fcca 28cba3bb
......@@ -161,9 +161,7 @@ def logout():
@app.route("/readingSession", methods=['POST'])
def reading_session():
req = request.get_json()
userId = req['userId']
token = save_session_details(userId, 1)
token = save_session_details(1)
response = {
"token": token,
"message": "Success",
......@@ -187,7 +185,7 @@ def reading_session_status_update(readingToken):
@app.route("/reading/<readingToken>", methods=['POST'])
def reading(readingToken):
def save_reading(readingToken):
assert readingToken == request.view_args['readingToken']
token = readingToken
req = request.get_json()
......@@ -205,4 +203,4 @@ def reading(readingToken):
if __name__ == "__main__":
app.run(host='192.168.1.100')
app.run(host='192.168.1.101')
......@@ -27,10 +27,10 @@ def save_activity_details(userId, word, token, level, triedCount):
return result
def save_session_details(userId, status):
def save_session_details(status):
token = getUUID()
qry = 'INSERT INTO readingSession (id,userId,token,status) VALUES (NULL, %s, %s, %s)'
args = (userId, token, status)
qry = 'INSERT INTO readingSession (id,token,status) VALUES (NULL, %s, %s)'
args = ( token, status)
insert(qry, args)
return token
......
......@@ -17,11 +17,24 @@ const ReadCategory = props => {
const navigation = useNavigation();
const checkReadingSession = () => {
AsyncStorage.getItem('readingSession')
.then(value => {
if (value == null) {
console.log('bfxcvbfvfdxv', value);
getReadingSession(value);
} else {
console.log('bfxcvbfvfdxv');
navigation.navigate(path);
}
})
.catch(error => {
console.log(error);
});
};
const getReadingSession = () => {
const data = {
userId: 1,
};
Client.post('readingSession', JSON.stringify(data), {
Client.post('readingSession', {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
......@@ -49,7 +62,7 @@ const ReadCategory = props => {
<View style={styles.gameItem}>
<TouchableOpacity
onPress={() => {
getReadingSession();
checkReadingSession();
}}>
<View>
{/* <View style={{...styles.gameItemRow, ...styles.gameItemHeader}}> */}
......
......@@ -74,6 +74,7 @@ const Login = () => {
};
const submitForm = () => {
AsyncStorage.setItem('userId', '1');
navigation.navigate('Start');
// if (isValidForm()) {
// loginFun(userInfo);
......@@ -100,7 +101,7 @@ const Login = () => {
const userToken = res.data.token;
const userId = res.data.userId;
AsyncStorage.setItem('userToken', userToken);
AsyncStorage.setItem('userId', userId);
AsyncStorage.setItem('userId', 1);
return navigation.navigate('Start');
}
})
......
......@@ -2,6 +2,6 @@ import axios from 'axios';
// export default axios.create({ baseURL: 'http://192.168.8.102:5000/', timeout: 15000, });
export default axios.create({
baseURL: 'http://192.168.1.100:5000/',
baseURL: 'http://192.168.1.101:5000/',
timeout: 15000,
});
......@@ -14,7 +14,7 @@ import {
TouchableHighlight,
} from 'react-native';
import Voice from '@react-native-voice/voice';
import {DummyReadResult} from '../../../assets/read/data/ReadData';
import {DummyReadResult, ImagePaths} from '../../../assets/read/data/ReadData';
import AudioRecord from 'react-native-audio-record';
import Client from '../../client/Client';
import AsyncStorage from '@react-native-async-storage/async-storage';
......@@ -24,7 +24,6 @@ export default function ReadActivityBird() {
// const userToken = Authorize();
const navigation = useNavigation();
const [error, setError] = useState('');
const [readingData, setReadingData] = useState({activity: ''});
// let user = AsyncStorage.getItem('readingSession');
// useEffect(() => {
......@@ -34,7 +33,6 @@ export default function ReadActivityBird() {
useEffect(() => {
Voice.onSpeechStart = onSpeechStartHandler;
Voice.onSpeechEnd = onSpeechEndHandler;
Voice.onSpeechResults = onSpeechResultsHandler;
Voice.onSpeechError = onSpeechError;
......@@ -75,16 +73,11 @@ export default function ReadActivityBird() {
console.log('start handler =>> ', e);
};
const onSpeechEndHandler = e => {
console.log('end handler =>> ', e);
};
const onSpeechResultsHandler = e => {
console.log('result handler =>> ', e);
};
const onSpeechError = e => {
setError(JSON.stringify(e.error));
const result = DummyReadResult.value;
const data = {
word: 'bird',
......
......@@ -15,40 +15,60 @@ import {
} from 'react-native';
import Voice from '@react-native-voice/voice';
import {DummyReadResult, ImagePaths} from '../../../assets/read/data/ReadData';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {Authorize} from '../../auth/AuthenticateUser';
import Client from '../../client/Client';
export default function ReadActivityNo() {
const navigation = useNavigation();
const [pitch, setPitch] = useState('');
const [error, setError] = useState('');
const [end, setEnd] = useState('');
const [started, setStarted] = useState('');
const [results, setResults] = useState([]);
const [partialResults, setPartialResults] = useState([]);
useEffect(() => {
Voice.destroy().then(Voice.removeAllListeners);
}, []);
const [readingData, setReadingData] = useState({
word: '',
userId: '',
level: 1,
triedCount: 1,
});
const [count, setCount] = useState(1);
useEffect(() => {
Voice.onSpeechStart = onSpeechStartHandler;
Voice.onSpeechEnd = onSpeechEndHandler;
Voice.onSpeechResults = onSpeechResultsHandler;
Voice.onSpeechError = onSpeechError;
Voice.onSpeechPartialResults = onSpeechPartialResults;
Voice.onSpeechVolumeChanged = onSpeechVolumeChanged;
return () => {
Voice.destroy().then(Voice.removeAllListeners);
};
}, []);
const onSpeechStartHandler = e => {
console.log('start handler =>> ', e);
const getToken = data => {
AsyncStorage.getItem('readingSession')
.then(readingSession => {
sendRedingData(data, readingSession);
})
.catch(error => {
console.log(error);
});
};
const onSpeechEndHandler = e => {
console.log('end handler =>> ', e);
const sendRedingData = (data, readingSession) => {
Client.post('reading/' + readingSession, JSON.stringify(data), {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
console.log(res.data);
// AsyncStorage.removeItem('readingSession');
navigation.navigate('ReadActivityGo');
})
.catch(error => {
console.log(error);
});
};
const onSpeechStartHandler = e => {
console.log('start handler =>> ', e);
};
const onSpeechResultsHandler = e => {
......@@ -57,23 +77,31 @@ export default function ReadActivityNo() {
const onSpeechError = e => {
console.log('onSpeechError: ', e);
setError(JSON.stringify(e.error));
const result = DummyReadResult.value;
if (result.includes('hello')) {
console.log('correct');
navigation.navigate('ReadActivityGo');
AsyncStorage.getItem('userId')
.then(userId => {
const data = {
word: 'no',
userId: userId,
level: 1,
triedCount: count,
};
console.log('correct', data);
getToken(data);
})
.catch(error => {
console.log(error);
});
} else {
setCount(count + 1);
Voice.start('en-US');
}
};
const onSpeechPartialResults = e => {
console.log('onSpeechPartialResults: ', e);
setPartialResults(e.value);
};
console.log('count', count);
const onSpeechVolumeChanged = e => {
console.log('onSpeechVolumeChanged: ', e);
setPitch(e.value);
console.log('count', count);
};
const startRecording = async () => {
......@@ -84,14 +112,6 @@ export default function ReadActivityNo() {
}
};
const stopRecording = async () => {
try {
await Voice.stop();
} catch (error) {
console.log(error);
}
};
return (
<SafeAreaView>
<View style={{flexDirection: 'column'}}>
......
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