Former-commit-id: d1e81673f9d104a159f0fc7012dad43a928d7bbb
This commit is contained in:
Ben
2022-04-11 23:50:53 +01:00
parent 7294a7a076
commit 4c53e7e568
10 changed files with 3531 additions and 47 deletions

4
.env
View File

@@ -6,8 +6,8 @@ PORT_DEV=8080
LOG_LEVEL=0
LOG_CONSOLE=true
LOG_FILE=logs.log
LOG_NET_HOST=127.0.0.1
LOG_NET_PORT=21
LOG_NET_HOST=165.22.114.213
LOG_NET_PORT=2082
DATABASE_HOST=localhost
DATABASE_PORT=5432

105
db/aggregator-stage-2.js Normal file
View File

@@ -0,0 +1,105 @@
// reads parts-to-include and sets-to-include and based off
// schema.sql, creates a new database with the data from
// the files.
const fs = require('fs');
fs.writeFileSync('./db/dump.sql', '');
function addLine(line) {
fs.appendFileSync('./db/dump.sql', line + '\n');
}
// first categories
addLine('-- categories\n');
const newcategory = (category, name) => `INSERT INTO tag (id, name) VALUES ('${category}', '${name}');`;
const categories = fs.readFileSync('db/res/categories.txt').toString().split('\n');
for (let i = 0; i < categories.length; i++) {
const category = categories[i].split('\t');
const categoryName = (category[1]).replace(/'/g, '');
console.log(`NEW category ${categoryName}`);
addLine(newcategory(category[0], categoryName));
}
// then colour type
addLine('\n-- colour type\n');
const newColourType = (type, name) => `INSERT INTO colour_type (id, name) VALUES ('${type}', '${name}');`;
const lookupTable = {
0: 'N/A',
1: 'Solid',
2: 'Transparent',
3: 'Chrome',
4: 'Pearl',
5: 'Satin',
6: 'Metallic',
7: 'Milky',
8: 'Glitter',
9: 'Speckle',
10: 'Modulex',
};
for (let i = 0; i < 11; i++) {
console.log(`NEW colour type ${i}`);
addLine(newColourType(i, lookupTable[i]));
}
// then colour
addLine('\n-- colour\n');
const newcolour = (id, name, RGB, type) => `INSERT INTO lego_brick_colour (id, name, hexrgb, col_type) VALUES ('${id}', '${name}', '${RGB}', '${type}');`;
const colours = fs.readFileSync('db/res/colors.txt').toString().split('\n');
for (let i = 0; i < colours.length; i++) {
const colour = colours[i].split('\t');
const RGB = colour[2];
// needs to get key from value
const type = Object.keys(lookupTable).find(key => lookupTable[key] === colour[3]);
const id = colour[0];
const name = colour[1];
console.log(`NEW colour ${name}`);
addLine(newcolour(id, name, RGB, type));
}
// then bricks
addLine('\n-- bricks\n');
const newBrick = (id, name, weight, dx, dy, dz) => `INSERT INTO lego_brick (id, name, weight, dimensions_x, dimensions_y, dimensions_z) VALUES ('${id}', '${name}', '${weight}', '${dx}', '${dy}', '${dz}');`;
const allBricks = fs.readFileSync('db/res/Parts.txt').toString().split('\n');
const brickIds = JSON.parse(fs.readFileSync('db/parts-to-include'));
for (let i = 0; i < brickIds.length; i++) {
const brickId = brickIds[i];
// find ID in allBricks
const brick = allBricks.find(brick => brick.split('\t')[2] === brickId);
if (!brick) {
console.log(`ERROR: brick ${brickId} not found`);
continue;
}
const brickData = brick.split('\t');
const name = brickData[3].replace(/'/g, '');
const weight = brickData[4];
const dx = brickData[5].split('x')[0].trim();
const dy = brickData[5].split('x')[1].trim();
const dz = brickData[5].split('x')[2].trim();
addLine(newBrick(brickId, name, weight, dx, dy, dz));
console.log(`NEW brick ${i} ${brickId}`);
}
// then sets
addLine('\n-- sets\n');
const newSet = (id, name, category, colour, bricks) => `INSERT INTO lego_set (id, name, category, colour, bricks) VALUES ('${id}', '${name}', '${category}', '${colour}', '${bricks}');`;
const sets = fs.readFileSync('db/res/Sets.txt').toString().split('\n');
const setIds = JSON.parse(fs.readFileSync('db/sets-to-include'));
for (let i = 0; i < setIds.length; i++) {
}
// then brick tags
// then set tags
// then pieces in sets
// then make up some random data for brick inventory
// then make up some random data for set inventory

File diff suppressed because it is too large Load Diff

View File

@@ -70464,4 +70464,4 @@
161 Plastic 10294pls01c Plastic Part for Set 10294 - Flag with United States (Circa 1912) Pattern ? ? x ? x ?
160 Sticker Sheet 42135stk01 Sticker Sheet for Set 42135 - (80224/6362701) ? ? x ? x ?
238 Minifigure, Head 3626cpb2978 Minifigure, Head Black Eyebrows, Red Glasses, Smile Pattern - Hollow Stud 0.58 ? x ? x ?
147 Animal, Land 80679pb03 Squirrel with Black Eyes, White Pupils, and Black Nose Pattern 0.73 ? x ? x ?
147 Animal, Land 80679pb03 Squirrel with Black Eyes, White Pupils, and Black Nose Pattern 0.73 ? x ? x ?

View File

@@ -1,5 +1,3 @@
Category ID Category Name
143 (Other)
318 12V
628 1950
@@ -1013,4 +1011,4 @@ Category ID Category Name
1044 xtra
152 Znap
389 Zoo
719 Zooters
719 Zooters

View File

@@ -1,5 +1,3 @@
Color ID Color Name RGB Type Parts In Sets Wanted For Sale Year From Year To
0 (Not Applicable) N/A 4587 12360 62547 10990 1954 2022
41 Aqua BCE5DC Solid 82 60 1233 116 1998 2006
11 Black 212121 Solid 10925 11692 15454 11229 1957 2022
@@ -186,4 +184,4 @@ Color ID Color Name RGB Type Parts In Sets Wanted For Sale Year From Year To
131 Mx Tile Brown 330000 Modulex 111
127 Mx Tile Gray 6B5A5A Modulex 41
147 Mx Violet BD7D85 Modulex 18 8
123 Mx White FFFFFF Modulex 419 411
123 Mx White FFFFFF Modulex 419 411

View File

@@ -12,32 +12,28 @@ CREATE TABLE IF NOT EXISTS colour_type (
CREATE TABLE IF NOT EXISTS lego_brick_colour (
id INT NOT NULL PRIMARY KEY,
name VARCHAR (100),
hexrgb VARCHAR (6) NOT NULL,
hexrgb VARCHAR (6),
col_type INT,
FOREIGN KEY ( col_type ) REFERENCES colour_type( id )
);
CREATE TABLE IF NOT EXISTS lego_brick (
id VARCHAR (50) NOT NULL PRIMARY KEY,
name VARCHAR NOT NULL,
weight VARCHAR (10),
dimensions_x VARCHAR (10),
dimensions_y VARCHAR (10),
dimensions_z VARCHAR (10)
);
CREATE TABLE IF NOT EXISTS lego_set (
id VARCHAR (50) NOT NULL PRIMARY KEY,
name VARCHAR (100),
description TEXT,
date_released TIMESTAMP WITHOUT TIME ZONE,
dimensions_x DECIMAL,
dimensions_y DECIMAL,
dimensions_z DECIMAL
);
CREATE TABLE IF NOT EXISTS lego_brick (
id VARCHAR (50) NOT NULL PRIMARY KEY,
name VARCHAR NOT NULL,
colour INT,
weight DECIMAL,
dimensions_x INT,
dimensions_y INT,
dimensions_z INT,
date_from TIMESTAMP WITHOUT TIME ZONE,
date_to TIMESTAMP WITHOUT TIME ZONE,
FOREIGN KEY ( colour ) REFERENCES lego_brick_colour( id )
dimensions_x VARCHAR (10),
dimensions_y VARCHAR (10),
dimensions_z VARCHAR (10)
);
CREATE TABLE IF NOT EXISTS lego_brick_tag (
@@ -103,9 +99,12 @@ CREATE TABLE IF NOT EXISTS orders (
CREATE TABLE IF NOT EXISTS order_items (
order_id VARCHAR (50) NOT NULL,
brick_id VARCHAR (50),
-- colour is a modifier for the brick
brick_colour INT,
set_id VARCHAR (50),
amount INT NOT NULL,
FOREIGN KEY ( order_id ) REFERENCES orders( id ),
FOREIGN KEY ( brick_id ) REFERENCES lego_brick( id ),
FOREIGN KEY ( brick_colour ) REFERENCES lego_brick_colour( id ),
FOREIGN KEY ( set_id ) REFERENCES lego_set( id )
);

36
package-lock.json generated
View File

@@ -3180,9 +3180,9 @@
"dev": true
},
"node_modules/follow-redirects": {
"version": "1.14.7",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==",
"version": "1.14.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz",
"integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==",
"funding": [
{
"type": "individual",
@@ -5032,9 +5032,9 @@
}
},
"node_modules/minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
},
"node_modules/mkdirp": {
"version": "1.0.4",
@@ -5048,9 +5048,9 @@
}
},
"node_modules/moment": {
"version": "2.29.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==",
"version": "2.29.2",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.2.tgz",
"integrity": "sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg==",
"engines": {
"node": "*"
}
@@ -11180,9 +11180,9 @@
"dev": true
},
"follow-redirects": {
"version": "1.14.7",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ=="
"version": "1.14.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz",
"integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w=="
},
"forwarded": {
"version": "0.2.0",
@@ -12567,9 +12567,9 @@
}
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
},
"mkdirp": {
"version": "1.0.4",
@@ -12577,9 +12577,9 @@
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
},
"moment": {
"version": "2.29.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
"version": "2.29.2",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.2.tgz",
"integrity": "sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg=="
},
"ms": {
"version": "2.1.2",

View File

@@ -63,7 +63,9 @@ async function main() {
resolve();
return;
}
// console.log(res);
for (const result of res) {
Logger.Database(result.command);
}
resolve();
});
});

View File

@@ -12,8 +12,8 @@ async function main() {
logLevel: process.env.LOG_LEVEL,
logToConsole: process.env.LOG_CONSOLE,
logFile: process.env.LOG_FILE,
// networkHost: process.env.LOG_NET_HOST,
// networkPort: process.env.LOG_NET_PORT,
networkHost: process.env.LOG_NET_HOST,
networkPort: process.env.LOG_NET_PORT,
});
Logger.Info('Pre-Init Complete');