def remove_class(active_user): classes_to_remove = [] users_object_path = root / "user_objects" / active_user schedule = open(users_object_path, "rb") users_schedule = pickle.load(schedule) while True: class_to_remove = input( "Please enter the class you wish to remove in the same format you entered it " "\"[class, length day]\" ex: W60 1 3. Or type \"done\": \n") if class_to_remove.lower() == "done": break try: class_list = class_to_remove.split() if len(class_list) == 3: classes_to_remove.append( Session(class_list[0], class_list[1], class_list[2])) logger.debug("You have entered the following classes:", end=" ") for session in classes_to_remove: logger.debug(session.code, "day = " + session.day_taught, end=" ") logger.debug("\n") logger.info(active_user + "removed the class" + class_to_remove + " from their schedule.") else: logger.debug( "Sorry it seems the data you entered doesnt match the required format. Please try again" ) logger.info( active_user + "attempted to removed the class via incorrect input " + class_to_remove + " from their schedule.") except: logger.debug( "Sorry it seems the data you entered doesnt match the required format. Please try again" ) logger.info(active_user + "attempted to removed the class via incorrect input" + class_to_remove + " from their schedule.") for day in users_schedule.week: for user_session in day.sessions: for delete_session in classes_to_remove: if user_session.code == delete_session.code and user_session.length == delete_session.length \ and user_session.day_taught == delete_session.day_taught: day.sessions.remove(user_session) schedule = open(users_object_path, "wb") pickle.dump(users_schedule, schedule) schedule.close()
def createSession(user): """Create a session object for the imported user. Returns the session ID of the created session. ACTUAL SESSION MANAGEMENT IS NOT THE RESPONSIBILITY OF THIS METHOD.""" # Generate a random session ID randomID = get_random_string(8) while randomID in sessions: randomID = get_random_string(8) print(sessions) print( f"Creating new session with ID {randomID} and user account Num {user.accountNum}" ) # Create the new session and add it to the session dict newSession = Session(randomID, user.accountNum) sessions[randomID] = newSession return newSession
from objects import Session, Race session = Session() for race in session.query(Race): entry_result = repr(race.entries[0].result) marks = entry_result[1:-1].split(' ') race_result = repr(race.result) marks2 = race_result[1:-1].split(' ') if len(marks) != len(marks2): print(race.result) print(entry_result)
e1.param['project'] = "NoProject" m.save(e1) m.save(e1) m.save(e1) m.save(e1) e2 = Experiment(project='YourProject', experimenter="John Doe") o1 = Observer(name="Max Mustermann", handedness="right", age=26) o2 = Observer(name="Susanne Sorgenfrei", handedness='left', age=38) o3 = Observer(name="Susi Sorgen", handedness='left', age=40) print o3.param["name"] import datetime s1 = Session(date=datetime.date.today()) s2 = Session(date=datetime.date.today()) # e1.context.append(Context(context=s2)) import pdb pdb.set_trace() s2.add_related(e1, note="Some Context") pdb.set_trace() #all objects are root #m.save(e1) #m.save(e2, o1, o2, o3) #m.save(s1, s2) with m.auto_session as session: session.add_all([e1, e2, o1, o2, o3, s1, s2])
def create_schedule(active_user, make_or_write): sessions = [] users_object_path = root / "user_objects" / active_user logger.debug( "\nPlease input your class info in EXACTLY the same format that will be described below: \n " "[class (W55) length(in hours) day (as a num)]. \n" "Days taught are entered as a number between 1-5 [1 = Monday 5 = Friday] \n" "Use the following example to format your input: \"W60 1 3\".\n" "The above means class W60, taught for one hour, on Wednesday \n" "Do not include " " or a space before W in your input. \n") if make_or_write.lower() == "set": while True: session_info = input( "Please input class information or type \"done\" if you are finished: \n" ) if session_info.lower() == "done": break else: try: session_list = session_info.split() if len(session_list) == 3: sessions.append( Session(session_list[0], session_list[1], session_list[2])) logger.debug("You have entered the following classes:", end=" ") for session in sessions: logger.debug(session.code, "day = ", session.day_taught, end=" ") logger.debug("\n") logger.info(active_user + " added the class", session_info, "to there schedule.") else: logger.debug( "Sorry it seems the data you entered doesnt the required format. Please try again" ) logger.info(active_user + "attempted to add the incorrect format: " + session_info + " to their schedule.") except: logger.debug( "Sorry it seems the data you entered doesnt the required format. Please try again" ) logger.info(active_user + "attempted to add the incorrect format:" + session_info + "" " to their schedule.") monday_sessions = [] tuesday_sessions = [] wednesday_sessions = [] thursday_sessions = [] friday_sessions = [] for session in sessions: if session.day_taught == "1": monday_sessions.append(session) elif session.day_taught == "2": tuesday_sessions.append(session) elif session.day_taught == "3": wednesday_sessions.append(session) elif session.day_taught == "4": thursday_sessions.append(session) elif session.day_taught == "5": friday_sessions.append(session) week = [] monday = Day("Monday", monday_sessions) week.append(monday) tuesday = Day("Tuesday", tuesday_sessions) week.append(tuesday) wednesday = Day("Wednesday", wednesday_sessions) week.append(wednesday) thursday = Day("Thursday", thursday_sessions) week.append(thursday) friday = Day("Friday", friday_sessions) week.append(friday) users_schedule = User(active_user, week) schedule = open(users_object_path, "wb") pickle.dump(users_schedule, schedule) schedule.close() logger.debug( "\nYour schedule has been successfully created, the program will now return you " "to the previous menu.. \n \n") logger.info(active_user + "has successfully set up their schedule.")
m.register(Experiment, Observer, Trial, Session) o1 = Observer(name="A") o2 = Observer(name="B") e1 = Experiment(project="E1", experimenter="X1") e2 = Experiment(project="E2", experimenter="X1") e3 = Experiment(project="E3") t1 = Trial(count=1) t2 = Trial(count=2) t3 = Trial(count=3) t4 = Trial(count=4) s1_1 = Session(count=1) s1_2 = Session(count=1) s2_1 = Session(count=1) s2_2 = Session(count=1) s3_1 = Session(count=1) s4_1 = Session(count=1) m.save(o1, o2, e1, e2, e3, t1, t2, t3, t4, s1_1, s1_2, s2_1, s2_2, s3_1, s4_1) t1.parent = e1 t2.parent = e1 t3.parent = e2 t4.parent = e3 s1_1.parent = t1 s1_2.parent = t1
import sys from csv import DictReader import parse from objects import Race, Track, Session, setup_db, RaceEntry, RaceEntryResult, Horse, Jockey, RaceResult from sqlalchemy.exc import IntegrityError if __name__ == '__main__': session = Session() if 'tracks' in sys.argv: with open('tracks.csv') as csvfile: rows = DictReader(csvfile) for track in rows: print(track['name']) track_db = Track(name=track['name'], country=track['country'].strip(), abv=track['abv'].strip()) session.add(track_db) session.commit() if 'charts' in sys.argv: try: files = [sys.argv[2]] except IndexError: files = parse.all_files() for file_name in files:
from objects import Session, RaceEntry, POINT_OF_CALL, POS, Race from charts import FURLONG_DISTANCE import copy from scipy.interpolate import interp1d session = Session() START = 0 STRETCH = -2 FINAL = -3 POINT_OF_CALL_DIST_MULT = { 1: None, 11: (START, .1875, .375, STRETCH, FINAL), 12: (START, .25, .375, STRETCH, FINAL), 13: (START, .25, .5, STRETCH, FINAL), 14: (START, .25, .5, STRETCH, FINAL), 15: (START, .25, .5, STRETCH, FINAL), 16: (START, .25, .5, .75, STRETCH, FINAL), 17: (START, .25, .5, .75, STRETCH, FINAL), 18: (START, .25, .5, .75, STRETCH, FINAL), 19: (START, .25, .5, .75, STRETCH, FINAL), 20: (.25, .5, .75, 1, STRETCH, FINAL), 21: (START, .25, .5, .75, STRETCH, FINAL), 22: (.25, .5, 1, 1.25, STRETCH, FINAL), 23: (START, .25, .5, .75, STRETCH, FINAL), 24: (.25, .5, 1, 1.375, STRETCH, FINAL), 25: (START, .25, .5, .75, STRETCH, FINAL), 26: (.25, .5, .75, 1, STRETCH, FINAL), 27: (.25, .5, .75, 1, STRETCH, FINAL)