Esempio n. 1
0
def test_YOSA():
    # subject_input_list = [
    #     Subject("알고리즘", 4, 1, 0, 0),
    #     # Subject("웹프", 3, 7, 1, 0),
    #     # Subject("직능훈", 2, 4, 2, 0),
    #     # Subject("알고리즘", 4, 5, 3, 1),
    #     Subject("C++", 4, 24, 4, 1),
    #     # Subject("웹프", 3, 3, 5, 1),
    #     # Subject("알고리즘", 4, 4, 6, 2),
    #     # Subject("데베설", 3, 5, 7, 2),
    #     # Subject("운영체제", 2, 6, 8, 2),
    # ]

    subject_input_list = [
        Subject("알고리즘", 1, 1, 0, 0),
        # Subject("웹프", 3, 7, 1, 0),
        # Subject("직능훈", 2, 4, 2, 0),
        # Subject("알고리즘", 4, 5, 3, 1),
        Subject("C++", 1, 23, 4, 1),
        # Subject("웹프", 3, 3, 5, 1),
        # Subject("알고리즘", 4, 4, 6, 2),
        # Subject("데베설", 3, 5, 7, 2),
        # Subject("운영체제", 2, 6, 8, 2),
    ]

    student_count = 2
    # for i in range(1, 40):
    #     yosa = YOSA(subject_input_list, student_count, i)
    #     yosa.run()
    yosa = YOSA(subject_input_list, student_count, 40)
    yosa.run()
    yosa = YOSA(subject_input_list, student_count, 35)
    yosa.run()
Esempio n. 2
0
    def find_maxima(self, start_sol, max_time):
        population = [Subject(i, self.evaluation(i)) for i in start_sol]

        t_end = time.time() + max_time
        while time.time() < t_end:
            strongest = self.select_strongest(population)

            for couple in strongest:

                new_genom = self.crossbreed(couple[0], couple[1])

                if new_genom in [p.genom for p in population]:
                    continue

                population.append(Subject(new_genom, self.evaluation(new_genom)) \
                                      if self.in_dict(new_genom) and self.can_assemble(new_genom) \
                                      else Subject(new_genom, 0))

            if len(population) > self.pop_count:
                population = sorted(population,
                                    key=lambda x: x.value,
                                    reverse=True)[0:self.pop_count]

        for e in population:
            print(e.genom)

        self.best_sol = sorted(population, key=lambda x: x.value,
                               reverse=True)[0].genom
        self.best_val = self.evaluation(self.best_sol)
Esempio n. 3
0
def main():
    s = Subject()
    subject = s.get_subject()
    if not (subject == ""):
        send_email_proccess(subject)
    else:
        print('You should entry the subject of email')
Esempio n. 4
0
 def setUp(self):
     self.EPSILON = 0.01
     sub1 = Subject("Biologia",
                    [[3.5, 2.5, 5.0], [1, 1, 1, 1, 1, 1, 1, 1, 0]])
     sub2 = Subject("Matematyka",
                    [[2.5, 3.0, 2.5], [1, 1, 0, 1, 0, 1, 0, 1, 1]])
     self.subjects = [sub1, sub2]
     self.andrzej = Student("Andrzej Abacki", self.subjects)
     self.diary = Diary("AGH", 2016, "data.json")
 def reducer(acc, term):
     subj = Subject(subject_id)
     score = term["score"][regno][subject_id]
     gradings = term["gradings"]
     ratio = term["ratio"]
     grade = subj.scoreToGrade(score, gradings)
     acc["score"] += score * ratio
     acc["grade"] += grade * ratio
     return acc
Esempio n. 6
0
def main():

    root = Tk()
    subject = Subject()
    _views = []

    for i in range(5):
        _views.append(Note(root, i, 'View %i' % i))

    for v in _views:
        subject.attach(v)

    my_gui = MainView(root, subject)
    root.mainloop()
Esempio n. 7
0
class TestSubject(TestCase):
    def setUp(self):
        self.sub1 = Subject("ZTI", [[4, 5, 5], [0, 1, 1, 1, 1]])
        self.sub2 = Subject("PITE", [[4.5, 5, 5, 4], [1, 1, 1, 1, 1]])

    def test_get_average1(self):
        self.assertAlmostEquals(self.sub1.get_average(), 14. / 3, 2)

    def test_get_average2(self):
        self.assertAlmostEquals(self.sub2.get_average(), 18.5 / 4, 2)

    def test_get_attendance1(self):
        self.assertEqual(self.sub1.get_attendance(), 80)

    def test_get_attendance2(self):
        self.assertEqual(self.sub2.get_attendance(), 100)
    def assign_new_semester(self):

        system('cls')

        id_student = int(input("Enter the student's identification: "))
        pos_student = self.__find_student(id_student)

        if pos_student != -1:
            name_subject = input("Enter the subject's name: ")
            notes = self.__load_notes()

            id_teacher = int(input("Enter the teacher's identification: "))
            pos_teacher = self.__find_teacher(id_teacher)

            if pos_teacher != -1:
                new_subject = Subject(name_subject, notes, self.teachers[pos_teacher])
                new_semester = Semestre(self.students[pos_student], new_subject)
                self.semestres.append(new_semester)

                system('cls')
                print("The assign was created successful")

            else:
                system('cls')
                print("The teacher not exists")

        else:
            print("The student not exists")

        input()
