-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcourses.py
More file actions
75 lines (60 loc) · 2.03 KB
/
courses.py
File metadata and controls
75 lines (60 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Author: Isa Blancett
# Project: Interactive Programming
# Date: 10.30.2017
# Description: Class for reading in a csv file containing course information and
# creating and instance for each course
# Acknowledgements: Script structure is modeled after Transcriptase's Game
# repository on Git
import csv
class Courses(object):
""" class for the different course options the user can choose from
contains:
label - 4 letter id
course - full title
description - in-depth summary of course
max - total number of levels
reqs - dependencies, '%s%s%s' % (effected level, needed course, needed level)
lvl - current level
order - order picked by user
"""
def setup(self, config):
self.config = config
self.label = config['label']
self.name = config['course']
self.description = config['description']
self.max = config['max']
self.reqs = config['dependencies']
self.range = config['xrange']
self.lvl = 0
self.order = 0
def create_course(config):
""" creates a single instance of a course given a config dictionary
returns: single course instance
"""
new_course = Courses()
new_course.setup(config)
return(new_course)
def populate():
""" sets up item objects by creating a config dictionary for each one
Sample config dictionary (can be copied for each new item):
config = {
'label':'LABEL'
'course':'COURSE TITLE',
'description':'DESCRIPTION',
'max': NUMBER OF LEVELS,
'dependencies': 'LVL' + 'NEEDEDCOURSE' + 'NEEDEDLEVEL',
'xrange': 'MIN MAX'
}
returns: dictionary of all course instances
"""
all_courses = {}
f = open('Source/courses.csv', 'r')
reader = csv.DictReader(f)
for row in reader:
if row != '0':
row['dependencies'] = row['dependencies'].split()
else:
row['dependencies'] = []
new_course = (create_course(row))
all_courses[new_course.label] = new_course
return all_courses