from psmdlsyncer.Tree import Tree from psmdlsyncer.utils import NS from psmdlsyncer.settings import define_command_line_arguments args = define_command_line_arguments(format='{lastfirst}{SPACE}({num})') tree = Tree() # TODO: Need to output an example for ease of use def notlegal(psID): if not psID.isdigit(): return True if not len(psID) == 5: return True if int(psID) < 30000: return True return False output = [] for teacher_key in tree.get_teacher_keys(): teacher = tree.get_teacher(teacher_key) ns = NS(teacher) if teacher.status == 1 and notlegal(teacher.num): print(ns('{lastfirst}{TAB}{num}'))
import re def name_to_email(long_name): try: where = long_name.index(')') except ValueError: where = -1 where += 1 long_name = long_name[where:].strip().lower() return re.sub('[^a-z]', '', long_name) if __name__ == "__main__": students = Tree() db = MoodleDBConnection() sf = NS() results = db.get_all_users_activity_enrollments() sf.domain = 'student.ssis-suzhou.net' sf.AT = '@' from collections import defaultdict postfix = defaultdict(list) activities = defaultdict(list) homerooms = defaultdict( lambda : defaultdict(list) ) # PARSE RESULTS for result in results:
def __init__(self): super().__init__() self.raw = self.sql("select distinct usr.firstname, usr.lastname, dr.timecreated, dc.content, dc.fieldid, dc.recordid from ssismdl_data_content dc " + "join ssismdl_data_records dr on dc.recordid = dr.id " + "join ssismdl_user usr on dr.userid = usr.id " + "join ssismdl_data_fields df on dc.fieldid = df.id " + "join ssismdl_data d on df.dataid = 4 order by dc.recordid")() record_ids = [] path_to_probe = config_get_section_attribute("DIRECTORIES", 'path_to_output') path_to_probe += '/probe/' for line in self.raw: r_id = line[k_record_id] if not r_id in record_ids: record_ids.append( r_id ) # teachers holds the data organized by teachers teachers = defaultdict(list) # powerschool variable holds the data that will actually be written to file powerschool = ['Student_Number\tTest_Date\tGrade_Level\tReading_Age_1\tScore_2\tCategory_3\tIndications_3\tDifferential_1'] # reads in student info from powerschool autosend student_info = Tree() # loop through the records in the database module, match them up with the student info # and export the data accordingly for record_id in record_ids: this_entry = [ i for i in self.raw if i[k_record_id] == record_id ] if this_entry: entry = NS() entry.teacher = this_entry[0][0] + " " + this_entry[0][1] entry.date = timestamp_to_python_date(this_entry[0][2]) entry.date_entered = entry.date.strftime('%m/%d/%Y') entry.test_date = {2012:make_date(2012, 10, 15), 2013:make_date(2013, 5, 15)}.get(entry.date.year) entry.test_date_output = entry.test_date.strftime('%m/%d/%Y') for row in this_entry: field_id = row[k_field_id] if field_id == k_student_name: entry.student = row[k_content] entry.powerschoolid = entry.student match = re.search( '\((.*) (.*)\)', entry.student) if match: entry.homeroom, entry.powerschoolid = match.groups() entry.grade = re.sub('[A-Z]', '', entry.homeroom) else: entry.homeroom = '' entry.grade = -1 elif field_id == k_percentage: entry.percent = row[k_content] elif field_id == k_analysis: entry.analysis = ', '.join(row[k_content].split('##')) if row[k_content] else "" elif field_id == k_type: entry.type = row[k_content] elif field_id == k_set: entry.set = row[k_content] if not entry.set: print(this_entry) entry.reading_age = reading_age_from_set.get(entry.set) # gets the student class that has autosend data student = student_info.get_student(str(entry.powerschoolid)) if not student: # student no longer at ssis continue if not entry.reading_age: # no longer in the system (left) just skip it # what about that dude's data!? print("Something wrong with the data of this student") continue date_to_age = lambda x: float(x.days) / 365.25 entry.age = date_to_age(entry.test_date - student.birthday) entry.differential = round(entry.reading_age - entry.age, 2) teachers[entry.teacher].append( entry ) powerschool.append( entry('{powerschoolid}{TAB}{test_date_output}{TAB}{grade}{TAB}{reading_age}{TAB}{percent}{TAB}{type}{TAB}{analysis}{TAB}{differential}') ) with open(path_to_probe + 'powerschool.txt', 'w') as f: f.write( "\n".join(powerschool) ) for teacher in teachers: with open(path_to_probe + '{}.txt'.format(teacher), 'w') as f: entries = teachers[teacher] entries.sort(key=lambda x: x.student) for entry in entries: f.write(entry.student+ '\n') f.write("\tSet: {}\n".format(entry.set)) f.write("\tPercent: {}\n".format(entry.percent)) f.write("\tAnalysis: {}\n".format(entry.analysis)) f.write("\tType: {}\n".format(entry.type)) f.write('\n')
from psmdlsyncer.Tree import Tree from psmdlsyncer.utils import NS from psmdlsyncer.settings import define_command_line_arguments args = define_command_line_arguments(format='{lastfirst}{SPACE}({num})') tree = Tree() # TODO: Need to output an example for ease of use output = [] print('idnumber,username,fullname,shortname,category,backup') for student in tree.students(): print(student) if student.is_secondary: ns = NS(student) print(ns('{ID}{COMMA}{username}{lastfirst}{COMMA}OLP{ID}{COMMA}"Invisible / Online Portfolios"{COMMA}backup-moodle2-course-1489-olptemplate-20131101-1225.mbz'))