Esempio n. 9
0
    def update_protocols(self):
        """
        If we change the protocol file, update the stored version in subject files
        """
        #
        # get list of protocol files
        protocols = os.listdir(prefs.PROTOCOLDIR)
        protocols = [p for p in protocols if p.endswith('.json')]

        subjects = self.list_subjects()
        for subject in subjects:
            if subject not in self.subjects.keys():
                self.subjects[subject] = Subject(subject)

            protocol_bool = [
                self.subjects[subject].protocol_name == p.rstrip('.json')
                for p in protocols
            ]
            if any(protocol_bool):
                which_prot = np.where(protocol_bool)[0][0]
                protocol = protocols[which_prot]
                self.subjects[subject].assign_protocol(
                    os.path.join(prefs.PROTOCOLDIR, protocol),
                    step_n=self.subjects[subject].step)

        msgbox = QtGui.QMessageBox()
        msgbox.setText("Subject Protocols Updated")
        msgbox.exec_()
Esempio n. 10
0
 def add_subject(self, subject_name, start_time, is_even, day):
     subs = self.subjects.get(day)
     s = Subject(subject_name, start_time, is_even)
     if (subs == None):
         self.subjects.update({day: [s]})
     else:
         subs.append(s)
Esempio n. 11
0
    def temp(self):
        filenames = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]

        self.data = []

        cnt = 0
        for filename in filenames:

            if filename.startswith("."):
                continue

            print(str(cnt) + ". " + filename.split("-")[0])
            cnt += 1

            s = Subject()
            s.readData(os.path.join(path, filename))
            self.data.append(s)
Esempio n. 12
0
    def __init__(self, name, service, view, data, caller):
        Subject.__init__(self)

        self.observers = []
        self.name = name
        self.caller = caller
        self.temperature = Temperature(None)
        self.rainfall = Rainfall(None)
        self.timestamp = None
        self.datestamp = None

        self.serviceType = service
        self.viewType = view
        self.dataType = data

        self.client = None
        self.timer = None
        self.setupClient()
class TestSubject(unittest.TestCase):
    
    def setUp(self):
        self.code=1
        self.name='aps'
        self.slist=None
        self.testobj=Subject(self.code,self.name,self.slist)
        
    def test_getSubjectName(self):
        print('subject name')
        self.assertEqual(self.testobj.getSubjectName(),self.name)
    
    def test_getSubjectCode(self):
        print('subject code')
        self.assertEqual(self.testobj.getSubjectCode(),self.code)
        
    def test_getSudentList(self):
        print('student list')
        self.assertEqual(self.testobj.getStudentList(),self.slist)
Esempio n. 14
0
    def reassign_protocols(self):
        """
        Batch reassign protocols and steps.

        Opens a :class:`.gui.Reassign` window after getting protocol data,
        and applies any changes made in the window.
        """
        # get list of protocol files
        protocols = os.listdir(prefs.PROTOCOLDIR)
        protocols = [
            os.path.splitext(p)[0] for p in protocols if p.endswith('.json')
        ]

        # get subjects and current protocols
        subjects = self.list_subjects()
        subjects_protocols = {}
        for subject in subjects:
            if subject not in self.subjects.keys():
                self.subjects[subject] = Subject(subject)

            subjects_protocols[subject] = [
                self.subjects[subject].protocol_name,
                self.subjects[subject].step
            ]

        reassign_window = Reassign(subjects_protocols, protocols)
        reassign_window.exec_()

        if reassign_window.result() == 1:
            subject_protocols = reassign_window.subjects

            for subject, protocol in subject_protocols.items():
                step = protocol[1]
                protocol = protocol[0]

                # since assign_protocol also changes the step, stash the step number here to tell if it's changed
                subject_orig_step = self.subjects[subject].step

                if self.subjects[subject].protocol_name != protocol:
                    self.logger.info(
                        'Setting {} protocol from {} to {}'.format(
                            subject, self.subjects[subject].protocol_name,
                            protocol))
                    protocol_file = os.path.join(prefs.PROTOCOLDIR,
                                                 protocol + '.json')
                    self.subjects[subject].assign_protocol(protocol_file, step)

                if subject_orig_step != step:
                    self.logger.info('Setting {} step from {} to {}'.format(
                        subject, subject_orig_step, step))
                    step_name = self.subjects[subject].current[step][
                        'step_name']
                    #update history also flushes current - aka it also actually changes the step number
                    self.subjects[subject].update_history(
                        'step', step_name, step)
Esempio n. 15
0
 def parse_data(self):
     for row in self.__information:
         lesson = Lesson(row[0], row[1], row[5], row[6], row[7])
         subject = Subject(row[4], row[9], lesson)
         student = Student(row[3], row[2], row[8], row[9], subject)
         if self.check_student(student):
             self.__student_list.append(student)
         else:
             for stud in self.__student_list:
                 if stud.get_surname() == student.get_surname(
                 ) and stud.get_group_code() == student.get_group_code():
                     stud.get_subject_list().append(subject)
