Merge pull request 'aspiration_units' (#18) from aspiration_units into dev
Reviewed-on: http://git.hronos.su:8080/sabron/repcofkk/pulls/18
This commit is contained in:
commit
c22844faf2
@ -1,4 +1,5 @@
|
||||
from apps.main.models.accident_stops import AccidentStop
|
||||
from apps.main.models.aspiration_unit import AspirationUnit
|
||||
from apps.main.models.scales_control import Position, ScalesControl, ShiftReport
|
||||
from apps.main.models.worktime import FabricWorkTime
|
||||
from django.contrib import admin
|
||||
@ -43,3 +44,8 @@ class PositionAdmin(admin.ModelAdmin):
|
||||
@admin.register(ShiftReport)
|
||||
class ShiftReportAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(AspirationUnit)
|
||||
class AspirationUnitAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
13
app/apps/main/models/aspiration_unit.py
Normal file
13
app/apps/main/models/aspiration_unit.py
Normal file
@ -0,0 +1,13 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class AspirationUnit(models.Model):
|
||||
mfsb_id = models.IntegerField()
|
||||
tag = models.CharField(max_length=50, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.mfsb_id} | {self.tag}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Аспирационная установка'
|
||||
verbose_name_plural = 'Аспирационные установки'
|
||||
27
app/apps/main/services/aspiration/service.py
Normal file
27
app/apps/main/services/aspiration/service.py
Normal file
@ -0,0 +1,27 @@
|
||||
import requests
|
||||
from apps.main.models.aspiration_unit import AspirationUnit
|
||||
from apps.main.services.base_service import DashboardBaseService
|
||||
from sabron.util.sabronmodule import get_settings
|
||||
|
||||
|
||||
class AspirationService(DashboardBaseService):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.api_host = get_settings('api_host')
|
||||
|
||||
def get_aspiration_unit_list(self) -> list[dict]:
|
||||
qs = AspirationUnit.objects.values_list('mfsb_id', flat=True)
|
||||
res = []
|
||||
for id_ in qs:
|
||||
asp_unit = self.get_aspiration_unit_by_id(id=id_)
|
||||
res.append(asp_unit)
|
||||
return res
|
||||
|
||||
def get_aspiration_unit_by_id(self, id) -> dict:
|
||||
response = requests.get(f'{self.api_host}/api/v2/scada/sensor/{id}')
|
||||
data = response.json()['responce']
|
||||
unit = {'name': data['name'], 'date': data['connect_time'], 'status': bool(data['value'])}
|
||||
return unit
|
||||
|
||||
def get_aspiration_unit_by_tag(self, tag) -> dict:
|
||||
pass
|
||||
8
app/apps/main/services/aspiration/views.py
Normal file
8
app/apps/main/services/aspiration/views.py
Normal file
@ -0,0 +1,8 @@
|
||||
from apps.main.services.aspiration.service import AspirationService
|
||||
from django.http import JsonResponse
|
||||
|
||||
|
||||
def get_aspiration_units_data(request):
|
||||
service = AspirationService()
|
||||
data = service.get_aspiration_unit_list()[::-1]
|
||||
return JsonResponse({'data': data})
|
||||
@ -1,4 +1,5 @@
|
||||
from apps.main.services.accident_stops.views import get_accident_stops
|
||||
from apps.main.services.aspiration.views import get_aspiration_units_data
|
||||
from apps.main.services.density_sensors.views import get_sensors_list
|
||||
from apps.main.services.scales_control.views import (
|
||||
fabric_goal,
|
||||
@ -33,5 +34,7 @@ urlpatterns = [
|
||||
path('scales/', get_scales_data, name='scales'),
|
||||
path('scales/kek_and_breed/recieve/', set_kek_and_breed, name='receive_kek_and_breed'),
|
||||
path('scales/kek_and_breed/', get_kek_and_breed, name='get_kek_and_breed'),
|
||||
path('scales/fabric_goal/', fabric_goal, name='fabric_goal')
|
||||
path('scales/fabric_goal/', fabric_goal, name='fabric_goal'),
|
||||
|
||||
path('aspiration_units/', get_aspiration_units_data),
|
||||
]
|
||||
|
||||
@ -1,133 +1,13 @@
|
||||
{% extends 'default.html' %}
|
||||
{% load static %}
|
||||
{% block extra_head %}
|
||||
<link href="{% static 'metronic/assets/vendors/custom/jquery-ui/jquery-ui.bundle.css' %}" rel="stylesheet"
|
||||
type="text/css">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row ui-sortable m-2 justify-content-center" id="m_sortable_portlets">
|
||||
<div class="col-xl-2 col-lg-4 col-sm-6">
|
||||
<div class="m-portlet m-portlet--mobile m-portlet--sortable">
|
||||
<div class="m-portlet__head ui-sortable-handle">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<h3 class="m-portlet__head-text m--font-success">
|
||||
Аспирационная установка №1
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body p-0">
|
||||
<img src="{% static 'img/aspiration.gif' %}" class="aspiration_img" alt="">
|
||||
</div>
|
||||
<div class="m-portlet__foot">
|
||||
<div class="d-flex align-items-center justify-content-end">
|
||||
<span style="color: var(--gray);">Данные от 22.08.2024 16:46</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet m-portlet--sortable-empty"></div>
|
||||
</div>
|
||||
<div class="col-xl-2 col-lg-4 col-sm-6">
|
||||
<div class="m-portlet m-portlet--mobile m-portlet--sortable">
|
||||
<div class="m-portlet__head ui-sortable-handle">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<h3 class="m-portlet__head-text m--font-success">
|
||||
Аспирационная установка №1
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body p-0">
|
||||
<img src="{% static 'img/aspiration.png' %}" class="aspiration_img" alt="">
|
||||
</div>
|
||||
<div class="m-portlet__foot">
|
||||
<div class="d-flex align-items-center justify-content-end">
|
||||
<span style="color: var(--gray);">Данные от 22.08.2024 16:46</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet m-portlet--sortable-empty"></div>
|
||||
</div>
|
||||
<div class="col-xl-2 col-lg-4 col-sm-6">
|
||||
<div class="m-portlet m-portlet--mobile m-portlet--sortable">
|
||||
<div class="m-portlet__head ui-sortable-handle">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<h3 class="m-portlet__head-text m--font-success">
|
||||
Аспирационная установка №1
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body p-0">
|
||||
<img src="{% static 'img/aspiration.gif' %}" class="aspiration_img" alt="">
|
||||
</div>
|
||||
<div class="m-portlet__foot">
|
||||
<div class="d-flex align-items-center justify-content-end">
|
||||
<span style="color: var(--gray);">Данные от 22.08.2024 16:46</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet m-portlet--sortable-empty"></div>
|
||||
</div>
|
||||
<div class="col-xl-2 col-lg-4 col-sm-6">
|
||||
<div class="m-portlet m-portlet--mobile m-portlet--sortable">
|
||||
<div class="m-portlet__head ui-sortable-handle">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<h3 class="m-portlet__head-text m--font-success">
|
||||
Аспирационная установка №1
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body p-0">
|
||||
<img src="{% static 'img/aspiration.gif' %}" class="aspiration_img" alt="">
|
||||
</div>
|
||||
<div class="m-portlet__foot">
|
||||
<div class="d-flex align-items-center justify-content-end">
|
||||
<span style="color: var(--gray);">Данные от 22.08.2024 16:46</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet m-portlet--sortable-empty"></div>
|
||||
</div>
|
||||
<div class="col-xl-2 col-lg-4 col-sm-6">
|
||||
<div class="m-portlet m-portlet--mobile m-portlet--sortable">
|
||||
<div class="m-portlet__head ui-sortable-handle">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<h3 class="m-portlet__head-text m--font-success">
|
||||
Аспирационная установка №1
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body p-0">
|
||||
<img src="{% static 'img/aspiration.gif' %}" class="aspiration_img" alt="">
|
||||
</div>
|
||||
<div class="m-portlet__foot">
|
||||
<div class="d-flex align-items-center justify-content-end">
|
||||
<span style="color: var(--gray);">Данные от 22.08.2024 16:46</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet m-portlet--sortable-empty"></div>
|
||||
</div>
|
||||
<div class="row m-2 justify-content-center" id="aspirationUnits">
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block script_footer %}
|
||||
<script src="{% static 'metronic/assets/demo/default/custom/components/portlets/draggable.js' %}"
|
||||
type="text/javascript"></script>
|
||||
<script src="{% static 'metronic/assets/vendors/custom/jquery-ui/jquery-ui.bundle.js' %}"
|
||||
type="text/javascript"></script>
|
||||
<script src="{% static 'js/charts/aspirationUnits.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
@ -16,7 +16,7 @@ INSTALLED_APPS = [
|
||||
"""Информация о приложении """
|
||||
SITE_TITLE = 'Система отчетов'
|
||||
SITE_TITLE_S = 'СиО'
|
||||
APP_VERSION = '0.9'
|
||||
APP_VERSION = '0.9.1'
|
||||
APP_VEK = '2024 г'
|
||||
APP_COPPIRIGHT = 'Система отчетов'
|
||||
|
||||
|
||||
91
app/static/js/charts/aspirationUnits.js
Normal file
91
app/static/js/charts/aspirationUnits.js
Normal file
@ -0,0 +1,91 @@
|
||||
(async function () {
|
||||
const aspiration_container = document.querySelector('#aspirationUnits');
|
||||
|
||||
function createAspirationCard(item) {
|
||||
// Создаем элементы
|
||||
const cardWrapper = document.createElement('div');
|
||||
cardWrapper.classList.add('col-xl-2', 'col-lg-4', 'col-sm-6');
|
||||
|
||||
const portlet = document.createElement('div');
|
||||
portlet.classList.add('m-portlet', 'm-portlet--mobile');
|
||||
|
||||
const portletHead = document.createElement('div');
|
||||
portletHead.classList.add('m-portlet__head');
|
||||
|
||||
const portletHeadCaption = document.createElement('div');
|
||||
portletHeadCaption.classList.add('m-portlet__head-caption');
|
||||
|
||||
const portletHeadTitle = document.createElement('div');
|
||||
portletHeadTitle.classList.add('m-portlet__head-title');
|
||||
|
||||
const portletHeadText = document.createElement('h3');
|
||||
portletHeadText.classList.add('m-portlet__head-text', 'm--font-success');
|
||||
portletHeadText.textContent = item.name;
|
||||
|
||||
// Собираем заголовок
|
||||
portletHeadTitle.appendChild(portletHeadText);
|
||||
portletHeadCaption.appendChild(portletHeadTitle);
|
||||
portletHead.appendChild(portletHeadCaption);
|
||||
portlet.appendChild(portletHead);
|
||||
|
||||
// Тело карточки
|
||||
const portletBody = document.createElement('div');
|
||||
portletBody.classList.add('m-portlet__body', 'p-0');
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.src = `/static/img/aspiration.${item.status ? 'gif' : 'png'}`;
|
||||
img.classList.add('aspiration_img');
|
||||
img.alt = '';
|
||||
|
||||
portletBody.appendChild(img);
|
||||
portlet.appendChild(portletBody);
|
||||
|
||||
// Нижняя часть карточки
|
||||
const portletFoot = document.createElement('div');
|
||||
portletFoot.classList.add('m-portlet__foot');
|
||||
|
||||
const footContainer = document.createElement('div');
|
||||
footContainer.classList.add('d-flex', 'align-items-center', 'justify-content-end');
|
||||
|
||||
const footText = document.createElement('span');
|
||||
footText.style.color = 'var(--gray)';
|
||||
footText.textContent = `Данные от ${item.date}`;
|
||||
|
||||
footContainer.appendChild(footText);
|
||||
portletFoot.appendChild(footContainer);
|
||||
portlet.appendChild(portletFoot);
|
||||
|
||||
cardWrapper.appendChild(portlet);
|
||||
|
||||
// Пустая карточка
|
||||
const emptyPortlet = document.createElement('div');
|
||||
emptyPortlet.classList.add('m-portlet', 'm-portlet--sortable-empty');
|
||||
cardWrapper.appendChild(emptyPortlet);
|
||||
|
||||
return cardWrapper;
|
||||
}
|
||||
|
||||
async function drawAspirationUnits() {
|
||||
try {
|
||||
const response = await fetch('/main/aspiration_units/');
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const json = await response.json();
|
||||
|
||||
// Очистка контейнера перед добавлением новых элементов
|
||||
aspiration_container.innerHTML = '';
|
||||
|
||||
// Добавление новых элементов
|
||||
for (let item of json['data']) {
|
||||
const card = createAspirationCard(item);
|
||||
aspiration_container.appendChild(card);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching aspiration units:', error);
|
||||
}
|
||||
}
|
||||
|
||||
await drawAspirationUnits();
|
||||
setInterval(drawAspirationUnits, 10000);
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user