Skip to content

Commit

Permalink
add schema generation and erd diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
dnoliver committed May 24, 2023
1 parent 31555c8 commit d5b5eaa
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
db.*
db.json
db.*.json
schema.*.json
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
# Intel Ark Scrapper

```
## Scrapper Execution

```bash
time node index.js 2>&1

real 262m20.010s
user 0m0.295s
sys 0m0.983s
```

## Schema Induction

```bash
node schema.js
```

## Product Types

```bash
jq '.[].name' db.json
```

## Product Brands

```bash
jq '.[0].products[].name' db.json
```

## Product Series

```bash
jq '.[0].products[0].subproducts[].name' db.json
```

## Products

```bash
jq '.[0].products[0].subproducts[0].skus[]."Product Name"' db.json
```

## Specification Categories

```bash
jq '.[0].products[0].subproducts[0].skus[0].specs | keys' db.json
```
Binary file added erd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"genson-js": "^0.0.8",
"prettier": "^2.8.8",
"selenium-webdriver": "^4.9.2"
},
Expand Down
37 changes: 37 additions & 0 deletions schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { createSchema } = require('genson-js');
const fs = require("fs");

fs.readFile("db.json", { encoding: "utf-8" }, async function (err, data) {
const db = JSON.parse(data);
// 1st item is Processors
const ProcessorSchema = createSchema(db[0]);
// 2nd item is Server Products
const ServerProductSchema = createSchema(db[1]);
// 3rd item is Intel NUCs
const IntelNucSchema = createSchema(db[2]);
// 4th item is Wireless
const WirelessSchema = createSchema(db[3]);
// 5th item is Ethernet Products
const EthernetProductsSchema = createSchema(db[4]);
// 6th item is Intel® FPGAs
const IntelFPGAsSchema = createSchema(db[5]);
// 7th item is Memory and Storage
const MemoryandStorageSchema = createSchema(db[6]);
// 8th item is Chipsets
const ChipsetsSchema = createSchema(db[7]);
// 9th item is Graphics
const GraphicsSchema = createSchema(db[8]);

// Save Schemas
await Promise.all([
fs.promises.writeFile("schema.processor.json", JSON.stringify(ProcessorSchema, null, '\t'), "utf-8"),
fs.promises.writeFile("schema.serverproducts.json", JSON.stringify(ServerProductSchema, null, '\t'), "utf-8"),
fs.promises.writeFile("schema.intelnucs.json", JSON.stringify(IntelNucSchema, null, '\t'), "utf-8"),
fs.promises.writeFile("schema.wireless.json", JSON.stringify(WirelessSchema, null, '\t'), "utf-8"),
fs.promises.writeFile("schema.ethernetproducts.json", JSON.stringify(EthernetProductsSchema, null, '\t'), "utf-8"),
fs.promises.writeFile("schema.intelfpgas.json", JSON.stringify(IntelFPGAsSchema, null, '\t'), "utf-8"),
fs.promises.writeFile("schema.memoryandstorage.json", JSON.stringify(MemoryandStorageSchema, null, '\t'), "utf-8"),
fs.promises.writeFile("schema.chipsets.json", JSON.stringify(ChipsetsSchema, null, '\t'), "utf-8"),
fs.promises.writeFile("schema.graphics.json", JSON.stringify(GraphicsSchema, null, '\t'), "utf-8")
]);
});
84 changes: 84 additions & 0 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
CREATE TABLE ProductTypes (
Id INT NOT NULL,
Name TEXT NOT NULL,

CONSTRAINT PK_ProductTypes PRIMARY KEY (Id),
CONSTRAINT UQ_ProductTypes_Name UNIQUE (Name)
);

CREATE TABLE ProductBrands (
ProductType INT NOT NULL,
Id INT NOT NULL,
Name TEXT NOT NULL,

CONSTRAINT PK_ProductBrands PRIMARY KEY (ProductType, Id),
CONSTRAINT FK_ProductBrands_ProductTypes FOREIGN KEY (ProductType) REFERENCES ProductTypes,
CONSTRAINT UQ_ProductBrands_Name UNIQUE (Name)
);

CREATE TABLE ProductSeries (
ProductType INT NOT NULL,
ProductBrand INT NOT NULL,
Id INT NOT NULL,
Name TEXT NOT NULL,
Url TEXT NOT NULL,

CONSTRAINT PK_ProductSeries PRIMARY KEY (ProductType, ProductBrand, Id),
CONSTRAINT FK_ProductSeries_ProductBrands FOREIGN KEY (ProductType, ProductBrand) REFERENCES ProductBrands (ProductType, Id),
CONSTRAINT UQ_ProductSeries_Name UNIQUE (Name),
CONSTRAINT UQ_ProductSeries_Url UNIQUE (Url)
);

CREATE TABLE Products (
ProductType INT NOT NULL,
ProductBrand INT NOT NULL,
ProductSerie INT NOT NULL,
Id INT NOT NULL,
Name TEXT NOT NULL,
Url TEXT NOT NULL,

CONSTRAINT PK_Product PRIMARY KEY (ProductType, ProductBrand, ProductSerie, Id),
CONSTRAINT FK_Product_ProductSeries FOREIGN KEY (ProductType, ProductBrand, ProductSerie) REFERENCES ProductSeries (ProductType, ProductBrand, Id),
CONSTRAINT UQ_Product_Name UNIQUE (Name),
CONSTRAINT UQ_Product_Url UNIQUE (Url)
);

CREATE TABLE SpecificationCategories (
Id INT NOT NULL,
Name TEXT NOT NULL,

CONSTRAINT PK_SpecificationCategories PRIMARY KEY (Id),
CONSTRAINT UQ_SpecificationCategories_Name UNIQUE (Name)
);

CREATE TABLE SpecificationProperties (
SpecificationCategory INT NOT NULL,
Id INT NOT NULL,
Name TEXT NOT NULL,

CONSTRAINT PK_SpecificationProperties PRIMARY KEY (SpecificationCategory, Id),
CONSTRAINT FK_SpecificationProperties_SpecificationCategories FOREIGN KEY (SpecificationCategory) REFERENCES SpecificationCategories (Id),
CONSTRAINT UQ_SpecificationProperties_Name UNIQUE (Name)
);

CREATE TABLE ProductsSpecifications (
ProductType INT NOT NULL,
ProductBrand INT NOT NULL,
ProductSerie INT NOT NULL,
ProductId INT NOT NULL,
SpecificationCategory INT NOT NULL,
SpecificationProperty INT NOT NULL,
Value TEXT NOT NULL,

CONSTRAINT PK_ProductsSpecifications PRIMARY KEY (ProductType, ProductBrand, ProductSerie, ProductId, SpecificationCategory, SpecificationProperty),
CONSTRAINT FK_ProductsSpecifications_Products FOREIGN KEY (ProductType, ProductBrand, ProductSerie, ProductId) REFERENCES Products (ProductType, ProductBrand, ProductSerie, Id),
CONSTRAINT FK_ProductsSpecifications_SpecificationProperties FOREIGN KEY (SpecificationCategory, SpecificationProperty) REFERENCES SpecificationProperties (SpecificationCategory, Id)
);

DROP TABLE ProductTypes;
DROP TABLE ProductBrands;
DROP TABLE ProductSeries;
DROP TABLE Products;
DROP TABLE SpecificationCategories;
DROP TABLE SpecificationProperties;
DROP TABLE ProductsSpecifications;

0 comments on commit d5b5eaa

Please sign in to comment.