Esempio n. 16
0
    def add(self, subject_name):
        """
        Add a subject by subject name

                Parameters:
                        subject_name (str): name of the subject

                Returns:
                        subject(Subject): subject that was added
        """
        self._subjects.append(Subject(subject_name))
        return self._subjects[-1]
Esempio n. 17
0
def main():

    startTime = datetime.now()

    runList = genSubjectList('t2_circles')

    for subject in runList:

        subject = Subject(subject)
        subjectDisplay(subject)

    print 'Subject Creation: ', datetime.now() - startTime
Esempio n. 18
0
def add_test_data(subjects, students):
    subjects.append(Subject("German"))

    students.append(Student("Donald", "Duck"))
    students[len(students) - 1].add_score(subjects[1], "01.01.2019",
                                          Student.ABSENT)
    students[len(students) - 1].add_score(subjects[2], "01.01.2019",
                                          Student.ABSENT)

    students.append(Student("Test", "Student"))
    students[len(students) - 1].add_score(subjects[0], "01.06.2030", 90)
    students[len(students) - 1].add_score(subjects[2], "0w.07.2023", 44)

    students.append(Student("Klaus", "Muster"))
    students[len(students) - 1].add_score(subjects[0], "01.04.2019", 77)
    students[len(students) - 1].add_score(subjects[2], "03.03.2019",
                                          Student.ABSENT)
    students[len(students) - 1].add_score(subjects[2], "10.03.2019", 64)
    students[len(students) - 1].add_score(subjects[2], "17.03.2019", 20)

    students.append(Student("Test", "Studentin"))
    students[len(students) - 1].add_score(subjects[0], "01.06.2030", 90)
    students[len(students) - 1].add_score(subjects[2], "0w.07.2023", 44)

    students.append(Student("Muster", "Studentin"))
    students[len(students) - 1].add_score(subjects[0], "01.06.2030", 90)
    students[len(students) - 1].add_score(subjects[2], "0w.07.2023", 44)

    students.append(Student("Muster", "Student"))
    students[len(students) - 1].add_score(subjects[0], "01.06.2030", 91)
    students[len(students) - 1].add_score(subjects[2], "0w.07.2023", 33)

    students.append(Student("Debug", "Studentin"))
    students[len(students) - 1].add_score(subjects[0], "01.06.2030", 90)
    students[len(students) - 1].add_score(subjects[0], "0w.07.2023", 44)

    students.append(Student("Debug", "Studentin"))
    students[len(students) - 1].add_score(subjects[1], "01.06.2030", 90)
    students[len(students) - 1].add_score(subjects[2], "0w.07.2023", 44)

    students.append(Student("Debug", "Student"))
    students[len(students) - 1].add_score(subjects[0], "01.06.2030", 91)
    students[len(students) - 1].add_score(subjects[1], "0w.07.2023", 33)

    students.append(Student("Thomas", "Muster"))
    students[len(students) - 1].add_score(subjects[0], "01.04.2019", 77)
    students[len(students) - 1].add_score(subjects[2], "03.03.2019",
                                          Student.ABSENT)
    students[len(students) - 1].add_score(subjects[2], "10.03.2019", 64)
    students[len(students) - 1].add_score(subjects[2], "17.03.2019", 20)

    return subjects, students
 def make_student_real_subject_list(self):
     real_subject_list = []
     for idx, best_subject_study_time in enumerate(
             self.best_solo_subject_study_case):
         if best_subject_study_time > 0:
             real_subject = copy.deepcopy(self.subject_list[idx])
             real_subject.bt = best_subject_study_time
             real_subject.remain_bt = real_subject.bt
             real_subject_list.append(real_subject)
     if self.best_each_team_play_time > 0:
         real_subject_list.append(
             Subject("팀프", 3, self.best_each_team_play_time, 14, -1), )
     return real_subject_list
Esempio n. 20
0
 def mapping_to_subject(datum):
     return Subject(datum['subject_id'],
                    datum['name'],
                    datum['region'],
                    datum['section'],
                    datum['kind'],
                    datum['price'],
                    datum['location'],
                    datum['sub_type'],
                    datum['pattern'],
                    datum['size'],
                    datum['floor'],
                    datum['contact_person'],
                    datum['url'])
Esempio n. 21
0
def getSynthesis():
    try:
        id_str = (request.form['subject'] + str(time())).replace(' ', '-')
        if request.form.get('wikipedia'):
            useWikipedia = True
        else:
            useWikipedia = False
        subject = Subject(request.form['subject'],
                          summaryLength=int(request.form['lines']),
                          useWikipedia=useWikipedia)
        q.enqueue(subject.build, job_id=id_str, timeout=600)
    except Exception as e:
        return '<h1>Error</h1>' + str(e)
    return render_template('working.html', url='/status/' + id_str)
