This repository was archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjump.js
More file actions
118 lines (102 loc) · 4.21 KB
/
Copy pathjump.js
File metadata and controls
118 lines (102 loc) · 4.21 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
var mongoose = require('mongoose-q')()
, Schema = mongoose.Schema
, Traversal = require('./traversal')
, moment = require('moment')
var lifespanEstimates = [
'Unknown',
'Not yet begun (>24h)',
'Beginning to decay (4-24h)',
'End of its lifetime (<4h)',
'Verge of dissipating (<15m)',
'Collapsing (<1m)'
];
exports.lifespanEstimates = lifespanEstimates;
var massEstimates = [
'Unknown',
'Not disrupted (>50%)',
'Under half remaining (<50%)',
'Critical (<10%)'
];
exports.massEstimates = massEstimates;
var JumpSchema = new Schema({
toSystem: Number,
fromSystem: Number,
toRegion: Number,
fromRegion: Number,
toConstellation: Number,
fromConstellation: Number,
updated_at: Number,
wormhole_data: {
reporterId: Number,
reporterName: String,
signature: String,
code: String,
mass_estimate: {type: String, enum: massEstimates},
mass_total: String,
jump_mass: String,
lifespan_estimate: {type: String, enum: lifespanEstimates},
traversals: [ Traversal.Schema ],
discovered_on: Number,
expires_on: Number
},
jumpbridge_data: {
fromPlanet: Number,
fromMoon: Number,
toPlanet: Number,
toMoon: Number,
status: String,
owner: String,
password: String,
distance: String,
route: String,
friendly: Boolean
}
});
JumpSchema.index({ toSystem: 1, fromSystem: 1 });
JumpSchema.methods.type = function() {
if (this.toObject().wormhole_data.expires_on !== undefined) return 'wormhole';
else if (this.toObject().jumpbridge_data !== undefined) return 'jumpbridge';
else if (this.toObject().toRegion != this.toObject().fromRegion) return 'region';
else if (this.toObject().toConstellation != this.toObject().fromConstellation) return 'constellation';
else return 'normal';
};
JumpSchema.statics.parseWormholeInfo = function(signature_id, code, text) {
var _ = require('lodash')
, static_data = require(__dirname + '/../../public/data/wormhole_types.json')
var info = {};
if (/^[A-Za-z]{3}$/.test(signature_id)) info['wormhole_data.signature'] = signature_id.toUpperCase();
if (_.include(_.map(static_data.wormhole_types, 'code'), code)) info['wormhole_data.code'] = code;
var type = _.find(static_data.wormhole_types, function(t) { return t.code == info['wormhole_data.code']; });
if (type) {
info['wormhole_data.jump_mass'] = parseInt(type.jump_mass);
info['wormhole_data.mass_total'] = parseInt(type.lifetime_mass);
}
if (/not yet begun/.test(text)) {
info['wormhole_data.lifespan_estimate'] = lifespanEstimates[1];
info['wormhole_data.expires_on'] = moment().add(24, 'hours').utc().unix();
} else if (/beginning to decay/.test(text)) {
info['wormhole_data.lifespan_estimate'] = lifespanEstimates[2];
info['wormhole_data.expires_on'] = moment().add(12, 'hours').utc().unix();
} else if (/reaching the ende/.test(text)) {
info['wormhole_data.lifespan_estimate'] = lifespanEstimates[3];
info['wormhole_data.expires_on'] = moment().add(4, 'hours').utc().unix();
} else if (/on the verge/.test(text)) {
info['wormhole_data.lifespan_estimate'] = lifespanEstimates[4];
info['wormhole_data.expires_on'] = moment().add(1, 'hour').utc().unix();
} else if (/collapsed/.test(text)) {
info['wormhole_data.lifespan_estimate'] = lifespanEstimates[5];
info['wormhole_data.expires_on'] = moment().utc().unix();
}
if (/has not yet had its stability significantly disrupted/.test(text)) {
info['wormhole_data.mass_estimate'] = massEstimates[1];
} else if (/has had its stability reduced by ships passing through it/.test(text)) {
info['wormhole_data.mass_estimate'] = massEstimates[2];
if (info['wormhole_data.mass_total']) info['wormhole_data.mass_total'] = info['wormhole_data.mass_total'] * 0.5;
} else if (/has had its stability critically disrupted/.test(text)) {
info['wormhole_data.mass_estimate'] = massEstimates[3];
if (info['wormhole_data.mass_total']) info['wormhole_data.mass_total'] = info['wormhole_data.mass_total'] * 0.1;
}
info.updated_at = moment().utc().unix();
return info;
};
module.exports = mongoose.model('Jump', JumpSchema);