Виджет "Переработанное сырье"

This commit is contained in:
zakhy 2024-08-01 13:18:28 +07:00
parent 59ce450e75
commit e62c08e380
6 changed files with 140 additions and 15 deletions

View File

@ -3,9 +3,12 @@ from django.db.models import QuerySet
from apps.main.models.scales_control import ScalesControl
from apps.main.services.base_service import DashboardBaseService
from sabron.util.sabronmodule import get_settings
class ScalesControlService(DashboardBaseService):
control_conveyor_month = get_settings('conveyor_month')
fabric_goal = get_settings('fabric_goal')
def get_scales_value(self, positions: QuerySet, interval: str) -> dict:
res = {}
@ -138,3 +141,9 @@ class ScalesControlService(DashboardBaseService):
'Y к-та': concentrate,
'Y отсева': dropout,
}
def get_scales_value_with_plan(self):
scales_obj_value = int(ScalesControl.objects.filter(name=self.control_conveyor_month).latest('time').value)
planned_value = int(self.fabric_goal)
percent = str(round(int(scales_obj_value) * 100 / int(planned_value))) + '%'
return {'value': scales_obj_value, 'percent': percent, 'goal': planned_value}

View File

@ -13,7 +13,8 @@ def get_scales_data(request):
monthly = service.get_scales_value(positions, 'Month')
average = service.get_scales_value_by_shifts(positions, 'Aver')
daily = service.get_scales_value_by_shifts(positions, 'Smena')
return JsonResponse({'daily': daily, 'average': average, 'monthly': monthly})
plan = service.get_scales_value_with_plan()
return JsonResponse({'daily': daily, 'average': average, 'monthly': monthly, 'plan': plan})
@base_view

View File

@ -1,7 +1,4 @@
from django.conf.urls import url
from django.urls import path
from apps.main import views_main
from apps.main.services.accident_stops.views import get_accident_stops
from apps.main.services.density_sensors.views import get_sensors_list
from apps.main.services.scales_control.views import get_scales_data, get_positions
@ -13,7 +10,7 @@ urlpatterns = [
path('worktime/', factory_work_time, name='factory_time'),
path('worktime/durations/', factory_work_time_durations, name='factory_time_durations'),
path('status/', get_current_status, name='current_status'),
path('scales/', get_scales_data, name='scales'),
path('positions/', get_positions, name='get_positions'),
path('density_sensors/', get_sensors_list, name='get_sensors_list')
path('density_sensors/', get_sensors_list, name='get_sensors_list'),
path('scales/', get_scales_data, name='scales'),
]

View File

@ -3,9 +3,7 @@
<div class="m-portlet__head justify-content-center">
<div class="m-portlet__head-caption">
<div class="m-portlet__head-title">
<h3 class="m-portlet__head-text">
Весовой контроль
</h3>
<div id="chartProgress"></div>
</div>
</div>
</div>

View File

@ -29,8 +29,8 @@
<!--Виджет показаний весов -->
{% include 'fabric_scales_control_widget.html' %}
<!--Количество аварийных остановок -->
{% include 'emergency_stops_widget.html' %}
<!--Виджет плотност ьв тяжелой среде -->
{# {% include 'emergency_stops_widget.html' %}#}
<!--Виджет плотность в тяжелой среде -->
{% include 'density_in_heavy.html' %}
</div>
@ -44,7 +44,7 @@
{% block script_footer %}
<script src="{% static 'js/charts/worktime.js' %}?ver={% settings_value 'APP_VERSION' %}"></script>
<script src="{% static 'js/charts/mainIndexCharts.js' %}?ver={% settings_value 'APP_VERSION' %}"></script>
<script src="{% static 'js/charts/accidentStops.js' %}?ver={% settings_value 'APP_VERSION' %}"></script>
{# <script src="{% static 'js/charts/accidentStops.js' %}?ver={% settings_value 'APP_VERSION' %}"></script>#}
<script src="{% static 'js/charts/workStatus.js' %}?ver={% settings_value 'APP_VERSION' %}"></script>
<script src="{% static 'js/charts/scaleControl.js' %}?ver={% settings_value 'APP_VERSION' %}"></script>
<script src="{% static 'js/charts/densityInHeavy.js' %}?ver={% settings_value 'APP_VERSION' %}"></script>

View File

@ -270,6 +270,99 @@
}
};
const optionsProgress = {
chart: {
height: 70,
width: 400,
type: 'bar',
stacked: true,
sparkline: {
enabled: true
}
},
plotOptions: {
bar: {
horizontal: true,
barHeight: '40%',
colors: {
backgroundBarColors: ['#40475D']
}
},
},
dataLabels: {
enabled: true,
formatter: function (val, opts) {
return val;
},
style: {
colors: ['#fff'],
fontSize: '16px',
fontWeight: 'bold'
},
textAnchor: 'start',
},
colors: ['var(--success)', 'var(--danger)'],
stroke: {
width: 0,
},
series: [
{
name: 'Факт',
data: [
{
x: 'Тонн за месяц',
y: 0,
goals: [
{
name: 'План',
value: 250000,
strokeHeight: 15,
strokeColor: 'var(--danger)'
}
]
},
]
},
],
noData: 'Загрузка...',
title: {
floating: true,
offsetX: -10,
offsetY: 5,
text: 'Пераработанное сырье',
style: {
fontSize: '14px'
}
},
subtitle: {
floating: true,
align: 'right',
offsetY: 3,
text: '',
style: {
fontSize: '15px'
}
},
tooltip: {
enabled: true,
shared: true,
intersect: false
},
xaxis: {
categories: ['Тонн за месяц'],
},
yaxis: {
max: 400000
},
}
const chartProgress = new ApexCharts(document.querySelector('#chartProgress'), optionsProgress);
await chartProgress.render();
const hoursBarChart = new ApexCharts(document.querySelector("#byHourScales"), hoursBarOptions);
await hoursBarChart.render();
@ -297,6 +390,34 @@
}
function setChartsData(response) {
chartProgress.updateOptions({
subtitle: {
text: response.plan.percent
},
yaxis: {
max: response.plan.goal + 100000
}
})
chartProgress.updateSeries([
{
name: 'Факт',
data: [
{
x: 'Тонн за месяц',
y: response.plan.value,
goals: [
{
name: 'План',
value: response.plan.goal,
strokeHeight: 15,
strokeColor: 'var(--danger)'
}
]
},
]
},
],)
monthlyScalesChart.updateSeries([{
name: 'Месяц',
data: Object.values(response.monthly.scales)
@ -309,7 +430,7 @@
name: 'Предыдущая смена',
data: Object.values(response.average.previous_work_shift)
}])
console.log(response)
dailyScalesChart.updateSeries([{
name: 'Текущая смена',
data: Object.values(response.daily.current_work_shift)
@ -317,8 +438,7 @@
name: 'Предыдущая смена',
data: Object.values(response.daily.previous_work_shift)
}], true)
for (let item in response) {
for (let item of ['daily', 'monthly', 'average']) {
let latestDate = document.querySelector(`#${item}LatestDate`)
const dateObj = new Date(response[`${item}`].latest_date)
const padZero = (num) => num.toString().padStart(2, '0');