Esempio n. 22
0
def enter():
    global student, subject, room, randombox, warning_bgm, buy_bgm, font

    student = Student()
    subject = Subject()
    room = Room()
    randombox = []
    font = load_font('ENCR10B.TTF', 16)

    warning_bgm = load_music('sounds/effects/warning.mp3')
    warning_bgm.set_volume(128)

    buy_bgm = load_music('sounds/effects/buy.mp3')
    buy_bgm.set_volume(128)
Esempio n. 23
0
 def task_actions(task_action, task_subject):
     for subject_name in task_subject:
         subject = Subject.get(subject_name)
         q2html = subject.render.q2html
         subject_db = db[subject_name]
         if 'suits' in task_action:
             print subject_name, 'cache suits start'
             cache_suits(subject_db, q2html, subject_name=subject_name)
         if 'plans' in task_action:
             print subject_name, 'cache plans start'
             cache_plans(subject_db, q2html, subject_name=subject_name)
         if 'items' in task_action:
             print subject_name, 'cache all items start'
             cache_items(subject_db, q2html, subject_name=subject_name)
Esempio n. 24
0
    def __getSubjectsDirectories(self):
        """Return directories who qualified for the pipeline

        Look into each subdirectory if it meet all the requirements. If yes, the subdirectory is consider
        a subject and is register into a list

        Returns:
            subjects: a list of directory containing qualified subjects

        """
        self.info("Looking for valid subjects.")
        subjects = []

        if self.arguments.subject:
            for dir in self.arguments.subject:
                if self.__isDirAValidSubject(dir):
                    subjects.append(Subject(self.__copyConfig(dir)))
        else:
            dirs = glob.glob("{}/*".format(self.studyDir))
            for dir in dirs:
                if self.__isDirAValidSubject(dir):
                    subjects.append(Subject(self.__copyConfig(dir)))

        return subjects
Esempio n. 25
0
    def set_species(self, dat):
        ''' Set the species list '''

        if dat != None:
            self.species = []
            dat.sort(key=itemgetter(self.key))

            temp_set = set()  # to avoid duplicates from observations
            for e in dat:
                temp_name = e[1] + e[2]
                subject = Subject(e[0], e[1], e[2], e[3], e[4], e[5], e[6])

                if not (temp_name in temp_set):
                    temp_set.add(temp_name)
                    self.species.append(subject)
Esempio n. 26
0
    def find(self, subject_name):
        """
        Find a subject by subject name

                Parameters:
                        subject_name (str): name of the subject

                Returns:
                        subjects(list): list of subjects
        """
        try:
            sub_index = self._subjects.index(Subject(subject_name))
            return self._subjects[sub_index]
        except ValueError:
            return None
Esempio n. 27
0
    def __subjectsFactory(self, directories):
        """Return a list of directories who qualified for the pipeline

        Args:
            directories: a list of directory to validate

        Returns:
            subjects: a list of directory containing qualified subjects

        """
        subjects=[]
        for directory in directories:
            subject = Subject(self.__copyConfig(directory))
            if subject.isAToadSubject():
                subject.activateLogDir()
                self.info("{} seem\'s a valid toad subject entry".format(directory))
                if self.config.getboolean('arguments', 'validation'):
                    if subject.isValidForPipeline():
                        self.info("{} is a valid subject, adding it to the list.".format(subject))
                        subjects.append(subject)

                    elif self.config.getboolean('arguments', 'prompt'):
                            msg = "It seem\'m like {} is having an issue and will probably fail!".format(subject)
                            if util.displayYesNoMessage(msg, "Would you like to remove it from the list (y or n)"):
                                self.info("Removing subject {} from the submitting list\n".format(subject))
                            else:
                                self.warning("Keeping {} even if we found issues will probably make the pipeline failing\n"
                                .format(subject))
                                subjects.append(subject)
                    else:
                        self.warning("Command prompt disabled, this submit will be submit anyway")
                        subjects.append(subject)
                else:
                    self.warning("Skipping validation have been requested, this is a unwise and dangerous decision")
                    subjects.append(subject)
        return subjects
Esempio n. 28
0
    def __init__(self, url=None, version=None, token=None):
        self.subject = Subject()
        self.aspect = Aspect()
        self.sample = Sample()

        if url:
            if url.endswith('/'):
                config.REFOCUS_URL = url
            else:
                config.REFOCUS_URL = url + '/'

        if config.API_VERSION or version:
            config.REFOCUS_URL += version if version else config.API_VERSION

        if token:
            config.REFOCUS_TOKEN = token
Esempio n. 29
0
def decode(data):
    subjects = []
    students = []
    for s in data["subjects"]:
        subjects.append(Subject(s["name"]))
    for s in data["students"]:
        student_append = Student(s["firstname"], s["lastname"])
        scores = s["scores"]
        score_keys = scores.keys()
        for subject_name in score_keys:
            subject_obj = None
            for o in subjects:
                if o.name == subject_name:
                    subject_obj = o
            student_append.scores[subject_obj] = scores[subject_name]
            students.append(student_append)
    return (subjects, students)
