• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uw-it-aca / pathways / 11332460857

14 Oct 2024 05:40PM UTC coverage: 59.134%. Remained the same
11332460857

push

github

web-flow
Merge pull request #274 from uw-it-aca/feature/new-career-outcomes

switching to admit.uw outcomes

0 of 1 new or added line in 1 file covered. (0.0%)

628 of 1062 relevant lines covered (59.13%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pathways/management/commands/import_data.py
1
# Copyright 2024 UW-IT, University of Washington
2
# SPDX-License-Identifier: Apache-2.0
3

4
from django.core.management.base import BaseCommand
×
5
import json
×
6
import csv
×
7
from pathways.data_import import import_major_data, import_course_data, \
×
8
    import_curric_data, import_level_coi, import_coi_ranges, \
9
    import_gateway_courses, import_bottleneck_courses, \
10
    import_career_center_mapping
11
from logging import getLogger
×
12
import time
×
13
import hashlib
×
14
from pathways.models.data_import import DataImport
×
15

16

17
logger = getLogger(__name__)
×
18
COI_PATH = "pathways/data/coi_scores.csv"
×
19
MAJOR_PATH = "pathways/data/major_data.json"
×
20
COURSE_PATH = "pathways/data/course_data.json"
×
21
CURRIC_PATH = "pathways/data/curric_data.json"
×
22
BOTTLENECK_PATH = "pathways/data/bottleneck_courses.csv"
×
23
GATEWAY_PATH = "pathways/data/gateway_courses.csv"
×
NEW
24
CAREER_CENTER_PATH = "pathways/data/admit_major_mapping.csv"
×
25

26

27
class Command(BaseCommand):
×
28
    help = 'Run all unit tests'
×
29

30
    def handle(self, *args, **options):
×
31
        start = time.time()
×
32
        if not self.data_needs_update():
×
33
            return
×
34
        with open(COI_PATH) as coi_file:
×
35
            reader = csv.reader(coi_file)
×
36
            # skip headers
37
            next(reader)
×
38
            coi_data = []
×
39
            for row in reader:
×
40
                coi_data.append({"course_id": row[0],
×
41
                                 "coi_score": float(row[1])})
42
            import_level_coi(coi_data)
×
43
            import_coi_ranges(coi_data)
×
44
            with open(MAJOR_PATH) as major_file:
×
45
                data = json.load(major_file)
×
46
                import_major_data(data)
×
47
            with open(COURSE_PATH) as course_file:
×
48
                data = json.load(course_file)
×
49
                import_course_data(data, coi_data)
×
50
            with open(CURRIC_PATH) as curric_file:
×
51
                data = json.load(curric_file)
×
52
                import_curric_data(data, coi_data)
×
53
            with open(GATEWAY_PATH) as gateway_file:
×
54
                data = csv.reader(gateway_file)
×
55
                import_gateway_courses(data)
×
56
            with open(BOTTLENECK_PATH) as bottleneck_file:
×
57
                data = csv.reader(bottleneck_file)
×
58
                import_bottleneck_courses(data)
×
59
            with open(CAREER_CENTER_PATH) as career_major_file:
×
60
                data = csv.reader(career_major_file)
×
61
                import_career_center_mapping(data)
×
62

63
        total_time = time.time() - start
×
64
        logger.info("Imported data in: %s" % total_time)
×
65

66
    def data_needs_update(self):
×
67
        needs_update = False
×
68
        coi_hash = self._get_hash_by_path(COI_PATH)
×
69
        if DataImport.needs_import('coi', coi_hash):
×
70
            needs_update = True
×
71
            DataImport.objects \
×
72
                .update_or_create(type='coi',
73
                                  defaults={'hash': coi_hash})
74
        major_hash = self._get_hash_by_path(MAJOR_PATH)
×
75
        if DataImport.needs_import('major', major_hash):
×
76
            needs_update = True
×
77
            DataImport.objects \
×
78
                .update_or_create(type='major',
79
                                  defaults={'hash': major_hash})
80
        course_hash = self._get_hash_by_path(COURSE_PATH)
×
81
        if DataImport.needs_import('course', course_hash):
×
82
            needs_update = True
×
83
            DataImport.objects \
×
84
                .update_or_create(type='course',
85
                                  defaults={'hash': course_hash})
86
        curric_hash = self._get_hash_by_path(CURRIC_PATH)
×
87
        if DataImport.needs_import('curric', curric_hash):
×
88
            needs_update = True
×
89
            DataImport.objects \
×
90
                .update_or_create(type='curric',
91
                                  defaults={'hash': curric_hash})
92
        gateway_hash = self._get_hash_by_path(GATEWAY_PATH)
×
93
        if DataImport.needs_import('gateway', gateway_hash):
×
94
            needs_update = True
×
95
            DataImport.objects \
×
96
                .update_or_create(type='gateway',
97
                                  defaults={'hash': gateway_hash})
98
        bottleneck_hash = self._get_hash_by_path(BOTTLENECK_PATH)
×
99
        if DataImport.needs_import('bottleneck', bottleneck_hash):
×
100
            needs_update = True
×
101
            DataImport.objects \
×
102
                .update_or_create(type='bottleneck',
103
                                  defaults={'hash': bottleneck_hash})
104
        career_hash = self._get_hash_by_path(CAREER_CENTER_PATH)
×
105
        if DataImport.needs_import('cc_major', career_hash):
×
106
            needs_update = True
×
107
            DataImport.objects \
×
108
                .update_or_create(type='cc_major',
109
                                  defaults={'hash': career_hash})
110
        return needs_update
×
111

112
    def _get_hash_by_path(self, path):
×
113
        return hashlib.md5(open(path, 'rb').read()).hexdigest()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc