Beispiel #1
0
 def test_get_school(self):
     """test grabbing a school by ID"""
     closed_school = School(pk=999999, operating=False)
     closed_school.save()
     test1 = get_school('155317')
     self.assertTrue(test1.pk == 155317)
     test2 = get_school('xxx')
     self.assertTrue(test2 is None)
     test3 = get_school('999999')
     self.assertTrue(test3 is None)
Beispiel #2
0
 def test_get_school(self):
     """test grabbing a school by ID"""
     closed_school = School(pk=999999, operating=False)
     closed_school.save()
     test1 = get_school('155317')
     self.assertTrue(test1.pk == 155317)
     test2 = get_school('xxx')
     self.assertTrue(test2 is None)
     test3 = get_school('999999')
     self.assertTrue(test3 is None)
def tag_schools(s3_url):
    """
    Sets schools' 'settlement_school' value based on a CSV

    Assumes the CSV's headings include fields for 'ipeds_unit_id' and 'flag'
    """
    counter = 0
    csv_data = read_in_s3(s3_url)
    if not csv_data[0]:
        return "ERROR: could not read data from {0}".format(s3_url)
    headings = csv_data[0].keys()
    for heading in ['ipeds_unit_id', 'flag']:
        if heading not in headings:
            return ("ERROR: CSV doesn't have required fields; "
                    "fields found were {}".format(headings))
    initial_flag = csv_data[0]['flag']
    for row in csv_data:
        school = None
        if row['ipeds_unit_id']:
            school = get_school(row['ipeds_unit_id'])
        if school:
            school.settlement_school = row['flag']
            school.save()
            counter += 1
    intro = "school was" if counter == 1 else "schools were"
    return "{} {} tagged as '{}' settlement schools".format(
        counter, intro, initial_flag)
def tag_schools(s3_url):
    """
    Sets schools' 'settlement_school' value based on a CSV

    Assumes the CSV's headings include fields for 'ipeds_unit_id' and 'flag'
    """
    counter = 0
    csv_data = read_in_s3(s3_url)
    if not csv_data[0]:
        return "ERROR: could not read data from {0}".format(s3_url)
    headings = csv_data[0].keys()
    for heading in ["ipeds_unit_id", "flag"]:
        if heading not in headings:
            return "ERROR: CSV doesn't have required fields; " "fields found were {}".format(headings)
    initial_flag = csv_data[0]["flag"]
    for row in csv_data:
        school = None
        if row["ipeds_unit_id"]:
            school = get_school(row["ipeds_unit_id"])
        if school:
            school.settlement_school = row["flag"]
            school.save()
            counter += 1
    intro = "school was" if counter == 1 else "schools were"
    return "{} {} tagged as '{}' settlement schools".format(counter, intro, initial_flag)
Beispiel #5
0
def load_values(dry_run=True):
    updated = 0
    points = 0
    oncampus = 0
    source_dict = process_datafiles()
    current_ids = [school.pk for school in School.objects.all()]
    missing = [pk for pk in source_dict.keys() if int(pk) not in current_ids]
    if missing and dry_run is False:
        process_missing(missing)
    for ID in source_dict:
        new_data = source_dict[ID]
        if 'onCampusAvail' in new_data:
            if new_data['onCampusAvail'] == '1':
                new_data['onCampusAvail'] = 'Yes'
                oncampus += 1
            else:
                new_data['onCampusAvail'] = 'No'
        school = get_school(ID)
        if school:
            school_data = STARTER_DICT
            for data_key in new_data:
                val = new_data[data_key]
                if val == '.':
                    val = None
                school_data[data_key.upper()] = val
                points += 1
            school.data_json = json.dumps(school_data)
            if not dry_run:
                school.save()
            updated += 1
    if dry_run:
        msg = (
            "DRY RUN:\n"
            "- {} would have updated {} data points for {} schools\n"
            "- {} schools found with on-campus housing\n"
            "- {} new school records "
            "would have been created".format(
                SCRIPT,
                icomma(points),
                icomma(updated),
                icomma(oncampus),
                len(missing)))
        return msg
    msg = (
        "{} updated {} data points for {} schools;\n"
        "{} new school records were created".format(
            SCRIPT,
            icomma(points),
            icomma(updated),
            len(missing)))
    return msg
Beispiel #6
0
def load_values(dry_run=True):
    updated = 0
    points = 0
    oncampus = 0
    source_dict = process_datafiles()
    current_ids = [school.pk for school in School.objects.all()]
    missing = [pk for pk in source_dict.keys() if int(pk) not in current_ids]
    if missing and dry_run is False:
        process_missing(missing)
    for ID in source_dict:
        new_data = source_dict[ID]
        if 'onCampusAvail' in new_data:
            if new_data['onCampusAvail'] == '1':
                new_data['onCampusAvail'] = 'Yes'
                oncampus += 1
            else:
                new_data['onCampusAvail'] = 'No'
        school = get_school(ID)
        if school:
            school_data = STARTER_DICT
            for data_key in new_data:
                val = new_data[data_key]
                if val == '.':
                    val = None
                school_data[data_key.upper()] = val
                points += 1
            school.data_json = json.dumps(school_data)
            if not dry_run:
                school.save()
            updated += 1
    if dry_run:
        msg = ("DRY RUN:\n"
               "- {} would have updated {} data points for {} schools\n"
               "- {} schools found with on-campus housing\n"
               "- {} new school records "
               "would have been created".format(SCRIPT,
                                                icomma(points),
                                                icomma(updated),
                                                icomma(oncampus),
                                                len(missing)))
        return msg
    msg = ("{} updated {} data points for {} schools;\n"
           "{} new school records were created".format(SCRIPT,
                                                       icomma(points),
                                                       icomma(updated),
                                                       len(missing)))
    return msg
Beispiel #7
0
 def test_get_school(self):
     """test grabbing a school by ID"""
     test1 = get_school('155317')
     self.assertTrue(test1.pk == 155317)
     test2 = get_school('xxx')
     self.assertTrue(test2 == '')
Beispiel #8
0
 def test_get_school(self):
     """test grabbing a school by ID"""
     test1 = get_school('155317')
     self.assertTrue(test1.pk == 155317)
     test2 = get_school('xxx')
     self.assertTrue(test2 == '')