Esempio n. 30
0
    def load(self):
        data_path = os.path.join(self.path, 'DATA')
        increment = 0
        files = os.listdir(data_path)
        for i, f in enumerate(files):
            if i == self.size:
                print("aqui")
                break
            print(" Percentage : {:.2f}".format((increment / len(files)) *
                                                100) if self.size is None else
                  (increment / self.size))
            if f.endswith(".xml") and f.startswith("subject"):
                sub = Subject(ET.parse(os.path.join(data_path, f)).getroot())
                self.subjects.append(sub)
            increment += 1

        self._load_gt()
Esempio n. 31
0
def main():

    startTime = datetime.now()

    outTable = r'C:\Users\jeffr_000\Desktop\Fall_2016\415\GEOG_415_Scarmazzi\Results\FinalRun_C.csv'
    writer = csvGen(outTable)

    ##
    # T1 = 134 Subjects, T2 = 133 Subjects
    ##
    subjectList = genSubjectList('t2_circles')
    errList = []
    runList = []
    for subject in subjectList:

        subjectNumber = subject
        subject = Subject(subject)

        try:
            t1Generation(subject, 't1_circles')
            t2Generation(subject, 't2_circles')

        except Exception as e:
            errList.append(subjectNumber)
            print '#' * 75
            print 'Problem: ', e.args
            print '#' * 75

        subjectDisplay(subject)

        csvWrite(writer, subject)

        runList.append(subject)

    print 'Subject Creation: ', datetime.now() - startTime
    print 'Problem Subjects: ', len(errList), errList
    print '*' * 50
    print '*' * 50

    ##
    # Console Logging
    ##
    r1Logging(runList)
    configLogging(runList)
Esempio n. 32
0
    def __init__(self, superuser=None, computer=None, user=None, code=None, branch=None, id_local_process='unused',
                 type_list=[None], case_list=[[None]], configuration_list=[None],
                 flow_process_list=[None], element_type_list=[[None]],
                 operation_type=None, operation=None,
                 test_mode='0',
                 db_user='******', db_password='******',
                 db_host='localhost', db_schema='testing_environment'):
        """
        These parameters can be preselected:
            belong to (test) Subject:
                :param superuser: has accounts on separate computer
                :param computer:
                :param user:
                :param code: belongs to source code tree
                :param branch: belongs to source code tree
            belong to (test) Item:
                :param type_list: belongs to example tree
                :param case_list: belongs to example tree
                :param configuration_list: belongs to example tree
                :param flow_process_list:
                :param element_type_list:
            :param operation_type: one-character string [b: building,s: simulating,p: plotting]
            :param operation: one-character string - meaning depends on operation_type
            :param test_mode:
        Parameters to access database:
            :param db_user:
            :param db_password:
            :param db_host:
            :param db_schema:
        """
        self.__flow_process_name_list = flow_process_list
        self.__element_type_name_list = element_type_list

        db_inst = Database(db_user, db_password, db_host, db_schema)
        self.__subject_inst = Subject(superuser, computer, user, code, branch, id_local_process)
        self.__setting_inst = Setting(type_list, case_list, configuration_list,
                                      operation_type, operation,
                                      test_mode, db_inst)

        if location == 'local':
            self.__subject_inst.print_selected_variables()
            self.__setting_inst.print_selected_variables()
        print('\n-----------------------------------------------------------------')
Esempio n. 33
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]
    parser = optparse.OptionParser()
    # add options here
    # ...
    opts, args = parser.parse_args(argv)
    
    # dummy run-through
    import lxml.etree as ET
    from subject import Subject
    logging.basicConfig()
#     log.setLevel(logging.DEBUG)
    
    # noisy error callback
    def raise_err(err):
        raise err.err
        
    subject = Subject.forpath('source/Case2.txt')
    errors = []
    messages = ET.parse(args[0]).getroot()
    messages_savedcopy = deepcopy_element(messages)
    
    # TODO: following is out of date
#     pipeline = SelectionPipeline(subject, errors)
#     processed_messages = pipeline(messages)

    if errors:
        print "Errors:"
        pprint(errors)
        return 1
    print ET.tostring(processed_messages)
    
    # TEMP sanity check
    from tailoring.elementutil import normalize
    def compare(a, b):
        # normalize and compare serializations
        normalize(a)
        normalize(b)
        return ET.tostring(a) == ET.tostring(b)
    assert compare(messages, messages_savedcopy)
    assert not compare(messages, processed_messages)
Esempio n. 34
0
    def __init__(self,
                 experiments_json,
                 subjects_json,
                 model_dir,
                 subject_analyses,
                 group_analyses,
                 image_dir,
                 jsons_dir="./jsons",
                 model_type="english1000"):

        self.model_type = model_type

        all_exp_info = read_json(experiments_json, jsons_dir)
        # exp2 = dict()
        # exp2['Binder2005'] = all_exp_info['Binder2005']
        # all_exp_info = exp2
        #all_exp_info2 = dict()
        #all_exp_info2['Bedny2013'] = all_exp_info['Bedny2013']
        #all_exp_info = all_exp_info2
        model_holder = ModelHolder(jsons_dir)
        self.experiments = {
            key: Experiment(model_holder=model_holder,
                            name=key,
                            image_dir=image_dir,
                            model_type=self.model_type,
                            nperm=1000,
                            **info)
            for (key, info) in all_exp_info.items()
        }

        subjects_info = read_json(subjects_json, jsons_dir)

        subjects = [
            Subject(name=key,
                    model_type=self.model_type,
                    model_dir=model_dir['subject_dir'],
                    analyses=subject_analyses,
                    **info) for (key, info) in subjects_info.items()
        ]

        self.subject_group = SubjectGroup(subjects, group_analyses)
