update : 15.02.2024 11:34:57,43

This commit is contained in:
Sabron 2024-02-15 11:34:57 +07:00
parent 397aaa8ed4
commit 84eab062e8
13 changed files with 616 additions and 6 deletions

View File

@ -8,11 +8,18 @@
<div class="m-subheader ">
<div class="d-flex align-items-center">
<div class="mr-auto">
<a href="scada/" target="_blank" class="btn btn-primary btn-lg">SCADA</a>
<a href="/main/scada/" target="_blank" class="btn btn-primary btn-lg">SCADA</a>
</div>
</div>
</div>
<div class="m-subheader ">
<div class="d-flex align-items-center">
<div class="mr-auto">
<a href="/montorem/" target="_blank" class="btn btn-primary btn-lg">Montorem</a>
</div>
</div>
</div>
<!-- END: Subheader -->
<div class="m-content">

View File

@ -0,0 +1 @@

3
apps/montorem/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

7
apps/montorem/apps.py Normal file
View File

@ -0,0 +1,7 @@
from django.apps import AppConfig
class MontoremConfig(AppConfig):
name = 'apps.montorem'
verbose_name = "Монторем"

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,255 @@
{% extends "default.html" %}
{% load static %}
{% load mysettings %}
{% block header_link %}
{% endblock header_link %}
{% block content %}
<div class="m-subheader ">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h3 class="m-subheader__title m-subheader__title--separator">Плотномеры</h3>
<ul class="m-subheader__breadcrumbs m-nav m-nav--inline">
<li class="m-nav__item m-nav__item--home">
<a href="#" class="m-nav__link m-nav__link--icon">
<i class="m-nav__link-icon la la-home"></i>
</a>
</li>
<li class="m-nav__separator">-</li>
<li class="m-nav__item">
<a href="/" class="m-nav__link">
<span class="m-nav__link-text">Главная</span>
</a>
</li>
<li class="m-nav__separator">-</li>
<li class="m-nav__item">
<a href="" class="m-nav__link">
<span class="m-nav__link-text">Плотномеры</span>
</a>
</li>
</ul>
</div>
<div>
</div>
</div>
</div>
<div class="m-content">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Список датчиков </h3>
<div class="card-tools">
</div>
</div>
<!-- /.card-header -->
<div class="card-body p-0">
<table class="table table-striped- table-bordered table-hover table-checkable dataTable no-footer dtr-inline">
<thead>
<tr>
<th style="width: 10px">№</th>
<th>Наименование</th>
<th>Дата</th>
<th>Ед.</th>
<th>Значение</th>
</tr>
</thead>
<tbody id="table_bo">
{% for sensor in sensor_list %}
<tr>
<td>
<a href="sensor/?id={{sensor.id}}">{{sensor.id}}</a>
</td>
<td>
<a href="sensor/?id={{sensor.id}}">{{sensor.name}}</a>
</td>
<td>
<a href="sensor/?id={{sensor.id}}">{{sensor.connect_time}}</a>
</td>
<td>
<a href="sensor/?id={{sensor.id}}">{{sensor.unit}}</a>
</td>
<td>
<a href="sensor/?id={{sensor.id}}">{{sensor.value}}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div><!-- /.container-fluid -->
{% endblock %}
{% block script_footer %}
<script>
const ctx = document.getElementById('lineChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [
],
datasets: [{
label: 'Показания датчика',
fill: false,
data:[
],
/*backgroundColor: [
'rgba(255, 99, 132, 0.2)',
/*'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],*/
borderColor: 'rgb(54, 162, 235, 1)',
/*
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],*/
//borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
function intime(d) {
var day = d.getDate();
var hrs = d.getHours();
var min = d.getMinutes();
var sec = d.getSeconds();
var mnt = new Array("января", "февраля", "марта", "апреля", "мая",
"июня", "июля", "августа", "сентября", "октября", "ноября", "декабря");
if (day <= 9) day="0" + day;
if (hrs <= 9) hrs="0" + hrs;
if (min <=9 ) min="0" + min;
if (sec <= 9) sec="0" + sec;
return "Дата последнего показания : " + hrs + ":" + min + ":" + sec + "&nbsp;&nbsp;&nbsp;" +
day + " " + mnt[d.getMonth()] + " " + d.getFullYear() + " г."
}
function show()
{
cmd = 'refresh';
id = document.getElementById('sensor_id').value
sensor_type = document.getElementById('sensor_type').value
$.ajax({
type: 'POST', // метод отправки
async:true,
url: window.location.pathname+'sensor_ajax/', // путь к обработчику
data: {
"cmd": cmd,
"id": id,
"sensor_type": sensor_type,
},
// dataType: 'text',
success: function (data) {
str_table = ''
start = 0
length = data.length-1
myChart.data.labels=[]
myChart.data.datasets[0].data = []
for (index = 0; index <= length; ++index) {
start = start + 1
myChart.data.labels.push(data[index].date_time);
myChart.data.datasets[0].data.push(data[index].value);
str_table = str_table + '<tr><td>' + (data.length-index) + '.</td><td>' + data[length-index].date_time + '</td><td>' + data[length-index].value + ' ({{sensor.unit}})</td></tr>'
$("#maxdate").html(intime(new Date(data[index].date_max)));
}
myChart.update();
$("#table_bo").html(str_table)
},
error: function (dataerr) {
console.log('Ошибка выполнение команды :'+dataerr)
}
});
}
function setparametrs(p) {
document.getElementById('sensor_type').setAttribute('value', p);
myChart.data.labels=[]
myChart.data.datasets[0].data = []
myChart.update();
}
$(function () {
show()
setInterval('show()', 2000);
})
function reportdownload() {
$("#reportPanelBody").html('<div class="overlay" style="height:60vh;"> <i class="fa fa-refresh fa-spin"></i></div>')
var DataStart = $("#id_DataStart").val();
var DataStop = $("#id_DataStop").val();
cmd = 'refresh';
id = document.getElementById('sensor_id').value
sensor_type = document.getElementById('sensor_type').value
if (!!DataStart) {
$.ajax({
type: 'POST', // метод отправки
url: window.location.pathname+'sensor_ajax/', // путь к обработчику,
async:true,
data: {
"DataStart": DataStart,
"DataStop": DataStop,
"cmd": cmd,
"id": id,
'sensor_type':sensor_type,
},
success: function (data) {
document.getElementById('reportPanel').style.height = '';
$("#reportPanelBody").html(data); // при успешном получении ответа от сервера, заносим полученные данные в элемент с классом answer
},
error: function (dataerr) {
$("#reportPanelBody").html(dataerr); // при успешном получении ответа от сервера, заносим полученные данные в элемент с классом answer
}
});
}
}
</script>
{% endblock script_footer %}

View File

@ -0,0 +1,220 @@
{% extends "default.html" %}
{% load static %}
{% load mysettings %}
{% block header_link %}
{% endblock header_link %}
{% block content %}
<div class="m-subheader ">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h4 class="m-subheader__title m-subheader__title--separator">{{sensor.name}} </h4>
<ul class="m-subheader__breadcrumbs m-nav m-nav--inline">
<li class="m-nav__item m-nav__item--home">
<a href="/montorem/" class="m-nav__link m-nav__link--icon">
<i class="m-nav__link-icon la la-home"></i>
</a>
</li>
<li class="m-nav__separator">-</li>
<li class="m-nav__item">
<a href="montorem" class="m-nav__link">
<span class="m-nav__link-text"> Последнее показание : {{sensor.connect_time}}</span>
</a>
</li>
</ul>
</div>
<div>
</div>
</div>
</div>
<div class="subheader">
<div class="row">
<div class="col-lg-6">
<!-- LINE CHART -->
<div class="card ">
<input id="sensor_type" type="hidden" name="sensor_type" value="min">
<div class="card-header">
<h3 class="card-title">График изменения ({{sensor.unit}})</h3>
<input id="sensor_id" type="hidden" value="{{sensor.id}}" name="sensor_id">
<div class="card-tools">
<ul class="nav nav-pills ml-auto">
<li class="nav-item">
<a class="nav-link" href="#" onclick="setparametrs('sec')" data-toggle="tab">Сек.</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="#" onclick="setparametrs('min')" data-toggle="tab">Мин.</a>
</li>
<li class="nav-item">
<a class="nav-link " href="#" onclick="setparametrs('hour')" data-toggle="tab">Час</a>
</li>
</ul>
</div>
</div>
<div class="card-body">
<div class="chart">
<div class="chartjs-size-monitor">
<div class="chartjs-size-monitor-expand">
<div class=""></div>
</div>
<div class="chartjs-size-monitor-shrink">
<div class=""></div>
</div>
</div>
<canvas id="lineChart" style="min-height: 250px; height: 250px; max-height: 250px; max-width: 100%; display: block; width: 764px;" width="764" height="250" class="chartjs-render-monitor"></canvas>
</div>
</div>
<!-- /.card-body -->
</div>
</div>
<div class="col-lg-6">
<div class="card">
<div class="card-header">
<h3 class="card-title">Показания датчика </h3>
<div class="card-tools">
</div>
</div>
<!-- /.card-header -->
<div class="card-body p-0">
<table class="table table-striped- table-bordered table-hover table-checkable dataTable no-footer dtr-inline">
<thead>
<tr>
<th style="width: 10px">№</th>
<th>Дата</th>
<th>Значение</th>
</tr>
</thead>
<tbody id="table_bo">
{% for sensor in sensor_list %}
<tr>
<td>1.</td>
<td>{{sensor.date_time}}</td>
<td>{{sensor.value}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div><!-- /.container-fluid -->
{% endblock %}
{% block script_footer %}
<!-- OPTIONAL SCRIPTS -->
<script src="{% static 'lte/plugins/chart.js/Chart.min.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script>
const ctx = document.getElementById('lineChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [
],
datasets: [{
label: 'Показания датчика',
fill: false,
data:[
],
borderColor: 'rgb(54, 162, 235, 1)',
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
min: 0,
max: 5,
},
//type: 'myScale',
//min: 0,
//max: 5,
}]
}
}
});
function intime(d) {
var day = d.getDate();
var hrs = d.getHours();
var min = d.getMinutes();
var sec = d.getSeconds();
var mnt = new Array("января", "февраля", "марта", "апреля", "мая",
"июня", "июля", "августа", "сентября", "октября", "ноября", "декабря");
if (day <= 9) day="0" + day;
if (hrs <= 9) hrs="0" + hrs;
if (min <=9 ) min="0" + min;
if (sec <= 9) sec="0" + sec;
return "Дата последнего показания : " + hrs + ":" + min + ":" + sec + "&nbsp;&nbsp;&nbsp;" +
day + " " + mnt[d.getMonth()] + " " + d.getFullYear() + " г."
}
function show()
{
cmd = 'refresh';
id = document.getElementById('sensor_id').value
sensor_type = document.getElementById('sensor_type').value
$.ajax({
type: 'POST', // метод отправки
async:true,
url: window.location.pathname+'sensor_ajax/', // путь к обработчику
data: {
"cmd": cmd,
"id": id,
"sensor_type": sensor_type,
},
// dataType: 'text',
success: function (data) {
console.log(data)
str_table = ''
start = 0
length = data.length-1
myChart.data.labels=[]
myChart.data.datasets[0].data = []
for (index = 0; index <= length; ++index) {
start = start + 1
myChart.data.labels.push(data[index].date_time);
myChart.data.datasets[0].data.push(data[index].value);
str_table = str_table + '<tr><td>' + (data.length-index) + '.</td><td>' + data[length-index].date_time + '</td><td>' + data[length-index].value + ' ({{sensor.unit}})</td></tr>'
$("#maxdate").html(intime(new Date(data[index].date_max)));
}
myChart.update();
$("#table_bo").html(str_table)
},
error: function (dataerr) {
console.log('Ошибка выполнение команды :'+dataerr)
}
});
}
function setparametrs(p) {
document.getElementById('sensor_type').setAttribute('value', p);
myChart.data.labels=[]
myChart.data.datasets[0].data = []
myChart.update();
}
$(function () {
show()
setInterval('show()', 2000);
})
</script>
{% endblock script_footer %}

