Skip to content

Commit

Permalink
#1 Fixed continent/country tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Javarome committed Mar 21, 2017
1 parent 3bf32eb commit ef46814
Showing 1 changed file with 239 additions and 27 deletions.
266 changes: 239 additions & 27 deletions udb.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const fs = require('fs');
const program = require('commander');

function range(val) {
return val.split('..').map(Number);
}
program
.version('0.0.1')
.option('-d, --data [dataFile]', 'Specify data file. Defaults to ./U.RND')
.option('-s, --sources [sourcesFile]', 'Specify sources file. Defaults to ./usources.txt')
.option('-wm, --worldmap [wmFile]', 'Specify world map file. Defaults to ./WM.VCE')
.option('-i, --interval <fromIndex>..<toIndex>', 'Specify first record to output. Defaults to 1')
.option('-r, --range <fromIndex>..<toIndex>', 'Specify first record to output. Defaults to 1..end', range)
.option('-r, --records <recordsIndexes>', 'Specify a list of indexes of records to output.')
.option('-c, --count <maxCount>', 'Specify the maximim number of records to output.')
.option('-f, --format <default|csv> [csvSeparator]', 'The format of the output')
.option('-o, --output <outputFile>', 'The name of the file to output. Will output as CSV if file extension is .csv')
.option('-o, --out <outputFile>', 'The name of the file to output. Will output as CSV if file extension is .csv')
.option('-v, --verbose', 'Displayed detailed processing information.')
.option('--debug', 'Displays debug info.')
.parse(process.argv);
Expand Down Expand Up @@ -146,20 +149,226 @@ sourcesReader
logVerbose('- ' + Object.keys(misc).length + ' misc. books, reports, files & correspondance');
logVerbose('- ' + discredited.length + ' discredited reports');

const countries = {};
countries[2] = 'USA';
countries[20] = 'Argentina';
countries[49] = 'Great Britain';
countries[51] = 'Germany';
countries[53] = 'France';
countries[54] = 'Spain';
countries[57] = 'Italy';
countries[83] = 'India';
countries[97] = 'Japan';
countries[163] = 'Irak';
countries[166] = 'Israël';
countries[170] = 'Lebanon';
countries[178] = 'Moon';
const continents = {
0: {
/**
* Actual Continent including Central America.
*/
name: 'North America',
countries: {
1: 'Canada',
2: 'USA',
3: 'Mexico',
4: 'Guatemala',
5: 'Belize',
6: 'Honduras',
7: 'El Salvador',
8: 'Nicaragua',
9: 'Costa Rica',
10: 'Panama',
}
},
1: {
/**
* Actual Continent.
*/
name: 'South America',
countries: {
1: 'Brazil',
2: 'Paraguay',
3: 'Uruguay',
4: 'Argentina',
5: 'Chile',
6: 'Bolivia',
7: 'Peru',
8: 'Ecuador',
9: 'Colombia',
10: 'Venezuela',
11: 'Guyanas (all 3 of them)',
}
},
2: {
/**
* AUSTRALIA / NEW ZEALAND and the great Oceans.
*/
name: 'Oceania',
countries: {
1: 'Australia',
2: 'New Zealand',
3: 'Atlantic Ocean + islands',
4: 'Pacific Ocean and non-Asian islands',
5: 'Caribbean area',
6: 'Indian Ocean + islands',
7: 'Arctic above 70 degrees North',
8: 'Antarctic below 70 degrees South',
9: 'Iceland',
10: 'Greenland',
}
},
3: {
/**
* Actual Continent.
*/
name: 'Western Europe',
countries: {
1: 'Great Britain and Ireland',
2: 'Scandanavian and Finland',
3: 'Germany',
4: 'Belgium, Netherlands and Luxembourg',
5: 'France',
6: 'Spain',
7: 'Portugal',
8: 'Austria',
9: 'Italy',
10: 'Switzerland',
11: 'Greece and Island nations',
}
},
4: {
/**
* Includes some former Soviet Republics.
*/
name: 'Eastern Europe',
countries: {
1: 'Poland',
2: 'Czech and Slovak Republics',
3: 'Hungary',
4: 'Former Yugoslavia (Province field indicates present republics)',
5: 'Romania',
6: 'Bulgaria',
7: 'Albania',
8: 'Estonia, Latvia & Lithuania',
9: 'Belorus',
10: 'Ukraine',
}
},
5: {
/**
* ( except Vietnam, Cambodia and Laos. )
*/
name: 'Asia Mainland',
countries: {
1: 'Red China',
2: 'Mongolia',
3: 'India',
4: 'Pakistan',
5: 'Afghanistan',
6: 'imalayan states: Nepal, Bhutan, Shangri-la etc.',
7: 'Bangladesh',
8: 'Burma',
9: 'Korea (both sides)',
}
},
6: {
/**
* (except Vietnam, Cambodia and Laos)
* Small remote islands are under Oceania
*/
name: 'Asia Pacific',
countries: {
1: 'Japan',
2: 'Philippines',
3: 'Taiwan China',
4: 'Vietnam',
5: 'Laos',
6: 'Cambodia',
7: 'Thailand',
8: 'Malaysia',
9: 'Indonesia',
}
},
7: {
/**
* North of the Equator.
*/
name: 'Northern and Northwest Africa',
countries: {
1: 'Egypt',
2: 'Sudan',
3: 'Ethiopia',
4: 'Libya',
5: 'Tunisia',
6: 'Algeria',
7: 'Morocco',
8: 'Sahara (includes Chad, Niger, Mali, Mauritania and Upper Volta)',
9: 'Ivory Coast, Ghana, Togo, Benin, Liberia.',
10: 'Nigeria',
}
},
8: {
/**
* Generally on or South of the Equator.
*/
name: 'Southern Africa',
countries: {
1: 'Rep of South Africa',
2: 'Zimbabwe & Zambia (Rhodesia)',
3: 'Angola',
4: 'Kalahari Desert: Botswana etc.',
5: 'Mozambique',
6: 'Tanzania',
7: 'Uganda',
8: 'Kenya',
9: 'Somalia',
10: 'Congo states (includes Congo, Zaire, Central Afr Rep, Rwanda, Burundi..)',
11: 'Ivory Coast,Ghana,Togo,Benin,Liberia etc.',
12: 'Nigeria.',
}
},
9: {
/**
* except Baltics, Ukraine & Belorus.
*/
name: 'Russia and former soviet',
countries: {
1: 'Russia (includes various ethnic Okrugs, all within the former RSFSR)',
2: 'Georgia',
3: 'Armenia',
4: 'Azerbaijan',
5: 'Kazakh Republic',
6: 'Turkmen Republic',
7: 'Uzbek Republic',
8: 'Tadzhik Republic',
}
},
10: {
/**
* Turkey, Israel, Iran and Arabic speaking lands.
*/
name: 'Middle East',
countries: {
1: 'Turkey',
2: 'Syria',
3: 'Iraq',
4: 'Iran',
5: 'Jordan',
6: 'Israel',
7: 'Arabian Peninsula (not Kuwait)',
8: 'Kuwait',
9: 'Cyprus',
10: 'Lebanon',
}
},
11: {
/**
* Anywhere outside of Earth's Atmosphere.
*/
name: 'Space',
countries: {
1: 'Earth Orbit. Space stations, capsules. Astronauts & Cosmonauts.',
2: 'The Moon',
3: 'Venus',
4: 'Mars',
5: 'Asteroids',
6: 'Jupiter',
7: 'Saturn',
8: 'Uranus',
9: 'Neptune',
10: 'Deep Space',
11: 'Pluto',
}
},
};

