-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
75 lines (63 loc) · 2.18 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import axios from "axios"
import AsyncStorage from '@react-native-async-storage/async-storage';
export async function getPredictedGPA(student) {
let {weightedGPA, unweightedGPA} = student.gpa;
let {grade} = student.info;
let {classes} = student
classes = classes.filter(course => parseFloat(course.grade) && !course.disabled);
classes.forEach((course) => {
course.credits = parseFloat(course.credits);
course.grade = parseFloat(course.grade);
course.weight = parseFloat(course.weight);
});
weightedGPA = parseFloat(weightedGPA);
unweightedGPA = parseFloat(unweightedGPA);
grade = parseFloat(grade);
const { data } = await axios.post("https://gradual-deploy.vercel.app/predictedGPA", {
weightedGPA,
unweightedGPA,
"studentGrade": grade,
"currentClasses" : classes
});
return data
}
export async function getStudentData(username, password, url) {
const { data } = await axios.get(`${url}?username=${username}&password=${password}`);
return data
}
export const storeClass = async (value) => {
try {
const jsonValue = JSON.stringify(value)
await AsyncStorage.setItem('class', jsonValue)
} catch (e) {
// saving error
}
}
export const readClass = async () => {
try {
const jsonValue = await AsyncStorage.getItem('class')
return jsonValue != null ? JSON.parse(jsonValue) : null;
} catch(e) {
// error reading value
}
}
export const storeStudent = async (value) => {
try {
const jsonValue = JSON.stringify(value)
await AsyncStorage.setItem('student', jsonValue)
} catch (e) {
// saving error
}
}
export const readStudent = async () => {
try {
const jsonValue = await AsyncStorage.getItem('student')
return jsonValue != null ? JSON.parse(jsonValue) : null;
} catch(e) {
// error reading value
}
}
export const infoURL = "https://gradual-deploy.vercel.app/students/info"
export const scheduleURL = "https://gradual-deploy.vercel.app/students/schedule"
export const currentClassesURL = "https://gradual-deploy.vercel.app/students/currentclasses"
export const gpaURL = "https://gradual-deploy.vercel.app/students/gpa"