add graphs to calibration
This commit is contained in:
parent
b64c897618
commit
92d92d4c50
@ -10,12 +10,15 @@ from trytond.pool import Pool
|
|||||||
from trytond.modules.currency.fields import Monetary
|
from trytond.modules.currency.fields import Monetary
|
||||||
from trytond.modules.product import price_digits
|
from trytond.modules.product import price_digits
|
||||||
|
|
||||||
from scipy.stats import t
|
|
||||||
import datetime
|
import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import math as mt
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
|
from scipy.stats import t
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
import math as mt
|
||||||
|
|
||||||
|
from io import BytesIO
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
|
|
||||||
_digits = (16, 2)
|
_digits = (16, 2)
|
||||||
@ -217,6 +220,9 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
|||||||
description_activity = fields.Char('Activity')
|
description_activity = fields.Char('Activity')
|
||||||
next_maintenance = fields.Function(fields.Date('Next Maintenance'), 'get_next_maintenance')
|
next_maintenance = fields.Function(fields.Date('Next Maintenance'), 'get_next_maintenance')
|
||||||
|
|
||||||
|
graph_calibration = fields.Binary('Graphs')
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
super(Maintenance, cls).__setup__()
|
super(Maintenance, cls).__setup__()
|
||||||
@ -372,6 +378,31 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
|||||||
|
|
||||||
return uncertain_eff
|
return uncertain_eff
|
||||||
|
|
||||||
|
def get_create_graph(matrix, patterns):
|
||||||
|
image = BytesIO()
|
||||||
|
#fig_width = 16
|
||||||
|
#fig_height = 16
|
||||||
|
all_data = matrix
|
||||||
|
labels = list(patterns)
|
||||||
|
fig, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(9, len(labels)+1))
|
||||||
|
# rectangular box plot
|
||||||
|
bplot1 = ax1.boxplot(all_data,
|
||||||
|
vert=True, # vertical box alignment
|
||||||
|
patch_artist=True, # fill with color
|
||||||
|
labels=labels) # will be used to label x-ticks
|
||||||
|
ax1.set_title('Error[D]')
|
||||||
|
# adding horizontal grid lines
|
||||||
|
for ax in [ax1]:
|
||||||
|
ax.yaxis.grid(True)
|
||||||
|
#ax.set_xlabel('Three separate samples')
|
||||||
|
#ax.set_ylabel('Observed values')
|
||||||
|
|
||||||
|
plt.savefig(image, format='png')
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
return image.getvalue()
|
||||||
|
|
||||||
|
|
||||||
@fields.depends('service_maintenance')
|
@fields.depends('service_maintenance')
|
||||||
def on_change_service_maintenance(self):
|
def on_change_service_maintenance(self):
|
||||||
self.propietary = self.service_maintenance.propietary
|
self.propietary = self.service_maintenance.propietary
|
||||||
@ -409,19 +440,24 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
|||||||
pool = Pool()
|
pool = Pool()
|
||||||
CalibrationLineTotal = pool.get('optical_equipment.maintenance.calibration')
|
CalibrationLineTotal = pool.get('optical_equipment.maintenance.calibration')
|
||||||
dates = {}
|
dates = {}
|
||||||
|
dates_mistake_pattern = {}
|
||||||
|
graph_data_matrix = []
|
||||||
patterns = set()
|
patterns = set()
|
||||||
|
|
||||||
for maintenance in maintenances:
|
for maintenance in maintenances:
|
||||||
maintenance.calibration_total = ()
|
maintenance.calibration_total = ()
|
||||||
if len(maintenance.lines_calibration) < 3:
|
if len(maintenance.lines_calibration) < 5:
|
||||||
raise UserError("Por favor Ingrese mas de (3) Muestras por patrón (Dioptría)")
|
raise UserError("Por favor Ingrese mas de (5) Muestras por patrón (Dioptría)")
|
||||||
else:
|
else:
|
||||||
for line in maintenance.lines_calibration:
|
for line in maintenance.lines_calibration:
|
||||||
if line.value_patterns.pattern not in patterns:
|
if line.value_patterns.pattern not in patterns:
|
||||||
patterns.add(line.value_patterns.pattern)
|
patterns.add(line.value_patterns.pattern)
|
||||||
dates[line.value_patterns.pattern] = [line.value_equipment]
|
dates[line.value_patterns.pattern] = [line.value_equipment]
|
||||||
|
dates_mistake_pattern[line.value_patterns.pattern] = [line.mistake]
|
||||||
else:
|
else:
|
||||||
dates[line.value_patterns.pattern].append(line.value_equipment)
|
dates[line.value_patterns.pattern].append(line.value_equipment)
|
||||||
|
dates_mistake_pattern[line.value_patterns.pattern].append(line.mistake)
|
||||||
|
|
||||||
|
|
||||||
for pattern in patterns:
|
for pattern in patterns:
|
||||||
samples = dates[pattern]
|
samples = dates[pattern]
|
||||||
@ -448,12 +484,17 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
|||||||
uncertain_c = mt.sqrt(sum_uncertain_c)
|
uncertain_c = mt.sqrt(sum_uncertain_c)
|
||||||
uncertain_eff = uncertain_c**4/((uncertain_type_A**4)/(len(samples)-1)+(uncertain_b1**4/U_subi)+(uncertain_b2_digital**4/U_subi))
|
uncertain_eff = uncertain_c**4/((uncertain_type_A**4)/(len(samples)-1)+(uncertain_b1**4/U_subi)+(uncertain_b2_digital**4/U_subi))
|
||||||
|
|
||||||
|
|
||||||
t_student = t.ppf(1-0.025, uncertain_eff)
|
t_student = t.ppf(1-0.025, uncertain_eff)
|
||||||
uncertain_expanded = round((t_student * uncertain_c),2)
|
uncertain_expanded = round((t_student * uncertain_c),2)
|
||||||
|
dates_mistake_pattern[pattern].append((uncertain_expanded*-1) if uncertain_expanded >= 0 else uncertain_expanded)
|
||||||
|
dates_mistake_pattern[pattern].append(uncertain_expanded)
|
||||||
|
dates_mistake_pattern[pattern].append(-0.25)
|
||||||
|
dates_mistake_pattern[pattern].append(0.25)
|
||||||
|
|
||||||
|
|
||||||
if maintenance.equipment.product.resolution_type == "analoga":
|
if maintenance.equipment.product.resolution_type == "analoga":
|
||||||
calibrationLineTotal = CalibrationLineTotal(
|
calibrationLineTotal = CalibrationLineTotal(
|
||||||
|
graph_dates=str(dates_mistake_pattern[pattern]),
|
||||||
diopter=pattern,
|
diopter=pattern,
|
||||||
dev_std=dev_std,
|
dev_std=dev_std,
|
||||||
uncertain_type_A=uncertain_type_A,
|
uncertain_type_A=uncertain_type_A,
|
||||||
@ -470,10 +511,10 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
|||||||
state='Aprobado' if uncertain_expanded <= a_resolution else 'Rechazado'
|
state='Aprobado' if uncertain_expanded <= a_resolution else 'Rechazado'
|
||||||
)
|
)
|
||||||
maintenance.calibration_total += (calibrationLineTotal,)
|
maintenance.calibration_total += (calibrationLineTotal,)
|
||||||
maintenance.save()
|
|
||||||
|
|
||||||
elif maintenance.equipment.product.resolution_type == "digital":
|
elif maintenance.equipment.product.resolution_type == "digital":
|
||||||
calibrationLineTotal = CalibrationLineTotal(
|
calibrationLineTotal = CalibrationLineTotal(
|
||||||
|
graph_dates=str(dates_mistake_pattern[pattern]),
|
||||||
diopter=pattern,
|
diopter=pattern,
|
||||||
dev_std=dev_std,
|
dev_std=dev_std,
|
||||||
uncertain_type_A=uncertain_type_A,
|
uncertain_type_A=uncertain_type_A,
|
||||||
@ -490,7 +531,15 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
|||||||
state='Aprobado' if uncertain_expanded <= d_resolution else 'Rechazado'
|
state='Aprobado' if uncertain_expanded <= d_resolution else 'Rechazado'
|
||||||
)
|
)
|
||||||
maintenance.calibration_total += (calibrationLineTotal,)
|
maintenance.calibration_total += (calibrationLineTotal,)
|
||||||
maintenance.save()
|
|
||||||
|
maintenance.save()
|
||||||
|
|
||||||
|
for i in dates_mistake_pattern.keys():
|
||||||
|
graph_data_matrix.append(dates_mistake_pattern[i])
|
||||||
|
|
||||||
|
image = cls.get_create_graph(graph_data_matrix, patterns)
|
||||||
|
maintenance.graph_calibration = image
|
||||||
|
maintenance.save()
|
||||||
|
|
||||||
|
|
||||||
class Calibration(ModelSQL, ModelView):
|
class Calibration(ModelSQL, ModelView):
|
||||||
@ -501,6 +550,7 @@ class Calibration(ModelSQL, ModelView):
|
|||||||
|
|
||||||
maintenance = fields.Many2One('optical_equipment.maintenance', "Maintenance", ondelete="CASCADE",
|
maintenance = fields.Many2One('optical_equipment.maintenance', "Maintenance", ondelete="CASCADE",
|
||||||
select=True, required=True)
|
select=True, required=True)
|
||||||
|
graph_dates = fields.Char("Graph Dates", readonly=True)
|
||||||
diopter = fields.Float("Diopter", states=_states)
|
diopter = fields.Float("Diopter", states=_states)
|
||||||
dev_std = fields.Float("Standart Desviation", states=_states)
|
dev_std = fields.Float("Standart Desviation", states=_states)
|
||||||
uncertain_type_A = fields.Float("Uncertain Type A", states=_states)
|
uncertain_type_A = fields.Float("Uncertain Type A", states=_states)
|
||||||
@ -513,6 +563,7 @@ class Calibration(ModelSQL, ModelView):
|
|||||||
uncertain_combinated = fields.Float("U_combinated", states=_states)
|
uncertain_combinated = fields.Float("U_combinated", states=_states)
|
||||||
uncertain_eff = fields.Float("U eff", states=_states)
|
uncertain_eff = fields.Float("U eff", states=_states)
|
||||||
t_student = fields.Float("T Student", states=_states)
|
t_student = fields.Float("T Student", states=_states)
|
||||||
|
|
||||||
uncertain_expanded = fields.Float("Uexpand", _digits, states=_states)
|
uncertain_expanded = fields.Float("Uexpand", _digits, states=_states)
|
||||||
|
|
||||||
state = fields.Char('State')
|
state = fields.Char('State')
|
||||||
@ -723,6 +774,7 @@ class MaintenanceLine(ModelSQL, ModelView):
|
|||||||
if not self.unit or self.unit.category != category:
|
if not self.unit or self.unit.category != category:
|
||||||
self.unit = self.maintenance_activity.sale_uom
|
self.unit = self.maintenance_activity.sale_uom
|
||||||
|
|
||||||
|
|
||||||
class MaintenanceActivity(ModelView, ModelSQL):
|
class MaintenanceActivity(ModelView, ModelSQL):
|
||||||
'Maintenance Activitys'
|
'Maintenance Activitys'
|
||||||
__name__ = 'optical_equipment_maintenance.activity'
|
__name__ = 'optical_equipment_maintenance.activity'
|
||||||
@ -809,25 +861,6 @@ class CreateContract(Wizard):
|
|||||||
invoice_address=self.start.invoice_address
|
invoice_address=self.start.invoice_address
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
|
||||||
def _create_contract_base(self, dates, subscription):
|
|
||||||
pool = Pool()
|
|
||||||
ContractBase = pool.get('optical_equipment.contract')
|
|
||||||
|
|
||||||
a = self._subscription_start
|
|
||||||
|
|
||||||
contractBase = ContractBase(
|
|
||||||
state='draft',
|
|
||||||
party=a['party'],
|
|
||||||
invoice_address=a['invoice_address'],
|
|
||||||
start_date=a['start_date'],
|
|
||||||
end_date=a['end_date'],
|
|
||||||
contact=a['contact'],
|
|
||||||
equipments=a['equipments']
|
|
||||||
)
|
|
||||||
contractBase.save()
|
|
||||||
"""
|
|
||||||
|
|
||||||
def do_create_contract(self, action):
|
def do_create_contract(self, action):
|
||||||
maintenance_service = self.records[0]
|
maintenance_service = self.records[0]
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
<field name="t_student"/>
|
<field name="t_student"/>
|
||||||
<label name="uncertain_expanded"/>
|
<label name="uncertain_expanded"/>
|
||||||
<field name="uncertain_expanded"/>
|
<field name="uncertain_expanded"/>
|
||||||
|
<label name="graph_dates"/>
|
||||||
|
<field name="graph_dates"/>
|
||||||
<label name="state"/>
|
<label name="state"/>
|
||||||
<field name="state"/>
|
<field name="state"/>
|
||||||
</form>
|
</form>
|
||||||
|
@ -49,6 +49,9 @@
|
|||||||
<field name="calibration_total"/>
|
<field name="calibration_total"/>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
|
<page string="Graph" id="graph">
|
||||||
|
<field name="graph_calibration"/>
|
||||||
|
</page>
|
||||||
</notebook>
|
</notebook>
|
||||||
<newline/>
|
<newline/>
|
||||||
<label name="state"/>
|
<label name="state"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user