salvataggio nome sessione, pulizia codice

This commit is contained in:
Marco Locatelli
2021-03-29 15:11:45 +02:00
parent ed636d077a
commit bd5a327d60
4 changed files with 44 additions and 93 deletions
+8 -9
View File
@@ -14,14 +14,13 @@ redSrv0 = redis.Redis(
port=REDIS_PORT,
db=0)
redSrv0.set('SETTINGS:LOG:STATUS',0)
#se non c'è un valore nei campi di redis, popolo il db
LOG_path = "/home/pi/Flythis/logger/log/"
DATA_path = "/home/pi/Flythis/logger/data/"
if redSrv0.get('SETTINGS:LOG:STATUS') is None:
redSrv0.set('SETTINGS:LOG:STATUS',1)
if redSrv0.get('SETTINGS:SELECTED_CH') is None:
redSrv0.set('SETTINGS:SELECTED_CH',0)
@@ -115,12 +114,12 @@ try:
redSrv0.set(redTime,str(now))
#print(logStatus)
# solo se su redis LOG è 1 eseguo il ciclo principale
logStatus = redSrv0.get('SETTINGS:LOG:STATUS').decode('utf-8')
if logStatus == "1" :
CHvalue = CH.ADS1256_GetAll()
#videoPrint(CHvalue)
#fileSave(CHvalue)
redisSave(CHvalue)
#logStatus = redSrv0.get('SETTINGS:LOG:STATUS').decode('utf-8')
#if logStatus == "1" :
CHvalue = CH.ADS1256_GetAll()
#videoPrint(CHvalue)
#fileSave(CHvalue)
redisSave(CHvalue)
time.sleep(int(redSrv0.get(redSampleFreq))/1000)
#eccezione da ctrl+c in terminale e chiusura
+14
View File
@@ -7,3 +7,17 @@
2021-03-29 11:36:32.642389 Program end. Ctrl+C from user
2021-03-29 11:36:39.298257 Program end. Ctrl+C from user
2021-03-29 11:37:09.962049 Program end. Ctrl+C from user
2021-03-29 12:26:08.253892 Program end. Ctrl+C from user
2021-03-29 12:34:34.762399 Program end. Ctrl+C from user
2021-03-29 12:35:59.824375 Program end. Ctrl+C from user
2021-03-29 12:41:24.933798 Program end. Ctrl+C from user
2021-03-29 12:43:32.139821 Program end. Ctrl+C from user
2021-03-29 12:45:05.686145 Program end. Ctrl+C from user
2021-03-29 12:46:23.743580 Program end. Ctrl+C from user
2021-03-29 12:53:23.943793 Program end. Ctrl+C from user
2021-03-29 13:04:38.212360 Program end. Ctrl+C from user
2021-03-29 13:11:50.548529 Program end. Ctrl+C from user
2021-03-29 13:12:03.872367 Program end. Ctrl+C from user
2021-03-29 13:12:47.701751 Program end. Ctrl+C from user
2021-03-29 14:49:22.191222 Program end. Ctrl+C from user
2021-03-29 15:04:18.258773 Program end. Ctrl+C from user
+11 -10
View File
@@ -1,7 +1,7 @@
#!/usr/bin/python
from flask import Flask, render_template, jsonify, request
import datetime
from datetime import datetime
from flask.wrappers import Request
import redis
import socket
@@ -133,7 +133,8 @@ def api_channels_all():
'ChScaleMax' : getRedisVal('SETTINGS:IN:MAX:'+str(numCh)),
'ChScaleMin' : getRedisVal('SETTINGS:IN:MIN:'+str(numCh)),
'ChRealMax' : getRedisVal('SETTINGS:OUT:MAX:'+str(numCh)),
'ChRealMin' : getRedisVal('SETTINGS:OUT:MIN:'+str(numCh))
'ChRealMin' : getRedisVal('SETTINGS:OUT:MIN:'+str(numCh)),
'LastSessionName' : getRedisVal('RTDATA:SESSION:NAME')
}
# restituisce in formato json i dati letti da redis
return jsonify(channelsData)
@@ -163,12 +164,20 @@ def api_channels_current():
def start_log():
#funzione start_log: scrive su redis LOG:STATUS -> 1
redSrv0.set('SETTINGS:LOG:STATUS', 1)
#data e time ora
lastDate = datetime.now()
#formato per data e time: dd/mm/YYYY H:M:S
format = "%d/%m/%Y_%H:%M:%S"
#format date e time adando strftime()
nameDate = lastDate.strftime(format) + ".csv"
redSrv0.set('RTDATA:SESSION:NAME', nameDate)
return "OK"
@flaskApp.route("/api/v1/log/stop", methods=['PUT'])
def stop_log():
#funzione stop_log: scrive su redis LOG:STATUS -> 0
redSrv0.set('SETTINGS:LOG:STATUS', 0)
redSrv0.set('RTDATA:SESSION:NAME', "-")
return "OK"
@flaskApp.route("/api/v1/setup/saveInMin", methods=['PUT'])
@@ -196,14 +205,6 @@ def selectChannel(numCh):
redSrv0.set('SETTINGS:SELECTED_CH', numCh)
return "OK"
@flaskApp.route("/api/v1/sessions", methods=['POST'])
def sessionCreate():
#funzione creazione sessione: scrive su redis SESSION:NAME prendendolo dall'input in pagina html con nome NewSessionName
sessionName = request.form['NewSessionName']
redSrv0.set('RTDATA:SESSION:NAME', sessionName)
# rimando in logger
return redirect("/logger")
@flaskApp.route("/api/v1/frequency", methods=['POST'])
def setFrequency():
#funzione set frequenza scrive su redis LOG:FREQ prendendolo dall'input in pagina html con nome LogFreq
+11 -74
View File
@@ -40,22 +40,19 @@
$("#ChanScaleMax").html(result.ChScaleMax);
$("#ChanRealMin").html(result.ChRealMin);
$("#ChanRealMax").html(result.ChRealMax);
$("#LastSessionName").html(result.LastSessionName);
}});
timeout = setTimeout(dataRefresh, intTime);
};
// Funzione startLog: fa chiamata per settare a 1 il LOG:STATUS
// Funzione startLog: chiamata /api/v1/log/start per avviare log e dare nome
function startLog(){
$.ajax({
type: 'PUT'
,url: "/api/v1/log/start"
,data: ""
,success: function(){
alert('Log Started');
}
})
intTime= 200;
};
// Funzione stopLog: fa chiamata per settare a 0 il LOG:STATUS
@@ -64,20 +61,9 @@
type: 'PUT'
,url: "/api/v1/log/stop"
,data: ""
,success: function(){
alert('Log Stopped');
}
})
intTime = 5000;
};
// Funzione startNewRec: assegna nuovo nome con data e ora al file .csv di record
function startNewRec(){
var d = new Date();
var name= d.toISOString().replace('T','_').replace('-','_').replace('-','_').replace(':','_').replace(':','_').replace('.','_').replace('Z','')+'.csv';
//console.log(name);
$('#NewSessionName').val(name);
}
</script>
<div class="container-fluid py-2 text-center">
<div class="row">
@@ -92,7 +78,6 @@
</strong>
</div>
</div>
<div class="card mb-4 col-6">
<div class="card-header">
Channel 2
@@ -105,54 +90,17 @@
</div>
</div>
</div>
<!-- <div class="card mb-4">
<div class="card-header">
Channels Reading
</div>
<div class="card-body">
<div class="row">
<div class="col-3">
Canale 1: <span id="Chan0"></span>
</div>
<div class="col-3">
Canale 2: <span id="Chan1"></span>
</div>
<div class="col-3">
Canale 3: <span id="Chan2"></span>
</div>
<div class="col-3">
Canale 4: <span id="Chan3"></span>
</div>
</div>
<div class="row">
<div class="col-3">
Canale 5: <span id="Chan4"></span>
</div>
<div class="col-3">
Canale 6: <span id="Chan5"></span>
</div>
<div class="col-3">
Canale 7: <span id="Chan6"></span>
</div>
<div class="col-3">
Canale 8: <span id="Chan7"></span>
</div>
</div>
</div>
</div> -->
<div class="alert alert-info text-center">
<strong>Logger Time: </strong> <span id="LoggerTime"></span>
<br>
<strong>Log frequency</strong> (edit in <a href="/settings">Settings</a>): <span id="LogFrequency"></span> (ms)
</div>
<div class="alert alert-info text-center">
<strong>Logger Time: </strong> <span id="LoggerTime"></span>
<br>
<strong>Log frequency</strong> (edit in <a href="/settings">Settings</a>): <span id="LogFrequency"></span> (ms)
</div>
</div>
<!--pulsanti start log e stop log-->
<center>
<div class="text-center">
<button type="button" class="btn btn-success" onclick="startLog()">Start Log</button>
<button type="button" class="btn btn-danger" onclick="stopLog()">Stop Log</button>
</center>
</div>
<br>
<div class="card mb-4">
<div class="card-header">
@@ -161,22 +109,11 @@
<i class="fas fa-table mr-1"></i>
Record Log
</div>
<div class="col-6 text-right">
<button type="button" class="btn btn-primary" onclick="startNewRec()">Create record File</button>
</div>
</div>
</div>
<div class="card-body">
<div class="row" id="divNewFile">
<form class="col-12" method="POST" action="/api/v1/sessions">
<div class="input-group mb-3">
<span class="input-group-text">Nuova sessione</span>
<input type="text" class="form-control" id="NewSessionName" name="NewSessionName"></input>
<div class="input-group-append">
<input type="submit" value="Invio" class="btn btn-success"></input>
</div>
</div>
</form>
<div class="input-group-text mb-3">
<span>Session: &nbsp;</span> <span id="LastSessionName"></span>
</div>
<div class="row">
<div class="col-2">check</div>