Esempio n. 35
0
def setup(script_name=''):
    Subject.Subject_name
    settings.define_app_options()
    self_dir = os.path.dirname(os.path.abspath(__file__))
    parse_command_line(final=False)
    conf_filename = "server.conf"
    if not options.debug:
        conf_filename = "prod.conf"
    conf_filename = os.path.join(os.path.dirname(self_dir), conf_filename)
    if os.path.exists(conf_filename):
        parse_config_file(conf_filename, final=False)
    else:
        print 'no {} found. skip it'.format(conf_filename)
    parse_command_line(final=True)
    setup_log(options)

    dbs = {}
    for subject in Subject.Subject_name:
        dbs[subject] = MongoClient(options.mongodb_host,
                     replicaSet=options.replica_set)[options[subject+'db_name']]
        print 'Connected to '+subject+'db ', options.mongodb_host

    env = Env
    env.db = dbs
    env.tc = {}
    env.deeprender_host = options.deeprender_host

    env.subject = Subject.get('math')

    if not options.debug:
        channel = logging.StreamHandler(sys.stdout)
        channel.setFormatter(LogFormatter())
        logging.getLogger().addHandler(channel)

    gen_log.info("Env was setup for %s. Subject: %s", script_name, env.subject.zh_name)

    return env
Esempio n. 36
0
    def notify(self, unix_timestamp):
        time = datetime.datetime.fromtimestamp(int(unix_timestamp)).strftime('%Y-%m-%d %I:%M:%S%p')
        print 'Observer', self.name, 'says:', time


class EUTimeObserver(Observer):

    def __init__(self, name):
        self.name = name

    def notify(self, unix_timestamp):
        time = datetime.datetime.fromtimestamp(int(unix_timestamp)).strftime('%Y-%m-%d %H:%M:%S')
        print 'Observer', self.name, 'says:', time

if __name__ == '__main__':
    subject = Subject()

    print 'Adding usa_time_observer'
    observer1 = USATimeObserver('usa_time_observer')
    subject.register_observer(observer1)
    subject.notify_observers()

    time.sleep(2)
    print 'Adding eu_time_observer'
    observer2 = EUTimeObserver('eu_time_observer')
    subject.register_observer(observer2)
    subject.notify_observers()

    time.sleep(2)
    print 'Removing usa_time_observer'
    subject.unregister_observer(observer1)
Esempio n. 37
0
def load(s):
    return Subject.load(s)