const locales = {};
locales[0] = 'Metropolis';
Expand Down Expand Up @@ -188,10 +397,7 @@ sourcesReader
const buffer = new Buffer(recordSize);

fs.open(dataFile, 'r', function (status, fd) {
let recordIndex = 1;
if (program.from) {
recordIndex = parseInt(program.from, 10);
}
let recordIndex = (program.range && program.range[0]) || 1;
logVerbose(`\nReading cases from #${recordIndex}:`);
if (status) {
console.log(status.message);
Expand Down Expand Up @@ -314,7 +520,7 @@ sourcesReader
readSignedInt('elevation');
readSignedInt('relativeAltitude');
skip(1);
readByte('countryCode');
readNibbles('continentCode', 'countryCode');
readString(3, 'area');
skip(1);
readByte('locationFlags');
Expand Down Expand Up @@ -413,7 +619,11 @@ sourcesReader
}

desc(record) {
const country = countries[record.countryCode] ? countries[record.countryCode] : 'country#' + record.countryCode;
const continent = continents[record.continentCode] ? continents[record.continentCode] : {
name: 'continent#' + record.continentCode,
countries: {}
};
const country = continent.countries[record.countryCode] ? continent.countries[record.countryCode] : 'country#' + record.countryCode;

const yearAccuracy = (record.ymdt >> 6) & 3;
const monthAccuracy = (record.ymdt >> 4) & 3;
Expand All @@ -439,7 +649,7 @@ sourcesReader
' Date : ' + year + '/' + month + '/' + day + ', ' + time + '\n';
let locationStr = ' Location : ' + locale + ', '
+ record.location
+ ' (' + record.area + ', ' + country + '), '
+ ' (' + record.area + ', ' + country + ', ' + continent.name + '), '
+ ddToDms(record.latitude, record.longitude) + '\n' +
(elevation || relativeAltitude ? (' ' + (elevation ? 'Elevation ' + elevation + ' m' : '')
+ (relativeAltitude ? ', relative altitude ' + relativeAltitude + ' m' : '') + '\n') : '');
Expand Down Expand Up @@ -475,7 +685,8 @@ sourcesReader
};
locationStr += ' Observer:\n' + flagsStr(record.locationFlags, locationFlagsLabels);

let descriptionStr = ' Description : ' + (record.description ? record.description : '') + '\n';
let description = record.description && record.description.replace(/\n/g, '\n ');
let descriptionStr = ' Description : ' + (description ? description : '') + '\n';
/**
* Miscellaneous details and features.
* @type {{SCI: string, TLP: string, NWS: string, MID: string, HOX: string, CNT: string, ODD: string, WAV: string}}
Expand Down Expand Up @@ -653,8 +864,8 @@ sourcesReader
}

let output = process.stdout;
if (program.output) {
output = fs.createWriteStream(program.output, {flags: 'w'});
if (program.out) {
output = fs.createWriteStream(program.out, {flags: 'w'});
}

let outputFormat;
Expand All @@ -665,7 +876,8 @@ sourcesReader
default:
outputFormat = new DefaultRecordOutput(output);
}
const recordEnumerator = new DefaultRecordEnumerator(program.count);
let maxCount = program.count || 10000000;
const recordEnumerator = new DefaultRecordEnumerator(maxCount);
//const recordEnumerator = new MaxCountRecordEnumerator(500);
//const recordEnumerator = new ArrayRecordEnumerator([18121]);

Expand Down

0 comments on commit ef46814

Please sign in to comment.