Skip to content

Commit

Permalink
#1 More explicit state/province
Browse files Browse the repository at this point in the history
  • Loading branch information
Javarome committed Mar 25, 2017
1 parent cfff0f4 commit 9b9c35e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
12 changes: 11 additions & 1 deletion csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ exports.ReadableCsvRecordOutput = class ReadableCsvRecordOutput extends CsvRecor
record.hour = time.getTime(record);
record.elevation = geo.getElevation(record);
record.relativeAltitude = geo.getRelativeAltitude(record);
record.stateOrProvince = geo.getStateOrProvince(record);
record.locationFlags = ReadableCsvRecordOutput.flagsKeysStr(record.locationFlags, flags.locationFlagsLabels);
record.miscellaneousFlags = ReadableCsvRecordOutput.flagsKeysStr(record.miscellaneousFlags, flags.miscellaneousFlagsLabels);
record.typeOfUfoCraftFlags = ReadableCsvRecordOutput.flagsKeysStr(record.typeOfUfoCraftFlags, flags.typeOfUfoCraftFlagsLabels);
Expand Down Expand Up @@ -117,6 +118,15 @@ exports.ReadableCsvRecordOutput = class ReadableCsvRecordOutput extends CsvRecor
delete headerRecord.countryCode;
headerRecord.country = 'country';

return super.getColumns(headerRecord);
let expectedKeysOrder = ['year', 'month', 'day', 'hour', 'stateOrProvince', 'country', 'continent', 'title', 'description', 'locale', 'duration',];
const sortedRecord = util.sortProps(headerRecord, (prop1, prop2) => {
let index1 = expectedKeysOrder.indexOf(prop1);
if (index1 < 0) index1 = 1000;
let index2 = expectedKeysOrder.indexOf(prop2);
if (index2 < 0) index2 = 1000;
return index1 < index2 ? -1 : index1 > index2 ? 1 : 0;
});

return super.getColumns(sortedRecord);
}
};
76 changes: 76 additions & 0 deletions geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,82 @@ const continents = {
},
};

const statesOrProvinces = {
CHL: 'Chaldea',

SIB: 'Siberia',

EST: 'Estonia',
SRB: 'Serbia',
PRS: 'Prussia',

IVC: 'Ivory Coast',

BLG: 'Belgium',

ALS: 'Alaska',
TYR: 'Tyre',
CLR: 'Colorado',
CNN: 'Connecticut',
HWI: 'Hawaii',
IOW: 'Iowa',
MNT: 'Montana',
MSC: 'Massachusetts',
MSO: 'Missouri',
MSP: 'Mississippi',
NBR: 'Nebraska',
NCR: 'North Carolina',
NDK: 'North Dakota',
OHI: 'Ohio',
ORG: 'Oregon',
SCR: 'South Carolina',
SDK: 'South Dakota',
UTA: 'Utah',
VRG: 'Virginia',
WVA: 'Western Virginia',
WSH: 'Washington',
NMX: 'New Mexico',

SNL: 'Sinaloa',
CHH: 'Chihuahua',

ALB: 'Alberta',
BCO: 'British Columbia',
MBA: 'Manitoba',
NBR: 'New Brunswick', // TODO: Duplicate!
NFL: 'Newfoundland',
NSC: 'Nova Scotia',
NWT: 'Northwest Territories',
ONT: 'Ontario',
QBC: 'Quebec',
SSK: 'Sasketchewan',
YUK: 'Yukon',
PEI: 'Prince Edward Island',
IRL: 'Ireland',
ENG: 'England',
SCT: 'Scotland',
WAL: 'Wales',
NI: 'Northern Ireland',
CLF: 'California',
NVD: 'Nevada',
KNS: 'Kansas',
ILN: 'Illinois',
IND: 'Indiana',
TXS: 'Texas',
MCH: 'Michigan',
ARK: 'Arkansas',

MSE: 'Meuse',

DRK: 'Dark side'
};

exports.getStateOrProvince = function (record) {
let stateOrProvinceKey = record.stateOrProvince;
let statesOrProvinceStr = statesOrProvinces[stateOrProvinceKey];
return statesOrProvinceStr ? statesOrProvinceStr : stateOrProvinceKey;
};

const locales = {};
locales[0] = 'Metropolis';
locales[1] = 'Residential';
Expand Down
5 changes: 3 additions & 2 deletions udb.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ sourcesReader
readSignedInt('relativeAltitude');
readByte('unknown2');
readNibbles('continentCode', 'countryCode');
readString(3, 'area');
readString(3, 'stateOrProvince');
readByte('unknown3');
readByte('locationFlags');
readByte('miscellaneousFlags');
Expand Down Expand Up @@ -298,9 +298,10 @@ sourcesReader
let desc = '\nRecord #' + recordIndex + '\n Title : ' + record.title + '\n' +
' Date : ' + year + '/' + month + '/' + day + ', ' + timeStr + '\n';
let countryStr = country.name + (country.description ? ` (${country.description})` : '');
let stateOrProvince = geo.getStateOrProvince(record);
let locationStr = ' Location : ' + localeStr + ', '
+ record.location
+ ' (' + record.area + ', ' + countryStr + ', ' + continent.name + '), '
+ ' (' + stateOrProvince + ', ' + countryStr + ', ' + continent.name + '), '
+ geo.ddToDms(record.latitude, record.longitude) + '\n' +
(elevationStr || relativeAltitudeStr ? (' ' + (elevationStr ? 'Elevation ' + elevationStr + ' m' : '')
+ (relativeAltitudeStr ? ', relative altitude ' + relativeAltitudeStr + ' m' : '') + '\n') : '');
Expand Down

0 comments on commit 9b9c35e

Please sign in to comment.