Ejemplo n.º 1
0
def add_institution(institution_name,
                    old_username,
                    ror_id_list,
                    is_consortium=False):
    logger.info(u"initializing institution {}".format(institution_name))

    my_institutions = db.session.query(Institution).filter(
        Institution.display_name == institution_name,
        Institution.id.notlike('%jisc%')).all()

    if my_institutions:
        my_institution = my_institutions[0]
        logger.info(
            u"  *** using existing institution {} ***".format(my_institution))

    if is_consortium:
        print "SETTING UP AS A CONSORTIUM ACCOUNT"

    else:
        my_institution = Institution()
        my_institution.display_name = institution_name
        my_institution.old_username = old_username
        my_institution.is_demo_institution = False
        my_institution.is_consortium = is_consortium
        db.session.add(my_institution)
        logger.info(u"  adding {}".format(my_institution))

    if not ror_id_list:
        return

    for ror_id in ror_id_list:
        add_ror(ror_id, my_institution.id)
Ejemplo n.º 2
0
def read_institutions(program:str):
	db = dfsapi.get_db()

	institutions = list()

	keys = db.child(program).child("institutions").shallow().get()

	if keys.val() == None:
		return False

	recentdb = max(keys.val())

	data = db.child(program).child("institutions").child(recentdb).get()

	for i in data.each():
		institution = i.val()

		Name = institution["Name"]
		Address = institution["Address"]
		County = institution["County"]
		Instructors = institution["Instructors"]
		Schedule = manageinstructors.schedule_to_dict(institution["Schedule"])

		institutions.append(Institution(Name, Address, County, 
			Instructors, Schedule))

	return institutions
Ejemplo n.º 3
0
def make_institution_list(info: dict, program: str):
    institutions = list()

    for school in info:
        new_schedule = schedule_to_dict(info[school]['Schedule'])
        institutions.append(
            Institution(info[school]['Name'], info[school]['Address'],
                        info[school]['County'], info[school]['Instructors'],
                        new_schedule))

    return institutions
def get_or_create_placeholder_institution():
    display_name = 'placeholder, see prepared_demo_publisher.py'
    institution = Institution.query.filter(
        Institution.display_name == display_name).scalar()

    if not institution:
        institution = Institution(display_name=display_name,
                                  is_consortium=False,
                                  is_demo_institution=True)
        db.session.add(institution)

    return institution
Ejemplo n.º 5
0
def test_lawInstitution_fields():
    # Verify, upon instantiation, that all fields of the law and institution
    # classes are of the type they should be.
    society = Society(population_size=10)
    institution = Institution(society)
    laws = institution._generate_laws(society)

    assert isinstance(institution.get_affiliation(), float)

    for law in laws:
        for person_id in range(society.population_size):
            assert isinstance(law.affected_persons[person_id], int)
        assert isinstance(law.mean, float)
        assert isinstance(law.law_type, str)
        assert isinstance(law.actual_value, float)
Ejemplo n.º 6
0
def read_institutions(program: str):
    db = dfsapi.get_db()

    institutions = list()

    keys = db.child(program).child("institutions").shallow().get()
    recentdb = max(keys.val())

    data = db.child(program).child("institutions").child(recentdb).get()

    for i in data.each():
        institution = i.val()

        Name = institution["Name"]
        Address = institution["Address"]
        County = institution["County"]
        Program = institution["Program"]
        Instructors = institution["Instructors"]

        Mon = dbtools.minute_range(institution["Monday"])
        Tue = dbtools.minute_range(institution["Tuesday"])
        Wed = dbtools.minute_range(institution["Wednesday"])
        Thurs = dbtools.minute_range(institution["Thursday"])
        Fri = dbtools.minute_range(institution["Friday"])

        Schedule = defaultdict(list)

        if Mon != None:
            Schedule[1].append(Mon)
        if Tue != None:
            Schedule[2].append(Tue)
        if Wed != None:
            Schedule[3].append(Wed)
        if Thurs != None:
            Schedule[4].append(Thurs)
        if Fri != None:
            Schedule[5].append(Fri)

        institutions.append(
            Institution(Name, Address, County, Program, Instructors, Schedule))

    return institutions
