Commit a5441b75 authored by Henrich Hanusovsky's avatar Henrich Hanusovsky
Browse files

Merge branch 'master' into build/smartly-ws

parents b2756b77 996603c7
.idea/
__pycache__
\ No newline at end of file
......@@ -9,9 +9,14 @@ class DatabaseService{
void addPossition(Position position) async{
String deviceId = await PlatformDeviceId.getDeviceId;
databaseReference.child("vehicles").child(deviceId).child("currentPos").set({
"lat" : position.latitude.toString(),
"lng" : position.longitude.toString()
});
databaseReference.child(deviceId).set({
"Latitude" : position.latitude.toString(),
"Longitude" : position.longitude.toString()
"lat" : position.latitude.toString(),
"lng" : position.longitude.toString()
});
}
......
# Raspberry PI
Raspberry PI directory containing all files required to control Raspberry PI
**Note: hackathon 2020 project**
## How to run
When using Raspberry PI with raspbian, no extra libraries nor packages need to be installed.
> python3 main.py
\ No newline at end of file
[
{
"id": 1,
"name": "Semafór zo Štúrovej",
"city_area_from": 6,
"city_area_to": [
14,
11
],
"green_port" : 2,
"orange_port": 3,
"red_port": 4,
"green_timer": 10
},
{
"id": 1,
"name": "Semafór z Moyzesovej",
"city_area_from": 7,
"city_areas_to": [
15,
14
],
"green_port" : 14,
"orange_port": 15,
"red_port": 18,
"green_timer": 10
},
{
"id": 1,
"name": "Semafór z ABCD",
"city_area_from": 14,
"city_areas_to": [
6,
7,
11
],
"green_port" : 17,
"orange_port": 27,
"red_port": 22,
"green_timer": 10
},
{
"id": 1,
"name": "Semafór z EFGH",
"city_area_from": 11,
"city_areas_to": [
6,
14,
15
],
"green_port" : 10,
"orange_port": 9,
"red_port": 11,
"green_timer": 10
}
]
\ No newline at end of file
# coding=utf-8
import json
import os
def getConfigFromJson():
configFilePath = os.getcwd() + '/assets/config.json'
with open(configFilePath, encoding='utf-8') as f:
configData = json.load(f)
return configData
# coding=utf-8
serverThread = None
lightsThread = None
config = None
def getServerThread():
global serverThread
return serverThread
def setServerThread(value):
global serverThread
serverThread = value
def getLightsThread():
global lightsThread
return lightsThread
def setLightsThread(value):
global lightsThread
lightsThread = value
def getConfig():
global config
return config
def setConfig(value):
global config
config = value
# coding=utf-8
from trafficControl import startTrafficControl
from trafficServer import run_server
import globals
from threading import Thread
from configuration import getConfigFromJson
def main():
globals.setConfig(getConfigFromJson())
globals.setLightsThread(Thread(target=startTrafficControl))
globals.getLightsThread().start()
globals.setServerThread(Thread(target=run_server))
globals.getServerThread().start()
main()
# coding=utf-8
from gpiozero import LED
import globals
import time
import threading
lights = []
currentLight = None
currentLightIndex = 0
interruptFlag = False
normalThread = None
interruptDone = True
normalDone = False
def interrupt(fromCityPart, toCityPart):
global interruptFlag, interruptDone
if interruptFlag:
return False
print("Interrupting normal TL", fromCityPart, toCityPart)
interruptFlag = True
interruptDone = False
threading.Thread(target=interruptMode, args=[fromCityPart, toCityPart]).start()
return True
def normalize():
global interruptFlag
print("Resetting normal TL")
interruptFlag = False
def initTest():
global lights
for light in lights:
light.get('leds')[0].on()
light.get('leds')[1].on()
light.get('leds')[2].on()
time.sleep(1)
light.get('leds')[0].off()
light.get('leds')[1].off()
light.get('leds')[2].off()
def initLeds():
global lights
for light in lights:
light.get('leds')[2].on()
def setupLeds():
global lights
for light in globals.getConfig():
currentLightTmp = {'greenPort': light.get('green_port'), 'orangePort': light.get('orange_port'),
'redPort': light.get('red_port'), 'leds': [LED(light.get('green_port')),
LED(light.get('orange_port')),
LED(light.get('red_port'))],
'timer': [light.get('green_timer'), 2], 'from': light.get('city_area_from'),
'to': light.get('city_area_to')}
lights.append(currentLightTmp)
def interruptMode(fromCityPart, toCityPart):
global lights, interruptFlag, interruptDone, normalDone, currentLight, currentLightIndex
affectedLights = []
while not normalDone:
time.sleep(1)
for light in lights:
if light.get('from') == fromCityPart:
affectedLights.append(light)
for light in affectedLights:
light.get('leds')[2].off()
for light in affectedLights:
light.get('leds')[1].on()
time.sleep(affectedLights[0].get('timer')[1])
for light in affectedLights:
light.get('leds')[1].off()
for light in affectedLights:
light.get('leds')[0].on()
while interruptFlag:
time.sleep(1)
for light in affectedLights:
light.get('leds')[0].off()
for light in affectedLights:
light.get('leds')[1].on()
time.sleep(affectedLights[0].get('timer')[1])
for light in affectedLights:
light.get('leds')[1].off()
for light in affectedLights:
light.get('leds')[2].on()
currentLightIndex = (currentLightIndex + (len(lights) - 1)) % len(lights)
currentLight = lights[currentLightIndex]
interruptDone = True
def normalMode():
global interruptFlag, currentLightIndex, currentLight, normalDone
while True:
while not interruptDone:
time.sleep(1)
normalDone = False
leds = currentLight.get('leds')
greenOn = False
leds[2].off()
leds[1].on()
# 1 orange
for x in range(currentLight.get('timer')[1]):
if interruptFlag:
break
time.sleep(1)
leds[1].off()
leds[0].on()
# 1 green
for x in range(currentLight.get('timer')[0]):
if interruptFlag:
break
greenOn = True
time.sleep(1)
leds[0].off()
leds[1].on()
# 2 orange
for x in range(currentLight.get('timer')[1]):
if interruptFlag and not greenOn:
break
time.sleep(1)
leds[1].off()
leds[2].on()
currentLightIndex = (currentLightIndex + 1) % len(lights)
currentLight = lights[currentLightIndex]
normalDone = True
def startTrafficControl():
global currentLightIndex, currentLight, normalThread
setupLeds()
initTest()
initLeds()
currentLight = lights[currentLightIndex]
normalThread = threading.Thread(target=normalMode)
normalThread.start()
# coding=utf-8
from trafficControl import interrupt, normalize
from flask import Flask, json, request, Response
host = 'localhost'
port = 5080
api = Flask(__name__)
@api.route('/health', methods=['GET'])
def get_health():
return json.jsonify("Health check")
@api.route('/reqInterrupt/<fromCityPart>/<toCityPart>', methods=['POST'])
def get_reqInterrupt(fromCityPart, toCityPart):
if interrupt(int(fromCityPart), int(toCityPart)):
return 'interrupt data through header'
return Response("", status=403, mimetype='application/json')
@api.route('/reqInterrupt/', methods=['POST'])
def get_reqInterruptBody():
data = json.loads(request.data)
fromCityPart = data.get("from", None)
toCityPart = data.get("to", None)
if interrupt(int(fromCityPart), int(toCityPart)):
return 'interrupt data through body'
return Response("", status=403, mimetype='application/json')
@api.route('/reqNormal', methods=['POST'])
def get_reqNormal():
normalize()
return 'normal data'
def run_server():
api.run(host=host, port=port)
[{"C:\\My Things\\maps\\my-app\\src\\App.tsx":"1","C:\\My Things\\maps\\my-app\\src\\pages\\MapPage.tsx":"2","C:\\My Things\\maps\\my-app\\src\\index.tsx":"3"},{"size":131,"mtime":1606766365049,"results":"4","hashOfConfig":"5"},{"size":5400,"mtime":1606827483560,"results":"6","hashOfConfig":"5"},{"size":511,"mtime":1606768165832,"results":"7","hashOfConfig":"5"},{"filePath":"8","messages":"9","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"lb4jsg",{"filePath":"10","messages":"11","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\My Things\\maps\\my-app\\src\\App.tsx",[],"C:\\My Things\\maps\\my-app\\src\\pages\\MapPage.tsx",[],"C:\\My Things\\maps\\my-app\\src\\index.tsx",[]]
\ No newline at end of file
[{"C:\\My Things\\maps\\my-app\\src\\App.tsx":"1","C:\\My Things\\maps\\my-app\\src\\pages\\MapPage.tsx":"2","C:\\My Things\\maps\\my-app\\src\\index.tsx":"3","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\App.tsx":"4","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\pages\\MapPage.tsx":"5","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\index.tsx":"6","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\mock\\ambulance-mock.ts":"7","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\mock\\intersection-mock.ts":"8","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\components\\Modal.tsx":"9","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\utils\\http.ts":"10","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\components\\VehicleMarker.tsx":"11","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\utils\\useInterval.ts":"12","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\components\\Button.tsx":"13","C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\components\\Area.tsx":"14"},{"size":131,"mtime":1606766365049,"results":"15","hashOfConfig":"16"},{"size":5400,"mtime":1606827483560,"results":"17","hashOfConfig":"16"},{"size":511,"mtime":1606768165832,"results":"18","hashOfConfig":"16"},{"size":131,"mtime":1606774443485,"results":"19","hashOfConfig":"20"},{"size":6682,"mtime":1606999429127,"results":"21","hashOfConfig":"20"},{"size":528,"mtime":1606989391178,"results":"22","hashOfConfig":"20"},{"size":398,"mtime":1606860336754,"results":"23","hashOfConfig":"20"},{"size":553,"mtime":1606858103945,"results":"24","hashOfConfig":"20"},{"size":3335,"mtime":1606990785833,"results":"25","hashOfConfig":"20"},{"size":3014,"mtime":1606996275297,"results":"26","hashOfConfig":"20"},{"size":6636,"mtime":1606999782903,"results":"27","hashOfConfig":"20"},{"size":493,"mtime":1606989391187,"results":"28","hashOfConfig":"20"},{"size":717,"mtime":1606989643523,"results":"29","hashOfConfig":"20"},{"size":963,"mtime":1606994358118,"results":"30","hashOfConfig":"20"},{"filePath":"31","messages":"32","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"lb4jsg",{"filePath":"33","messages":"34","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"35","messages":"36","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"37","messages":"38","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1powns5",{"filePath":"39","messages":"40","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"41","messages":"42","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"43"},{"filePath":"44","messages":"45","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"43"},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"56","messages":"57","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"58"},{"filePath":"59","messages":"60","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"43"},"C:\\My Things\\maps\\my-app\\src\\App.tsx",[],"C:\\My Things\\maps\\my-app\\src\\pages\\MapPage.tsx",[],"C:\\My Things\\maps\\my-app\\src\\index.tsx",[],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\App.tsx",[],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\pages\\MapPage.tsx",[],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\index.tsx",[],["61","62"],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\mock\\ambulance-mock.ts",[],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\mock\\intersection-mock.ts",[],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\components\\Modal.tsx",[],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\utils\\http.ts",[],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\components\\VehicleMarker.tsx",[],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\utils\\useInterval.ts",[],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\components\\Button.tsx",[],["63","64"],"C:\\My Things\\school\\3.rocnik - zimny semester\\hackathon-2020\\react\\src\\components\\Area.tsx",[],{"ruleId":"65","replacedBy":"66"},{"ruleId":"67","replacedBy":"68"},{"ruleId":"65","replacedBy":"69"},{"ruleId":"67","replacedBy":"70"},"no-native-reassign",["71"],"no-negated-in-lhs",["72"],["71"],["72"],"no-global-assign","no-unsafe-negation"]
\ No newline at end of file
......@@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.eslintcache
.eslintcache~smartly-ws
\ No newline at end of file
{
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100
}
{
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100
}
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `yarn start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `yarn test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `yarn build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `yarn eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `yarn start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `yarn test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `yarn build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `yarn eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
This diff is collapsed.
{
"name": "my-app",
"name": "smartly",
"version": "0.1.0",
"private": true,
"dependencies": {
......@@ -9,10 +9,15 @@
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/qs": "^6.9.5",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"@types/react-modal": "^3.10.6",
"axios": "^0.21.0",
"qs": "^6.9.4",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-modal": "^3.12.1",
"react-scripts": "4.0.1",
"typescript": "^4.0.3",
"web-vitals": "^0.2.4"
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"