Commit f003b5e4 authored by Lihinikaduwa D.N.R.  's avatar Lihinikaduwa D.N.R.

Merge branch 'it18257632' into 'master'

It18257632

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