First Commit
This commit is contained in:
		
							
								
								
									
										248
									
								
								app.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										248
									
								
								app.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,248 @@
 | 
				
			|||||||
 | 
					$(document).ready(function () {
 | 
				
			||||||
 | 
					    var chart24hLabel = [];
 | 
				
			||||||
 | 
					    var chart24hData = [];
 | 
				
			||||||
 | 
					    var chart24hColor = [];
 | 
				
			||||||
 | 
					    var chart24hColorRoom = [];
 | 
				
			||||||
 | 
					    var chart24hDataRoom = [];
 | 
				
			||||||
 | 
					    var chartLabel = [];
 | 
				
			||||||
 | 
					    var chartData = [];
 | 
				
			||||||
 | 
					    var chartColor = [];
 | 
				
			||||||
 | 
					    var chartColorRoom = [];
 | 
				
			||||||
 | 
					    var chartDataRoom = [];
 | 
				
			||||||
 | 
					    var arr24h = [];
 | 
				
			||||||
 | 
					    var arr = [];
 | 
				
			||||||
 | 
					    var entrylist = [];
 | 
				
			||||||
 | 
					    function unixToFormatted(unixdate, type) {
 | 
				
			||||||
 | 
					        var date = new Date((unixdate- 3600) * 1000 );
 | 
				
			||||||
 | 
					        var months = ['Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'];
 | 
				
			||||||
 | 
					        var day = date.getDate();
 | 
				
			||||||
 | 
					        var month = date.getMonth();
 | 
				
			||||||
 | 
					        if(month=="12"){ month="1"; } else { month=parseInt(month)+parseInt("1");}
 | 
				
			||||||
 | 
					        var year = date.getFullYear();
 | 
				
			||||||
 | 
					        var hours = date.getHours();
 | 
				
			||||||
 | 
					        var minutes = "0" + date.getMinutes();
 | 
				
			||||||
 | 
					        var formattedTime = hours + ':' + minutes.substr(-2);
 | 
				
			||||||
 | 
					        //var formattedDate = day + ' ' + month + ' ' + year
 | 
				
			||||||
 | 
					        var formattedDate =  day + "." + month + "." + year;
 | 
				
			||||||
 | 
					        var formattedDate2 =  day + "." + month + ".";
 | 
				
			||||||
 | 
					        if (type == "time")
 | 
				
			||||||
 | 
					            return formattedTime;
 | 
				
			||||||
 | 
					        if (type == "date")
 | 
				
			||||||
 | 
					            return formattedDate;
 | 
				
			||||||
 | 
					        if (type == "date2")
 | 
				
			||||||
 | 
					            return formattedDate2;
 | 
				
			||||||
 | 
					    } 
 | 
				
			||||||
 | 
					    $.ajax({
 | 
				
			||||||
 | 
					        type: 'GET',
 | 
				
			||||||
 | 
					        crossDomain: true,
 | 
				
			||||||
 | 
					        dataType: 'json',
 | 
				
			||||||
 | 
					        url: 'https://brauereiapi.truenoobs.de/',
 | 
				
			||||||
 | 
					        success: function(jsondata){
 | 
				
			||||||
 | 
					            jQuery.each(jsondata, function() {
 | 
				
			||||||
 | 
					                entrylist.push(this["time"]);
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            entrylist.sort();
 | 
				
			||||||
 | 
					            var latestTimestamp = entrylist[entrylist.length-1];
 | 
				
			||||||
 | 
					            jQuery.each(entrylist, function() {
 | 
				
			||||||
 | 
					                if(this > latestTimestamp-86400) {
 | 
				
			||||||
 | 
					                    chart24hLabel.push(unixToFormatted(this, "time"));
 | 
				
			||||||
 | 
					                    chart24hColor.push("rgba(223, 63, 63, 1)");
 | 
				
			||||||
 | 
					                    chart24hColorRoom.push("rgba(102, 178, 255, 1)");
 | 
				
			||||||
 | 
					                    chart24hData.push(jsondata[this]["temp"]);
 | 
				
			||||||
 | 
					                    chart24hDataRoom.push(jsondata[this]["temproom"]);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                chartLabel.push(unixToFormatted(this, "date2"));
 | 
				
			||||||
 | 
					                chartColor.push("rgba(223, 63, 63, 1)");
 | 
				
			||||||
 | 
					                chartColorRoom.push("rgba(102, 178, 255, 1)");
 | 
				
			||||||
 | 
					                chartData.push(jsondata[this]["temp"]);
 | 
				
			||||||
 | 
					                chartDataRoom.push(jsondata[this]["temproom"]);
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            /*jQuery.each(entrylist, function() {
 | 
				
			||||||
 | 
					                var date = new Date(this * 1000);
 | 
				
			||||||
 | 
					                var day = date.getDate();
 | 
				
			||||||
 | 
					                var month = date.getMonth();
 | 
				
			||||||
 | 
					                var year = date.getFullYear();
 | 
				
			||||||
 | 
					                var hours = date.getHours();
 | 
				
			||||||
 | 
					                var minutes = date.getMinutes();
 | 
				
			||||||
 | 
					                if(this > latestTimestamp-86400) {
 | 
				
			||||||
 | 
					                    if(!(year in arr24h)){arr24h[year]=[]};
 | 
				
			||||||
 | 
					                    if(!(month in arr24h[year])){arr24h[year][month]=[]};
 | 
				
			||||||
 | 
					                    if(!(day in arr24h[year][month])){arr24h[year][month][day]=[]};
 | 
				
			||||||
 | 
					                    if(!(hours in arr24h[year][month][day])){arr24h[year][month][day][hours]=[]};
 | 
				
			||||||
 | 
					                    arr24h[year][month][day][hours][minutes]=[];
 | 
				
			||||||
 | 
					                    arr24h[year][month][day][hours][minutes].push(jsondata[this]["time"]);
 | 
				
			||||||
 | 
					                    arr24h[year][month][day][hours][minutes].push(unixToFormatted(jsondata[this]["time"], "date"));
 | 
				
			||||||
 | 
					                    arr24h[year][month][day][hours][minutes].push(unixToFormatted(jsondata[this]["time"], "time"));
 | 
				
			||||||
 | 
					                    arr24h[year][month][day][hours][minutes].push(jsondata[this]["temproom"]);
 | 
				
			||||||
 | 
					                    arr24h[year][month][day][hours][minutes].push(jsondata[this]["temp"]);
 | 
				
			||||||
 | 
					                    arr24h[year][month][day][hours][minutes].push(jsondata[this]["bubbles"]);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            for(var i=0;i<arr24h.length;i++){
 | 
				
			||||||
 | 
					                console.log(arr24h[i]);
 | 
				
			||||||
 | 
					            }*/
 | 
				
			||||||
 | 
					            entrylist.reverse();
 | 
				
			||||||
 | 
					            jQuery.each(entrylist, function() {
 | 
				
			||||||
 | 
					                $("#table").append(
 | 
				
			||||||
 | 
					                    `<tr>
 | 
				
			||||||
 | 
					                    <td style="display:none">${jsondata[this]["time"]}</td>
 | 
				
			||||||
 | 
					                    <td>${unixToFormatted(jsondata[this]["time"], "date")}</td>
 | 
				
			||||||
 | 
					                    <td>${unixToFormatted(jsondata[this]["time"], "time")}</td>
 | 
				
			||||||
 | 
					                    <td>${jsondata[this]["temproom"]}</td>
 | 
				
			||||||
 | 
					                    <td>${jsondata[this]["temp"]}</td>
 | 
				
			||||||
 | 
					                    <td>${jsondata[this]["bubbles"]}</td>
 | 
				
			||||||
 | 
					                    <!-- <td>0</td> -->
 | 
				
			||||||
 | 
					                    </tr>`
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            jQuery.each(entrylist, function() {
 | 
				
			||||||
 | 
					                if(this > latestTimestamp-86400) {
 | 
				
			||||||
 | 
					                    $("#table24h").append(
 | 
				
			||||||
 | 
					                        `<tr>
 | 
				
			||||||
 | 
					                        <td style="display:none">${jsondata[this]["time"]}</td>
 | 
				
			||||||
 | 
					                        <td>${unixToFormatted(jsondata[this]["time"], "date")}</td>
 | 
				
			||||||
 | 
					                        <td>${unixToFormatted(jsondata[this]["time"], "time")}</td>
 | 
				
			||||||
 | 
					                        <td>${jsondata[this]["temproom"]}</td>
 | 
				
			||||||
 | 
					                        <td>${jsondata[this]["temp"]}</td>
 | 
				
			||||||
 | 
					                        <td>${jsondata[this]["bubbles"]}</td>
 | 
				
			||||||
 | 
					                        <!-- <td>0</td> -->
 | 
				
			||||||
 | 
					                        </tr>`
 | 
				
			||||||
 | 
					                    );
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            var ctx = document.getElementById('myChart24h');
 | 
				
			||||||
 | 
					            var myChart24h = new Chart(ctx, {
 | 
				
			||||||
 | 
					                type: 'line',
 | 
				
			||||||
 | 
					                data: {
 | 
				
			||||||
 | 
					                    labels: chart24hLabel,
 | 
				
			||||||
 | 
					                    datasets: [{
 | 
				
			||||||
 | 
					                        label: 'Biertemperatur',
 | 
				
			||||||
 | 
					                        data: chart24hData,
 | 
				
			||||||
 | 
					                        backgroundColor: [
 | 
				
			||||||
 | 
					                            'rgba(223, 63, 63, 0.1)'
 | 
				
			||||||
 | 
					                        ],
 | 
				
			||||||
 | 
					                        borderColor: chart24hColor,
 | 
				
			||||||
 | 
					                        borderWidth: 3,
 | 
				
			||||||
 | 
					                        pointRadius: 1
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        label: 'Raumtemperatur',
 | 
				
			||||||
 | 
					                        data: chart24hDataRoom,
 | 
				
			||||||
 | 
					                        backgroundColor: [
 | 
				
			||||||
 | 
					                            'rgba(102, 178, 255, 0.1)'
 | 
				
			||||||
 | 
					                        ],
 | 
				
			||||||
 | 
					                        borderColor: chart24hColorRoom,
 | 
				
			||||||
 | 
					                        borderWidth: 3,
 | 
				
			||||||
 | 
					                        pointRadius: 1
 | 
				
			||||||
 | 
					                    }]
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                options: {
 | 
				
			||||||
 | 
					                    scales: {
 | 
				
			||||||
 | 
					                        yAxes: [{
 | 
				
			||||||
 | 
					                            stacked: false
 | 
				
			||||||
 | 
					                        }]
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            var ctx = document.getElementById('myChart');
 | 
				
			||||||
 | 
					            var myChart = new Chart(ctx, {
 | 
				
			||||||
 | 
					                type: 'line',
 | 
				
			||||||
 | 
					                yAxisID: "25",
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					                data: {
 | 
				
			||||||
 | 
					                    labels: chartLabel,
 | 
				
			||||||
 | 
					                    datasets: [{
 | 
				
			||||||
 | 
					                        label: 'Biertemperatur',
 | 
				
			||||||
 | 
					                        data: chartData,
 | 
				
			||||||
 | 
					                        backgroundColor: [
 | 
				
			||||||
 | 
					                            'rgba(223, 63, 63, 0.1)'
 | 
				
			||||||
 | 
					                        ],
 | 
				
			||||||
 | 
					                        borderColor: chartColor,
 | 
				
			||||||
 | 
					                        borderWidth: 3,
 | 
				
			||||||
 | 
					                        pointRadius: 1,
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        label: 'Raumtemperatur',
 | 
				
			||||||
 | 
					                        data: chartDataRoom,
 | 
				
			||||||
 | 
					                        backgroundColor: [
 | 
				
			||||||
 | 
					                            'rgba(102, 178, 255, 0.1)'
 | 
				
			||||||
 | 
					                        ],
 | 
				
			||||||
 | 
					                        borderColor: chartColorRoom,
 | 
				
			||||||
 | 
					                        borderWidth: 3,
 | 
				
			||||||
 | 
					                        pointRadius: 1
 | 
				
			||||||
 | 
					                    }]
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                options: {
 | 
				
			||||||
 | 
					                    scales: {
 | 
				
			||||||
 | 
					                        yAxes: [{
 | 
				
			||||||
 | 
					                            ticks: {
 | 
				
			||||||
 | 
					                                suggestedMin: 0,
 | 
				
			||||||
 | 
					                                suggestedMax: 30
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        }]
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            $("#import").click(function(){
 | 
				
			||||||
 | 
					                var xhr = new XMLHttpRequest();
 | 
				
			||||||
 | 
					                var url = "https://brauereiapi.truenoobs.de/import";
 | 
				
			||||||
 | 
					                xhr.open("POST", url, true);
 | 
				
			||||||
 | 
					                xhr.setRequestHeader("Content-Type", "application/json");
 | 
				
			||||||
 | 
					                xhr.onreadystatechange = function () {
 | 
				
			||||||
 | 
					                    if (xhr.readyState === 4 && xhr.status === 200) {
 | 
				
			||||||
 | 
					                        var json = JSON.parse(xhr.responseText);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					                var data = JSON.stringify(jsondata);
 | 
				
			||||||
 | 
					                xhr.send(data);
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    $.prototype.kb_table_csv = function() {
 | 
				
			||||||
 | 
					        var kb_tidy_content = function(text){
 | 
				
			||||||
 | 
					            text = text.replace(/"/g, '""');
 | 
				
			||||||
 | 
					            return '"'+text+'"';
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        $(this).each(function(){
 | 
				
			||||||
 | 
					            var table = $(this);
 | 
				
			||||||
 | 
					            var caption = $(this).find('caption').text();
 | 
				
			||||||
 | 
					            var title = [];
 | 
				
			||||||
 | 
					            var rows = [];
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            $(this).find('tr').each(function(){
 | 
				
			||||||
 | 
					                var data = [];
 | 
				
			||||||
 | 
					                $(this).find('td').each(function(){
 | 
				
			||||||
 | 
					                    var text = kb_tidy_content($(this).text());
 | 
				
			||||||
 | 
					                    if(!text.includes(" ") && !text.includes(":")) {
 | 
				
			||||||
 | 
					                        data.push(text);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					                data = data.join(",");
 | 
				
			||||||
 | 
					                if(data!=""){
 | 
				
			||||||
 | 
					                    rows.push(data);
 | 
				
			||||||
 | 
					                }    
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            title = title.join(",");
 | 
				
			||||||
 | 
					            rows = rows.join("\n");
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            var csv = title + rows;
 | 
				
			||||||
 | 
					            var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv);
 | 
				
			||||||
 | 
					            var download_link = document.createElement('a');
 | 
				
			||||||
 | 
					            download_link.href = uri;
 | 
				
			||||||
 | 
					            var ts = new Date().getTime();
 | 
				
			||||||
 | 
					            if(caption==""){
 | 
				
			||||||
 | 
					                download_link.download = ts+".csv";
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                download_link.download = caption+"-"+ts+".csv";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            document.body.appendChild(download_link);
 | 
				
			||||||
 | 
					            download_link.click();
 | 
				
			||||||
 | 
					            document.body.removeChild(download_link);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    $("#export").click(function(){
 | 
				
			||||||
 | 
					        $("table").kb_table_csv();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										26
									
								
								database.csv
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								database.csv
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					1615301362,38.00,88
 | 
				
			||||||
 | 
					1615301382,38.00,88
 | 
				
			||||||
 | 
					1615301403,38.00,88
 | 
				
			||||||
 | 
					1615301423,38.00,88
 | 
				
			||||||
 | 
					1615301443,38.00,88
 | 
				
			||||||
 | 
					1615301463,38.00,88
 | 
				
			||||||
 | 
					1615301483,38.00,88
 | 
				
			||||||
 | 
					1615301503,38.00,88
 | 
				
			||||||
 | 
					1615301524,38.00,88
 | 
				
			||||||
 | 
					1615301544,38.00,88
 | 
				
			||||||
 | 
					1615301564,38.00,88
 | 
				
			||||||
 | 
					1615301584,38.00,88
 | 
				
			||||||
 | 
					1615301604,38.00,88
 | 
				
			||||||
 | 
					1615301624,38.00,88
 | 
				
			||||||
 | 
					1615301645,38.00,88
 | 
				
			||||||
 | 
					1615301665,38.00,88
 | 
				
			||||||
 | 
					1615301685,38.00,88
 | 
				
			||||||
 | 
					1615301705,38.00,88
 | 
				
			||||||
 | 
					1615301725,38.00,88
 | 
				
			||||||
 | 
					1615301745,38.00,88
 | 
				
			||||||
 | 
					1615301766,38.00,88
 | 
				
			||||||
 | 
					1615301786,38.00,88
 | 
				
			||||||
 | 
					1615301806,38.00,88
 | 
				
			||||||
 | 
					1615301826,38.00,88
 | 
				
			||||||
 | 
					1615301846,38.00,88
 | 
				
			||||||
 | 
					1615301867,38.00,88
 | 
				
			||||||
		
		
			
  | 
							
								
								
									
										17
									
								
								database.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								database.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					2021/03/09 14:37:20 38.00 88
 | 
				
			||||||
 | 
					2021/03/09 14:37:40 39.00 78
 | 
				
			||||||
 | 
					2021/03/09 14:38:01 40.00 90
 | 
				
			||||||
 | 
					2021/03/09 14:38:21 35.00 88
 | 
				
			||||||
 | 
					2021/03/09 14:38:41 36.00 86
 | 
				
			||||||
 | 
					2021/03/09 14:39:04 37.00 84
 | 
				
			||||||
 | 
					2021/03/09 14:39:24 38.00 85
 | 
				
			||||||
 | 
					2021/03/09 14:39:44 31.50 86
 | 
				
			||||||
 | 
					2021/03/09 14:40:04 32.00 87
 | 
				
			||||||
 | 
					2021/03/09 14:40:25 33.50 88
 | 
				
			||||||
 | 
					2021/03/09 14:40:45 34.70 88
 | 
				
			||||||
 | 
					2021/03/09 14:41:05 35.00 90
 | 
				
			||||||
 | 
					2021/03/09 14:41:25 37.00 91
 | 
				
			||||||
 | 
					2021/03/09 14:41:45 41.00 92
 | 
				
			||||||
 | 
					2021/03/09 14:42:06 43.00 90
 | 
				
			||||||
 | 
					2021/03/09 14:42:26 45.00 70
 | 
				
			||||||
 | 
					2021/03/09 14:42:46 47.00 75
 | 
				
			||||||
							
								
								
									
										84
									
								
								index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,84 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html lang="de"> 
 | 
				
			||||||
 | 
					<!--Head-->
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <meta charset="utf-8">
 | 
				
			||||||
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
 | 
				
			||||||
 | 
					    <title>Brauvorgang</title>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
 | 
				
			||||||
 | 
					    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
 | 
				
			||||||
 | 
					    <script src="https://canvasjs.com/assets/script/jquery.canvasjs.min.js"></script>
 | 
				
			||||||
 | 
					    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.bundle.min.js "></script>
 | 
				
			||||||
 | 
					    <script type="text/javascript" src="app.js"></script>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					    <div class="container-fluid h-100">
 | 
				
			||||||
 | 
					        <div class="row">
 | 
				
			||||||
 | 
					            <div class="col-12 col-md-6 d-print-none">
 | 
				
			||||||
 | 
					                <div class="card-header">
 | 
				
			||||||
 | 
					                    <h3>Die letzten 24 Stunden</h3>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="card card-body">
 | 
				
			||||||
 | 
					                    <canvas id="myChart24h"></canvas>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="col-12 col-md-6">
 | 
				
			||||||
 | 
					                <div class="card-header d-print-none">
 | 
				
			||||||
 | 
					                    <h3>Seit Braubeginn</h3>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="card card-body">
 | 
				
			||||||
 | 
					                    <canvas id="myChart"></canvas>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <div class="row">
 | 
				
			||||||
 | 
					            <div class="col-12 col-md-6 d-print-none">
 | 
				
			||||||
 | 
					                <div class="card-header">
 | 
				
			||||||
 | 
					                    <h3>Die letzten 24 Stunden</h3>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="card card-body">
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    <table id="table24h" class="table table-striped table-sm" cellspacing="0" width="100%">
 | 
				
			||||||
 | 
					                        <thead>
 | 
				
			||||||
 | 
					                            <tr>
 | 
				
			||||||
 | 
					                                <th data-field="timestamp" style="display:none">Timestamp</th>
 | 
				
			||||||
 | 
					                                <th data-field="date">Datum</th>
 | 
				
			||||||
 | 
					                                <th data-field="time">Uhrzeit</th>
 | 
				
			||||||
 | 
					                                <th data-field="temp">°C Raum</th>
 | 
				
			||||||
 | 
					                                <th data-field="temp">°C Bier</th>
 | 
				
			||||||
 | 
					                                <th data-field="bubbles">Blasen</th>
 | 
				
			||||||
 | 
					                            </tr>
 | 
				
			||||||
 | 
					                        </thead>
 | 
				
			||||||
 | 
					                    </table>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="col-12 col-md-6">
 | 
				
			||||||
 | 
					                <div class="card-header d-print-none">
 | 
				
			||||||
 | 
					                    <h3>Seit Braubeginn</h3>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="card card-body">
 | 
				
			||||||
 | 
					                    <table id="table" class="table table-striped table-sm" cellspacing="0" width="100%">
 | 
				
			||||||
 | 
					                        <thead>
 | 
				
			||||||
 | 
					                            <tr>
 | 
				
			||||||
 | 
					                                <th data-field="timestamp" style="display:none">Timestamp</th>
 | 
				
			||||||
 | 
					                                <th data-field="date">Datum</th>
 | 
				
			||||||
 | 
					                                <th data-field="time">Uhrzeit</th>
 | 
				
			||||||
 | 
					                                <th data-field="temp">°C Raum</th>
 | 
				
			||||||
 | 
					                                <th data-field="temp">°C Bier</th>
 | 
				
			||||||
 | 
					                                <th data-field="bubbles">Blasen</th>
 | 
				
			||||||
 | 
					                            </tr>
 | 
				
			||||||
 | 
					                        </thead>
 | 
				
			||||||
 | 
					                    </table>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="col-12 col-md-12 d-print-none">
 | 
				
			||||||
 | 
					                <div class="card card-body">
 | 
				
			||||||
 | 
					                    <button id="export" class="btn btn-secondary" data-export="export">Download CSV</button>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					    </div> 
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
							
								
								
									
										64
									
								
								run.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								run.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from flask import Flask, json, request
 | 
				
			||||||
 | 
					import csv
 | 
				
			||||||
 | 
					from collections import OrderedDict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					api = Flask(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					database = {}
 | 
				
			||||||
 | 
					ordered_dict = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def open_csv():
 | 
				
			||||||
 | 
					    result = ""
 | 
				
			||||||
 | 
					    with open('database.csv') as csv_file:
 | 
				
			||||||
 | 
					        csv_reader = csv.reader(csv_file, delimiter=',')
 | 
				
			||||||
 | 
					        line_count = 0
 | 
				
			||||||
 | 
					        for row in csv_reader:
 | 
				
			||||||
 | 
					            id = row[0]
 | 
				
			||||||
 | 
					            database[id] = { "time":row[0], "temproom":row[1], "temp":row[2],"bubbles":row[3]}
 | 
				
			||||||
 | 
					            #print("Time: " + row[0] + " | Raumtemperatur: " + row[1]+ " | Biertemperatur: " + row[2]+ " | Blasen: " + row[3])
 | 
				
			||||||
 | 
					    sort_dict()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def sort_dict():
 | 
				
			||||||
 | 
					    newlist = sorted(database, reverse=True)
 | 
				
			||||||
 | 
					    #print(newlist)
 | 
				
			||||||
 | 
					    for entry in newlist:
 | 
				
			||||||
 | 
					        ordered_dict[entry] = {}
 | 
				
			||||||
 | 
					        ordered_dict[entry] = database[entry]
 | 
				
			||||||
 | 
					    #print(ordered_dict)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def write_dict():
 | 
				
			||||||
 | 
					    f = open('database.csv', 'w')
 | 
				
			||||||
 | 
					    with f:
 | 
				
			||||||
 | 
					        fnames = ['time', 'temproom', 'temp', 'bubbles']
 | 
				
			||||||
 | 
					        writer = csv.DictWriter(f, fieldnames=fnames)
 | 
				
			||||||
 | 
					        #writer.writeheader()
 | 
				
			||||||
 | 
					        for entry in ordered_dict:
 | 
				
			||||||
 | 
					            writer.writerow({"time":ordered_dict[entry]["time"], "temproom":ordered_dict[entry]["temproom"], "temp":ordered_dict[entry]["temp"], "bubbles":ordered_dict[entry]["bubbles"]})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@api.route('/', methods=['GET'])
 | 
				
			||||||
 | 
					def get_values():
 | 
				
			||||||
 | 
					    #print (ordered_dict)
 | 
				
			||||||
 | 
					    open_csv()
 | 
				
			||||||
 | 
					    return (ordered_dict)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@api.route('/b6dg4V', methods=['POST'])
 | 
				
			||||||
 | 
					def post_values():
 | 
				
			||||||
 | 
					    s = str(request.data)
 | 
				
			||||||
 | 
					    s = s.replace("b'", "")
 | 
				
			||||||
 | 
					    s = s.replace("'", "")
 | 
				
			||||||
 | 
					    split = s.split(" ")
 | 
				
			||||||
 | 
					    print("Zeit: " + split[0] )
 | 
				
			||||||
 | 
					    print("Raumtemp: " + split[1] )
 | 
				
			||||||
 | 
					    print("Temp: " + split[2] )
 | 
				
			||||||
 | 
					    print("Blasen: " + split[3] )
 | 
				
			||||||
 | 
					    database[split[0]] = { "time":split[0], "temproom":split[1], "temp":split[2], "bubbles":split[3] }
 | 
				
			||||||
 | 
					    sort_dict()
 | 
				
			||||||
 | 
					    write_dict()
 | 
				
			||||||
 | 
					    return json.dumps({"success": True}), 201
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 | 
					    open_csv()
 | 
				
			||||||
 | 
					    api.run(host='0.0.0.0', port=5632)
 | 
				
			||||||
							
								
								
									
										26
									
								
								webfile.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								webfile.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					1615301362,38.00,88
 | 
				
			||||||
 | 
					1615301382,38.00,88
 | 
				
			||||||
 | 
					1615301403,38.00,88
 | 
				
			||||||
 | 
					1615301423,38.00,88
 | 
				
			||||||
 | 
					1615301443,38.00,88
 | 
				
			||||||
 | 
					1615301463,38.00,88
 | 
				
			||||||
 | 
					1615301483,38.00,88
 | 
				
			||||||
 | 
					1615301503,38.00,88
 | 
				
			||||||
 | 
					1615301524,38.00,88
 | 
				
			||||||
 | 
					1615301544,38.00,88
 | 
				
			||||||
 | 
					1615301564,38.00,88
 | 
				
			||||||
 | 
					1615301584,38.00,88
 | 
				
			||||||
 | 
					1615301604,38.00,88
 | 
				
			||||||
 | 
					1615301624,38.00,88
 | 
				
			||||||
 | 
					1615301645,38.00,88
 | 
				
			||||||
 | 
					1615301665,38.00,88
 | 
				
			||||||
 | 
					1615301685,38.00,88
 | 
				
			||||||
 | 
					1615301705,38.00,88
 | 
				
			||||||
 | 
					1615301725,38.00,88
 | 
				
			||||||
 | 
					1615301745,38.00,88
 | 
				
			||||||
 | 
					1615301766,38.00,88
 | 
				
			||||||
 | 
					1615301786,38.00,88
 | 
				
			||||||
 | 
					1615301806,38.00,88
 | 
				
			||||||
 | 
					1615301826,38.00,88
 | 
				
			||||||
 | 
					1615301846,38.00,88
 | 
				
			||||||
 | 
					1615301867,38.00,88
 | 
				
			||||||
		Reference in New Issue
	
	Block a user