2017-11-23 09:52:10 +00:00
|
|
|
|
2016-08-22 07:27:09 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import frappe
|
|
|
|
import random
|
|
|
|
from frappe.utils import cstr
|
|
|
|
from frappe.utils.make_random import get_random
|
|
|
|
from datetime import timedelta
|
2017-11-23 09:52:10 +00:00
|
|
|
from erpnext.education.api import get_student_group_students, make_attendance_records, enroll_student, \
|
2017-06-01 13:00:35 +00:00
|
|
|
get_fee_schedule, collect_fees, get_course
|
2017-11-23 09:52:10 +00:00
|
|
|
|
2016-08-22 07:27:09 +00:00
|
|
|
|
|
|
|
def work():
|
2017-11-23 09:52:10 +00:00
|
|
|
frappe.set_user(frappe.db.get_global('demo_education_user'))
|
2018-02-28 10:42:51 +00:00
|
|
|
for d in range(20):
|
2016-08-22 07:27:09 +00:00
|
|
|
approve_random_student_applicant()
|
|
|
|
enroll_random_student(frappe.flags.current_date)
|
2017-06-01 13:00:35 +00:00
|
|
|
# if frappe.flags.current_date.weekday()== 0:
|
2021-08-19 08:11:10 +00:00
|
|
|
# make_course_schedule(frappe.flags.current_date, frappe.utils.add_days(frappe.flags.current_date, 5))
|
2016-08-22 07:27:09 +00:00
|
|
|
mark_student_attendance(frappe.flags.current_date)
|
2017-06-01 13:00:35 +00:00
|
|
|
# make_assessment_plan()
|
2016-08-22 07:27:09 +00:00
|
|
|
make_fees()
|
|
|
|
|
|
|
|
def approve_random_student_applicant():
|
|
|
|
random_student = get_random("Student Applicant", {"application_status": "Applied"})
|
|
|
|
if random_student:
|
|
|
|
status = ["Approved", "Rejected"]
|
|
|
|
frappe.db.set_value("Student Applicant", random_student, "application_status", status[weighted_choice([9,3])])
|
|
|
|
|
|
|
|
def enroll_random_student(current_date):
|
2017-06-01 13:00:35 +00:00
|
|
|
batch = ["Section-A", "Section-B"]
|
2016-08-22 07:27:09 +00:00
|
|
|
random_student = get_random("Student Applicant", {"application_status": "Approved"})
|
|
|
|
if random_student:
|
|
|
|
enrollment = enroll_student(random_student)
|
|
|
|
enrollment.academic_year = get_random("Academic Year")
|
|
|
|
enrollment.enrollment_date = current_date
|
2017-06-01 13:00:35 +00:00
|
|
|
enrollment.student_batch_name = batch[weighted_choice([9,3])]
|
2016-08-22 07:27:09 +00:00
|
|
|
fee_schedule = get_fee_schedule(enrollment.program)
|
|
|
|
for fee in fee_schedule:
|
|
|
|
enrollment.append("fees", fee)
|
2017-06-01 13:00:35 +00:00
|
|
|
enrolled_courses = get_course(enrollment.program)
|
|
|
|
for course in enrolled_courses:
|
|
|
|
enrollment.append("courses", course)
|
2016-08-22 07:27:09 +00:00
|
|
|
enrollment.submit()
|
|
|
|
frappe.db.commit()
|
2017-06-01 13:00:35 +00:00
|
|
|
assign_student_group(enrollment.student, enrollment.student_name, enrollment.program,
|
|
|
|
enrolled_courses, enrollment.student_batch_name)
|
2021-08-19 08:11:10 +00:00
|
|
|
|
2017-06-01 13:00:35 +00:00
|
|
|
def assign_student_group(student, student_name, program, courses, batch):
|
|
|
|
course_list = [d["course"] for d in courses]
|
2018-07-27 05:29:14 +00:00
|
|
|
for d in frappe.get_list("Student Group", fields=("name"), filters={"program": program, "course":("in", course_list), "disabled": 0}):
|
2017-06-01 13:00:35 +00:00
|
|
|
student_group = frappe.get_doc("Student Group", d.name)
|
|
|
|
student_group.append("students", {"student": student, "student_name": student_name,
|
|
|
|
"group_roll_number":len(student_group.students)+1, "active":1})
|
|
|
|
student_group.save()
|
2018-07-27 05:29:14 +00:00
|
|
|
student_batch = frappe.get_list("Student Group", fields=("name"), filters={"program": program, "group_based_on":"Batch", "batch":batch, "disabled": 0})[0]
|
2017-06-01 13:00:35 +00:00
|
|
|
student_batch_doc = frappe.get_doc("Student Group", student_batch.name)
|
|
|
|
student_batch_doc.append("students", {"student": student, "student_name": student_name,
|
|
|
|
"group_roll_number":len(student_batch_doc.students)+1, "active":1})
|
|
|
|
student_batch_doc.save()
|
|
|
|
frappe.db.commit()
|
|
|
|
|
|
|
|
def mark_student_attendance(current_date):
|
|
|
|
status = ["Present", "Absent"]
|
2018-07-27 05:29:14 +00:00
|
|
|
for d in frappe.db.get_list("Student Group", filters={"group_based_on": "Batch", "disabled": 0}):
|
2017-06-01 13:00:35 +00:00
|
|
|
students = get_student_group_students(d.name)
|
|
|
|
for stud in students:
|
|
|
|
make_attendance_records(stud.student, stud.student_name, status[weighted_choice([9,4])], None, d.name, current_date)
|
2021-08-19 08:11:10 +00:00
|
|
|
|
2017-06-01 13:00:35 +00:00
|
|
|
def make_fees():
|
|
|
|
for d in range(1,10):
|
|
|
|
random_fee = get_random("Fees", {"paid_amount": 0})
|
2021-08-19 08:11:10 +00:00
|
|
|
collect_fees(random_fee, frappe.db.get_value("Fees", random_fee, "outstanding_amount"))
|
2016-08-22 07:27:09 +00:00
|
|
|
|
2017-06-01 13:00:35 +00:00
|
|
|
def make_assessment_plan(date):
|
|
|
|
for d in range(1,4):
|
2018-07-27 05:29:14 +00:00
|
|
|
random_group = get_random("Student Group", {"group_based_on": "Course", "disabled": 0}, True)
|
2017-06-01 13:00:35 +00:00
|
|
|
doc = frappe.new_doc("Assessment Plan")
|
|
|
|
doc.student_group = random_group.name
|
|
|
|
doc.course = random_group.course
|
|
|
|
doc.assessment_group = get_random("Assessment Group", {"is_group": 0, "parent": "2017-18 (Semester 2)"})
|
|
|
|
doc.grading_scale = get_random("Grading Scale")
|
|
|
|
doc.maximum_assessment_score = 100
|
2021-08-19 08:11:10 +00:00
|
|
|
|
2016-08-22 07:27:09 +00:00
|
|
|
def make_course_schedule(start_date, end_date):
|
|
|
|
for d in frappe.db.get_list("Student Group"):
|
|
|
|
cs = frappe.new_doc("Scheduling Tool")
|
|
|
|
cs.student_group = d.name
|
|
|
|
cs.room = get_random("Room")
|
|
|
|
cs.instructor = get_random("Instructor")
|
|
|
|
cs.course_start_date = cstr(start_date)
|
|
|
|
cs.course_end_date = cstr(end_date)
|
|
|
|
day = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
|
2018-02-28 10:42:51 +00:00
|
|
|
for x in range(3):
|
2016-08-22 07:27:09 +00:00
|
|
|
random_day = random.choice(day)
|
|
|
|
cs.day = random_day
|
|
|
|
cs.from_time = timedelta(hours=(random.randrange(7, 17,1)))
|
|
|
|
cs.to_time = cs.from_time + timedelta(hours=1)
|
|
|
|
cs.schedule_course()
|
|
|
|
day.remove(random_day)
|
|
|
|
|
|
|
|
|
|
|
|
def weighted_choice(weights):
|
|
|
|
totals = []
|
|
|
|
running_total = 0
|
|
|
|
|
|
|
|
for w in weights:
|
|
|
|
running_total += w
|
|
|
|
totals.append(running_total)
|
|
|
|
|
|
|
|
rnd = random.random() * running_total
|
|
|
|
for i, total in enumerate(totals):
|
|
|
|
if rnd < total:
|
2021-08-19 08:11:10 +00:00
|
|
|
return i
|