Commit 28cba3bb authored by Lihinikaduwa D.N.R.  's avatar Lihinikaduwa D.N.R.

Merge branch 'it18257632' into 'master'

It18257632

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