Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Elyx0 committed Apr 18, 2019
0 parents commit d9eb0a1
Show file tree
Hide file tree
Showing 23 changed files with 8,779 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
npm-debug.log
Dockerfile
.dockerignore
126 changes: 126 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2017
},
"rules": {
"indent": [
2,
4,
{
"SwitchCase": 1
}
],
"quotes": [
2,
"single",
"avoid-escape"
],
"semi": [
2,
"always"
],
"no-multiple-empty-lines": [
2,
{
"max": 2
}
],
"new-cap": [
2,
{
"newIsCap": true,
"capIsNew": true
}
],
"one-var": [
2,
"never"
],
"object-curly-spacing": [
2,
"never"
],
"array-bracket-spacing": [
2,
"never"
],
"space-before-function-paren": [
2,
{
"anonymous": "always",
"named": "never"
}
],
"keyword-spacing": [
2,
{
"before": true,
"after": true
}
],
"operator-linebreak": [
2,
"after"
],
"space-in-parens": [
2,
"never"
],
"space-before-blocks": [
2,
"always"
],
"yoda": [
2,
"never"
],
"eqeqeq": [
2,
"smart"
],
"space-unary-ops": [
2,
{
"words": true,
"nonwords": false
}
],
"no-implicit-coercion": [
2,
{
"boolean": true,
"number": true,
"string": true
}
],
"spaced-comment": [
2,
"always"
],
"no-throw-literal": 2,
"no-eval": 2,
"no-unneeded-ternary": 2,
"no-with": 2,
"curly": 1,
"brace-style": 2,
"no-spaced-func": 2,
"comma-style": 2,
"semi-spacing": 2,
"key-spacing": 2,
"new-parens": 2,
"no-console": 0,
"eol-last": 2,
"no-trailing-spaces": 2,
"camelcase": 2,
"no-undef": 2
},
"env": {
"node": true,
"mocha": true,
"es6": true
},
"extends": ["eslint:recommended","plugin:@typescript-eslint/recommended"]
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Any build artifacts for any and every VCSes have to be excluded
# from storing in repository.
.env
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
build

pids
logs
results

npm-debug.log
.nyc_output
coverage
node_modules

build

.idea
*.iml
yarn.lock
.DS_store
54 changes: 54 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Current File",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-r ts-node/register",
"--timeout",
"999999",
"--colors",
"${file}"
],
//"console": "integratedTerminal",
//"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Debug local server build",
"program": "${workspaceFolder}/src/server.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/build/**/*.js"
]
},
{
"type": "node",
"request": "launch",
"name": "Launch in Docker",
"preLaunchTask": "tsc-watch",
"runtimeExecutable": "npm",
"runtimeArgs": [ "run", "docker-debug" ],
"port": 9222,
"restart": true,
"timeout": 60000,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/app",
"outFiles": [
"${workspaceFolder}/build/**/*.js"
],
"skipFiles": [
"<node_internals>/**/*.js",
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM node:11-alpine
RUN apk add --update --no-progress make python bash
ENV NPM_CONFIG_LOGLEVEL error

# Dumb init so PID != 1
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

RUN mkdir -p /usr/src/app
RUN adduser -S nodejs
WORKDIR /usr/src/app
COPY package*.json ./
RUN chown nodejs: /usr/src/app
RUN chmod -R 777 .
USER nodejs




#COPY package.json .
#COPY package-lock.json .

COPY --chown=nodejs:node . ./
#RUN NODE_ENV=production

RUN npm install
RUN npm run build

ENV HOST "0.0.0.0"
ENV PORT 3000
EXPOSE 3000

ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "start"]
84 changes: 84 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

![GitHub license](https://img.shields.io/badge/license-ISC-blue.svg)


### Simple Kalichkin NVT Fetcher for BTC market

The Network Value to Transactions (NVT) ratio measures the dollar value of cryptoasset transaction activity relative to network value. This is a simple way to compare how the market prices one unit of on-chain transactions across different networks.

Generally speaking, a “low” market to transaction value denotes an asset which is more cheaply valued per unit of on-chain transaction volume.

Network value consists of the total market value of all tokens in circulation. The transaction element is an estimate of the value of on-chain transaction activity drawn from block explorers and blockchains.

---
### How does it work


The code is build with [Typescript](https://www.typescriptlang.org/)

- It fetches the queries from [sqlite3](sqlite3) database
- ![conditions](https://i.gyazo.com/163bb010e14539cdd3057b7e8eeaa357.png)

- It uses chrome headless with [puppeteer](https://github.com/GoogleChrome/puppeteer) to grab the canvas rendered screenshot at the last interval

- ![conditions](screenshot.png)

- enlarges it with [sharp](https://sharp.pixelplumbing.com) then
- extracts the text from [tesseract](https://github.com/naptha/tesseract.js#tesseractjs)
image recognition models

- Saves it into `history` table

- ![saved](https://i.gyazo.com/14a2acac3731a51998751cb2298404fd.png)

- sends the results by email using [mailgun](mailgun.com)

---

#### Development

You will need the following env vars or using a `.env` file:
```
PORT=8888
MAILGUN_API_KEY=239e8293e72398whateverwhatever
MAILGUN_DOMAIN=sandbox23892y3e82whatever.mailgun.org
[email protected]
```

- Edit the `seed.ts` to your liking

Then after `npm install` install run *once*: `npm run seed`

Locally:

`npm install && npm run build && npm run fastLocal`

To get the code coverage:
`npm run coverage`

To run the tests in watch mode:
`npm run watch`

##### Debugging

`.vscode` launch options are provided for debugging locally

#### On Docker:

- Build the image: `npm run docker-build`
- Run the image: `npm run docker-run`

Alternatively: `docker-compose up`

---

Ideally run on a daily basis with `cron`, ex:
2am every day:
```
0 2 * * * /usr/local/node /your/code/path/build/server.js
```

Ex on my mac local:
```
* 2 * * * /usr/local/bin/node /Sites/nvt/build/server.js >> /Sites/nvt/cron.log 2>&1
```
Binary file added database.db
Binary file not shown.
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "2"

services:
web:
build: .
command: npm run debug
volumes:
- ./build:/usr/src/app/build
ports:
- "3000:3000"
- "5858:5858"
Binary file added eng.traineddata
Binary file not shown.
Loading

0 comments on commit d9eb0a1

Please sign in to comment.