Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
akelsch committed Jul 15, 2020
1 parent 000a191 commit afbd974
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 84 deletions.
2 changes: 0 additions & 2 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import './scheduler'

import express from 'express'
import morgan from 'morgan'
import cookieParser from 'cookie-parser'
import cors from 'cors'

import { casesRouter, mapdataRouter, optionsRouter } from './routes'
Expand All @@ -17,7 +16,6 @@ const app = express()
app.use(morgan('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(cors())
app.use(express.static('public'))

Expand Down
16 changes: 8 additions & 8 deletions lib/database-init.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import sequelize from './database'
import db from './database'
import * as rki from './utils/rki'
import { CountyCase, CountyGeometry, StateCase, StateGeometry } from './models'
import { fetchCountyCases, fetchCountyGeometries, fetchStateCases, fetchStateGeometries } from './utils/rki'
import { updateNormalizedValues, convertGermanDate } from './scheduler'

sequelize.drop()
db.drop()
.then(() => {
sequelize.sync()
db.sync()
.then(async () => {
await initStateGeometries()
await initCountyGeometries()
Expand All @@ -16,7 +16,7 @@ sequelize.drop()
})

async function initStateGeometries () {
const data = await fetchStateGeometries()
const data = await rki.fetchStateGeometries()

for (const element of data.features) {
element.geometry.crs = data.crs
Expand All @@ -29,7 +29,7 @@ async function initStateGeometries () {
}

async function initCountyGeometries () {
const data = await fetchCountyGeometries()
const data = await rki.fetchCountyGeometries()

for (const element of data.features) {
element.geometry.crs = data.crs
Expand All @@ -42,7 +42,7 @@ async function initCountyGeometries () {
}

async function initStateCases () {
const data = await fetchStateCases()
const data = await rki.fetchStateCases()

for (const element of data.features) {
await StateCase.create({
Expand All @@ -61,7 +61,7 @@ async function initStateCases () {
}

async function initCountyCases () {
const data = await fetchCountyCases()
const data = await rki.fetchCountyCases()

for (const element of data.features) {
await CountyCase.create({
Expand Down
9 changes: 4 additions & 5 deletions lib/database.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CountyCase, CountyGeometry, Option, StateCase, StateGeometry } from './models'
import * as models from './models'

import sequelize from 'sequelize'
const { Sequelize } = sequelize
Expand All @@ -8,12 +8,11 @@ const USERNAME = 'postgres'
const PASSWORD = 'mysecretpassword'
const HOST = process.env.PG_HOST || 'localhost'

const connection = new Sequelize(DATABASE, USERNAME, PASSWORD, {
const db = new Sequelize(DATABASE, USERNAME, PASSWORD, {
host: HOST,
dialect: 'postgres'
})

const models = [CountyCase, CountyGeometry, Option, StateCase, StateGeometry]
models.forEach(model => model.init(connection))
Object.values(models).forEach(model => model.init(db))

export default connection
export default db
1 change: 0 additions & 1 deletion lib/models/StateCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default class StateCase extends Model {
},
cases7Per100k: {
type: DataTypes.DOUBLE,
// allowNull: false,
validate: {
min: 0,
max: 100000
Expand Down
6 changes: 3 additions & 3 deletions lib/scheduler.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import cron from 'node-cron'

import * as rki from './utils/rki'
import { CountyCase, StateCase } from './models'
import { fetchCountyCases, fetchStateCases } from './utils/rki'

cron.schedule('0 4 * * *', () => {
updateStateCases()
updateCountyCases()
})

async function updateStateCases () {
const data = await fetchStateCases()
const data = await rki.fetchStateCases()

for (const element of data.features) {
await StateCase.update({
Expand All @@ -30,7 +30,7 @@ async function updateStateCases () {
}

async function updateCountyCases () {
const data = await fetchCountyCases()
const data = await rki.fetchCountyCases()

for (const element of data.features) {
await CountyCase.update({
Expand Down
15 changes: 8 additions & 7 deletions lib/services/mapdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ export async function findMapdataByStateId (stateId, resolution, zoom) {
return adjustMapdata(mapdata)
}

function adjustMapdata (mapdata) {
return mapdata.filter(elem => elem.geometry !== null)
.map(({ dataValues: { geometry: { coordinates }, ...rest } }) => {
return { ...rest, coordinates }
})
}

function getScaleFactor (zoom) {
// Google Maps Konstante
const initialScale = 591657550.500000

const maxZoomLevel = 20
Expand All @@ -66,10 +74,3 @@ function getEpsilon (resolution) {
return 4
}
}

function adjustMapdata (mapdata) {
return mapdata.filter(elem => elem.geometry !== null)
.map(({ dataValues: { geometry: { coordinates }, ...rest } }) => {
return { ...rest, coordinates }
})
}
48 changes: 0 additions & 48 deletions lib/utils/algorithms.js

This file was deleted.

9 changes: 0 additions & 9 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"dependencies": {
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"express": "^4.17.1",
"morgan": "^1.10.0",
Expand Down

0 comments on commit afbd974

Please sign in to comment.