-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample-object.js
290 lines (282 loc) · 5.87 KB
/
sample-object.js
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/**
* Generate a sample object to demonstrate the JSON OBJECT EDITOR
* @type {Object}
*/
var SAMPLE = {
sampleID: 131117,
name: "DOM Representation of a JSON object using Canadian Military ranks and some random data",
units: [],
minister: "Right Honourable H. S.",
Governor_General: "Her Excellency J. P.",
}
function department(){
name=null;
title=null;
address=null;
budget=null;
officers=[];
log= new Date();
}
function officer(){
name=null;
rank=null;
command=[];
division=null,
log=new Date();
}
var divisions= ["Army","Navy","Air Force"];
var addr = ["1239 Defence Way Blvd, Capital City, Wingsland WL7a-67D",
"78 Landslock Square, Captial City North, Wingsland TE9x-07S",
"2878 Crypton Street, Captial City South, Wingsland AWW8-08AF",
"324 Banks Road, Captial City , Wingsland WYE-90WR",
"913 Mainway Highway N, Captial City , Wingsland WHW-765S"];
var navy_ranks = [
"Admiral (Adm)",
"Vice-Admiral (VAdm)",
"Rear-Admiral (RAdm)",
"Commodore (Cmdre)",
"Captain(N) (Capt(N))",
"Commander (Cdr)",
"Lieutenant-Commander (LCdr)",
"Lieutenant(N) (Lt(N))",
"Sub-Lieutenant (SLt)",
"Acting Sub-Lieutenant (A/SLt)",
"Naval Cadet (NCdt)",
"Chief Petty Officer 1st class(CPO 1)",
"Chief Petty Officer 2nd class(CPO 2)",
"Petty Officer 1st class(PO 1)",
"Petty Officer 2nd class(PO 2)",
"Master Seaman (MS)",
"Leading Seaman (LS)",
"Able Seaman (AB)",
"Ordinary Seaman (OS)"
];
var ranks=[
"General (Gen)",
"Lieutenant-General (LGen)",
"Major-General (MGen)",
"Brigadier-General (BGen)",
"Colonel (Col)",
"Lieutenant-Colonel (LCol)",
"Major (Maj)",
"Captain (Capt)",
"Lieutenant (Lt)",
"Second Lieutenant (2Lt)",
"Officer Cadet (OCdt)",
"Chief Warrant Officer(CWO)",
"Master Warrant Officer (MWO)",
"Warrant Officer (WO)",
"Sergeant (Sgt)",
"Master Corporal (MCpl)",
"Corporal (Cpl)",
"Private (Trained) (Pte (T)) / Aviator (Trained) (Avr (T))",
"Private (Basic) (Pte (B)) / Aviator (Basic) (Avr (B))"
];
var fnames=[
"Olivia",
"Emma",
"Charlotte",
"Sophia",
"Aria",
"Ava",
"Chloe",
"Zoey",
"Abigail",
"Amelia",
"Emily",
"Isabella",
"Mila",
"Maya",
"Lily",
"Riley",
"Madison",
"Mia",
"Nora",
"Ella",
"Noah",
"Liam",
"Jackson",
"Lucas",
"Logan",
"Benjamin",
"Jacob",
"William",
"Oliver",
"James",
"Lincoln",
"Jack",
"Ethan",
"Carter",
"Aiden",
"Grayson",
"Mason",
"Owen",
"Leo",
"Nathan"
]
var lnames=[
"Smith",
"Brown",
"Tremblay",
"Martin",
"Roy",
"Wilson",
"Macdonald",
"Gagnon",
"Johnson",
"Taylor",
"Cote",
"Campbell",
"Anderson",
"Leblanc",
"Lee",
"Jones",
"White",
"Williams",
"Miller",
"Thompson",
"Gauthier",
"Young",
"Van",
"Morin",
"Bouchard",
"Scott",
"Stewart",
"Belanger",
"Reid",
"Pelletier",
"Moore",
"Lavoie",
"King",
"Robinson",
"Levesque",
"Murphy",
"Fortin",
"Gagne",
"Wong",
"Clark",
"Johnston",
"Clarke",
"Ross",
"Walker",
"Thomas",
"Boucher",
"Landry",
"Kelly",
"Bergeron",
"Davis",
"Mitchell",
"Murray",
"Poirier",
"Mcdonald",
"Richard",
"Wright",
"Girard",
"Lewis",
"Baker",
"Roberts",
"Simard",
"Graham",
"Caron",
"Harris",
"Jackson",
"Green",
"Beaulieu",
"Fraser",
"Fournier",
"Kennedy",
"Hall",
"Hill",
"Chan",
"Wood",
"Lapointe"
]
/**
* Randomizig method to compile a sample JSON object
* @return {[type]} [description]
*/
function make_sample(){
var push_to_command= function(i, p , pos){
switch(pos.length){
case 1:
SAMPLE.units[i].officers[pos[0]].command.push(p);
break;
case 2:
SAMPLE.units[i].officers[pos[0]].command[pos[1]].command.push(p);
break;
case 3:
SAMPLE.units[i].officers[pos[0]].command[pos[1]].command[pos[2]].command.push(p);
break;
case 4:
SAMPLE.units[i].officers[pos[0]].command[pos[1]].command[pos[2]].command[pos[3]].command.push(p);
break;
case 5:
SAMPLE.units[i].officers[pos[0]].command[pos[1]].command[pos[2]].command[pos[3]].command[pos[4]].command.push(p);
break;
case 6:
SAMPLE.units[i].officers[pos[0]].command[pos[1]].command[pos[2]].command[pos[3]].command[pos[4]].command[pos[5]].command.push(p);
break;
default:
SAMPLE.units[i].officers[pos[0]].command[pos[1]].command[pos[2]].command[pos[3]].command[pos[4]].command[pos[5]].command[pos[6]].command.push(p);
break;
}
}
var locate_commander= function(arr, rank, pos){
var bool = false;
for( var i = 0; i < arr.length;i++ ){
bool = ( arr[i].division=="Navy")?true:false;
if( locate_rank_pos(rank, bool) > locate_rank_pos(arr[i].rank, bool)){
pos.push(i)
if( arr[i].command.length > 0 ){
pos = locate_commander(arr[i].command, rank, pos)
}
i = arr.length;
}
}
return pos;
}
var locate_rank_pos= function(rank, navy){
if( navy){
for(var i =0; i < navy_ranks.length; i++){
if( navy_ranks[i] == rank){
return i;
}
}
}else{
for(var i =0; i < ranks.length; i++){
if( ranks[i] == rank){
return i;
}
}
}
}
var make_person = function(div){
var temp = new officer();
temp.name = fnames[(Math.floor( Math.random()* fnames.length) )]+" "+lnames[(Math.floor( Math.random()* lnames.length) )];
if( div== "Navy"){
temp.rank = navy_ranks[(Math.floor( Math.random()* navy_ranks.length ))];
}else{
temp.rank = ranks[(Math.floor( Math.random()* ranks.length) )];
}
temp.division =div;
temp.command=[];
return temp;
}
for ( var i = 0; i < divisions.length; i++){
var d = new department();
d.name = divisions[i];
d.budget = Math.floor( Math.random()* 100000000)
d.address = addr[i] ;
d.officers = [];
SAMPLE.units.push( d)
for( var j = 0 ; j < Math.floor(Math.random()*30000); j++){
var p = new make_person(d.name);
var pos = locate_commander(d.officers, p.rank, []);
if( pos.length == 0 ){
d.officers.push( p);
}else{
push_to_command(i, p , pos);
}
}
}
}