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 mysql
from flask import Flask, redirect, url_for, render_template, request, jsonify, make_response
import random
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.readModel import get_reading_activities
from API.model.userModel import getStudentByName
>>>>>>> 4377b9c5fafb5c155a043560f662f4da96c37e12
from API.routers.router import funtion_one
# from backend.IT18218640.keyword_spotting_service import Keyword_Spotting_service
# from flask_mysqldb import MySQL
......@@ -17,36 +22,12 @@ from API.routers.router import funtion_one
app = Flask(__name__)
# Initial Route
@app.route("/")
def home():
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)
......@@ -56,20 +37,28 @@ def home():
def getColorActivities1():
return get_color_activities1()
@app.route("/getColorActivities2")
def getColorActivities2():
return get_color_activities2()
@app.route("/getColorActivitiesResult")
def getColorActivitiesResult():
# print("data_dic")
return get_color_activity_result()
@app.route("/predict", methods=["POST"])
def predict():
<<<<<<< HEAD
data = request.get_json()
print((f"{data}"))
=======
try:
data = request.get_json()
>>>>>>> 4377b9c5fafb5c155a043560f662f4da96c37e12
fileitem = data['uri']
......@@ -149,11 +138,11 @@ def store():
# Read Function Route (IT)
@app.route("/testings")
def checkothers():
return "testing funtions"
@app.route("/ru")
def abc():
response_val = funtion_one()
......@@ -164,24 +153,27 @@ def abc():
# return make_response(d, 200)
return response_val
# Loging
@app.route("/login", methods=['POST'])
def login():
req = request.get_json()
email = req['email']
password = req['password']
user = getStudentByName(email, password)
if len(user) == 0:
user = getUser(email, password)
userId = user[0]
if userId == 0:
data = {
"body": [],
"message": "Failed",
"status": 404
}
else:
token = saveUserSession(userId)
data = {
"body": user,
"token": token,
"message": "Success",
"status": 200
}
......@@ -189,7 +181,26 @@ def login():
body = jsonify(data)
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__":
<<<<<<< HEAD
app.run(host='192.168.1.101')
=======
app.run(host='192.168.8.101')
# app.run(host='192.168.8.102')
# app.run(debug=True)
\ No newline at end of file
# app.run(debug=True)
>>>>>>> 4377b9c5fafb5c155a043560f662f4da96c37e12
from API.db.dbConnection import get_reading_data
from API.db.dbConnection import get_reading_data, insert
from flask import jsonify
......@@ -17,3 +17,10 @@ def get_reading_activities():
data_dic.append(ob)
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 insert
from API.util.util import getUUID
from datetime import datetime
def getStudentByName(email, password):
def getUser(email, password):
qry = 'SELECT * FROM `user` WHERE email = "{}" AND password = "{}"'.format(email, password)
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'),
roundTwo: require('../image/round2.png'),
summery: require('../image/ReadHeaderImg4.webp'),
robot1: require('../image/robot1.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';
import White from '../screen/activity/White';
import Read from '../screen/Read';
import ReadActivity from '../screen/reading/ReadActivity';
import ReadActivityBird from '../screen/reading/advanced/ReadActivityBird';
import ColorResult from '../screen/result/ColorResult';
import PrimaryType from '../screen/activity/PrimaryType';
import SecondaryType from '../screen/activity/SecondaryType';
......@@ -128,6 +129,11 @@ const AppRouter = () => {
name="ReadActivity"
component={ReadActivity}
/>
<Stack.Screen
options={{headerShown: false}}
name="ReadActivityBird"
component={ReadActivityBird}
/>
<Stack.Screen
options={{headerShown: false}}
name="ColorResult"
......
......@@ -20,7 +20,7 @@ import {
import ImageButton from '../component/ImageButton';
import ButtonView from '../component/buttonView';
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';
......@@ -65,7 +65,7 @@ export default function Read() {
<TouchableOpacity style={styles.screen}>
<ReadCategory
id={1}
title={'First Round'}
title={'Basic'}
image={ImagePaths.roundOne}
onSelectGame={() => {
navigation.navigate('ReadActivity');
......@@ -73,10 +73,10 @@ export default function Read() {
/>
<ReadCategory
id={1}
title={'Second Round'}
title={'Advanced'}
image={ImagePaths.roundTwo}
onSelectGame={() => {
navigation.navigate('ReadActivity');
navigation.navigate('ReadActivityBird');
}}
/>
<ReadCategory
......@@ -95,7 +95,7 @@ export default function Read() {
const styles = StyleSheet.create({
screenHeader: {
height:200
height: 200,
},
screen: {
flex: 1,
......
......@@ -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({
<<<<<<< HEAD
baseURL: 'http://192.168.1.101:5000/',
=======
baseURL: 'http://192.168.8.101:5000/',
>>>>>>> 4377b9c5fafb5c155a043560f662f4da96c37e12
timeout: 15000,
});
......@@ -14,25 +14,23 @@ import {
TouchableHighlight,
} from 'react-native';
import Voice from '@react-native-voice/voice';
import {DummyReadResult} from '../../assets/read/data/ReadData';
export default function ReadActivity() {
const navigation = useNavigation();
// React.useEffect(() => {
// const unsubscribe = navigation.addListener('focus', () => {
// // The screen is focused
// // Call any action
// Orientation.unlockAllOrientations();
// Orientation.lockToLandscape();
// });
// return unsubscribe;
// }, [navigation]);
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.onSpeechStart = onSpeechStartHandler;
Voice.onSpeechEnd = onSpeechEndHandler;
Voice.onSpeechResults = onSpeechResultsHandler;
Voice.onSpeechError = onSpeechError;
Voice.onSpeechPartialResults = onSpeechPartialResults;
Voice.onSpeechVolumeChanged = onSpeechVolumeChanged;
return () => {
Voice.destroy().then(Voice.removeAllListeners);
......@@ -51,6 +49,26 @@ export default function ReadActivity() {
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 () => {
try {
await Voice.start('en-US');
......@@ -106,11 +124,6 @@ export default function ReadActivity() {
}}
/>
</TouchableHighlight>
<Button
style={styles.button}
title="Stop"
onPress={stopRecording}
/>
</View>
</ImageBackground>
</View>
......@@ -188,11 +201,14 @@ const styles = StyleSheet.create({
height: 50,
},
horizontalView: {
backgroundColor: 'rgba(0,0,0,0.2)',
borderRadius: 50,
flexDirection: 'row',
position: 'absolute',
bottom: 0,
flexDirection: 'row',
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