Commit 11460df0 authored by Lihinikaduwa D.N.R.  's avatar Lihinikaduwa D.N.R.

Merge branch 'it18257632' into 'master'

It18257632

See merge request !155
parents 4377b9c5 065e790b
import re
# import MySQLdb # import MySQLdb
import mysql
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
<<<<<<< HEAD
from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result
from API.model.readModel import get_reading_activities, save_activity_details
from API.model.userModel import getUser, saveUserSession
=======
from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result, storeResult from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result, storeResult
from API.model.readModel import get_reading_activities from API.model.readModel import get_reading_activities
from API.model.userModel import getStudentByName from API.model.userModel import getStudentByName
>>>>>>> 4377b9c5fafb5c155a043560f662f4da96c37e12
from API.routers.router import funtion_one from API.routers.router import funtion_one
# from backend.IT18218640.keyword_spotting_service import Keyword_Spotting_service # from backend.IT18218640.keyword_spotting_service import Keyword_Spotting_service
# from flask_mysqldb import MySQL # from flask_mysqldb import MySQL
...@@ -17,36 +22,12 @@ from API.routers.router import funtion_one ...@@ -17,36 +22,12 @@ from API.routers.router import funtion_one
app = Flask(__name__) app = Flask(__name__)
# Initial Route # Initial Route
@app.route("/") @app.route("/")
def home(): def home():
return render_template('home.html') return render_template('home.html')
# @app.route('/register', methods =['POST'])
# def register():
# msg = ''
# if request.method == 'POST' and 'username' in request.form and 'password' in request.form and 'email' in request.form:
# username = request.form['username']
# password = request.form['password']
# email = request.form['email']
# cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
# cursor.execute('SELECT * FROM user WHERE name = % s', (username,))
# account = cursor.fetchone()
# if account:
# msg = 'Account already exists !'
# elif not re.match(r'[^@]+@[^@]+\.[^@]+', email):
# msg = 'Invalid email address !'
# elif not re.match(r'[A-Za-z0-9]+', username):
# msg = 'Username must contain only characters and numbers !'
# elif not username or not password or not email:
# msg = 'Please fill out the form !'
# else:
# cursor.execute('INSERT INTO accounts VALUES (NULL, % s, % s, % s)', (username, password, email,))
# mysql.connection.commit()
# msg = 'You have successfully registered !'
# elif request.method == 'POST':
# msg = 'Please fill out the form !'
# return msg
# Color Function Route (IT18218640) # Color Function Route (IT18218640)
...@@ -56,20 +37,28 @@ def home(): ...@@ -56,20 +37,28 @@ def home():
def getColorActivities1(): def getColorActivities1():
return get_color_activities1() return get_color_activities1()
@app.route("/getColorActivities2") @app.route("/getColorActivities2")
def getColorActivities2(): def getColorActivities2():
return get_color_activities2() return get_color_activities2()
@app.route("/getColorActivitiesResult") @app.route("/getColorActivitiesResult")
def getColorActivitiesResult(): def getColorActivitiesResult():
# print("data_dic") # print("data_dic")
return get_color_activity_result() return get_color_activity_result()
@app.route("/predict", methods=["POST"]) @app.route("/predict", methods=["POST"])
def predict(): def predict():
<<<<<<< HEAD
data = request.get_json()
print((f"{data}"))
=======
try: try:
data = request.get_json() data = request.get_json()
>>>>>>> 4377b9c5fafb5c155a043560f662f4da96c37e12
fileitem = data['uri'] fileitem = data['uri']
...@@ -149,11 +138,11 @@ def store(): ...@@ -149,11 +138,11 @@ def store():
# Read Function Route (IT) # Read Function Route (IT)
@app.route("/testings") @app.route("/testings")
def checkothers(): def checkothers():
return "testing funtions" return "testing funtions"
@app.route("/ru") @app.route("/ru")
def abc(): def abc():
response_val = funtion_one() response_val = funtion_one()
...@@ -164,24 +153,27 @@ def abc(): ...@@ -164,24 +153,27 @@ def abc():
# return make_response(d, 200) # return make_response(d, 200)
return response_val return response_val
# Loging # Loging
@app.route("/login", methods=['POST']) @app.route("/login", methods=['POST'])
def login(): def login():
req = request.get_json() req = request.get_json()
email = req['email'] email = req['email']
password = req['password'] password = req['password']
user = getStudentByName(email, password) user = getUser(email, password)
if len(user) == 0: userId = user[0]
if userId == 0:
data = { data = {
"body": [], "body": [],
"message": "Failed", "message": "Failed",
"status": 404 "status": 404
} }
else: else:
token = saveUserSession(userId)
data = { data = {
"body": user, "body": user,
"token": token,
"message": "Success", "message": "Success",
"status": 200 "status": 200
} }
...@@ -189,7 +181,26 @@ def login(): ...@@ -189,7 +181,26 @@ def login():
body = jsonify(data) body = jsonify(data)
return make_response(body) return make_response(body)
@app.route("/reading", methods=['POST'])
def reading():
req = request.get_json()
word = req['word']
userId = req['userId']
token = req['token']
level = req['level']
triedCount = req['triedCount']
result = save_activity_details(userId, word, token, level, triedCount)
print(result)
body = jsonify(word)
return make_response(body)
if __name__ == "__main__": if __name__ == "__main__":
<<<<<<< HEAD
app.run(host='192.168.1.101')
=======
app.run(host='192.168.8.101') app.run(host='192.168.8.101')
# app.run(host='192.168.8.102') # app.run(host='192.168.8.102')
# app.run(debug=True) # app.run(debug=True)
\ No newline at end of file >>>>>>> 4377b9c5fafb5c155a043560f662f4da96c37e12
from API.db.dbConnection import get_reading_data from API.db.dbConnection import get_reading_data, insert
from flask import jsonify from flask import jsonify
...@@ -17,3 +17,10 @@ def get_reading_activities(): ...@@ -17,3 +17,10 @@ def get_reading_activities():
data_dic.append(ob) data_dic.append(ob)
return jsonify(data_dic) return jsonify(data_dic)
def save_activity_details(userId, word, token, level, triedCount):
qry = 'INSERT INTO reading (id,userId,word,token,triedCount,level) VALUES (NULL, %s, %s, %s, %s, %s)'
args = (userId, word, token, level, triedCount)
result = insert(qry, args)
return result
from API.db.dbConnection import get_data from API.db.dbConnection import get_data
from API.db.dbConnection import insert
from API.util.util import getUUID
from datetime import datetime
def getUser(email, password):
def getStudentByName(email, password):
qry = 'SELECT * FROM `user` WHERE email = "{}" AND password = "{}"'.format(email, password) qry = 'SELECT * FROM `user` WHERE email = "{}" AND password = "{}"'.format(email, password)
user = get_data(qry) user = get_data(qry)
return user return user[0]
def saveUserSession(userId):
loginTime = datetime.now()
token = getUUID()
qry = 'INSERT INTO userSession (id,userId,token,loginTime,status) VALUES (NULL, %s, %s, %s, %s)'
args = (userId, token, loginTime, 1)
result = insert(qry, args)
return token
import uuid
def getUUID():
return uuid.uuid1().hex
\ No newline at end of file
const ImagePaths = { export const ImagePaths = {
roundOne: require('../image/round1.jpeg'), roundOne: require('../image/round1.jpeg'),
roundTwo: require('../image/round2.png'), roundTwo: require('../image/round2.png'),
summery: require('../image/ReadHeaderImg4.webp'), summery: require('../image/ReadHeaderImg4.webp'),
robot1: require('../image/robot1.png'), robot1: require('../image/robot1.png'),
robot2: require('../image/activity-2-rob.png'), robot2: require('../image/activity-2-rob.png'),
}; };
export default ImagePaths;
export const DummyReadResult = {
value: ['yellow', 'yelo', 'hello', 'Yello', 'yah lo'],
};
...@@ -18,6 +18,7 @@ import Yellow from '../screen/activity/Yellow'; ...@@ -18,6 +18,7 @@ import Yellow from '../screen/activity/Yellow';
import White from '../screen/activity/White'; import White from '../screen/activity/White';
import Read from '../screen/Read'; import Read from '../screen/Read';
import ReadActivity from '../screen/reading/ReadActivity'; import ReadActivity from '../screen/reading/ReadActivity';
import ReadActivityBird from '../screen/reading/advanced/ReadActivityBird';
import ColorResult from '../screen/result/ColorResult'; import ColorResult from '../screen/result/ColorResult';
import PrimaryType from '../screen/activity/PrimaryType'; import PrimaryType from '../screen/activity/PrimaryType';
import SecondaryType from '../screen/activity/SecondaryType'; import SecondaryType from '../screen/activity/SecondaryType';
...@@ -128,6 +129,11 @@ const AppRouter = () => { ...@@ -128,6 +129,11 @@ const AppRouter = () => {
name="ReadActivity" name="ReadActivity"
component={ReadActivity} component={ReadActivity}
/> />
<Stack.Screen
options={{headerShown: false}}
name="ReadActivityBird"
component={ReadActivityBird}
/>
<Stack.Screen <Stack.Screen
options={{headerShown: false}} options={{headerShown: false}}
name="ColorResult" name="ColorResult"
......
...@@ -20,7 +20,7 @@ import { ...@@ -20,7 +20,7 @@ import {
import ImageButton from '../component/ImageButton'; import ImageButton from '../component/ImageButton';
import ButtonView from '../component/buttonView'; import ButtonView from '../component/buttonView';
import ReadCategory from '../component/reading/ReadCategory'; import ReadCategory from '../component/reading/ReadCategory';
import ImagePaths from '../assets/read/data/ReadData'; import {ImagePaths} from '../assets/read/data/ReadData';
const webUrel = 'http://127.0.0.1:5000/reading'; const webUrel = 'http://127.0.0.1:5000/reading';
...@@ -65,7 +65,7 @@ export default function Read() { ...@@ -65,7 +65,7 @@ export default function Read() {
<TouchableOpacity style={styles.screen}> <TouchableOpacity style={styles.screen}>
<ReadCategory <ReadCategory
id={1} id={1}
title={'First Round'} title={'Basic'}
image={ImagePaths.roundOne} image={ImagePaths.roundOne}
onSelectGame={() => { onSelectGame={() => {
navigation.navigate('ReadActivity'); navigation.navigate('ReadActivity');
...@@ -73,10 +73,10 @@ export default function Read() { ...@@ -73,10 +73,10 @@ export default function Read() {
/> />
<ReadCategory <ReadCategory
id={1} id={1}
title={'Second Round'} title={'Advanced'}
image={ImagePaths.roundTwo} image={ImagePaths.roundTwo}
onSelectGame={() => { onSelectGame={() => {
navigation.navigate('ReadActivity'); navigation.navigate('ReadActivityBird');
}} }}
/> />
<ReadCategory <ReadCategory
...@@ -95,7 +95,7 @@ export default function Read() { ...@@ -95,7 +95,7 @@ export default function Read() {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
screenHeader: { screenHeader: {
height:200 height: 200,
}, },
screen: { screen: {
flex: 1, flex: 1,
......
...@@ -2,6 +2,10 @@ import axios from 'axios'; ...@@ -2,6 +2,10 @@ 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({
<<<<<<< HEAD
baseURL: 'http://192.168.1.101:5000/',
=======
baseURL: 'http://192.168.8.101:5000/', baseURL: 'http://192.168.8.101:5000/',
>>>>>>> 4377b9c5fafb5c155a043560f662f4da96c37e12
timeout: 15000, timeout: 15000,
}); });
...@@ -14,25 +14,23 @@ import { ...@@ -14,25 +14,23 @@ 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';
export default function ReadActivity() { export default function ReadActivity() {
const navigation = useNavigation(); const [pitch, setPitch] = useState('');
const [error, setError] = useState('');
// React.useEffect(() => { const [end, setEnd] = useState('');
// const unsubscribe = navigation.addListener('focus', () => { const [started, setStarted] = useState('');
// // The screen is focused const [results, setResults] = useState([]);
// // Call any action const [partialResults, setPartialResults] = useState([]);
// Orientation.unlockAllOrientations();
// Orientation.lockToLandscape();
// });
// return unsubscribe;
// }, [navigation]);
useEffect(() => { useEffect(() => {
Voice.onSpeechStart = onSpeechStartHandler; Voice.onSpeechStart = onSpeechStartHandler;
Voice.onSpeechEnd = onSpeechEndHandler; Voice.onSpeechEnd = onSpeechEndHandler;
Voice.onSpeechResults = onSpeechResultsHandler; Voice.onSpeechResults = onSpeechResultsHandler;
Voice.onSpeechError = onSpeechError;
Voice.onSpeechPartialResults = onSpeechPartialResults;
Voice.onSpeechVolumeChanged = onSpeechVolumeChanged;
return () => { return () => {
Voice.destroy().then(Voice.removeAllListeners); Voice.destroy().then(Voice.removeAllListeners);
...@@ -51,6 +49,26 @@ export default function ReadActivity() { ...@@ -51,6 +49,26 @@ export default function ReadActivity() {
console.log('result handler =>> ', e); console.log('result handler =>> ', e);
}; };
const onSpeechError = e => {
console.log('onSpeechError: ', e);
setError(JSON.stringify(e.error));
const result = DummyReadResult.value;
if (result.includes('hello')) {
console.log('correct');
}
};
const onSpeechPartialResults = e => {
console.log('onSpeechPartialResults: ', e);
setPartialResults(e.value);
};
const onSpeechVolumeChanged = e => {
console.log('onSpeechVolumeChanged: ', e);
setPitch(e.value);
};
const startRecording = async () => { const startRecording = async () => {
try { try {
await Voice.start('en-US'); await Voice.start('en-US');
...@@ -106,11 +124,6 @@ export default function ReadActivity() { ...@@ -106,11 +124,6 @@ export default function ReadActivity() {
}} }}
/> />
</TouchableHighlight> </TouchableHighlight>
<Button
style={styles.button}
title="Stop"
onPress={stopRecording}
/>
</View> </View>
</ImageBackground> </ImageBackground>
</View> </View>
...@@ -188,11 +201,14 @@ const styles = StyleSheet.create({ ...@@ -188,11 +201,14 @@ const styles = StyleSheet.create({
height: 50, height: 50,
}, },
horizontalView: { horizontalView: {
backgroundColor: 'rgba(0,0,0,0.2)',
borderRadius: 50,
flexDirection: 'row', flexDirection: 'row',
position: 'absolute', position: 'absolute',
bottom: 0, bottom: 0,
flexDirection: 'row', flexDirection: 'row',
marginBottom: 140, marginBottom: 140,
marginLeft: 50 marginLeft: 50,
padding: 7,
}, },
}); });
import {useNavigation} from '@react-navigation/native';
import Orientation from 'react-native-orientation-locker';
import React, {useEffect, useState} from 'react';
import {
Text,
TouchableOpacity,
StyleSheet,
View,
ImageButton,
SafeAreaView,
ImageBackground,
Button,
Image,
TouchableHighlight,
} from 'react-native';
import Voice from '@react-native-voice/voice';
import {DummyReadResult} from '../../../assets/read/data/ReadData';
import AudioRecord from 'react-native-audio-record';
import Client from '../../client/Client';
export default function ReadActivityBird() {
const [pitch, setPitch] = useState('');
const [error, setError] = useState('');
const [readingData, setReadingData] = useState({activity: ''});
const [started, setStarted] = useState('');
const [results, setResults] = useState([]);
const [partialResults, setPartialResults] = useState([]);
useEffect(() => {
Voice.onSpeechStart = onSpeechStartHandler;
Voice.onSpeechEnd = onSpeechEndHandler;
Voice.onSpeechResults = onSpeechResultsHandler;
Voice.onSpeechError = onSpeechError;
return () => {
Voice.destroy().then(Voice.removeAllListeners);
};
}, []);
const onSpeechStartHandler = e => {
console.log('start handler =>> ', e);
};
const onSpeechEndHandler = e => {
console.log('end handler =>> ', e);
};
const onSpeechResultsHandler = e => {
console.log('result handler =>> ', e);
};
const onSpeechError = e => {
console.log('onSpeechError: ', e);
setError(JSON.stringify(e.error));
const result = DummyReadResult.value;
const data = {
word: 'bird',
userId: 1,
};
if (result.includes('hello')) {
setReadingData(data);
console.log(data);
sendRedingData(data);
}
};
const startRecording = async () => {
try {
await Voice.start('en-US');
} catch (error) {
console.log('error =>> ', error);
}
};
const sendRedingData = data => {
Client.post('reading', JSON.stringify(data), {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
console.log(res.data);
})
.catch(error => {
console.log(error);
});
};
return (
<SafeAreaView>
<View style={{flexDirection: 'column'}}>
<ImageBackground
style={styles.image}
source={require('../../../assets/read/image/activity-2-backg.jpeg')}>
<View style={styles.imageContainer}>
<View style={styles.imageView}>
<View style={styles.robo}>
<Image
source={require('../../../assets/read/image/activity-2-rob.png')}></Image>
</View>
</View>
<View style={styles.textBody}>
<Text style={styles.text}>Pronounce this Word!</Text>
</View>
</View>
{/* <View style={styles.textBody}>
<Text style={styles.text}>Pronounce this Word!</Text>
</View>
<View style={styles.robo}>
<Image
source={require('../../assets/read/activity-2-rob.png')}></Image>
</View> */}
<View>
<Image
style={styles.blackboard}
source={require('../../../assets/read/image/backboard3.png')}></Image>
</View>
<View style={styles.horizontalView}>
<TouchableHighlight onPress={startRecording}>
<Image
style={styles.imageButton}
source={{
uri: 'https://raw.githubusercontent.com/AboutReact/sampleresource/master/microphone.png',
}}
/>
</TouchableHighlight>
</View>
</ImageBackground>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
imageContainer: {
flexDirection: 'row',
marginTop: 70,
},
imageView: {
width: 180,
height: 300,
// borderWidth:1,
// borderColor: "#000",
marginHorizontal: 1,
marginVertical: 100,
},
body: {
flex: 1,
},
image: {
width: '100%',
height: '100%',
},
box: {
width: 180,
height: 180,
// borderColor: "#000000",
backgroundColor: 'blue',
marginTop: -370,
marginLeft: 455,
borderRadius: 100,
},
blackboard: {
marginTop: -320,
marginLeft: 200,
width: '50%',
height: 300,
},
robo: {
marginTop: 90,
marginLeft: 5,
width: 150,
height: 200,
},
textBody: {
marginTop: 150,
marginLeft: -30,
// backgroundColor: '#00008B',
width: 150,
borderRadius: 50,
padding: 5,
},
text: {
fontSize: 25,
justifyContent: 'center',
alignItems: 'center',
color: '#00008B',
borderRadius: 10,
backgroundColor: 'rgba(0,0,0,0.2)',
textAlign: 'center',
fontWeight: 'bold',
},
button: {
padding: 10,
marginLeft: 5,
color: '#000000',
},
imageButton: {
width: 50,
height: 50,
},
horizontalView: {
flexDirection: 'row',
position: 'absolute',
bottom: 0,
flexDirection: 'row',
marginBottom: 140,
marginLeft: 50,
},
});
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