Commit 7bb80673 authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

some changes

parents 1e002c7d 1f81dca2
...@@ -3,8 +3,8 @@ from flask import Flask, redirect, url_for, render_template, request, jsonify, m ...@@ -3,8 +3,8 @@ from flask import Flask, redirect, url_for, render_template, request, jsonify, m
import random import random
import os import os
from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result 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.readModel import get_reading_activities, save_activity_details, save_session_details
from API.model.userModel import getUser, saveUserSession from API.model.userModel import getUser, saveUserSession, logoutUser
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.routers.router import funtion_one from API.routers.router import funtion_one
...@@ -108,9 +108,9 @@ def predict(): ...@@ -108,9 +108,9 @@ def predict():
# return jsonify("print") # return jsonify("print")
# return "Print" # return "Print"
@app.route("/store", methods=["POST"]) @app.route("/store", methods=["POST"])
def store(): def store():
req = request.get_json() req = request.get_json()
value = req['value'] value = req['value']
date = req['date'] date = req['date']
...@@ -127,8 +127,9 @@ def store(): ...@@ -127,8 +127,9 @@ def store():
print(e) print(e)
return e return e
# Read Function Route (IT) # Read Function Route (IT)
# Loging # Login
@app.route("/login", methods=['POST']) @app.route("/login", methods=['POST'])
def login(): def login():
req = request.get_json() req = request.get_json()
...@@ -156,6 +157,33 @@ def login(): ...@@ -156,6 +157,33 @@ def login():
return make_response(body) return make_response(body)
@app.route("/logout", methods=['POST'])
def logout():
req = request.get_json()
token = req['token']
if(logoutUser(token) == 1):
data = {
"message": "Success",
"status": 200
}
body = jsonify(data)
return make_response(body)
@app.route("/readingSession", methods=['POST'])
def reading_session():
req = request.get_json()
userId = req['userId']
token = save_session_details(userId, 1)
data = {
"token": token,
"message": "Success",
"status": 200
}
body = jsonify(data)
return make_response(body)
@app.route("/reading", methods=['POST']) @app.route("/reading", methods=['POST'])
def reading(): def reading():
req = request.get_json() req = request.get_json()
...@@ -165,9 +193,8 @@ def reading(): ...@@ -165,9 +193,8 @@ def reading():
level = req['level'] level = req['level']
triedCount = req['triedCount'] triedCount = req['triedCount']
result = save_activity_details(userId, word, token, level, triedCount) result = save_activity_details(userId, word, token, level, triedCount)
print(result)
body = jsonify(word) body = jsonify(word)
return make_response(body) return make_response(body)
if __name__ == "__main__": if __name__ == "__main__":
app.run(host='192.168.8.101') app.run(host='192.168.1.100')
...@@ -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
...@@ -32,7 +32,6 @@ def get_all_data(query): ...@@ -32,7 +32,6 @@ def get_all_data(query):
return result return result
def insert_data_pandas_df(pd_df, table_name): def insert_data_pandas_df(pd_df, table_name):
db = create_con_pandas() db = create_con_pandas()
pd_df.to_sql(name=table_name, con=db, if_exists='append', index=False) pd_df.to_sql(name=table_name, con=db, if_exists='append', index=False)
......
from API.db.dbConnection import get_all_data, insert from API.db.dbConnection import get_all_data, insert
from flask import jsonify from flask import jsonify
from API.util.util import getUUID
def get_reading_activities(): def get_reading_activities():
data_dic = [] data_dic = []
...@@ -24,3 +24,11 @@ def save_activity_details(userId, word, token, level, triedCount): ...@@ -24,3 +24,11 @@ def save_activity_details(userId, word, token, level, triedCount):
args = (userId, word, token, level, triedCount) args = (userId, word, token, level, triedCount)
result = insert(qry, args) result = insert(qry, args)
return result return result
def save_session_details(userId, status):
token = getUUID()
qry = 'INSERT INTO readingSession (id,userId,token,status) VALUES (NULL, %s, %s, %s)'
args = (userId, token, status)
insert(qry, args)
return token
from API.db.dbConnection import get_data from API.db.dbConnection import insert, update_data, get_data
from API.db.dbConnection import insert
from API.util.util import getUUID from API.util.util import getUUID
from datetime import datetime from datetime import datetime
...@@ -18,3 +17,8 @@ def saveUserSession(userId): ...@@ -18,3 +17,8 @@ def saveUserSession(userId):
args = (userId, token, loginTime, 1) args = (userId, token, loginTime, 1)
insert(qry, args) insert(qry, args)
return token return token
def logoutUser(token):
qry = 'UPDATE userSession SET status = 0 WHERE token = "{}"'.format(token)
return update_data(qry)
...@@ -26,3 +26,6 @@ android.enableJetifier=true ...@@ -26,3 +26,6 @@ android.enableJetifier=true
# Version of flipper SDK to use with React Native # Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.99.0 FLIPPER_VERSION=0.99.0
#AsyncStorage
AsyncStorage_db_size_in_MB=10
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"name": "firstapp", "name": "firstapp",
"version": "0.0.1", "version": "0.0.1",
"dependencies": { "dependencies": {
"@react-native-async-storage/async-storage": "^1.17.3",
"@react-native-community/netinfo": "^7.1.7", "@react-native-community/netinfo": "^7.1.7",
"@react-native-voice/voice": "^3.2.3", "@react-native-voice/voice": "^3.2.3",
"@react-navigation/drawer": "^6.1.8", "@react-navigation/drawer": "^6.1.8",
...@@ -2820,6 +2821,17 @@ ...@@ -2820,6 +2821,17 @@
"react": "^16.8.0 || ^17.0.0-rc.1" "react": "^16.8.0 || ^17.0.0-rc.1"
} }
}, },
"node_modules/@react-native-async-storage/async-storage": {
"version": "1.17.3",
"resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.17.3.tgz",
"integrity": "sha512-2dxdlGwBjBP2qYu6F72U7cRRFshISYiNEWCaQNOJtxUERCMaYRWcniYqhL248KSbGUMpRhFCEtliztsiGoYYMA==",
"dependencies": {
"merge-options": "^3.0.4"
},
"peerDependencies": {
"react-native": "^0.0.0-0 || 0.60 - 0.68 || 1000.0.0"
}
},
"node_modules/@react-native-community/cli": { "node_modules/@react-native-community/cli": {
"version": "6.1.0", "version": "6.1.0",
"resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-6.1.0.tgz", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-6.1.0.tgz",
...@@ -8428,6 +8440,14 @@ ...@@ -8428,6 +8440,14 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/is-plain-obj": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz",
"integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==",
"engines": {
"node": ">=8"
}
},
"node_modules/is-plain-object": { "node_modules/is-plain-object": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
...@@ -10808,6 +10828,17 @@ ...@@ -10808,6 +10828,17 @@
"integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==", "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==",
"peer": true "peer": true
}, },
"node_modules/merge-options": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz",
"integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==",
"dependencies": {
"is-plain-obj": "^2.1.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/merge-stream": { "node_modules/merge-stream": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
...@@ -17601,6 +17632,14 @@ ...@@ -17601,6 +17632,14 @@
"clsx": "^1.1.1" "clsx": "^1.1.1"
} }
}, },
"@react-native-async-storage/async-storage": {
"version": "1.17.3",
"resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.17.3.tgz",
"integrity": "sha512-2dxdlGwBjBP2qYu6F72U7cRRFshISYiNEWCaQNOJtxUERCMaYRWcniYqhL248KSbGUMpRhFCEtliztsiGoYYMA==",
"requires": {
"merge-options": "^3.0.4"
}
},
"@react-native-community/cli": { "@react-native-community/cli": {
"version": "6.1.0", "version": "6.1.0",
"resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-6.1.0.tgz", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-6.1.0.tgz",
...@@ -21898,6 +21937,11 @@ ...@@ -21898,6 +21937,11 @@
"has-tostringtag": "^1.0.0" "has-tostringtag": "^1.0.0"
} }
}, },
"is-plain-obj": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz",
"integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA=="
},
"is-plain-object": { "is-plain-object": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
...@@ -23719,6 +23763,14 @@ ...@@ -23719,6 +23763,14 @@
"integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==", "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==",
"peer": true "peer": true
}, },
"merge-options": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz",
"integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==",
"requires": {
"is-plain-obj": "^2.1.0"
}
},
"merge-stream": { "merge-stream": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"lint": "eslint ." "lint": "eslint ."
}, },
"dependencies": { "dependencies": {
"@react-native-async-storage/async-storage": "^1.17.3",
"@react-native-community/netinfo": "^7.1.7", "@react-native-community/netinfo": "^7.1.7",
"@react-native-voice/voice": "^3.2.3", "@react-native-voice/voice": "^3.2.3",
"@react-navigation/drawer": "^6.1.8", "@react-navigation/drawer": "^6.1.8",
......
...@@ -8,21 +8,59 @@ import { ...@@ -8,21 +8,59 @@ import {
TouchableNativeFeedback, TouchableNativeFeedback,
Platform, Platform,
} from 'react-native'; } from 'react-native';
import {useNavigation} from '@react-navigation/native';
import Client from '../../screen/client/Client';
import AsyncStorage from '@react-native-async-storage/async-storage';
const ReadCategory = props => { const ReadCategory = props => {
const {title, image, id, color, onSelectGame, path} = props; const {title, image, id, color, path} = props;
const navigation = useNavigation();
const getReadingSession = () => {
const data = {
userId: 1,
};
Client.post('readingSession', JSON.stringify(data), {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
console.log(res.data);
if (res.status == 200) {
console.log(res.data);
const token = res.data.token;
try {
AsyncStorage.setItem('token', token);
} catch (error) {
console.log(error);
}
navigation.navigate(path);
}
})
.catch(error => {
console.log(error);
});
};
return ( return (
<View style={styles.gameItem}> <View style={styles.gameItem}>
<TouchableOpacity onPress={onSelectGame}> <TouchableOpacity
onPress={() => {
getReadingSession();
}}>
<View> <View>
{/* <View style={{...styles.gameItemRow, ...styles.gameItemHeader}}> */} {/* <View style={{...styles.gameItemRow, ...styles.gameItemHeader}}> */}
<ImageBackground style={styles.bgImage} source={image}> <ImageBackground style={styles.bgImage} source={image}>
<View style={styles.titleContainer}> <View style={styles.titleContainer}>
<Text style={styles.title} numberOfLines={1}> <Text style={styles.title} numberOfLines={1}>
{title} {title}
</Text> </Text>
</View> </View>
</ImageBackground> </ImageBackground>
{/* </View> */} {/* </View> */}
</View> </View>
</TouchableOpacity> </TouchableOpacity>
...@@ -32,7 +70,6 @@ const ReadCategory = props => { ...@@ -32,7 +70,6 @@ const ReadCategory = props => {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
gameItem: { gameItem: {
height: 300, height: 300,
width: '100%', width: '100%',
backgroundColor: '#ccc', backgroundColor: '#ccc',
...@@ -55,7 +92,6 @@ const styles = StyleSheet.create({ ...@@ -55,7 +92,6 @@ const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
}, },
bgImage: { bgImage: {
height: '100%', height: '100%',
width: '100%', width: '100%',
justifyContent: 'flex-end', justifyContent: 'flex-end',
......
...@@ -22,25 +22,12 @@ import ButtonView from '../component/buttonView'; ...@@ -22,25 +22,12 @@ 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';
export default function Read() { export default function Read() {
const [activity, setActivity] = useState([]); const [activity, setActivity] = useState([]);
const navigation = useNavigation(); const navigation = useNavigation();
function getColorActivities() {
axios
.get(webUrel)
.then(response => {
setActivity(response.data);
console.log('response.data');
})
.catch(err => {});
}
React.useEffect(() => { React.useEffect(() => {
getColorActivities();
const unsubscribe = navigation.addListener('focus', () => { const unsubscribe = navigation.addListener('focus', () => {
// The screen is focused // The screen is focused
// Call any action // Call any action
...@@ -67,25 +54,19 @@ export default function Read() { ...@@ -67,25 +54,19 @@ export default function Read() {
id={1} id={1}
title={'Basic'} title={'Basic'}
image={ImagePaths.roundOne} image={ImagePaths.roundOne}
onSelectGame={() => { path={'ReadActivity'}
navigation.navigate('ReadActivity');
}}
/> />
<ReadCategory <ReadCategory
id={1} id={1}
title={'Advanced'} title={'Advanced'}
image={ImagePaths.roundTwo} image={ImagePaths.roundTwo}
onSelectGame={() => { path={'ReadActivityBird'}
navigation.navigate('ReadActivityBird');
}}
/> />
<ReadCategory <ReadCategory
id={1} id={1}
title={'Result & Summery'} title={'Result & Summery'}
image={ImagePaths.summery} image={ImagePaths.summery}
onSelectGame={() => { path={'ReadActivity'}
navigation.navigate('ReadActivity');
}}
/> />
</TouchableOpacity> </TouchableOpacity>
</ScrollView> </ScrollView>
......
import {useNavigation} from '@react-navigation/native';
import AsyncStorage from '@react-native-async-storage/async-storage';
export function Authorize() {
const navigation = useNavigation();
AsyncStorage.getItem('userToken')
.then(value => {
console.log(value);
if (value) {
return value;
} else {
alert('Please Login.......');
navigation.navigate('Login');
}
})
.catch(error => {
console.log(error);
});
}
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
TouchableOpacity, TouchableOpacity,
Image, Image,
} from 'react-native'; } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import client from '../client/Client'; import client from '../client/Client';
const isValidObjectField = obj => { const isValidObjectField = obj => {
...@@ -97,6 +97,8 @@ const Login = () => { ...@@ -97,6 +97,8 @@ const Login = () => {
return updateError('Please register our system', setError); return updateError('Please register our system', setError);
} }
if (response.data.status == 200) { if (response.data.status == 200) {
const userToken = res.data.token;
AsyncStorage.setItem('userToken', userToken);
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.8.101:5000/', baseURL: 'http://192.168.1.100:5000/',
timeout: 15000, timeout: 15000,
}); });
...@@ -17,14 +17,19 @@ import Voice from '@react-native-voice/voice'; ...@@ -17,14 +17,19 @@ import Voice from '@react-native-voice/voice';
import {DummyReadResult} from '../../../assets/read/data/ReadData'; import {DummyReadResult} 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 {Authorize} from '../../auth/AuthenticateUser';
export default function ReadActivityBird() { export default function ReadActivityBird() {
const [pitch, setPitch] = useState(''); const userToken = Authorize();
const [error, setError] = useState(''); const [error, setError] = useState('');
const [readingData, setReadingData] = useState({activity: ''}); const [readingData, setReadingData] = useState({activity: ''});
const [started, setStarted] = useState(''); const readToken = AsyncStorage.getItem('readingSession');
const [results, setResults] = useState([]);
const [partialResults, setPartialResults] = useState([]); // useEffect(() => {
// if (Authorize) {
// }
// }, []);
useEffect(() => { useEffect(() => {
Voice.onSpeechStart = onSpeechStartHandler; Voice.onSpeechStart = onSpeechStartHandler;
...@@ -37,6 +42,16 @@ export default function ReadActivityBird() { ...@@ -37,6 +42,16 @@ export default function ReadActivityBird() {
}; };
}, []); }, []);
useEffect(() => {
AsyncStorage.getItem('token')
.then(value => {
console.log(value);
})
.catch(error => {
console.log(error);
});
}, []);
const onSpeechStartHandler = e => { const onSpeechStartHandler = e => {
console.log('start handler =>> ', e); console.log('start handler =>> ', e);
}; };
...@@ -56,10 +71,13 @@ export default function ReadActivityBird() { ...@@ -56,10 +71,13 @@ export default function ReadActivityBird() {
const data = { const data = {
word: 'bird', word: 'bird',
userId: 1, userId: 1,
token: readToken,
level: 1,
triedCount: 1,
}; };
if (result.includes('hello')) { if (result.includes('hello')) {
setReadingData(data); setReadingData(data);
console.log(data); console.log(localStorage.getItem('readingSession'));
sendRedingData(data); sendRedingData(data);
} }
}; };
......
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