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

Merge branch 'master' into 'it18257632'

# Conflicts:
#   frontend/src/screen/auth/Login.js
parents 49bae6b6 bd42bb29
......@@ -4,6 +4,13 @@ from keras.layers import Dense,Dropout
from keras.models import Sequential
import keras.backend as K
#creating the tables using sqlalchemy
from flask_sqlalchemy import SQLAlchemy
import datetime
#serialize and deserialize data
from flask_marshmallow import Marshmallow
scaler_x = joblib.load('scaler_x.pkl')
scaler_y = joblib.load('scaler_y.pkl')
......@@ -53,4 +60,67 @@ def get_level():
results=[{"level":float(result)}]
return (jsonify(results=results))
app.run(host='0.0.0.0',port=5000)
userpass = 'mysql://root:''@'
basedir = '127.0.0.1'
dbname = '/helply'
socket = '?unix_socket=/opt/lampp/var/mysql/mysql.sock'
dbname = dbname + socket
app.config['SQLALCHEMY_DATABASE_URI'] = userpass + basedir + dbname
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
#DB Connection
db = SQLAlchemy(app)
#crate a object of marshmallow
ma = Marshmallow(app)
#creating the table
class MemoryResults(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20))
age = db.Column(db.String(10))
game_level = db.Column(db.String(50))
time_duration = db.Column(db.Float())
result = db.Column(db.String(20))
date = db.Column(db.DateTime, default = datetime.datetime.now)
def __init__(self, name, age, game_level, time_duration, result):
self.name = name
self.age = age
self.game_level = game_level
self.time_duration = time_duration
self.result = result
#for serializing and deserializing , create the schema
#create Results schema
class ResultsSchema(ma.Schema):
class Meta:
fields = ('id', 'name', 'age', 'game_level', 'time_duration', 'result', 'date') # fields to serialize
result_schema = ResultsSchema()
results_schema = ResultsSchema(many=True)
#add results => POST method
@app.route('/add', methods = ['POST'])
def add_result():
# title = request.json['title']
# body = request.json['body']
name = request.json['name']
age = request.json['age']
game_level = request.json['game_level']
time_duration = request.json['time_duration']
result = request.json['result']
#object of class table
results = MemoryResults(name, age, game_level, time_duration, result)
#add to the db
db.session.add(results)
#commit to the db
db.session.commit()
return result_schema.jsonify(results)
#run the flask file
if __name__ == "__main__":
# app.run(debug=True)
app.run(host='0.0.0.0', port=5000, debug=True)
......@@ -20,12 +20,14 @@ import {createStore, combineReducers} from 'redux';
import {Provider} from 'react-redux';
import memoryReducer from './src/store/reducers/memory';
import timeReducer from './src/store/reducers/memory'
import userReducer from './src/store/reducers/login';
import AppRouter from "./src/router/router"
const rootReducer = combineReducers({
memory: memoryReducer,
time: timeReducer
time: timeReducer,
users: userReducer
});
const store = createStore(rootReducer);
......
export default {
elementry: 'elementry_level',
level2: 'level_two',
level3: 'level_three'
}
\ No newline at end of file
import Users from '../model/Users';
export const USERS = [
new Users(
'1',
'teran@helply.com',
'12345678',
'teran'
),
new Users(
'2',
'rusiru@helply.com',
'12345678',
'rusiru'
),
new Users(
'3',
'madawa@helply.com',
'12345678',
'madawa'
),
new Users(
'4',
'navodh@helply.com',
'12345678',
'navodh'
),
]
\ No newline at end of file
class Users {
constructor(uid,email, password, name){
this.uid = uid,
this.email = email,
this.password = password,
this.name = name
}
}
export default Users;
\ No newline at end of file
......@@ -7,7 +7,7 @@ import Home from '../screen/home';
import Start from '../screen/Start';
import Register from '../screen/auth/Register';
import Login from '../screen/auth/Login';
import Splash from '../screen/splash/Splash';
import Splash from '../screen/splash/splash';
import Color from '../screen/Color';
import Blue from '../screen/activity/Blue';
import Read from '../screen/Read';
......
import {useNavigation} from '@react-navigation/native';
import Orientation from 'react-native-orientation-locker';
import React, {useState} from 'react';
import {
SafeAreaView,
ScrollView,
View,
StyleSheet,
ImageBackground,
Text,
TextInput,
TouchableOpacity,
Image,
} from 'react-native';
import React, { useState } from "react";
import { SafeAreaView, ScrollView, View, StyleSheet, ImageBackground, Text, TextInput, TouchableOpacity, Image } from "react-native";
import {useSelector, useDispatch} from 'react-redux';
import {userLogin} from '../../store/actions/login';
import client from '../client/Client';
import client from "../client/Client";
const isValidObjectField = obj => {
return Object.values(obj).every(value => value.trim());
};
const isValidObjectField = (obj) => {
return Object.values(obj).every(value => value.trim());
}
const updateError = (error, stateUpdater) => {
stateUpdater(error);
......@@ -34,10 +26,23 @@ const isValidEmail = value => {
const Login = () => {
const navigation = useNavigation();
React.useEffect(() => {
const unsubscribe = navigation.addListener('focus', () => {
Orientation.unlockAllOrientations();
Orientation.lockToPortrait();
const dispatch = useDispatch();
const users = useSelector(state=>state.users.users);
const navigation = useNavigation();
React.useEffect(() => {
const unsubscribe = navigation.addListener("focus", () => {
Orientation.unlockAllOrientations();
Orientation.lockToPortrait();
});
return unsubscribe;
}, [navigation]);
const [userInfo, setUserInfo] = useState({
email: '',
password: '',
});
return unsubscribe;
}, [navigation]);
......@@ -62,124 +67,75 @@ const Login = () => {
return updateError('Required all fields!', setError);
}
if (!isValidEmail(email)) {
return updateError('Invalid email !', setError);
const loginHandler = () => {
const loggedInUser = users.find(user=>user.email === email && user.password === password)
if(loggedInUser){
console.log(loggedInUser);
dispatch(userLogin({
name: loggedInUser.name,
id: loggedInUser.uid
}));
navigation.navigate('Home');
}else{
console.log('Invalid user credentials...');
}
}
const submitForm = () => {
if (isValidForm()){
loginFun(userInfo)
}
}
if (!password.trim() || password.length < 8) {
return updateError('Password is less than 8 characters !', setError);
}
return true;
};
const submitForm = () => {
// if (isValidForm()){
loginFun(userInfo);
// }
};
const loginFun = () => {
// var formData = JSON.stringify(userInfo);
// client.post('login', formData, {
// headers: {
// Accept: 'application/json',
// 'Content-Type': 'application/json',
// },
// })
// .then((response) => {
// console.log(response.data);
// if(response.data.status == 404){
// return updateError('Please register our system', setError);
// }
// if(response.data.status == 200){
// return navigation.navigate("Start");
// }
// })
// .catch((err) => {
// console.log(err);
// });
navigation.navigate('Start');
};
return (
<SafeAreaView>
<ScrollView>
<View style={styles.continer}>
<ImageBackground
style={styles.backgroundImage}
source={require('../../assets/login/login_background.png')}
resizeMode="cover">
<View>
<Image
style={styles.logo}
source={require('../../assets/login/logo1.png')}
resizeMode="contain"></Image>
</View>
<View elevation={5} style={styles.main_container}>
<Text style={styles.main_title}>Sign In</Text>
{error ? (
<Text style={{color: 'red', fontSize: 18, textAlign: 'center'}}>
{error}
</Text>
) : null}
<View style={styles.form_input}>
<TextInput
id="email"
value={email}
autoCapitalize="none"
onChangeText={value => handleOnChangeText(value, 'email')}
style={styles.text_input}
placeholder="Enter Email"></TextInput>
</View>
<View style={styles.form_input}>
<TextInput
id="password"
value={password}
autoCapitalize="none"
secureTextEntry
onChangeText={value => handleOnChangeText(value, 'password')}
style={styles.text_input}
placeholder="Enter Password"></TextInput>
</View>
<View style={styles.form_input}>
<TouchableOpacity onPress={submitForm} style={styles.btn}>
<Text style={styles.btn_text}>Sign In</Text>
</TouchableOpacity>
</View>
{/* onPress={submitForm} */}
<View style={styles.text_if}>
<TouchableOpacity
onPress={() => {
navigation.navigate('Register');
}}>
<Text style={styles.btn_text2}>
If you don't have account? Sign Up
</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
</View>
</ScrollView>
</SafeAreaView>
);
};
return(
<SafeAreaView>
<ScrollView>
<View style={styles.continer}>
<ImageBackground style={styles.backgroundImage} source={require('../../assets/login/login_background.png')} resizeMode="cover">
<View>
<Image style={styles.logo} source={require('../../assets/login/logo1.png')} resizeMode="contain"></Image>
</View>
<View elevation={5} style={styles.main_container}>
<Text style={styles.main_title}>Sign In</Text>
{error ? (<Text style={{color: 'red', fontSize: 18, textAlign: 'center'}}>{error}</Text>) : null}
<View style={styles.form_input}>
<TextInput id="email" value={email} autoCapitalize="none" onChangeText={value => handleOnChangeText(value, 'email')} style={styles.text_input} placeholder="Enter Email"></TextInput>
</View>
<View style={styles.form_input}>
<TextInput id="password" value={password} autoCapitalize="none" secureTextEntry onChangeText={value => handleOnChangeText(value, 'password')} style={styles.text_input} placeholder="Enter Password"></TextInput>
</View>
<View style={styles.form_input}>
<TouchableOpacity onPress={ ()=>{navigation.navigate("Start");}} style={styles.btn}>
<Text style={styles.btn_text}>
Sign In
</Text>
</TouchableOpacity>
</View>
{/* onPress={submitForm} */}
<View style={styles.text_if}>
<TouchableOpacity onPress={()=> { navigation.navigate("Register")}}>
<Text style={styles.btn_text2}>
If you don't have account? Sign Up
</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
</View>
</ScrollView>
</SafeAreaView>
)
}
const styles = StyleSheet.create({
continer: {
......
......@@ -8,10 +8,13 @@ const GameOverScreen = ({navigation}) => {
const dispatch = useDispatch();
const passedLevel = useSelector(state=>state.memory.gameLevel);
const passedData = useSelector(state=>state.memory.memoryData);
const passedTime = useSelector(state=>state.time.screenTime);
console.log(passedData);
console.log(passedTime);
console.log(passedLevel);
let totalTime = 0;
......@@ -27,9 +30,10 @@ const GameOverScreen = ({navigation}) => {
console.log(seconds);
const [data, setData] = useState([]);
// const [level, setLevel] = useState('');
const [loading, setIsLoading] = useState(true);
let disorderLevel;
let disorderLevel;
let resultText;
const gameData = {
......@@ -48,6 +52,7 @@ const GameOverScreen = ({navigation}) => {
})
.then(resp => resp.json())
.then(data=>{
console.log('level :', data.results[0].level);
setData(data.results[0].level)
setIsLoading(false)
})
......@@ -62,7 +67,26 @@ const GameOverScreen = ({navigation}) => {
disorderLevel = 'low'
}
const insertData = () => {
fetch('http://192.168.8.170:5000/add', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'child 1',
age: '5',
game_level: passedLevel,
time_duration: seconds,
result: disorderLevel
})
})
.then(resp => resp.json())
.catch(error => console.log(error))
}
if(!loading){
insertData();
resultText=(
<Text style={styles.resultText}>
<Text>Child's disorder level is </Text> <Text style={styles.highlight}>{disorderLevel}</Text>
......
......@@ -2,6 +2,9 @@ import React, {useState, useEffect} from 'react';
import {View, Text, StyleSheet, Image, BackHandler} from 'react-native';
import Header from '../../../component/memory/Header';
import CountDown from 'react-native-countdown-component';
import {useDispatch} from 'react-redux';
import * as memoryActions from '../../../store/actions/memory';
import Levels from '../../../constants/Levels';
const GameScreenOne = ({navigation}) => {
......@@ -10,6 +13,12 @@ const GameScreenOne = ({navigation}) => {
// return () => backHandler.remove()
// },[]);
const dispatch = useDispatch();
useEffect(()=>{
dispatch(memoryActions.setGameLevel(Levels.elementry))
})
return(
<View style={styles.sreen}>
<Text></Text>
......
export const USER_LOGIN = 'USER_LOGIN';
export const userLogin = (user) => {
return {type: USER_LOGIN, user: user}
}
\ No newline at end of file
export const SET_ANSWERS = 'SET_ANSWERS';
export const SET_TIME = 'SET_TIME';
export const CLEAR_DATA = 'CLEAR_DATA';
export const SET_GAME_LEVEL = 'SET_GAME_LEVEL';
export const setGameLevel = (level) => {
return {type: SET_GAME_LEVEL, level: level}
}
export const setAnswers = (data) => {
return {type: SET_ANSWERS, data: data}
......
import {USER_LOGIN} from '../actions/login';
import { USERS } from '../../data/dummy-data';
const initialState = {
users : USERS,
loggedInUser: {}
}
const userReducer = (state = initialState, action) => {
switch (action.type) {
case USER_LOGIN:
return{
...state,
loggedInUser: action.user
}
default:
return state;
}
return state;
}
export default userReducer;
\ No newline at end of file
import { CLEAR_DATA, SET_ANSWERS, SET_TIME } from "../actions/memory";
import { CLEAR_DATA, SET_ANSWERS, SET_GAME_LEVEL, SET_TIME } from "../actions/memory";
const initialState = {
gameLevel: null,
memoryData: {},
screenTime: {}
}
const memoryReducer = (state=initialState, action) => {
switch(action.type){
case SET_GAME_LEVEL:
const level = action.level;
return{
...state,
gameLevel: level
}
case SET_ANSWERS:
const addedAnswer = action.data;
const question = addedAnswer.question;
......@@ -31,7 +40,8 @@ const memoryReducer = (state=initialState, action) => {
return{
...state,
memoryData: {},
screenTime: {}
screenTime: {},
gameLevel: null
}
default:
......
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