Ejemplo n.º 7
0
 def parse(self, token):
     self.parsed = json.loads(self.data)
     # print formatted received json
     # print(json.dumps(self.parsed, indent=4, sort_keys=True))
     db = DataBase()
     self.institutions = []
     for row in self.parsed["data"]:
         new_institution = Institution()
         new_institution.id = row["id"]
         new_institution.address = self.try_figure_out(row, "address")
         new_institution.benefit = self.try_figure_out(row, "benefit")
         new_institution.car_park = self.try_figure_out(row, "car-park")
         new_institution.locality = self.try_figure_out(row, "locality")
         new_institution.phone = self.try_figure_out(row, "phone")
         new_institution.place = self.try_figure_out(row, "place")
         new_institution.provider = self.try_figure_out(row, "provider")
         new_institution.regon = self.try_figure_out(row, "regon-provider")
         if token is not None:
             new_institution.is_fav = db.is_fav(token, row["id"])
         # new_institution.p_print()
         self.institutions.append(new_institution)
     self.create_response_dict()
Ejemplo n.º 8
0
 def parse_id_response(self):
     self.parsed = json.loads(self.data)
     new_institution = Institution()
     new_institution.id = self.parsed["data"]["id"]
     new_institution.address = self.try_figure_out(self.parsed["data"],
                                                   "address")
     new_institution.benefit = self.try_figure_out(self.parsed["data"],
                                                   "benefit")
     new_institution.car_park = self.try_figure_out(self.parsed["data"],
                                                    "car-park")
     new_institution.locality = self.try_figure_out(self.parsed["data"],
                                                    "locality")
     new_institution.phone = self.try_figure_out(self.parsed["data"],
                                                 "phone")
     new_institution.place = self.try_figure_out(self.parsed["data"],
                                                 "place")
     new_institution.provider = self.try_figure_out(self.parsed["data"],
                                                    "provider")
     new_institution.regon = self.try_figure_out(self.parsed["data"],
                                                 "regon-provider")
     new_institution.is_fav = True
     self.institutions = [new_institution]
     self.create_response_dict()
Ejemplo n.º 9
0
	def login( self, institution_cnpj, password ):
		new_institution = Institution( institution_cnpj, password )
Ejemplo n.º 10
0
	def removeInstitution( self, institution_cnpj, password ):
		institution = Institution( institution_cnpj, password )
		institution.deleteFromStorage()
Ejemplo n.º 11
0
	def registerInstitution( self, institution_name, cnpj, address, phone_number, email, access_password ):
		new_institution = Institution( cnpj, access_password, address, phone_number, email, institution_name )
		new_institution.registerToStorage( access_password )
Ejemplo n.º 12
0
# Import institution mAtch data
# Make the list of Institutions
print('importing institution data')
data2008 = InstitutionData('/Users/vmd/Dropbox/Match/residency-match-simulation/matchdata2008.csv', 140, 'C', 1)
data2008.read_data_file()
data2008.prep_data()
data2008.select_data()

print('Setting Institution Attributes')
all_institutions = []
for x in data2008.finaldata:

#TODO: how to name the instances
    tname = x[1] # the Code is set as the object instance name, (I don't think this really works)
    tname = Institution() # the Code is set as the object instance name
    tname.name = x[1] #The name attribute is also set as the Code
    tname.openings = x[6] #Set the number of openings, comes from quota in the data file
    tname.prog_type = x[4] #Set the Type, for example 'C' is categorical
    tname.specialty = x[3] #Set the specialty, for example 140 is internal medicine
    tname.institution = x[2] #Set the institution number, basicly the name without the prog_type and specialty info
    tname.specialty_name = x[0] #This is the Speacialty name rather then code
    tname.obs_match = x[7] # The is the number that matched in the actual data set

    # Comment out the Following to use defualt
    tname.quality = max(min(r.gauss(50, 30), 100), 1) # on a scale 0-100
    tname.number_to_interview = 10 * tname.openings
    tname.observe_1 = r.gauss(1, .2)
    tname.observe_2 = tname.observe_2 = (r.gauss(1, .1)- tname.observe_1)
    tname.observed_1 = r.gauss(1, .2)
    tname.observed_2 = (r.gauss(1, .1)- tname.observed_1) # based on applicant interviewed, percentage