Skip to content

Commit

Permalink
Minor datatype changes
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenfree committed Jun 4, 2020
1 parent 5e8a445 commit 63ee6d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
26 changes: 2 additions & 24 deletions src/datatypes/DataTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Enumerated types
@enum Degree AA AS AAS BA BS
@enum System semester quarter
@enum Requisite pre co strict_co
@enum Requisite pre co strict_co custom
@enum EdgeClass tree_edge back_edge forward_edge cross_edge

# fundamental data types for curricular analytics
Expand All @@ -13,26 +13,4 @@ include("curriculum.jl")
include("degreeplan.jl")

# additional types
include("coursecatalog.jl")

# Returns a requisite as a string
function requisite_to_string(req::Requisite)
if req == pre
return "CurriculumPrerequisite"
elseif req == co
return "CurriculumCorequisite"
else
return "CurriculumStrictCorequisite"
end
end

# Returns a requisite (enumerated type) from a string
function string_to_requisite(req::String)
if (req == "prereq" || req == "CurriculumPrerequisite")
return pre
elseif (req == "coreq" || req == "CurriculumCorequisite")
return co
elseif (req == "strict-coreq" || req == "CurriculumStrictCorequisite")
return strict_co
end
end
include("coursecatalog.jl")
3 changes: 2 additions & 1 deletion src/datatypes/course.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mutable struct Course
this.cross_listed = cross_listed
this.canonical_name = canonical_name
this.requisites = Dict{Int, Requisite}()
#this.requisite_formula
this.metrics = Dict{String, Any}()
this.metadata = Dict{String, Any}()
this.learning_outcomes = learning_outcomes
Expand All @@ -70,7 +71,7 @@ mutable struct Course
end

function course_id(prefix::AbstractString, num::AbstractString, name::AbstractString, institution::AbstractString)
mod(hash(name * prefix * num * institution), UInt32)
convert(Int, mod(hash(name * prefix * num * institution), UInt32))
end

"""
Expand Down
11 changes: 6 additions & 5 deletions src/datatypes/coursecatalog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ mutable struct CourseCatalog
name::AbstractString # Name of the course catalog
institution::AbstractString # Institution offering the courses in the catalog
date_range::Tuple # range of dates the catalog is applicable over
catalog::Dict{UInt32, Course} # dictionary of courses in (course_id, course) format
catalog::Dict{Int, Course} # dictionary of courses in (course_id, course) format

# Constructor
function CourseCatalog(name::AbstractString, institution::AbstractString; courses::Array{Course}=Array{Course,1}(),
catalog::Dict{UInt32,Course}=Dict{UInt32,Course}(), date_range::Tuple=(), id::Int=0)
catalog::Dict{Int,Course}=Dict{Int,Course}(), date_range::Tuple=(), id::Int=0)
this = new()
this.name = name
this.institution = institution
this.catalog = catalog
this.date_range = date_range
this.id = id
this.id = mod(hash(this.name * this.institution), UInt32)
length(courses) > 0 ? add_course!(this, courses) : nothing
return this
end
Expand All @@ -37,8 +37,9 @@ function is_duplicate(cc::CourseCatalog, course::Course)
course.id in keys(cc.catalog) ? true : false
end

function course(cc::CourseCatalog, prefix::AbstractString, num::AbstractString, name::AbstractString, institution::AbstractString)
hash_val = mod(hash(name * prefix * num * institution), UInt32)
# Return a course in a course catalog
function course(cc::CourseCatalog, prefix::AbstractString, num::AbstractString, name::AbstractString)
hash_val = mod(hash(name * prefix * num * cc.institution), UInt32)
if hash_val in keys(cc.catalog)
return cc.catalog[hash_val]
else
Expand Down

0 comments on commit 63ee6d5

Please sign in to comment.