-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcifcodes.js
More file actions
593 lines (572 loc) · 15.9 KB
/
cifcodes.js
File metadata and controls
593 lines (572 loc) · 15.9 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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
const path = require('path')
const fs = require('fs')
var train_category = {
parse(data){
data = data.toString()
var rows = data.split(/\r?\n/)
var starting = ""
var obj = {}
var currentItems = []
for(var i = 0; i < rows.length; i++){
var item = rows[i]
if(item.includes(',')) currentItems.push(item)
else {
var innerobj = {}
for(var j = 0; j < currentItems.length; j++){
var inneritem = currentItems[j].split(',')
innerobj[inneritem[0]] = inneritem[1]
}
obj[starting] = innerobj
starting = item
currentItems = []
}
}
return obj
},
parseIntoArray(data){
data = data.toString()
var rows = data.split(/\r?\n/)
var starting = ""
var arr = []
var currentItems = []
for(var i = 0; i < rows.length; i++){
var item = rows[i]
if(item.includes(',')) currentItems.push(item)
else {
for(var j = 0; j < currentItems.length; j++){
var inneritem = currentItems[j].split(',')
arr.push({
code: inneritem[0],
description: inneritem[1],
type: starting
})
}
starting = item
currentItems = []
}
}
return arr
}
}
train_category.parsed = train_category.parse(fs.readFileSync(path.join(__dirname, "./trainCategory.txt")).toString())
train_category.parsedIntoArray = train_category.parseIntoArray(fs.readFileSync(path.join(__dirname, "./trainCategory.txt")).toString())
train_category.fromCode = code => {
return train_category.parsedIntoArray.find(a => a.code === code)
}
var power_type = {
object: {
D: "Diesel",
DEM: "Diesel Electric Multiple Unit",
DMU: "Diesel Mecahnical Multiple Unit",
E: "Electric",
ED: "Electro-Diesel",
EML: "EMU plus Diesel, Electric or Electro-Diesel locomotive",
EMU: "Electric Multiple Unit",
HST: "High Speed Train"
},
array: [
{
description: "Diesel",
code: "D"
},
{
description: "Diesel Electric Multiple Unit",
code: "DEM"
},
{
description: "Diesel Mechanical Multiple Unit",
code: "DMU"
},
{
description: "Electric",
code: "E"
},
{
description: "Electro-Diesel",
code: "ED"
},
{
description: "EMU + D,E,ED locomotive",
code: "EML"
},
{
description: "Electric Multiple Unit",
code: "EMU"
},
{
description: "High Speed Train",
code: "HST"
}
],
fromCode(code){
return this.array.find(a => a.code === code)
}
}
function isEmpty(obj) {
for (const prop in obj) {
if (Object.hasOwn(obj, prop)) {
return false;
}
}
return true;
}
var timing_load = {
fromCode(code, power_type){
var tl = {}
switch(code){
case "69":
tl = {
type: "DMU - Air Brake",
unit: ["172/0", "172/1", "172/2"]
}
break;
case "A":
tl = {
type: "DMU - Air Brake",
unit: ["172/0", "172/1", "172/2"]
}
break;
case "E": {
tl = {
type: "DMU - Air Brake",
unit: ["158", "168", "170", "175"]
}
break;
}
case "N":
tl = {
type: "DMU - Air Brake",
unit: ["165/0"]
}
break;
case "S":
tl = {
type: "DMU - Air Brake",
unit: ["150", "153", "155", "156"]
}
break;
case "T":
tl = {
type: "DMU - Air Brake",
unit: ["165/1", "166"]
}
break;
case "V":
tl = {
type: "DMU - Air Brake",
unit: ["220", "221"]
}
break;
case "T":
tl = {
type: "DMU - Air Brake",
unit: ["159"]
}
break;
case "X":
tl = {
type: "DMU - Air Brake",
unit: ["165/0"]
}
break;
case "D1":
tl = {
type: "DMU - Vacuum Brake",
unit: ["Power Car + Trailer"]
}
break;
case "D2":
tl = {
type: "DMU - Vacuum Brake",
unit: ["2 Power Cars + Trailer"]
}
case "D3": {
tl = {
type: "DMU - Vacuum Brake",
unit: ["Power Twin"]
}
}
}
if(isEmpty(tl)){
if(power_type === "EMU"){
tl.type = "EMU"
if(code === "AT") tl.unit = ["Accelerated Timings"]
else if(code === "E") tl.unit = ["458"]
else if(code === "0") tl.unit = ["380"]
else if(code === "506") tl.unit = ["350/1"]
else tl.unit = [code]
} else {
if(code === "325"){
tl = {
type: "EMU",
unit: ["325"]
}
} else {
tl = {
type: "Hauled train E,D or ED",
unit: [code]
}
}
}
} else {
tl = {
type: power_type,
unit: ["unknown"]
}
}
if(tl.unit[0] === "") tl.unit = ["unknown"]
return tl
}
}
var operating_characteristics = {
object: {
B: "Vacuum Braked",
C: "Timed at 100 m.p.h.",
D: "DOO (Coaching stock trains)",
E: "Conveys Mark 4 Coaches",
G: "Trainman (Guard) required",
M: "Timed at 110 m.p.h.",
P: "Push/Pull train",
Q: "Runs as required",
R: "Air conditioned with PA system",
S: "Steam Heated",
Y: "Runs to Terminals/Yards as required",
Z: "May convey traffic to SB1C gauge. Not to be diverted from booked route without authority."
},
array: [
{
code: "B",
description: "Vacuum Braked"
},
{
code: "C",
description: "Timed at 100 m.p.h."
},
{
code: "D",
description: "DOO (Coaching stock trains)"
},
{
code: "E",
description: "Conveys Mark 4 Coaches"
},
{
code: "G",
description: "Trainman (Guard) required"
},
{
code: "M",
description: "Timed at 110 m.p.h."
},
{
code: "P",
description: "Push/Pull train"
},
{
code: "Q",
description: "Runs as required"
},
{
code: "R",
description: "Air conditioned with PA system"
},
{
code: "S",
description: "Steam Heated"
},
{
code: "Y",
description: "Runs to Terminals/Yards as required"
},
{
code: "Z",
description: "May convey traffic to SB1C gauge. Not to be diverted from booked route without authority."
}
],
fromCode(code){
return this.array.find(a => a.code === code)
}
}
var train_status = {
object: {
B: "Bus (Permanent)",
F: "Freight (Permanent - WTT)",
P: "Passenger & Parcels (Permanent - WTT)",
S: "Ship (Permanent)",
T: "Trip (Permanent)",
"1": "STP Passenger & Parcels",
"2": "STP Freight",
"3": "STP Trip",
"4": "STP Ship",
"5": "STP Bus"
},
array: [
{
code: "B",
description: "Bus (Permanent)"
},
{
code: "F",
description: "Freight (Permanent - WTT)"
},
{
code: "P",
description: "Passenger & Parcels (Permanent - WTT)"
},
{
code: "S",
description: "Ship (Permanent)"
},
{
code: "T",
description: "Thip (Permanent)"
},
{
code: "1",
description: "STP Passenger & Parcels"
},
{
code: "2",
description: "STP Freight"
},
{
code: "3",
description: "STP Trip"
},
{
code: "4",
description: "STP Ship"
},
{
code: "5",
description: "Bus"
}
],
fromCode(code){
return this.array.find(a => a.code === code)
}
}
var train_class = {
object: {
S: "Standard class only",
B: "First and standard"
},
array: [
{
code: "S",
description: "Standard class only"
},
{
code: "B",
description: "First and standard"
},
{
code: "",
description: "First and standard"
}
],
fromCode(value){
if(value === "S") return "Standard class only"
else return "First and standard class"
},
}
var sleeping_accomodation = {
object: {
S: "Standard class only",
F: "First class only",
B: "First and standard class"
},
array: [
{
code: "S",
description: "Standard class only"
},
{
code: "F",
description: "First class only"
},
{
code: "B",
description: "First and standard class"
}
],
fromCode(code){
var found = this.array.find(a => a.code === code)
if(found) return found
else return "No sleeping accomodation available"
}
}
var reservations = {
object: {
A: "Reservations compulsory",
E: "Reservations for bicycles essential",
R: "Reservations recommended",
S: "Reservations possible from any station"
},
array: [
{
code: "A",
description: "Reservations compulsory"
},
{
code: "E",
description: "Reservations for bicycles essential"
},
{
code: "R",
description: "Reservations recommended"
},
{
code: "S",
description: "Reservations possible from any station"
}
],
fromCode(code){
var found = this.array.find(a => a.code === code)
if(found) return found
else return "Reservations not available"
}
}
var catering = {
object: {
C: "Buffet Service",
F: "Restaurant Car available for First Class passengers",
H: "Hot food available",
M: "Meal included for First Class passengers",
P: "Wheelchair only reservations",
R: "Restaurant",
T: "Trolley service"
},
array: [
{
code: "C",
description: "Buffet Service",
},
{
code: "F",
description: "Restaurant Car available for First Class passengers",
},
{
code: "H",
description: "Hot food available",
},
{
code: "M",
description: "Meal included for First Class passengers",
},
{
code: "P",
description: "Wheelchair only reservations",
},
{
code: "R",
description: "Restaurant",
},
{
code: "T",
description: "Trolley Service",
},
],
fromCode(code){
var found = this.array.find(a => a.code === code)
if(found) return found
else return "No catering"
},
parse(string){
var split = string.replaceAll(' ', '').split('')
split = split.map(element => {
return this.array.find(a => a.code === element)
})
return split
}
}
var schedule_type = {
object: {
C: "STP cancellation of permanent schedule",
N: "New STP schedule (not an overlay)",
O: "STP overlay of permanent schedule",
P: "Permanent"
},
array: [
{
code: "C",
description: "Short term plan cancellation of permanent schedule"
},
{
code: "N",
description: "New short term plan schedule"
},
{
code: "O", //overlay
description: "Alteration to permanent schedule"
},
{
code: "P",
description: "Permanent schedule"
}
],
fromCode(code){
return this.array.find(a => a.code === code)
}
}
class activitycodesObj {
constructor(){
this.object = {
"-D": "Stops to detach vehicles",
"-T": "Stops to attach and detach vehicles",
"-U": "Stops to attach vehicles",
A: "Stops or shunts for other trains to pass",
AE: "Attach/Detach assisting locomotive",
AX: "Shows as 'X' on arrival",
BL: "Stops for banking locomotive",
C: "Stops to change traincrew",
D: "Stops to set down passengers (shows 's' in GBTT)",
E: "Stops for examination",
G: "GBPRTT Data to add",
H: "Notional activity to prevent WTT columns merge",
HH: "As H, to prevent WTT column merge where 3rd Column",
K: "Passenger count point",
KC: "Ticket collection and examination point",
KE: "Ticket examination point",
KF: "Ticket examination point - first class only",
KS: "Selective Ticket Examination Point",
L: "Stops to change locomotive",
N: "Stop not advertised",
OP: "Stops for other operating reasons",
OR: "Train Locomotive on rear",
PR: "Propelling between points shown",
R: "Stops when required (shows 'x' in GBTT)",
RM: "Stops for reversing move or driver changes ends",
RR: "Stops for locomotive to run round train",
S: "Stops for Railway Personnel Only",
T: "Stops to Take Up and Set Down passengers",
TB: "Train Begins (Origin)",
TF: "Train Finishes (Destination)",
TS: "Activity requested for TOPS reporting purposes",
TW: "Stops or passes for tablet, staff or token",
U: "Stops to take up passengers (shows 'u' in GBTT)",
W: "Stops for watering of coaches",
X: "Passes another train at crossing point on a single line",
}
this.array = Object.entries(this.object).map(item => {
const [ code, description ] = item
return { code, description }
})
this.fromCode = code => {
return this.array.find(a => a.code === code)
}
}
}
module.exports = {
train_category,
power_type,
timing_load,
operating_characteristics,
train_status,
train_class,
sleeping_accomodation,
reservations,
catering,
schedule_type,
activity_codes: new activitycodesObj()
}