Skip to content
This repository has been archived by the owner on Oct 25, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
fxsth committed Jul 1, 2020
2 parents 215c047 + bb5a470 commit 3c8aba5
Show file tree
Hide file tree
Showing 44 changed files with 13,246 additions and 0 deletions.
19 changes: 19 additions & 0 deletions position-service/backend/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
autopep8 = "*"

[packages]
fastapi = "*"
uvicorn = "*"
scikit-learn = "*"
numpy = "*"
sqlalchemy = "*"
psycopg2 = "*"
sklearn = "*"

[requires]
python_version = "3.7"
311 changes: 311 additions & 0 deletions position-service/backend/Pipfile.lock

Large diffs are not rendered by default.

Empty file.
20 changes: 20 additions & 0 deletions position-service/backend/db/session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from sqlalchemy import create_engine, MetaData, Table, Column, String
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.automap import automap_base


engine_postgres = create_engine(
"postgresql+psycopg2://postgres@localhost:5432/test")

Base = automap_base()
Base.prepare(engine_postgres, reflect=True)


Ort = Base.classes.ort
Pakete = Base.classes.pakete
Person = Base.classes.person
Zustellbasis = Base.classes.zustellbasis
Zustellbasisart = Base.classes.zustellbasisart

SessionLocal = sessionmaker(
autocommit=False, autoflush=False, bind=engine_postgres)
2 changes: 2 additions & 0 deletions position-service/backend/geo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import numpy as np
from sklearn import
96 changes: 96 additions & 0 deletions position-service/backend/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

"""
Calculate the point in time of packstation
1. Calculate the Positions in time with biasis toward being near in the timeframe
"""


from fastapi import FastAPI, Depends
from starlette.middleware.cors import CORSMiddleware
from db.session import Pakete, Ort, SessionLocal
from sqlalchemy.orm import Session
from schemas.paket import PaketRep
from sklearn.cluster import KMeans

import random
import numpy as np

app = FastAPI()
origins = [
"http:localhost",
"http:localhost:4200",
"http://localhost:4200",
"https://localhost:4200",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)


def get_db():
try:
db = SessionLocal()
yield db
finally:
db.close()


@app.get("/")
def info_root():
return {"Version": "1.0.0"}


@app.get("/random_long_lat")
def get_random_long_lat():
long_lat_list = []
for i in range(20):
long_minutes = random.randint(-150, 330)
lat_minutes = random.randint(-18, 18)
lat = (5_151_000 + long_minutes) / 100000
long = (7468 + lat_minutes) / 1_000
lat_long_dict = {"long": long, "lat": lat}
long_lat_list.append(lat_long_dict)
return long_lat_list


@app.get("/random_long_lat_cluster")
def create_clustering():
long_lat_list = []
for i in range(30):
long_minutes = random.randint(-150, 330)
lat_minutes = random.randint(-18, 18)
lat = (5_151_000 + long_minutes) / 100000
long = (7468 + lat_minutes) / 1_000
lat_long_tupel = (long, lat)
long_lat_list.append(lat_long_tupel)
data_array = np.array(long_lat_list)
kmeans_result = KMeans(
n_clusters=4, random_state=0).fit_predict(data_array)
result_dict_list = []
for long_lat, cluster in zip(long_lat_list, kmeans_result):
lat_long_result_dict = {
"long": long_lat[0], "lat": long_lat[1], "cluster": int(cluster)}
result_dict_list.append(lat_long_result_dict)
return result_dict_list


def get_pakete(db: Session = Depends(get_db)):
db = SessionLocal()
answer = db.query(Pakete, Ort).filter(Pakete.zustellbasis_id == None).filter(
Pakete.wunschort_id != None).join(Ort, Pakete.wunschort_id == Ort.id).all()
for row in answer:
paket = row[0]
ort = row[1]
paket_rep = PaketRep(id=paket.id, groesse=paket.groesse,
fach_nummer=paket.fach_nummer, empfaenger_id=paket.empfaenger_id, absender_id=paket.absender_id, wunschort_id=paket.wunschort_id, long=ort.long, lat=ort.lat)
print(paket_rep)


create_clustering()
19 changes: 19 additions & 0 deletions position-service/backend/schemas/paket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pydantic import BaseModel
from datetime import datetime


class PaketRep(BaseModel):
id: int
groesse: int
fach_nummer: int = None
empfaenger_id: int
zustellbasis_id: int = None
absender_id: int = None
interaktion_von: datetime = None
interaktion_bis: datetime = None
wunschort_id: int
long: float
lat: float

class Config:
orm_mode = True
13 changes: 13 additions & 0 deletions position-service/frontend/position-admin/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
46 changes: 46 additions & 0 deletions position-service/frontend/position-admin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc
# Only exists if Bazel was run
/bazel-out

# dependencies
/node_modules

# profiling files
chrome-profiler-events*.json
speed-measure-plugin*.json

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db
27 changes: 27 additions & 0 deletions position-service/frontend/position-admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# PositionAdmin

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.3.25.

## Development server

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

## Code scaffolding

Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.

## Running unit tests

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
120 changes: 120 additions & 0 deletions position-service/frontend/position-admin/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"position-admin": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/position-admin",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": ["src/favicon.ico", "src/assets"],
"styles": [
"src/styles.css",
"./node_modules/leaflet/dist/leaflet.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "position-admin:build"
},
"configurations": {
"production": {
"browserTarget": "position-admin:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "position-admin:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": ["src/favicon.ico", "src/assets"],
"styles": [
"src/styles.css",
"./node_modules/leaflet/dist/leaflet.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": ["**/node_modules/**"]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "position-admin:serve"
},
"configurations": {
"production": {
"devServerTarget": "position-admin:serve:production"
}
}
}
}
}
},
"defaultProject": "position-admin"
}
12 changes: 12 additions & 0 deletions position-service/frontend/position-admin/browserslist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# You can see what browsers were selected by your queries by running:
# npx browserslist

> 0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11 # For IE 9-11 support, remove 'not'.
Loading

0 comments on commit 3c8aba5

Please sign in to comment.