Esempio n. 38
0
class Environment:
    """
    main object of icbc:
        hosts instance of classes subject, setting
    """
    def __init__(self, superuser=None, computer=None, user=None, code=None, branch=None, id_local_process='unused',
                 type_list=[None], case_list=[[None]], configuration_list=[None],
                 flow_process_list=[None], element_type_list=[[None]],
                 operation_type=None, operation=None,
                 test_mode='0',
                 db_user='******', db_password='******',
                 db_host='localhost', db_schema='testing_environment'):
        """
        These parameters can be preselected:
            belong to (test) Subject:
                :param superuser: has accounts on separate computer
                :param computer:
                :param user:
                :param code: belongs to source code tree
                :param branch: belongs to source code tree
            belong to (test) Item:
                :param type_list: belongs to example tree
                :param case_list: belongs to example tree
                :param configuration_list: belongs to example tree
                :param flow_process_list:
                :param element_type_list:
            :param operation_type: one-character string [b: building,s: simulating,p: plotting]
            :param operation: one-character string - meaning depends on operation_type
            :param test_mode:
        Parameters to access database:
            :param db_user:
            :param db_password:
            :param db_host:
            :param db_schema:
        """
        self.__flow_process_name_list = flow_process_list
        self.__element_type_name_list = element_type_list

        db_inst = Database(db_user, db_password, db_host, db_schema)
        self.__subject_inst = Subject(superuser, computer, user, code, branch, id_local_process)
        self.__setting_inst = Setting(type_list, case_list, configuration_list,
                                      operation_type, operation,
                                      test_mode, db_inst)

        if location == 'local':
            self.__subject_inst.print_selected_variables()
            self.__setting_inst.print_selected_variables()
        print('\n-----------------------------------------------------------------')

    def __del__(self):
        del self.__subject_inst
        del self.__setting_inst

    def run(self):
        """
        main function of icbc:
            1. connect to and disconnect from data base if on local computer
            2. call select functions
            3. call loop if selects successful
        :return: 0
        """
        if location == 'local':
            self.__setting_inst.connect_to_db()

        operation_inst = self.select()  # rerun if reselect chosen
        if operation_inst == 1:
            self.run()  # rerun

        self.loop(operation_inst)
        del operation_inst

        if location == 'local':
            self.__setting_inst.disconnect_from_db()  # to reconnect each run in case of table update
            if self.__setting_inst.test_mode == '0':  # control with shell
                self.run()

        return 0

    def select(self):
        """
        select
        1. select operation type and operation
        2. do configurations which are independent of test item
        3. select test items
        :return: (Operation(Building, Simulating, or Plotting)) operation instance; 1 if operation reselect or exception
        """
        self.__subject_inst.select(self.__setting_inst)

        selected_operation_type = self.__setting_inst.select_operation_type()
        operation_inst = self.select_operation(selected_operation_type)
        if operation_inst == 1:
            return 1

        if operation_inst.selected_operation == 's':  # reselect
            self.__setting_inst.reselect(self.__subject_inst)  # decide what to reselect
            return 1

        self.configure(operation_inst)

        self.__setting_inst.select_items_to_test(selected_operation_type,
                                                 operation_inst.selected_operation, self.__subject_inst.computer)

        if self.__setting_inst.operation == 'reselect':
            self.__setting_inst.operation = None
            self.run()  # now reselection is finished, rerun to select next operation

        return operation_inst

    def select_operation(self, operation_type):
        """
        1. generate operation instance,
        2. call select_operation where operation is chosen
        :param operation_type: one-character string [b: building,s: simulating,p: plotting]
        :return: operation instance Building, Simulating, Plotting; 1 if error
        """
        if operation_type == 'b':  # building
            operation_inst = Building(self.__subject_inst)
        elif operation_type == 's':  # simulating
            operation_inst = Simulating(self.__subject_inst)
        elif operation_type == 'p':  # plotting
            operation_inst = Plotting(self.__subject_inst)
        else:
            message(mode='ERROR', not_supported=operation_type)
            return 1

        operation_inst.select_operation(self.__setting_inst.operation)

        return operation_inst

    def configure(self, operation_inst):
        """
        0.  call function to set flags for file uploads
        1.  if operation is to compare results with references, clear log file with names of
            deviating files from previous runs
        2. check if list entries for test items exit
        :param operation_inst: (class Building, Simulating, Plotting (Operation))
        :return: 0 if success; 1 if lists for item not complete
        """
        operation_inst.set_upload_file_flags()

        if operation_inst.selected_operation_type == 's' and operation_inst.selected_operation == 'o':
            # the selected operation is to compare results with references
            files = glob(adapt_path('{}references\\deviatingFiles*'.format(self.__subject_inst.directory)))
            for file in files:
                remove_file(file, False)

            #clear_file(adapt_path('{}references\\deviatingFiles_{}.log'.format(
            #    self._subject_inst.directory, self._item.configuration)))

    def loop(self, operation_inst):
        """
        loop over type, case, and configuration lists
        :param operation_inst: (class Building, Simulating, Plotting (Operation))
        :return:
        """
        type_list_counter = 0
        for item_type in self.__setting_inst.item_constituents.type_list:
            for item_case in self.__setting_inst.item_constituents.case_list[type_list_counter]:
                self.set_inner_loop_elements(item_case)

                for item_configuration in self.__setting_inst.item_constituents.configuration_list:
                    if self.item_is_to_test(item_case):
                        self.loop_inner(operation_inst, item_type, item_case, item_configuration)
            if len(self.__setting_inst.item_constituents.case_list) > 1:
                type_list_counter += 1

    def set_inner_loop_elements(self, item_case):
        """
        set lists with process name and element type
        :param item_case: (string)
        :return:
        """
        if item_case is None:
            self.__flow_process_name_list = [None]
            self.__element_type_name_list = [[None]]
        else:
            if location == 'local':
                self.__flow_process_name_list = self.__setting_inst.query_flow_process_name_list(item_case)
                self.__element_type_name_list = self.__setting_inst.query_element_type_name_list(
                    item_case, self.__flow_process_name_list)

    def item_is_to_test(self, item_case):
        """
        check test_mode, state,
        used for simulation, plotting  operation type (case item exists)
        (all items (i.e. configurations) involved in building operation type)
        :param item_case: (string or None)
        :return: (bool )False: not involved, True: involved or ERROR
        """
        execute_flag = True

        if location == 'local' and item_case:
            if self.__setting_inst.test_mode == '0':
                # no test mode - select everything by typing on console
                #                and than the items in the loop (in environment run) is involved
                pass
            elif self.__setting_inst.test_mode == '1':
                # via browser
                execute_flag = self.__setting_inst.query_column_entry_for_name('cases', item_case, 'state')
            elif self.__setting_inst.test_mode == '2':
                # via CI tool
                if not self.__setting_inst.query_column_entry_for_name('cases', item_case, 'active'):
                    execute_flag = False
            else:
                message(mode='ERROR', not_supported=self.__setting_inst.test_mode)  # returns '1'

        return execute_flag  # remote always '1'

    def loop_inner(self, operation_inst, item_type, item_case, item_configuration):
        """
        1. generate (and delete) item instance
        2. call write files (for numerics, processing)
        3. call operation run function
        :param operation_inst: (class Building, Simulating, or Plotting)
        :param item_type: (string)
        :param item_case: (string)
        :param item_configuration: (string)
        :return:
        """
        for index, flow_process_name in enumerate(self.__flow_process_name_list):
            for element_type_name in self.__element_type_name_list[index]:
                # take all for remote, building or plotting
                if location == 'remote' or operation_inst.selected_operation_type == 'b' or \
                                operation_inst.selected_operation_type == 'p' or\
                        (str2bool(self.__setting_inst.query_column_entry_for_name(
                        'flow_processes', flow_process_name, 'active')) and
                                                str2bool(self.__setting_inst.query_column_entry_for_name(
                                                    'element_types', element_type_name, 'active'))):

                    item_inst = self.generate_item_instance(
                        operation_inst, item_type, item_case, item_configuration, flow_process_name, element_type_name)

                    operation_inst.set_numerics_and_processing_data(item_type, item_case, item_configuration,
                                                                    flow_process_name, element_type_name,
                                                                    self.__setting_inst, self.__subject_inst.location)
                    operation_inst.run(item_inst)

                    del item_inst

    def generate_item_instance(
            self, operation_inst, item_type, item_case, item_configuration, flow_process, element_type):
        """
        generate Build, Sim or Plot according to chosen operation
        :param operation_inst:
        :param item_type:
        :param item_case:
        :param item_configuration:
        :param flow_process:
        :param element_type
        :return: child of Item instance (Build, Sim, Plot)
        """
        if operation_inst.selected_operation_type == 'b':  # building
            return Build(self.__subject_inst, item_configuration)
        elif operation_inst.selected_operation_type == 's':  # simulating
            return Sim(self.__subject_inst, item_type, item_case, item_configuration, flow_process, element_type)
        elif operation_inst.selected_operation_type == 'p':  # plotting
            return Plot(self.__subject_inst, item_type, item_case, item_configuration, flow_process, element_type)
        else:
            message(mode='ERROR', not_supported=operation_inst.selected_operation_type)
            return 1  # check this
