Commit 4b0e7a6a authored by Lihinikaduwa D.N.R.  's avatar Lihinikaduwa D.N.R.

basic acivity completed

parent b66bac08
...@@ -3,7 +3,8 @@ from flask import Flask, render_template, request, jsonify, make_response ...@@ -3,7 +3,8 @@ from flask import Flask, render_template, request, jsonify, make_response
from API.model.color.colorModel import save_color_session_details, sendPredictData from API.model.color.colorModel import save_color_session_details, sendPredictData
from API.model.readModel import save_activity_details, save_session_details from API.model.readModel import save_activity_details, save_session_details
from API.model.userModel import getUser, saveUserSession, logoutUser from API.model.userModel import getUser, saveUserSession, logoutUser
from API.model.color.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result, storeResult, save_color_session_details from API.model.color.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result, \
storeResult, save_color_session_details
from flask import Flask, redirect, url_for, render_template, request, jsonify, make_response from flask import Flask, redirect, url_for, render_template, request, jsonify, make_response
import random import random
import os import os
...@@ -73,11 +74,8 @@ def predict(): ...@@ -73,11 +74,8 @@ def predict():
print(ValueError) print(ValueError)
@app.route("/colorSession", methods=['POST']) @app.route("/colorSession", methods=['POST'])
def color_session(): def color_session():
token = save_color_session_details(1) token = save_color_session_details(1)
response = { response = {
"token": token, "token": token,
...@@ -166,7 +164,7 @@ def reading_session(userId): ...@@ -166,7 +164,7 @@ def reading_session(userId):
return make_response(body) return make_response(body)
@app.route("/readingSession/<userId>", methods=['PUT']) @app.route("/readingSession/<readingToken>", methods=['PUT'])
def reading_session_status_update(readingToken): def reading_session_status_update(readingToken):
assert readingToken == request.view_args['readingToken'] assert readingToken == request.view_args['readingToken']
token = readingToken token = readingToken
...@@ -201,6 +199,7 @@ def get_completed_levels(userId): ...@@ -201,6 +199,7 @@ def get_completed_levels(userId):
assert userId == request.view_args['userId'] assert userId == request.view_args['userId']
level = get_completed_levels_by_user(userId) level = get_completed_levels_by_user(userId)
x = level[0] x = level[0]
if(len(level) >= 2):
y = level[1] y = level[1]
response = { response = {
"level1": x[0], "level1": x[0],
...@@ -213,4 +212,4 @@ def get_completed_levels(userId): ...@@ -213,4 +212,4 @@ def get_completed_levels(userId):
if __name__ == "__main__": if __name__ == "__main__":
app.run(host='192.168.8.100') app.run(host='192.168.1.101')
...@@ -12,7 +12,7 @@ def create_con(): ...@@ -12,7 +12,7 @@ def create_con():
database="helply", database="helply",
host="127.0.0.1", host="127.0.0.1",
user="root", user="root",
password="rp19970520" password="12345678"
) )
return db return db
......
...@@ -41,5 +41,5 @@ def update_session_status(token): ...@@ -41,5 +41,5 @@ def update_session_status(token):
def get_completed_levels_by_user(userId): def get_completed_levels_by_user(userId):
qry = 'SELECT level FROM readingSession WHERE userId = "{}"'.format(userId) qry = 'SELECT status FROM readingSession WHERE userId = "{}"'.format(userId)
return get_data(qry) return get_data(qry)
...@@ -25,8 +25,8 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; ...@@ -25,8 +25,8 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import Client from './client/Client'; import Client from './client/Client';
export default function Read() { export default function Read() {
const [level1, setLevel1] = useState([]); const [level1, setLevel1] = useState(0);
const [level2, setLevel2] = useState([]); const [level2, setLevel2] = useState(0);
const navigation = useNavigation(); const navigation = useNavigation();
...@@ -42,34 +42,33 @@ export default function Read() { ...@@ -42,34 +42,33 @@ export default function Read() {
return unsubscribe; return unsubscribe;
}, [navigation]); }, [navigation]);
useEffect(() => { // useEffect(() => {
getCompletedLevel(); // getCompletedLevel();
// }, [navigation]);
}, [navigation]); // const getCompletedLevel = () => {
const getCompletedLevel = () => { // AsyncStorage.getItem('userId')
AsyncStorage.getItem('userId') // .then(value => {
.then(value => { // Client.get('level/' + value, {
Client.get('level/' + value, { // headers: {
headers: { // Accept: 'application/json',
Accept: 'application/json', // 'Content-Type': 'application/json',
'Content-Type': 'application/json', // },
}, // })
}) // .then(res => {
.then(res => { // console.log(res.data);
console.log(res.data); // setLevel1(res.data.level1);
setLevel1(res.data.level1); // setLevel2(res.data.level2);
setLevel2(res.data.level2); // })
// .catch(error => {
}) // console.log(error);
.catch(error => { // });
console.log(error); // })
}); // .catch(error => {
}) // console.log(error);
.catch(error => { // });
console.log(error); // console.log('getCompletedLevel', level1, level2);
}); // };
console.log('getCompletedLevel', level1, level2);
};
return ( return (
<SafeAreaView> <SafeAreaView>
...@@ -88,16 +87,25 @@ export default function Read() { ...@@ -88,16 +87,25 @@ export default function Read() {
image={ImagePaths.roundOne} image={ImagePaths.roundOne}
path={'ReadActivityNo'} path={'ReadActivityNo'}
/> />
{level1 == 0 && (
<>
<ReadCategory <ReadCategory
title={'Advanced'} title={'Advanced'}
image={ImagePaths.roundTwo} image={ImagePaths.roundTwo}
path={'ReadActivityBird'} path={'ReadActivityBird'}
/> />
</>
)}
{level2 == 0 && (
<>
<ReadCategory <ReadCategory
title={'Result & Summery'} title={'Result & Summery'}
image={ImagePaths.summery} image={ImagePaths.summery}
path={'ReadActivity'} path={'ReadActivity'}
/> />
</>
)}
</TouchableOpacity> </TouchableOpacity>
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
......
...@@ -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.8.100:5000/', baseURL: 'http://192.168.1.101:5000/',
timeout: 15000, timeout: 15000,
}); });
...@@ -15,16 +15,14 @@ import { ...@@ -15,16 +15,14 @@ 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 ReadActivityGo() { export default function ReadActivityGo() {
const navigation = useNavigation(); const navigation = useNavigation();
const [pitch, setPitch] = useState(''); const [count, setCount] = useState(1);
const [error, setError] = useState('');
const [end, setEnd] = useState('');
const [started, setStarted] = useState('');
const [results, setResults] = useState([]);
const [partialResults, setPartialResults] = useState([]);
useEffect(() => { useEffect(() => {
Voice.destroy().then(Voice.removeAllListeners); Voice.destroy().then(Voice.removeAllListeners);
...@@ -32,23 +30,31 @@ export default function ReadActivityGo() { ...@@ -32,23 +30,31 @@ export default function ReadActivityGo() {
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 sendRedingData = (data, readingSession) => {
console.log('start handler =>> ', e); Client.post('reading/' + readingSession, JSON.stringify(data), {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
navigation.navigate('ReadActivityHe');
})
.catch(error => {
console.log(error);
});
}; };
const onSpeechEndHandler = e => { const onSpeechStartHandler = e => {
console.log('end handler =>> ', e); console.log('start handler =>> ', e);
}; };
const onSpeechResultsHandler = e => { const onSpeechResultsHandler = e => {
...@@ -57,23 +63,38 @@ export default function ReadActivityGo() { ...@@ -57,23 +63,38 @@ export default function ReadActivityGo() {
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('ReadActivityHe'); .then(userId => {
} const data = {
word: 'go',
userId: userId,
level: 1,
triedCount: count,
}; };
getToken(data);
})
.catch(error => {
console.log(error);
});
} else {
setCount(count + 1);
Voice.start('en-US');
}
console.log('count', count);
const onSpeechPartialResults = e => { console.log('count', count);
console.log('onSpeechPartialResults: ', e);
setPartialResults(e.value);
}; };
const onSpeechVolumeChanged = e => { const getToken = data => {
console.log('onSpeechVolumeChanged: ', e); AsyncStorage.getItem('readingSession')
setPitch(e.value); .then(readingSession => {
sendRedingData(data, readingSession);
})
.catch(error => {
console.log(error);
});
}; };
const startRecording = async () => { const startRecording = async () => {
...@@ -100,6 +121,7 @@ export default function ReadActivityGo() { ...@@ -100,6 +121,7 @@ export default function ReadActivityGo() {
<Text style={styles.text}>Pronounce this Word!</Text> <Text style={styles.text}>Pronounce this Word!</Text>
</View> </View>
</View> </View>
<View> <View>
<Image style={styles.blackboard} source={ImagePaths.go}></Image> <Image style={styles.blackboard} source={ImagePaths.go}></Image>
</View> </View>
......
...@@ -15,16 +15,14 @@ import { ...@@ -15,16 +15,14 @@ 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 ReadActivityHe() { export default function ReadActivityHe() {
const navigation = useNavigation(); const navigation = useNavigation();
const [pitch, setPitch] = useState(''); const [count, setCount] = useState(1);
const [error, setError] = useState('');
const [end, setEnd] = useState('');
const [started, setStarted] = useState('');
const [results, setResults] = useState([]);
const [partialResults, setPartialResults] = useState([]);
useEffect(() => { useEffect(() => {
Voice.destroy().then(Voice.removeAllListeners); Voice.destroy().then(Voice.removeAllListeners);
...@@ -32,23 +30,49 @@ export default function ReadActivityHe() { ...@@ -32,23 +30,49 @@ export default function ReadActivityHe() {
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 sendRedingData = (data, readingSession) => {
console.log('start handler =>> ', e); Client.post('reading/' + readingSession, JSON.stringify(data), {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
updateReadingSession(readingSession);
})
.catch(error => {
console.log(error);
});
}; };
const onSpeechEndHandler = e => { const updateReadingSession = readingSession => {
console.log('end handler =>> ', e); console.log('fuck');
Client.put('readingSession/' + readingSession, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
AsyncStorage.removeItem('readingSession');
alert('Basic Level Completed');
navigation.navigate('Read');
})
.catch(error => {
console.log(error);
});
};
const onSpeechStartHandler = e => {
console.log('start handler =>> ', e);
}; };
const onSpeechResultsHandler = e => { const onSpeechResultsHandler = e => {
...@@ -57,23 +81,38 @@ export default function ReadActivityHe() { ...@@ -57,23 +81,38 @@ export default function ReadActivityHe() {
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('ReadActivityHe'); .then(userId => {
} const data = {
word: 'he',
userId: userId,
level: 1,
triedCount: count,
}; };
getToken(data);
})
.catch(error => {
console.log(error);
});
} else {
setCount(count + 1);
Voice.start('en-US');
}
console.log('count', count);
const onSpeechPartialResults = e => { console.log('count', count);
console.log('onSpeechPartialResults: ', e);
setPartialResults(e.value);
}; };
const onSpeechVolumeChanged = e => { const getToken = data => {
console.log('onSpeechVolumeChanged: ', e); AsyncStorage.getItem('readingSession')
setPitch(e.value); .then(readingSession => {
sendRedingData(data, readingSession);
})
.catch(error => {
console.log(error);
});
}; };
const startRecording = async () => { const startRecording = async () => {
...@@ -84,14 +123,6 @@ export default function ReadActivityHe() { ...@@ -84,14 +123,6 @@ export default function ReadActivityHe() {
} }
}; };
const stopRecording = async () => {
try {
await Voice.stop();
} catch (error) {
console.log(error);
}
};
return ( return (
<SafeAreaView> <SafeAreaView>
<View style={{flexDirection: 'column'}}> <View style={{flexDirection: 'column'}}>
......
...@@ -22,12 +22,6 @@ import Client from '../../client/Client'; ...@@ -22,12 +22,6 @@ import Client from '../../client/Client';
export default function ReadActivityNo() { export default function ReadActivityNo() {
const navigation = useNavigation(); const navigation = useNavigation();
const [readingData, setReadingData] = useState({
word: '',
userId: '',
level: 1,
triedCount: 1,
});
const [count, setCount] = useState(1); const [count, setCount] = useState(1);
useEffect(() => { useEffect(() => {
...@@ -40,8 +34,6 @@ export default function ReadActivityNo() { ...@@ -40,8 +34,6 @@ export default function ReadActivityNo() {
}; };
}, []); }, []);
const sendRedingData = (data, readingSession) => { const sendRedingData = (data, readingSession) => {
Client.post('reading/' + readingSession, JSON.stringify(data), { Client.post('reading/' + readingSession, JSON.stringify(data), {
headers: { headers: {
...@@ -50,8 +42,6 @@ export default function ReadActivityNo() { ...@@ -50,8 +42,6 @@ export default function ReadActivityNo() {
}, },
}) })
.then(res => { .then(res => {
console.log(res.data);
// AsyncStorage.removeItem('readingSession');
navigation.navigate('ReadActivityGo'); navigation.navigate('ReadActivityGo');
}) })
.catch(error => { .catch(error => {
...@@ -79,18 +69,15 @@ export default function ReadActivityNo() { ...@@ -79,18 +69,15 @@ export default function ReadActivityNo() {
level: 1, level: 1,
triedCount: count, triedCount: count,
}; };
console.log('correct', data);
getToken(data); getToken(data);
}) })
.catch(error => { .catch(error => {
console.log(error); console.log(error);
}); });
} else { } else {
setCount(count + 1); setCount(count + 1);
Voice.start('en-US'); Voice.start('en-US');
} }
console.log('count', count); console.log('count', count);
console.log('count', count); console.log('count', count);
...@@ -99,7 +86,6 @@ export default function ReadActivityNo() { ...@@ -99,7 +86,6 @@ export default function ReadActivityNo() {
const getToken = data => { const getToken = data => {
AsyncStorage.getItem('readingSession') AsyncStorage.getItem('readingSession')
.then(readingSession => { .then(readingSession => {
console.log('correct', readingSession);
sendRedingData(data, readingSession); sendRedingData(data, readingSession);
}) })
.catch(error => { .catch(error => {
......
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