diff --git a/apps/main/services/scales_control/service.py b/apps/main/services/scales_control/service.py
index 5d8f6d9..37297f0 100644
--- a/apps/main/services/scales_control/service.py
+++ b/apps/main/services/scales_control/service.py
@@ -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}
diff --git a/apps/main/services/scales_control/views.py b/apps/main/services/scales_control/views.py
index dac9ab8..abd188f 100644
--- a/apps/main/services/scales_control/views.py
+++ b/apps/main/services/scales_control/views.py
@@ -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
diff --git a/apps/main/services/urls.py b/apps/main/services/urls.py
index 7933a70..3472498 100644
--- a/apps/main/services/urls.py
+++ b/apps/main/services/urls.py
@@ -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'),
]
diff --git a/apps/main/templates/fabric_scales_control_widget.html b/apps/main/templates/fabric_scales_control_widget.html
index 5cac0ec..6dc6e90 100644
--- a/apps/main/templates/fabric_scales_control_widget.html
+++ b/apps/main/templates/fabric_scales_control_widget.html
@@ -3,9 +3,7 @@
diff --git a/apps/main/templates/main_index.html b/apps/main/templates/main_index.html
index 5ba799b..c9fc31b 100644
--- a/apps/main/templates/main_index.html
+++ b/apps/main/templates/main_index.html
@@ -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' %}
@@ -44,7 +44,7 @@
{% block script_footer %}
-
+{# #}
diff --git a/static/js/charts/scaleControl.js b/static/js/charts/scaleControl.js
index 4ba2638..bb34628 100644
--- a/static/js/charts/scaleControl.js
+++ b/static/js/charts/scaleControl.js
@@ -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');