-
Notifications
You must be signed in to change notification settings - Fork 6
/
data-generator.html
169 lines (136 loc) · 5.53 KB
/
data-generator.html
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
<html>
<head>
<script>
/*
TODO:
- Incorporate the courses (after adding more);
- randomly add a second non-duplticating affliate
*/
var surnames = ["Gasper", "Smith", "Anderson", "Roberts", "Davis", "Brown", "Langenberg", "Vales",
"Grady", "Doe", "Morrison", "Walters", "Johnson", "Williams", "Peterson", "Martinez", "Thompson",
"White", "Lee", "Clark", "Lewis", "Lopez", "Gonazles", "Scott", "Henderson", "Butler", "Price"];
var givenNames = ["John", "Michael", "Jennifer", "Nancy", "Bill", "William",
"Kiersten", "Marie", "Lori", "Mark", "Eric", "David", "Ann",
"Donna", "Paul", "Thomas", "Robert", "David", "Jim", "James",
"Blake", "Sarah", "Karoline", "Kim", "Erik", "Greg", "Karl",
"Colin", "Jo", "Betty", "Lisa", "Heather", "Mary", "Jennifer"];
var departments = ["Computer Science", "Engineering", "Business", "Accounting",
"Law", "Physical Education", "Language Arts", "Financial Aid",
"Information Technology", "Advising", "Purchasing", "Account Payable"];
var affliations = ["student", "staff", "faculty", "member", "alum", "community"];
var courses = ["ACCT101", "ACCT201", "MATH100", "MATH101", "CS251", "CS252", "SCI123",
"SCI123", "SCI404"];
function generateData() {
var people = [];
var uids = [];
var personCount = parseInt(document.getElementById('count').value)-1;
var tableName = document.getElementById('table_name').value;
var peopleOu = document.getElementById('people_ou').value;
for (i=0; i <= personCount; i++) {
surname = surnames[Math.floor(Math.random() * surnames.length)];
givenName = givenNames[Math.floor(Math.random() * givenNames.length)];
department = departments[Math.floor(Math.random() * departments.length)];
affliation = selectUnduplicated(affliations, 2);
course = selectUnduplicated(courses, 4);
uid = givenName[0] + surname;
if (uids.indexOf(uid) >= 0) {
uid = uid + i;
}
uids.push(uid);
var person = {uid: uid.toLowerCase(), surname: surname, givenName: givenName, department: department, affliations: affliation, courses: course};
people.push(person);
}
var ldif = "";
for (j = 0; j < people.length; j++) {
ldif += formatLdif(people[j], peopleOu);
}
document.getElementById('ldif').value = ldif;
var sql = "";
sql += sqlHeader(tableName);
for (k = 0; k < people.length; k++) {
sql += formatSqlSubjects(people[k], tableName);
sql += formatSqlCourses(people[k], tableName);
}
document.getElementById('sql').value = sql;
}
function formatLdif(person, ou) {
var output =
"dn: uid=<uid>," + ou +"\n" +
"objectClass: organizationalPerson\n" +
"objectClass: person\n" +
"objectClass: top\n" +
"objectClass: inetOrgPerson\n" +
"objectClass: eduPerson\n" +
"surname: <surname>\n" +
"givenName: <givenName>\n" +
"cn: <givenName> <surname>\n" +
"uid: <uid>\n" +
"mail: <uid>@example.edu\n" +
"businessCategory:<department>\n" +
"userPassword: password\n";
output = output.replace(/<uid>/g, person.uid);
output = output.replace(/<surname>/g, person.surname);
output = output.replace(/<givenName>/g, person.givenName);
output = output.replace(/<department>/g, person.department);
for (i=0; i < person.affliations.length; i++) {
output += "eduPersonAffiliation: " + person.affliations[i] + "\n";
}
return output + "\n";
}
function sqlHeader(tableName) {
return "DROP TABLE " + tableName + ";\n" +
"\n" +
"CREATE TABLE " + tableName + " (\n" +
" uid varchar(255) NOT NULL,\n" +
" surname varchar(255) default NULL,\n" +
" givenName varchar(255) default NULL,\n" +
" courseId varchar(255) default NULL,\n" +
" PRIMARY KEY (uid, courseId)\n" +
");\n\n";
}
function formatSqlSubjects(person, tableName) {
var template =
"INSERT INTO " + tableName + " (uid, surname, givenName, courseId) " +
"VALUES ('<uid>','<surname>','<givenName>','<courseId>');\n";
var output = "";
for (i=0; i < person.courses.length; i++) {
temp = template.replace(/<uid>/g, person.uid);
temp = temp.replace(/<surname>/g, person.surname);
temp = temp.replace(/<givenName>/g, person.givenName);
temp = temp.replace(/<courseId>/g, person.courses[i]);
output += temp;
}
return output;
}
function formatSqlCourses(person) {
var output =
"";
output = output.replace(/<uid>/g, person.uid);
output = output.replace(/<surname>/g, person.surname);
output = output.replace(/<givenName>/g, person.givenName);
return output;
}
function selectUnduplicated(source, max) {
var output = [];
count = Math.floor(Math.random() * max) + 1;
while (output.length < count) {
item = source[Math.floor(Math.random() * source.length)];
if (output.indexOf(item) == -1) {
output.push(item);
}
}
return output;
}
</script>
</head>
<body>
<form>
Number of Subjects: <input type="text" name="count" id="count" value="10"/> <br />
Table Name: <input type="text" name="table_name" id="table_name" value="SIS_Courses"/> <br />
People OU: <input type="text" name="people_ou" id="people_ou" value="ou=People,dc=example,dc=edu"/> <br />
<input type="button" onclick="generateData(); return false;" value="Run" /> <br />
</form>
Ldif: <br /><textarea cols="100" rows="15" id="ldif"></textarea><br />
Sql: <br /><textarea cols="100" rows="15" id="sql"></textarea> <br />
</body>
</html>