12
apps/montorem/urls.py Normal file
View File

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
from django.conf.urls import url
from django.contrib.auth.decorators import login_required
from django.conf.urls import include # Используйте include() чтобы добавлять URL из каталога приложения
from apps.montorem.views import views_main
urlpatterns = [
url(r'^$', views_main.mainindex, name='mainindex'),
url(r'^sensor/$', views_main.sensor, name='sensor'),
url(r'sensor/sensor_ajax/$', views_main.sensor_ajax, name='sensor_ajax'),
]

View File

@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
import traceback
import datetime
import requests
import base64
import json
from datetime import datetime
from requests.auth import HTTPBasicAuth
from django.conf import settings
from django.db.models import Q
from django.shortcuts import render
from django.http import HttpResponse
from django.conf import settings
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from django.views.decorators.cache import never_cache
from django.db.models import Avg, Max, Min
from apps.util import generalmodule
from sabron.util import logging
@login_required(login_url='/accounts/login/?next=')
@never_cache
def mainindex(request):
try:
if request.method == "GET":
response = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor_list',auth=('user_api', 'qwerty*1'))
js = response.json()
if js['status'] == 0:
context={
'updatepage':True,
'sensor_list':js['respose'],
}
else:
context={
'updatepage':True,
}
return render(request, 'montorem_index.html',context)
except Exception as err:
logging.error(traceback.format_exc())
@login_required(login_url='/accounts/login/?next=')
@never_cache
def sensor(request):
try:
if request.method == "GET":
get_param=request.GET.dict()
response_sensor = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor&id='+get_param['id'],auth=('user_api', 'qwerty*1'))
sensor = response_sensor.json()
response = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor_readings&id='+get_param['id'],auth=('user_api', 'qwerty*1'))
js = response.json()
if js['status'] == 0:
context={
'sensor':sensor['respose'],
'sensor_list':js['respose'],
}
else:
context={
'updatepage':True,
}
return render(request, 'sensor_index.html',context)
except Exception as err:
logging.error(traceback.format_exc())
@login_required(login_url='/accounts/login/?next=')
@never_cache
def sensor_ajax(request):
try:
if request.method == "POST":
m_sensor=[]
sensor_dict = dict()
param = request.POST.dict()
print(param)
response_sensor = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor&id='+param['id'],auth=('user_api', 'qwerty*1'))
sensor = response_sensor.json()
#connect_time = sensor['connect_time']
#value = sensor['value']
response = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor_readings&id='+param['id']+'&sensor_type='+param['sensor_type'],auth=('user_api', 'qwerty*1'))
sensor_list = response.json()
print(sensor_list['respose'])
return generalmodule.ReturnJson(200,sensor_list['respose'])
except Exception as err:
logging.error(traceback.format_exc())

