Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced admin page #829

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ async def get_student_courses(request: Request):
courses, error = course_select.get_selection(request.session['user']['user_id'])
return courses if not error else Response(error, status_code=500)

# TODO:
@app.get('/api/user/stats')
async def get_user_stats():
return user_controller.get_user_stats()


@app.get('/api/user/{session_id}')
async def get_user_info(request: Request, session_id):
Expand Down Expand Up @@ -273,6 +278,11 @@ async def update_user_info(request:Request, user:updateUser):

return user_controller.update_user(user)

# TODO:
@app.get('/api/session/stats')
async def get_session_stats():
return session_controller.get_session_stats()

@app.post('/api/session')
async def log_in(request: Request, credentials: SessionPydantic):
session_res = session_controller.add_session(credentials.dict())
Expand Down
5 changes: 5 additions & 0 deletions src/api/controller/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ def add_session(form):
"startTime": str(start_time),
"userName" : users_founded[0]['name']
})
# TODO:
def get_session_stats():
session = SessionModel()
num_sessions=session.get_session_stats()
return msg.success_msg({"num_sessions": num_sessions})
6 changes: 6 additions & 0 deletions src/api/controller/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,9 @@ def add_user(form):
return msg.error_msg("Failed to add user.")

return msg.success_msg({"msg": "User added successfully."})

# TODO:
def get_user_stats():
users = UserModel()
total_users=users.get_all_users()
return msg.success_msg({"total_users": total_users})
4 changes: 4 additions & 0 deletions src/api/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ def end_session(self, session_id='%', uid='%', end_time=datetime.utcnow()):
sql = """UPDATE public.user_session SET end_time = %s WHERE session_id::text LIKE %s AND user_id::text LIKE %s;"""
args = (end_time, session_id, str(uid))
return self.db.execute(sql, args, False)[0]

def get_session_stats(self):
sql = """SELECT count(*) FROM public.user_session;"""
return self.db.execute(sql, True)[0][0]['count']
7 changes: 7 additions & 0 deletions src/api/db/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ def update_user(self, args):
user_id = %(UID)s;
"""
return self.db.execute(sql, args, False)[0]
# TODO:
def get_all_users(self):
# Note to devs: this method is rather slow. need to find a faster method later.
sql = """
SELECT count(*) FROM public.user_account;
"""
return self.db.execute(sql, True)[0][0]['count']
2 changes: 1 addition & 1 deletion src/web/src/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ export default {
};
</script>

<style></style>
<style></style>
41 changes: 33 additions & 8 deletions src/web/src/pages/Admin.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<b-container>
<h1>Admin Panel</h1>
<hr />
<br />
<br><b-button href="/">Go back home</b-button><br>
<h2 style="text-align: center;">Admin Panel</h2>
<br /><hr /><h2>Operations</h2><hr /><br />

<a v-b-modal.csvModal class="text-primary d-block" style="cursor: pointer;">
Import Courses via CSV
Expand Down Expand Up @@ -51,13 +51,18 @@
<b-modal id="jsonModal" title="Import Professors via JSON" size="xl">
<UploadJson />
</b-modal>

<!-- Footer of Admin Panel -->
<br /><hr /><h2>Statistics</h2><hr /><br />
Total Users: {{ this.total_users }}<br>
Logged-in Users: {{ this.num_sessions }}<br>
<br>
Current Number of people on the site:
Network bandwith:
<br>
Total Courses:<br>
Last update:<br>
<br />
<hr />
<br />

<b-button href="/">Go back home</b-button>
</b-container>
</template>

Expand All @@ -68,6 +73,9 @@ import SetDefault from "@/pages/SetDefault";
import EditProfessors from "@/pages/EditProfessors";
import UploadJson from "@/pages/UploadJson.vue";

import { getUserStats } from "@/services/UserService";
import {getSessionStats} from "@/services/AdminService";

export default {
name: "AdminPage",
components: {
Expand All @@ -79,7 +87,24 @@ export default {
// ManageAccounts,
},
data() {
return {};
return {
total_users:"",
num_sessions:"",
};
},
mounted() {
//setInterval(() => {
this.getUserStats();
//}, 1000);
},
methods: {
async getUserStats() {
console.log("here")
let userStats=await getUserStats();
let sessionStats=await getSessionStats();
this.total_users = userStats.data.content.total_users;
this.num_sessions = sessionStats.data.content.num_sessions;
},
},
};
</script>
3 changes: 3 additions & 0 deletions src/web/src/services/AdminService.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ export const addProfessors = (msg) =>

export const addProfessorsTest = () =>
client.post("/professor/add/test").then((res) => res.data);

// TODO:
export const getSessionStats=()=>client.get(`/session/stats`)
3 changes: 3 additions & 0 deletions src/web/src/services/UserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ export const logout = (sessionId) =>
"Content-Type": "application/json",
},
});

// TODO:
export const getUserStats=()=>client.get(`/user/stats`)
Loading