Lots of fixes, docker optimization
- fixes status check for logger - adds ability to test sample data - adds PLC Handshaking capability - adds portainer as container manager - exposes mysql port for reading database (as 6603)
This commit is contained in:
@@ -5,7 +5,7 @@ COPY mysql-install.sh /tmp/mysql-install.sh
|
||||
RUN chmod +x /tmp/mysql-install.sh && /tmp/mysql-install.sh
|
||||
|
||||
RUN mkdir /root/tag-logger
|
||||
COPY flask /root/tag-logger/flask
|
||||
|
||||
|
||||
COPY mysql-connector-python-2.1.4 /tmp/mysql
|
||||
RUN cd /tmp/mysql && python setup.py install && cd ~
|
||||
@@ -18,6 +18,7 @@ RUN pip install flask flask-restless flask-sqlalchemy pyopenssl
|
||||
RUN apt-get clean
|
||||
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
COPY flask /root/tag-logger/flask
|
||||
RUN service mysql restart && python /root/tag-logger/flask/setupdb.py
|
||||
|
||||
CMD ["/root/startup.sh"]
|
||||
|
||||
@@ -5,7 +5,7 @@ COPY mysql-install.sh /tmp/mysql-install.sh
|
||||
RUN chmod +x /tmp/mysql-install.sh && /tmp/mysql-install.sh
|
||||
|
||||
RUN mkdir /root/tag-logger
|
||||
COPY flask /root/tag-logger/flask
|
||||
|
||||
|
||||
COPY mysql-connector-python-2.1.4 /tmp/mysql
|
||||
RUN cd /tmp/mysql && python setup.py install && cd ~
|
||||
@@ -18,6 +18,8 @@ RUN pip install flask flask-restless flask-sqlalchemy pyopenssl
|
||||
RUN apt-get clean
|
||||
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
COPY flask /root/tag-logger/flask
|
||||
RUN service mysql restart && python /root/tag-logger/flask/setupdb.py
|
||||
|
||||
CMD ["/root/startup.sh"]
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ from werkzeug.utils import secure_filename
|
||||
from sqlalchemy import and_
|
||||
import mysql.connector
|
||||
|
||||
|
||||
DAQ_HOSTNAME = "daq"
|
||||
UPLOAD_FOLDER = '/root/tag-server/flask/app/docs'
|
||||
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'zip'])
|
||||
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'zip'}
|
||||
|
||||
app = Flask('app', static_url_path='')
|
||||
app.config.update(
|
||||
@@ -21,6 +23,7 @@ app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
|
||||
app.secret_key = 'henry_pump'
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
|
||||
def allowed_file(filename):
|
||||
return '.' in filename and \
|
||||
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
|
||||
@@ -34,9 +37,14 @@ def catch_all(path):
|
||||
from .datalogger import datalogger
|
||||
from .datalogger.models import *
|
||||
|
||||
|
||||
@app.route('/api/latest')
|
||||
def get_latest_tag_vals():
|
||||
res = db.engine.execute('SELECT v1.id as id, v1.created_on as dtime, t.id as t_id, t.name as name, t.tag as tag, v1.value as value, t.units as units, t.description as description, t.min_expected as min_expected, t.max_expected as max_expected FROM tag_vals v1 INNER JOIN tags t ON t.id = v1.tag_id WHERE v1.id = (SELECT v2.id FROM tag_vals v2 WHERE v2.tag_id = v1.tag_id ORDER BY v2.id DESC LIMIT 1) ORDER BY t.id')
|
||||
res = db.engine.execute('SELECT v1.id as id, v1.created_on as dtime, t.id as t_id, t.name as name, t.tag as tag, '
|
||||
'v1.value as value, t.units as units, t.description as description, '
|
||||
't.min_expected as min_expected, t.max_expected as max_expected FROM tag_vals v1 '
|
||||
'INNER JOIN tags t ON t.id = v1.tag_id WHERE v1.id = (SELECT v2.id FROM tag_vals v2 '
|
||||
'WHERE v2.tag_id = v1.tag_id ORDER BY v2.id DESC LIMIT 1) ORDER BY t.id')
|
||||
lat = res.fetchall()
|
||||
latest_tags = list(map(latest_to_obj, lat))
|
||||
return jsonify(latest_tags)
|
||||
@@ -45,7 +53,8 @@ def get_latest_tag_vals():
|
||||
@app.route('/api/valuesbetween/<string:ids>/<string:start>/<string:end>')
|
||||
def get_tag_vals_between(ids, start, end):
|
||||
ids = ids.split(',')
|
||||
res = Tag_val.query.filter(and_(Tag_val.tag_id.in_(ids), Tag_val.created_on > start, Tag_val.created_on <= end)).all()
|
||||
res = Tag_val.query.filter(and_(Tag_val.tag_id.in_(ids), Tag_val.created_on > start,
|
||||
Tag_val.created_on <= end)).all()
|
||||
return jsonify([i.serialize for i in res])
|
||||
|
||||
|
||||
@@ -55,21 +64,22 @@ def get_multiple_tags(ids):
|
||||
res = Tag.query.filter(Tag.id.in_(ids)).all()
|
||||
return jsonify([i.serialize for i in res])
|
||||
|
||||
|
||||
@app.route('/doc/upload', methods=['POST'])
|
||||
def upload_file():
|
||||
# check if the post request has the file part
|
||||
if 'file' not in request.files:
|
||||
flash('No file part')
|
||||
return redirect("/#/docs")
|
||||
file = request.files['file']
|
||||
upl_file = request.files['file']
|
||||
# if user does not select file, browser also
|
||||
# submit a empty part without filename
|
||||
if file.filename == '':
|
||||
if upl_file.filename == '':
|
||||
flash('No selected file')
|
||||
return redirect("/#/docs")
|
||||
if file and allowed_file(file.filename):
|
||||
filename = secure_filename(file.filename)
|
||||
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||
if upl_file and allowed_file(upl_file.filename):
|
||||
filename = secure_filename(upl_file.filename)
|
||||
upl_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||
d = Doc(name=filename)
|
||||
db.session.add(d)
|
||||
db.session.commit()
|
||||
@@ -77,11 +87,13 @@ def upload_file():
|
||||
filename=filename))
|
||||
return redirect("/#/docs")
|
||||
|
||||
|
||||
@app.route('/docs/<filename>')
|
||||
def uploaded_file(filename):
|
||||
return send_from_directory(app.config['UPLOAD_FOLDER'],
|
||||
filename)
|
||||
|
||||
|
||||
@app.route('/csv/all')
|
||||
def get_csv_all():
|
||||
csv_string = "datetime,"
|
||||
@@ -95,13 +107,15 @@ def get_csv_all():
|
||||
val_objs = [{'value': x['value'], 'tag_name': x['tag']['name'], 'datetime': x['created_on']} for x in all_vals]
|
||||
for v in val_objs:
|
||||
tag_ind = all_tag_names.index(v['tag_name'])
|
||||
csv_string += "{},".format(v['datetime']) + "," * tag_ind + "{},".format(v['value']) + "," * (len(all_tag_names) - tag_ind) + "\n"
|
||||
csv_string += "{},".format(v['datetime']) + "," * tag_ind + "{},".format(v['value']) + \
|
||||
"," * (len(all_tag_names) - tag_ind) + "\n"
|
||||
return Response(
|
||||
csv_string,
|
||||
mimetype="text/csv",
|
||||
headers={"Content-disposition":
|
||||
"attachment; filename=datadump.csv"})
|
||||
|
||||
|
||||
@app.route('/csv/<string:ids>')
|
||||
def get_csv_selected(ids):
|
||||
csv_string = "datetime,"
|
||||
@@ -115,9 +129,18 @@ def get_csv_selected(ids):
|
||||
val_objs = [{'value': x['value'], 'tag_name': x['tag']['name'], 'datetime': x['created_on']} for x in all_vals]
|
||||
for v in val_objs:
|
||||
tag_ind = all_tag_names.index(v['tag_name'])
|
||||
csv_string += "{},".format(v['datetime']) + "," * tag_ind + "{},".format(v['value']) + "," * (len(all_tag_names) - tag_ind) + "\n"
|
||||
csv_string += "{},".format(v['datetime']) + "," * tag_ind + "{},".format(v['value']) + \
|
||||
"," * (len(all_tag_names) - tag_ind) + "\n"
|
||||
return Response(
|
||||
csv_string,
|
||||
mimetype="text/csv",
|
||||
headers={"Content-disposition":
|
||||
"attachment; filename=datadump{}.csv".format(ids.replace(",","-"))})
|
||||
"attachment; filename=datadump{}.csv".format(ids.replace(",", "-"))})
|
||||
|
||||
|
||||
@app.route("/logger_status")
|
||||
def get_logger_status():
|
||||
ping_response = os.system("ping -c 1 " + DAQ_HOSTNAME)
|
||||
if ping_response == 0:
|
||||
return jsonify({"status": "up"})
|
||||
return jsonify({"status": "down"})
|
||||
|
||||
@@ -49,10 +49,15 @@ poconsole.controller('configCtrl', function($scope, Page, $log, config, devices,
|
||||
var checkLoggerStatus = config.getLoggerStatus();
|
||||
checkLoggerStatus.then(function(data){
|
||||
$scope.loggerLoading = false;
|
||||
$scope.loggerRunning = data.status;
|
||||
console.log("Logger Status = " + data.status);
|
||||
if (data.status == "up"){
|
||||
$scope.loggerRunning = true;
|
||||
} else {
|
||||
$scope.loggerRunning = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
// $scope.checkLogger();
|
||||
$scope.checkLogger();
|
||||
|
||||
$scope.restartLogger = function(){
|
||||
var restartLogger = config.restartLogger();
|
||||
|
||||
@@ -50,7 +50,6 @@ poconsole.factory('config',function($q, $http, $log){
|
||||
var deferred = $q.defer();
|
||||
$http.get('/logger_status').success(function(data) {
|
||||
deferred.resolve({
|
||||
pid:data.pid,
|
||||
status: data.status
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,7 +23,6 @@ poconsole.controller('tagsCtrl', function($scope, $route, $http, $routeParams, P
|
||||
|
||||
$scope.submitAddTag = function(){
|
||||
var createStatus = tags.createTag($scope.newTag);
|
||||
$scope.createStatus = createStatus.status;
|
||||
$scope.loadTagList();
|
||||
};
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<h1 ng-if="loggerLoading">
|
||||
<span class="label label-warning">Checking Logger Status...</span>
|
||||
</h1>
|
||||
<button class="btn btn-primary btn-large" ng-click="checkLogger()">Check Logger</button> <button class="btn btn-warning btn-large" ng-click="restartLogger()">Restart Logger</button>
|
||||
<button class="btn btn-primary btn-large" ng-click="checkLogger()">Check Logger</button> <!-- <button class="btn btn-warning btn-large" ng-click="restartLogger()">Restart Logger</button> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
service mysql start
|
||||
sleep 5
|
||||
python /root/tag-logger/flask/run.py
|
||||
|
||||
Reference in New Issue
Block a user