-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.ml
More file actions
200 lines (161 loc) · 6.24 KB
/
Copy pathusers.ml
File metadata and controls
200 lines (161 loc) · 6.24 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
open Parser
open Gserver
(******************************************************************************)
(* Redefining types *)
type error = Exception of exn
type vector = | AI | Compt | GG | MrkNt | WebNt | PL | SWE | SysDB | Theory
| Robot | Arch | Ren
type year = | Freshman | Sophomore | Junior | Senior
type club = | ACSU | WICC | URMC | CDS | COS | AD | CCC
type rating = int * int
type future = | Grad | Industry | Undecided
type user_result = {name: string;
netID: string;
year: year;
likes: int list;
dislikes: int list;
vector: vector;
clubs: club list;
goals: future;
}
(******************************************************************************)
(* Map for classes to corresponding vectors *)
module VClass = struct
type t = int
let compare = Pervasives.compare
end
module VMap = Map.Make(VClass)
let vecs = [AI; Compt; GG; MrkNt; WebNt; PL; SWE;
SysDB; Theory; Robot; Arch; Ren]
let all_vectors = [([4300; 4700; 4732; 4740; 4780; 4786], AI);
([2770; 4210; 4220; 4744; 4775], Compt);
([3152; 4152; 4154; 4620; 4654], GG);
([2850; 4852], MrkNt);
([4450; 5114; 5412; 5413], WebNt);
([2024; 2043; 4120; 4860; 5110; 5114; 5120], PL);
([2048; 5150; 5152], SWE);
([3300; 4320; 4830], SysDB);
([4810; 4812; 4850], Theory);
([3758; 4670; 4750; 4752; 4754], Robot);
([4420; 5220; 5300; 5420], Arch)]
(******************************************************************************)
let str_of_yr = function
| Freshman -> "Freshman"
| Sophomore -> "Sophomore"
| Junior -> "Junior"
| Senior -> "Senior"
let str_of_vec = function
| AI -> "Artificial Intelligence"
| Compt -> "Computational Fields"
| GG -> "Games and Graphics"
| MrkNt -> "Market Networks"
| WebNt -> "Web Networks"
| PL -> "Programming Languages"
| SWE -> "Software Engineering"
| SysDB -> "Systems Databases"
| Theory -> "Theory"
| Robot -> "Robotics"
| Arch -> "Computer Architecture"
| Ren -> "Renaissance"
let str_of_club = function
| ACSU -> "ACSU"
| WICC -> "WICC"
| URMC -> "URMC"
| CDS -> "Cornell Data Science"
| COS -> "Cornell Open Source"
| AD -> "Cornell App Development"
| CCC -> "Creative Computing Club"
let str_of_fut = function
| Grad -> "Grad"
| Industry -> "Industry"
| Undecided -> "Undecided"
(* [year_match s] is string [s] representing a year converted to a [year]
* variant type. *)
let year_match = function
| "Freshman" -> Freshman
| "Sophomore" -> Sophomore
| "Junior" -> Junior
| "Senior" -> Senior
| _ -> failwith "Year Match failed"
(* [club_match s] is string [s] representing a club converted to a [club]
* variant type. *)
let club_match = function
| "ACSU" -> ACSU
| "WICC" -> WICC
| "URMC" -> URMC
| "Cornell Data Science" -> CDS
| "Cornell Open Source" -> COS
| "Cornell App Development" -> AD
| "Creative Computing Club" -> CCC
| _ -> failwith "Club Match failed"
(* [fut_match s] is string [s] representing a future converted to a [future]
* variant type. *)
let fut_match = function
| "Grad" -> Grad
| "Industry" -> Industry
| "Undecided" -> Undecided
| _ -> failwith "Future Match failed"
(* [make_vec_bindings tup mp] is a mapping from class numbers to vectors. The
* mappings are specified by [tup] and will be added to the VMap [mp]*)
let rec make_vec_bindings tup mp =
match tup with
| ([], _ ) -> mp
| (h::t, v) ->
let new_map = VMap.add h v mp in
make_vec_bindings (t,v) new_map
(* [make_vector_map outter_lst mp] is a mapping from class numbers to vectors.
* The bindings are made by the mappings found in [outter_lst] and [mp] is the
* vector map that will be appended to. *)
let rec make_vector_map outter_lst mp =
match outter_lst with
| [] -> mp
| h :: t -> make_vector_map t (make_vec_bindings h mp)
let vector_map = make_vector_map all_vectors VMap.empty
(* [elective_of u] is a list of all class electives of user_result [u]*)
let elective_of u = u.electives |> List.split |> fst
(* [possible_vectors lst] is a list of vectors that are determined by the
* classes in [lst]*)
let rec possible_vectors lst =
match lst with
| [] -> []
| h::t ->
(match (VMap.find_opt h vector_map) with
|Some x -> x :: (possible_vectors t)
|None -> Ren :: (possible_vectors t)
)
(* [count_occ elm lst] is the number of times [elm] occurs in list [lst]. *)
let count_occ elm lst =
List.filter (fun x -> x = elm) lst |> List.length
(* [find_max lst] is the element of the list that occurs most frequently. *)
let find_max lst =
List.fold_left (fun x acc -> if x > acc then x else acc) min_int lst
(* [determine_vector u] is the vector variant type determined for user_result
* [u] based on the user's electives. *)
let determine_vector u =
(* try *)
let pos_vectors = possible_vectors (elective_of u) in
let counts = List.map (fun x -> count_occ x pos_vectors) vecs in
let zip = List.combine counts vecs in
match List.assoc_opt (find_max counts) zip with
| Some vec -> vec
| None -> Ren
(* with (e:exn) -> failwith (Printexc.to_string e) *)
let all_classes (u : pre_user) = u.cores @ u.pracs @ u.electives
(* [likes u] is a list of classes user [u] liked. *)
let likes u =
List.filter (fun x -> (snd x) > 3) (all_classes u) |> List.map fst
(* [dislikes u] is a list of classes user [u] disliked. *)
let dislikes u =
List.filter (fun x -> (snd x) < 3) (all_classes u) |> List.map fst
(* [make_user_result up] is a user_result [u] whose information matches [up]
* and whose vector has been determined. *)
let make_user_result (up : pre_user) =
{name = up.name;
netID = up.netID;
year = up.year |> year_match;
likes = likes up;
dislikes = dislikes up;
vector = determine_vector up;
clubs = List.map club_match up.clubs;
goals = up.goals |> fut_match;
}