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

Merge branch 'it18218640' into 'master'

It18218640

See merge request !165
parents 4e870f04 732c6e72
......@@ -2,7 +2,8 @@
from flask import Flask, redirect, url_for, render_template, request, jsonify, make_response
import random
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, \
save_color_session_details
from API.model.readModel import get_reading_activities, save_activity_details, save_session_details
from API.model.userModel import getUser, saveUserSession, logoutUser
from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result, storeResult
......@@ -19,33 +20,32 @@ app = Flask(__name__)
def home():
return render_template('home.html')
#=================================================================================
# Color Function Route (IT18218640)
# Get Color activities route
# Get Color activities 1 route
@app.route("/getColorActivities1")
def getColorActivities1():
return get_color_activities1()
# Get Color activities 2 route
@app.route("/getColorActivities2")
def getColorActivities2():
return get_color_activities2()
# Get Color result route
@app.route("/getColorActivitiesResult")
def getColorActivitiesResult():
req = request.get_json()
# userId = req['userId']
userId = req['userId']
# print("data_dic")
# result = get_color_activity_result(userId)
return req
result = get_color_activity_result(userId)
return result
# Predict route
@app.route("/predict", methods=["POST"])
def predict():
data = request.get_json()
......@@ -108,18 +108,32 @@ def predict():
# return jsonify("print")
# return "Print"
@app.route("/colorSession", methods=['POST'])
def color_session():
req = request.get_json()
userId = req['userId']
token = save_color_session_details(userId, 1)
data = {
"token": token,
"message": "Success",
"status": 200
}
body = jsonify(data)
return make_response(body)
# Store activity details route
@app.route("/store", methods=["POST"])
def store():
req = request.get_json()
value = req['value']
date = req['date']
token = req['token']
result = "Good"
time = "2S"
userId = 1
try:
response = storeResult(date, result, userId, time, value)
response = storeResult(date, result, userId, time, value, token)
print(response)
body = jsonify(value)
return make_response(body)
......@@ -127,6 +141,7 @@ def store():
print(e)
return e
#=================================================================================
# Read Function Route (IT)
# Login
......@@ -156,7 +171,6 @@ def login():
body = jsonify(data)
return make_response(body)
@app.route("/logout", methods=['POST'])
def logout():
req = request.get_json()
......@@ -169,7 +183,6 @@ def logout():
body = jsonify(data)
return make_response(body)
@app.route("/readingSession", methods=['POST'])
def reading_session():
req = request.get_json()
......@@ -197,4 +210,4 @@ def reading():
return make_response(body)
if __name__ == "__main__":
app.run(host='192.168.1.101')
app.run(host='192.168.8.101')
from flask import jsonify
from API.db.dbConnection import get_all_data, insert_data_json, insert_data, insert, get_data
from API.util.util import getUUID
# get color activity 1 fun
def get_color_activities1():
data_dic = []
......@@ -23,6 +23,7 @@ def get_color_activities1():
return jsonify(data_dic)
# get color activity 2 fun
def get_color_activities2():
data_dic = []
......@@ -43,12 +44,13 @@ def get_color_activities2():
return jsonify(data_dic)
def storeResult(date, result, userId, time, value):
# store color activity result fun
def storeResult(date, result, userId, time, value, token):
try:
qry = 'INSERT INTO coloractivityresult (idColorActivityResult, date, result, userId, time, value) VALUES (NULL, %s, %s, %s, %s, %s)'
qry = 'INSERT INTO coloractivityresult (idColorActivityResult, date, result, userId, time, value, token) VALUES (NULL, %s, %s, %s, %s, %s, %s)'
args = (date, result, userId, time, value)
args = (date, result, userId, time, value, token)
response = insert(qry, args)
return response
......@@ -57,6 +59,7 @@ def storeResult(date, result, userId, time, value):
print(e)
return e
# get color activity result fun
def get_color_activity_result(userId):
data_dic = []
......@@ -77,3 +80,10 @@ def get_color_activity_result(userId):
return jsonify(data_dic)
# store color activity session fun
def save_color_session_details(userId, status):
token = getUUID()
qry = 'INSERT INTO colorsession (id,userId,token,status) VALUES (NULL, %s, %s, %s)'
args = (userId, token, status)
insert(qry, args)
return token
\ No newline at end of file
......@@ -33,7 +33,7 @@ export default function App() {
console.log(data);
client.get('getColorActivitiesResult', data, {
client.post('getColorActivitiesResult', data, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
......
......@@ -5,7 +5,8 @@ import Orientation from 'react-native-orientation-locker';
import { StyleSheet, TouchableOpacity, View, Text, Pressable, SafeAreaView, ScrollView, Image, ImageBackground, Dimensions, Animated, Easing, NativeModules } from 'react-native';
import ImageButton from "../component/ImageButton";
import ColorActivity from "../component/colorActivity";
import Client from "./client/Client";
import client from "./client/Client";
import AsyncStorage from '@react-native-async-storage/async-storage';
export default function Color() {
......@@ -20,6 +21,36 @@ export default function Color() {
return unsubscribe;
}, [navigation]);
const getColorSession = () => {
const data = {
userId: 1,
};
client.post('colorSession', 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);
navigation.navigate("PrimaryType", { title: 'Primary Activities', id: 1 })
} catch (error) {
console.log(error);
}
navigation.navigate(path);
}
})
.catch(error => {
console.log(error);
});
};
return (
<SafeAreaView>
......@@ -35,7 +66,7 @@ export default function Color() {
</View> */}
<View style={{ marginTop: 40 }}>
<TouchableOpacity onPress={() => { navigation.navigate("PrimaryType", { title: 'Primary Activities', id: 1 }) }}
<TouchableOpacity onPress={() => { getColorSession(); }}
style={styles.card}>
<View style={[{ flexDirection: "row" }]}>
......@@ -46,16 +77,31 @@ export default function Color() {
</View>
<View style={{ flex: 0.6 }}>
{/* <Text style={styles.cardDescription}>{id}</Text> */}
<Text style={styles.cardTitle}>Primary</Text>
</View>
</View>
</TouchableOpacity>
{/* <TouchableOpacity onPress={() => { navigation.navigate("PrimaryType", { title: 'Primary Activities', id: 1 }) }}
style={styles.card}>
<View style={[{ flexDirection: "row" }]}>
<View style={styles.cardImage}>
<Image source={require("../assets/type/navo1.png")}
style={{ width: 200, height: 200, borderRadius: 30 }}></Image>
</View>
<View style={{ flex: 0.6 }}>
<Text style={styles.cardTitle}>Primary</Text>
</View>
</View>
</TouchableOpacity>
</TouchableOpacity> */}
</View>
<View style={{ marginTop: 20 }}>
......@@ -80,6 +126,7 @@ export default function Color() {
</TouchableOpacity>
</View>
<View style={{ marginTop: 20, marginBottom: 40 }}>
<TouchableOpacity onPress={() => { navigation.navigate("ColorResult") }}
style={styles.card3}>
......@@ -104,10 +151,6 @@ export default function Color() {
</TouchableOpacity>
</View>
{/* {datas.map((data, index) =>{
return(<ColorActivity key={index} title={data.name} image={data.image} id={data.idcolorActivities} des={data.des} color={data.color}/>)
})} */}
</ScrollView>
</SafeAreaView>
)
......
import {useNavigation} from '@react-navigation/native';
import { useNavigation } from '@react-navigation/native';
import axios from 'axios';
import Orientation from 'react-native-orientation-locker';
import React, {useState, useEffect} from 'react';
import React, { useState, useEffect } from 'react';
import {
StyleSheet,
View,
......@@ -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';
export default function Read() {
const [activity, setActivity] = useState([]);
......
......@@ -9,10 +9,13 @@ import CountDown from 'react-native-countdown-component';
import client from "../client/Client";
import Voice from '@react-native-voice/voice';
import BackButton from "../../component/BackButton"
import AsyncStorage from '@react-native-async-storage/async-storage';
export default function Red() {
const colorToken = AsyncStorage.getItem('colorSession');
const [modalVisible, setModalVisible] = useState(false);
const [colorData, setColorData] = useState({activity: ''});
const navigation = useNavigation();
......@@ -43,6 +46,18 @@ export default function Red() {
};
}, []);
useEffect(() => {
console.log(colorToken);
// AsyncStorage.getItem('token')
// .then(value => {
// console.log(value);
// })
// .catch(error => {
// console.log(error);
// });
}, []);
const onSpeechStartHandler = e => {
// console.log('start handler =>> ', e);
};
......@@ -93,11 +108,15 @@ export default function Red() {
var data = {
value: value,
date: todayData
date: todayData,
token: colorToken,
}
data = JSON.stringify(data);
setColorData(data);
// console.log(localStorage.getItem('colorSession'));
client.post('store', data, {
headers: {
Accept: 'application/json',
......
......@@ -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.1.100:5000/',
baseURL: 'http://192.168.8.101:5000/',
timeout: 15000,
});
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