Skip to content

Commit

Permalink
Merge branch 'main' of github.com:EVS-GIS/woodcam-rm into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sdunesme committed Sep 8, 2022
2 parents b706e6d + 81568b9 commit 66b4fce
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 243 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DEFAULT_EMAIL=
SCHEDULER_TIMEZONE='Europe/Paris'
APP_URL=
GRAFANA_URL=
PROMETHEUS_URL=
FTP_USER=
FTP_PASSWORD=

Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ WORKDIR /app

COPY . .

RUN apt-get -y update && apt-get -y install python3-opencv && apt-get clean
ENV PYTHONPATH "${PYTHONPATH}:/usr/lib/python3/dist-packages"

RUN pip install -e .
RUN pip install gunicorn

Expand Down
90 changes: 1 addition & 89 deletions grafana/provisioning/dashboards/main-dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,94 +125,6 @@
"title": "Mobile signal stregth",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "woodcamrmprometheus"
},
"description": "From gateway SNMP protocol",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "decbytes"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 15,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [{
"datasource": {
"type": "prometheus",
"uid": "woodcamrmprometheus"
},
"editorMode": "code",
"expr": "sum by (common_name) (increase(ifHCInOctets{ifName='tun1'}[31d])+increase(ifHCOutOctets{ifName='tun1'}[31d]))",
"legendFormat": "{{common_name}}",
"range": true,
"refId": "A"
}],
"title": "Data transferred over 31 rolling days",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
Expand Down Expand Up @@ -381,7 +293,7 @@
"range": true,
"refId": "A"
}],
"title": "Data transmitted 31 rolling days geneko SNMP",
"title": "Data transmitted 31 rolling days",
"type": "timeseries"
},
{
Expand Down
6 changes: 0 additions & 6 deletions prometheus/queries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ pg_woodcamrm_stations:
- last_hydro:
usage: "GAUGE"
decription: "Station API water level"
- current_data:
usage: "GAUGE"
description: "Data plan usage"
- ping_alert:
usage: "COUNTER"
description: "Last ping didn't respond"
- current_daymode:
usage: "GAUGE"
description: "Current night/day mode"
Expand Down
36 changes: 19 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@
include_package_data=True,
zip_safe=False,
install_requires=[
'flask',
'flask-restx',
'flask-sqlalchemy',
'flask-apscheduler',
'flask-mail',
'flask-wtf',
'flask-migrate',
'psycopg2-binary',
'requests',
'python-dotenv',
'pysnmp',
'geoalchemy2',
'suntime',
'celery[redis]',
'opencv-python-headless',
'pyyaml',
'bcrypt'
'bcrypt==3.2.2',
'celery[redis]==5.2.7',
'flask==2.1.2',
'flask_httpauth==4.7.0',
'flask-restx==0.5.1',
'flask-sqlalchemy==2.5.1',
'flask-apscheduler==1.12.4',
'flask-mail==0.9.1',
'flask-wtf==1.0.1',
'flask-migrate==3.1.0',
'geoalchemy2==0.12.1',
'psycopg2-binary==2.9.3',
'pysnmp==4.4.12',
'python-dotenv==0.20.0',
'pyyaml==6.0',
'requests==2.28.1',
'simplejson==3.17.6',
'suntime==1.2.5',
'werkzeug==2.1.2'
],
)
2 changes: 1 addition & 1 deletion woodcamrm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def save_video_file(filepath, rtsp_url, station_id):
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
# Get current height of frame
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'MJPG')

Expand Down
49 changes: 44 additions & 5 deletions woodcamrm/api_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
import sys
import simplejson as json
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import check_password_hash

from flask_restx import Resource
from woodcamrm import api
from woodcamrm.db import Stations, Users


auth = HTTPBasicAuth()

@auth.verify_password
def authenticate(username, password):
if username and password:

user = Users.query.filter_by(username=username).first()

error = None

if user is None:
error = 'Incorrect username.'
elif not check_password_hash(user.password, password):
error = 'Incorrect password.'

if error is None:
return True
else:
return False



@api.route('/datarecovery')
@api.doc(params={'station': 'Station ID',
'from_ts': 'From timestamp',
'to_ts': 'To timestamp'})
class DataRecovery(Resource):

@api.doc(responses={403: 'Not Authorized'})
def get(self, station, from_ts, to_ts):
api.abort(403)
decorators = [auth.login_required]

def post(self, station, from_ts, to_ts):
return {'station': station,
'from_ts': from_ts,
'to_ts': to_ts}
'to_ts': to_ts}


@api.route('/stations')
class StationsEndpoint(Resource):
decorators = [auth.login_required]

def get(self):

stations = Stations.query.all()
results = {st.common_name:st.__dict__ for st in stations}
results = json.dumps(results, use_decimal=True, default=lambda o: 'NA')

return {'data': results}
4 changes: 0 additions & 4 deletions woodcamrm/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,12 @@ def seed_db():
download_records = Jobs(job_name = 'download_records',
full_name = 'Download records',
description = 'Archive records to FTP server and remove temporary clips.')
check_data_plan = Jobs(job_name = 'check_data_plan',
full_name = 'Check data plan',
description = 'Estimate 4G data plan usage.')

dbsql.session.add(default_user)
dbsql.session.add(alive_check)
dbsql.session.add(hydrodata_update)
dbsql.session.add(records_check)
dbsql.session.add(download_records)
dbsql.session.add(check_data_plan)

dbsql.session.commit()

Expand Down
Loading

0 comments on commit 66b4fce

Please sign in to comment.