Extend Graph.html

This commit is contained in:
jomjol
2022-10-24 21:20:46 +02:00
parent 716c23fed3
commit e0ae9b8e4f
12 changed files with 245 additions and 142 deletions

View File

@@ -36,6 +36,8 @@ extern "C" {
#include "defines.h"
#include "ClassLogFile.h"
#include "server_tflite.h""
#include "server_help.h"
#include "interface_mqtt.h"
#include "server_GPIO.h"
@@ -78,13 +80,69 @@ using namespace std;
string SUFFIX_ZW = "_0xge";
esp_err_t get_numbers_file_handler(httpd_req_t *req)
{
std::string ret = tfliteflow.getNumbersName();
// ESP_LOGI(TAG, "Result get_numbers_file_handler: %s", ret.c_str());
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_type(req, "text/plain");
httpd_resp_sendstr_chunk(req, ret.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
esp_err_t get_data_file_handler(httpd_req_t *req)
{
struct dirent *entry;
std::string _filename, _fileext;
size_t pos = 0;
const char verz_name[] = "/sdcard/log/data";
ESP_LOGD(TAG, "Suche TFLITE in /sdcard/log/data");
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_type(req, "text/plain");
DIR *dir = opendir(verz_name);
while ((entry = readdir(dir)) != NULL)
{
_filename = std::string(entry->d_name);
ESP_LOGD(TAG, "File: %s", _filename.c_str());
// ignore all files with starting dot (hidden files)
if (_filename.rfind(".", 0) == 0) {
continue;
}
_fileext = _filename;
pos = _fileext.find_last_of(".");
if (pos != std::string::npos)
_fileext = _fileext.erase(0, pos + 1);
ESP_LOGD(TAG, " Extension: %s", _fileext.c_str());
if (_fileext == "txt")
{
_filename = _filename + "\t";
httpd_resp_sendstr_chunk(req, _filename.c_str());
}
}
closedir(dir);
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
esp_err_t get_tflite_file_handler(httpd_req_t *req)
{
// DIR *verzeichnis;
// struct dirent *files;
struct dirent *entry;
// struct stat entry_stat;
std::string _filename, _fileext;
size_t pos = 0;

View File

@@ -10,3 +10,6 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st
void delete_all_in_directory(std::string _directory);
esp_err_t get_tflite_file_handler(httpd_req_t *req);
esp_err_t get_data_file_handler(httpd_req_t *req);
esp_err_t get_numbers_file_handler(httpd_req_t *req);

View File

@@ -647,6 +647,12 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
return result;
}
string ClassFlowControll::getNumbersName()
{
return flowpostprocessing->getNumbersName();
}
string ClassFlowControll::getJSON(std::string _id, std::string _mac)
{
return flowpostprocessing->GetJSON(_id, _mac);

View File

@@ -51,6 +51,7 @@ public:
string GetPrevalue(std::string _number = "");
bool ReadParameter(FILE* pfile, string& aktparamgraph);
string getJSON(std::string _id = "", std::string _mac = "");
string getNumbersName();
string TranslateAktstatus(std::string _input);

View File

@@ -21,6 +21,22 @@ static const char* TAG = "class_flow_postproc";
#define PREVALUE_TIME_FORMAT_INPUT "%d-%d-%dT%d:%d:%d"
std::string ClassFlowPostProcessing::getNumbersName()
{
std::string ret="";
for (int i = 0; i < NUMBERS.size(); ++i)
{
ret += NUMBERS[i]->name;
if (i < NUMBERS.size()-1)
ret = ret + "\t";
}
// ESP_LOGI(TAG, "Result ClassFlowPostProcessing::getNumbersName: %s", ret.c_str());
return ret;
}
std::string ClassFlowPostProcessing::GetJSON(std::string _id, std::string _mac, std::string _lineend)
{
std::string json="{" + _lineend;

View File

@@ -65,6 +65,7 @@ public:
void SetPreValue(double zw, string _numbers, bool _extern = false);
std::string GetJSON(std::string _id = "", std::string _mac = "", std::string _lineend = "\n");
std::string getNumbersName();
void UpdateNachkommaDecimalShift();

View File

@@ -397,6 +397,18 @@ esp_err_t handler_editflow(httpd_req_t *req)
}
}
if (_task.compare("namenumbers") == 0)
{
ESP_LOGI(TAGTFLITE, "Get NUMBER list");
return get_numbers_file_handler(req);
}
if (_task.compare("data") == 0)
{
ESP_LOGI(TAGTFLITE, "Get data list");
return get_data_file_handler(req);
}
if (_task.compare("tflite") == 0)
{
ESP_LOGD(TAGTFLITE, "Get tflite list");

View File

@@ -3,6 +3,7 @@
#include <esp_http_server.h>
#include "CImageBasis.h"
#include "ClassFlowControll.h"
//#include "ClassControllCamera.h"
@@ -19,3 +20,5 @@ std::string GetMQTTMainTopic();
esp_err_t GetJPG(std::string _filename, httpd_req_t *req);
esp_err_t GetRawJPG(httpd_req_t *req);
extern ClassFlowControll tfliteflow;

View File

@@ -328,21 +328,6 @@ textarea {
Time to keep the separated digit images (in days, resp. "0" = forever)
</td>
</tr>
<!--
<tr class="expert" id="ex9">
<td class="indent1">
<class id="Digits_ModelInputSize_text" style="color:black;">ModelInputSize</class>
</td>
<td>
x: <input type="number" id="Digits_ModelInputSize_value1" class="smallSelect" min="1" step="1">
y: <input type="number" id="Digits_ModelInputSize_value2" class="smallSelect" min="1" step="1">
</td>
<td style="font-size: 80%;">
Size of the input image for the CNN model
</td>
</tr>
-->
<tr id="Category_Analog_ex4">
<td colspan="3" style="padding-left: 20px;">
@@ -377,19 +362,6 @@ textarea {
<td style="font-size: 80%;"> Time to keep the separated digit images (in days, resp. "0" = forever) </td>
</tr>
<!--
<tr class="expert" id="ex10">
<td class="indent1"> </td>
<td> <class id="Analog_ModelInputSize_text" style="color:black;">ModelInputSize</class> </td>
<td>
x: <input type="number" id="Analog_ModelInputSize_value1" class="smallSelect" min="1" step="1">
y: <input type="number" id="Analog_ModelInputSize_value2" class="smallSelect" min="1" step="1">
</td>
<td style="font-size: 80%;"> Size of the input image for the CNN model </td>
</tr>
-->
<tr>
<td colspan="3" style="padding-left: 20px;"><h4>PostProcessing</h4></td>
</tr>
@@ -1727,11 +1699,9 @@ function UpdateInput() {
WriteParameter(param, category, "Digits", "CNNGoodThreshold", true);
WriteParameter(param, category, "Digits", "LogImageLocation", true);
WriteParameter(param, category, "Digits", "LogfileRetentionInDays", true);
// WriteParameter(param, category, "Digits", "ModelInputSize", false);
WriteParameter(param, category, "Analog", "LogImageLocation", true);
WriteParameter(param, category, "Analog", "LogfileRetentionInDays", true);
// WriteParameter(param, category, "Analog", "ModelInputSize", false);
WriteParameter(param, category, "PostProcessing", "PreValueUse", true);
WriteParameter(param, category, "PostProcessing", "PreValueAgeStartup", true);
@@ -1844,12 +1814,10 @@ function ReadParameterAll()
ReadParameter(param, "Digits", "CNNGoodThreshold", true);
ReadParameter(param, "Digits", "LogImageLocation", true);
ReadParameter(param, "Digits", "LogfileRetentionInDays", true);
// ReadParameter(param, "Digits", "ModelInputSize", false);
ReadParameter(param, "Analog", "Model", false);
ReadParameter(param, "Analog", "LogImageLocation", true);
ReadParameter(param, "Analog", "LogfileRetentionInDays", true);
// ReadParameter(param, "Analog", "ModelInputSize", false);
ReadParameter(param, "PostProcessing", "PreValueUse", true);
ReadParameter(param, "PostProcessing", "PreValueAgeStartup", true);

View File

@@ -2,6 +2,11 @@
<html>
<head>
<script src='https://cdn.plot.ly/plotly-2.14.0.min.js'></script>
<script type="text/javascript" src="./gethost.js"></script>
<script type="text/javascript" src="./readconfigcommon.js"></script>
<script type="text/javascript" src="./readconfigparam.js"></script>
<style>
textarea {
width: 600px;
@@ -13,30 +18,31 @@
var el = document.getElementById('cnsl');
el && eval(el.value);
}
</script>
</head>
<body>
<div id='chart'></div>
<select id="selector" onchange="document.location.href=document.location.href.split('#')[0]+'#'+this.value;run();"></select>
<select id="datafiles" onchange="run();"></select>
<select id="numbers" onchange="run();"></select>
<select id="datatype" onchange="run();">
<option value="3">Value</option>
<option value="4">PreValue</option>
<option value="5">Change-Rate</option>
<option value="6">Change-Absolut</option>
</select>
<button onclick="document.getElementById('editor').hidden = false; this.hidden = true;" >Editor</button>
<div id='editor' hidden='true'>
<textarea id="cnsl">
var hash = window.location.hash;
console.log (hash);
var d = new Date();
var options="<option>Please Select...</option>";
for (var i=0; i<27; i++) {
var currentDate = new Date(d-i*60*60*24*1000);
var option = currentDate.getFullYear()+"-"+(currentDate.getMonth()+1)+"-"+currentDate.getDate()
options += "<option>"+option+"</option>\n";
}
document.getElementById("selector").innerHTML = options;
datefile = document.getElementById("datafiles").value;
numbername = document.getElementById("numbers").value;
datatype = document.getElementById("datatype").value;
//alert("Auslesen: " + datefile + " " + numbername);
var dateString = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate();
if (hash!="") {
dateString = hash.substring(1);
}
fetch('/fileserver/log/data/data_'+dateString+'.txt')
_basepath = getbasepath();
fetch(_basepath + '/fileserver/log/data/' + datefile)
.then(response => {
// handle the response
if (response.status == 404) {
@@ -55,7 +61,9 @@ fetch('/fileserver/log/data/data_'+dateString+'.txt')
for (let line of lines) {
{
console.log(line);
var value = line.split("\t")[3];
if (line.split("\t")[1] == numbername)
{
var value = line.split("\t")[datatype];
var time = line.split("\t")[0];
console.log("> "+time+" "+value+"\n");
if (value<1000) {
@@ -65,6 +73,7 @@ fetch('/fileserver/log/data/data_'+dateString+'.txt')
}
}
}
}
console.log(trace);
var data = [trace];
Plotly.newPlot('chart', data);
@@ -77,6 +86,52 @@ alert("test");
</textarea><br />
<button onclick="run();">run</button>
</div>
<script>run();</script>
<script>
function WriteModelFiles()
{
list_data = getDATAList();
var _indexDig = document.getElementById("datafiles");
while (_indexDig.length)
_indexDig.remove(0);
for (var i = list_data.length - 1; i >= 0; --i)
{
var optionDig = document.createElement("option");
var text = list_data[i];
optionDig.text = text;
optionDig.value = list_data[i];
_indexDig.add(optionDig);
}
}
function WriteNumbers()
{
list_data = getNUMBERSList();
var _indexDig = document.getElementById("numbers");
while (_indexDig.length)
_indexDig.remove(0);
for (var i = 0; i < list_data.length; ++i)
{
var optionDig = document.createElement("option");
var text = list_data[i];
optionDig.text = text;
optionDig.value = list_data[i];
_indexDig.add(optionDig);
}
}
WriteModelFiles();
WriteNumbers();
run();
</script>
</body>
</html>

View File

@@ -1,82 +0,0 @@
<html>
<head>
<script src='https://cdn.plot.ly/plotly-2.14.0.min.js'></script>
<style>
textarea {
width: 600px;
height: 300px;
}
</style>
<script>
function run() {
var el = document.getElementById('cnsl');
el && eval(el.value);
}
</script>
</head>
<body>
<div id='chart'></div>
<select id="selector" onchange="document.location.href=document.location.href.split('#')[0]+'#'+this.value;run();"></select>
<button onclick="document.getElementById('editor').hidden = false; this.hidden = true;" >Editor</button>
<div id='editor' hidden='true'>
<textarea id="cnsl">
var hash = window.location.hash;
console.log (hash);
var d = new Date();
var options="<option>Please Select...</option>";
for (var i=0; i<27; i++) {
var currentDate = new Date(d-i*60*60*24*1000);
var option = currentDate.getFullYear()+"-"+(currentDate.getMonth()+1)+"-"+currentDate.getDate()
options += "<option>"+option+"</option>\n";
}
document.getElementById("selector").innerHTML = options;
var dateString = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate();
if (hash!="") {
dateString = hash.substring(1);
}
fetch('/fileserver/log/message/log_'+dateString+'.txt')
.then(response => {
// handle the response
if (response.status == 404) {
alert("no log data available for "+dateString);
}
response.text()
.then( result => {
var lines = result.split("\n");
var trace = {
x: [],
y: [],
type: 'scatter'
};
var timex = 1;
for (let line of lines) {
if (line.includes("PostProcessing - Raw")) {
console.log(line);
var value = line.split(" ")[6];
var time = line.split(" ")[0];
console.log("> "+time+" "+value+"\n");
if (value<1000) {
trace.x.push(timex);
timex += 1;
trace.y.push(value);
}
}
}
console.log(trace);
var data = [trace];
Plotly.newPlot('chart', data);
});
}).catch((error) => {
// handle the error
console.log(error);
alert("test");
});
</textarea><br />
<button onclick="run();">run</button>
</div>
<script>run();</script>
</body>
</html>

View File

@@ -11,6 +11,68 @@ var NUMBERS = new Array(0);
var REFERENCES = new Array(0);
function getNUMBERSList() {
_basepath = getbasepath();
var datalist = "";
var xhttp = new XMLHttpRequest();
xhttp.addEventListener('load', function(event) {
if (xhttp.status >= 200 && xhttp.status < 300) {
datalist = xhttp.responseText;
} else {
console.warn(request.statusText, request.responseText);
}
});
try {
url = _basepath + '/editflow.html?task=namenumbers';
xhttp.open("GET", url, false);
xhttp.send();
}
catch (error)
{
alert("Loading Hostname failed");
}
datalist = datalist.split("\t");
// datalist.pop();
return datalist;
}
function getDATAList() {
_basepath = getbasepath();
tflitelist = "";
var xhttp = new XMLHttpRequest();
xhttp.addEventListener('load', function(event) {
if (xhttp.status >= 200 && xhttp.status < 300) {
tflitelist = xhttp.responseText;
} else {
console.warn(request.statusText, request.responseText);
}
});
try {
url = _basepath + '/editflow.html?task=data';
xhttp.open("GET", url, false);
xhttp.send();
}
catch (error)
{
// alert("Loading Hostname failed");
}
tflitelist = tflitelist.split("\t");
tflitelist.pop();
return tflitelist;
}
function getTFLITEList() {
_basepath = getbasepath();
tflitelist = "";