View File

@ -18,12 +18,13 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'apps.main.apps.MainConfig', # Стартовая страница
'apps.montorem.apps.MontoremConfig', # Подсистема монторем
]
"""Информация о приложении """
SITE_TITLE = u'Система отчетов'
SITE_TITLE_S = u'СиО'
APP_VER = u'1.0.0.7'
APP_VER = u'1.0.0.9'
APP_VEK = u'2024 г'
APP_COPPIRIGHT = u'Система отчетов'

View File

@ -12,6 +12,7 @@ from . import views
urlpatterns = [
url(r'^$', RedirectView.as_view(url='/main/', permanent=True)), #Перенаправляет все запросы
url(r'^main/', include('apps.main.urls')),
url(r'^montorem/', include('apps.montorem.urls')),
url(r'^accounts/logout/', views.user_logout, name='user_logout'),
url(r'^accounts/', views.user_login, name='user_login'),

View File

@ -108,7 +108,7 @@
</button>
<div id="m_header_menu" class="m-header-menu m-aside-header-menu-mobile m-aside-header-menu-mobile--offcanvas m-header-menu--skin-light m-header-menu--submenu-skin-light m-aside-header-menu-mobile--skin-dark m-aside-header-menu-mobile--submenu-skin-dark ">
<ul class="m-menu__nav m-menu__nav--submenu-arrow ">
<li class="m-menu__item m-menu__item--submenu m-menu__item--rel m-menu__item--open-dropdown m-menu__item--hover" m-menu-submenu-toggle="click" m-menu-link-redirect="1" aria-haspopup="true">
<li class="m-menu__item m-menu__item--submenu m-menu__item--rel" m-menu-submenu-toggle="click" m-menu-link-redirect="1" aria-haspopup="true">
<a href="javascript:;" class="m-menu__link m-menu__toggle">
<i class="m-menu__link-icon flaticon-line-graph"></i>
<span class="m-menu__link-text">Отчеты</span>
@ -126,13 +126,27 @@
</h3>
<ul class="m-menu__inner">
<li class="m-menu__item " m-menu-link-redirect="1" aria-haspopup="true">
<a href="scada/" class="m-menu__link " target="_blank">
<a href="/main/scada/" class="m-menu__link " target="_blank">
<i class="m-menu__link-icon flaticon-graphic-2"></i>
<span class="m-menu__link-text">Обзорный экран</span>
</a>
</li>
</ul>
</li>
<li class="m-menu__item">
<h3 class="m-menu__heading m-menu__toggle">
<span class="m-menu__link-text">Монторем</span>
<i class="m-menu__ver-arrow la la-angle-right"></i>
</h3>
<ul class="m-menu__inner">
<li class="m-menu__item " m-menu-link-redirect="1" aria-haspopup="true">
<a href="/montorem/" class="m-menu__link " >
<i class="m-menu__link-icon flaticon-graphic-2"></i>
<span class="m-menu__link-text">Плотномеры</span>
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
@ -293,7 +307,7 @@
<script type="text/javascript" src="{% static '/metronic/assets/app/js/dashboard.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<!--end::Page Snippets -->
<script src="{% static 'js/main.js' %}?ver={% settings_value 'APP_VER' %}"></script>
{% block script_footer %}
{% endblock script_footer %}

View File

@ -31,7 +31,7 @@
<div class="m-login__wrapper">
<div class="m-login__logo">
<a href="#">
<img width="120" height="120" src="{% static 'img/login_logo.png' %}?ver={% settings_value 'APP_VER' %}" alt="logo">
<img width="35%" height="35%" src="{% static 'img/login_logo.png' %}?ver={% settings_value 'APP_VER' %}" alt="logo">
</a>
</div>
<div class="m-login__signin">