Esempio n. 39
0
 def __init__(self, number_of_correct_answer=0):
     Subject.__init__(self, 'KOREA', 4, number_of_correct_answer)
Esempio n. 40
0
 def __init__(self, ip, port, username, password):
     Subject.__init__(self)
     print('Connecting...')
     self.network_connect(ip, port, username, password)
def load_student_data(filename):
    """A function that reads data from a CSV file and stores it into objects.

    Args:
       filename: Name of the file

    Returns:
        A dictionary of Grade objects.

    """

    grades_dict = {}

    csv_f = open(filename, 'r')
    i = 0
    for line in csv_f:
        # print "line no:", i, "=", line
        if i > 0:
            # We don't need to read the header, so
            # we do not read line 0
            line_list = []
            line_list = line.split(',')

            grade_number = int(line_list[0])
            # Only create a grade object if it doesn't already exist
            if grade_number in grades_dict:
                grade_temp = grades_dict[grade_number]
            else:
                grade_temp = Grade(grade_number)

            sections_dict = grade_temp.get_sections()
            section_number = int(line_list[1])
            # Only create a section object if it doesn't already exist
            # in that grade
            if section_number in sections_dict:
                section_temp = sections_dict[section_number]
            else:
                section_temp = Section(section_number)

            students_dict = section_temp.get_students()
            student_name = line_list[2]
            # Only create a student object if it doesn't already exist
            # in that section
            if student_name in students_dict:
                student_temp = students_dict[student_name]
            else:
                student_temp = Student(student_name)

            subjects_dict = student_temp.get_subjects()
            subject_name = line_list[3]
            # Only create a subjects object if it doesn't already exist
            # in that student object
            if subject_name in subjects_dict:
                subject_temp = subjects_dict[subject_name]
            else:
                subject_temp = Subject(subject_name)

            tests_dict = subject_temp.get_tests()
            test_obj = Test(line_list[4], int(line_list[5]), int(line_list[6]),
                            line_list[7], line_list[8])

            tests_dict[test_obj.get_test_name()] = test_obj
            subject_temp.set_tests(tests_dict)

            subjects_dict[subject_temp.get_subject_name()] = subject_temp
            student_temp.set_subjects(subjects_dict)

            students_dict[student_temp.get_student_name()] = student_temp
            section_temp.set_students(students_dict)

            sections_dict[section_temp.get_section_number()] = section_temp
            grade_temp.set_sections(sections_dict)

            grades_dict[grade_temp.get_grade_number()] = grade_temp
        # variable i tracks line numbers read
        i = i + 1
    csv_f.close()
    return grades_dict
Esempio n. 42
0
 def __init__(self, name=""):
     Subject.__init__(self)
     self.name = name
     self.data = None
Esempio n. 43
0
 def __init__(self, number_of_correct_answer=0):
     Subject.__init__(self, 'ENGLISH', 5, number_of_correct_answer)
Esempio n. 44
0
 def __init__(self, number_of_correct_answer=0):
     Subject.__init__(self, 'MATH', 3, number_of_correct_answer)