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.product import price_digits
|
||||
|
||||
from scipy.stats import t
|
||||
import datetime
|
||||
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
|
||||
|
||||
_digits = (16, 2)
|
||||
@ -217,6 +220,9 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
||||
description_activity = fields.Char('Activity')
|
||||
next_maintenance = fields.Function(fields.Date('Next Maintenance'), 'get_next_maintenance')
|
||||
|
||||
graph_calibration = fields.Binary('Graphs')
|
||||
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Maintenance, cls).__setup__()
|
||||
@ -371,6 +377,31 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
||||
uncertain_eff = uncertain_c**4/((uncertain_type_A**4)/(len(sample)-1)+(uncertain_b1**4/U_subi)+(uncertain_b2**4/U_subi))
|
||||
|
||||
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')
|
||||
def on_change_service_maintenance(self):
|
||||
@ -409,20 +440,25 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
||||
pool = Pool()
|
||||
CalibrationLineTotal = pool.get('optical_equipment.maintenance.calibration')
|
||||
dates = {}
|
||||
dates_mistake_pattern = {}
|
||||
graph_data_matrix = []
|
||||
patterns = set()
|
||||
|
||||
for maintenance in maintenances:
|
||||
maintenance.calibration_total = ()
|
||||
if len(maintenance.lines_calibration) < 3:
|
||||
raise UserError("Por favor Ingrese mas de (3) Muestras por patrón (Dioptría)")
|
||||
if len(maintenance.lines_calibration) < 5:
|
||||
raise UserError("Por favor Ingrese mas de (5) Muestras por patrón (Dioptría)")
|
||||
else:
|
||||
for line in maintenance.lines_calibration:
|
||||
if line.value_patterns.pattern not in patterns:
|
||||
patterns.add(line.value_patterns.pattern)
|
||||
dates[line.value_patterns.pattern] = [line.value_equipment]
|
||||
dates_mistake_pattern[line.value_patterns.pattern] = [line.mistake]
|
||||
else:
|
||||
dates[line.value_patterns.pattern].append(line.value_equipment)
|
||||
|
||||
dates_mistake_pattern[line.value_patterns.pattern].append(line.mistake)
|
||||
|
||||
|
||||
for pattern in patterns:
|
||||
samples = dates[pattern]
|
||||
U_subi = maintenance.equipment.product.Usubi
|
||||
@ -448,12 +484,17 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
||||
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))
|
||||
|
||||
|
||||
t_student = t.ppf(1-0.025, uncertain_eff)
|
||||
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":
|
||||
calibrationLineTotal = CalibrationLineTotal(
|
||||
graph_dates=str(dates_mistake_pattern[pattern]),
|
||||
diopter=pattern,
|
||||
dev_std=dev_std,
|
||||
uncertain_type_A=uncertain_type_A,
|
||||
@ -470,10 +511,10 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
||||
state='Aprobado' if uncertain_expanded <= a_resolution else 'Rechazado'
|
||||
)
|
||||
maintenance.calibration_total += (calibrationLineTotal,)
|
||||
maintenance.save()
|
||||
|
||||
elif maintenance.equipment.product.resolution_type == "digital":
|
||||
calibrationLineTotal = CalibrationLineTotal(
|
||||
graph_dates=str(dates_mistake_pattern[pattern]),
|
||||
diopter=pattern,
|
||||
dev_std=dev_std,
|
||||
uncertain_type_A=uncertain_type_A,
|
||||
@ -490,8 +531,16 @@ class Maintenance(Workflow, ModelSQL, ModelView):
|
||||
state='Aprobado' if uncertain_expanded <= d_resolution else 'Rechazado'
|
||||
)
|
||||
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):
|
||||
'Calibration of Maintenance'
|
||||
@ -501,6 +550,7 @@ class Calibration(ModelSQL, ModelView):
|
||||
|
||||
maintenance = fields.Many2One('optical_equipment.maintenance', "Maintenance", ondelete="CASCADE",
|
||||
select=True, required=True)
|
||||
graph_dates = fields.Char("Graph Dates", readonly=True)
|
||||
diopter = fields.Float("Diopter", states=_states)
|
||||
dev_std = fields.Float("Standart Desviation", 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_eff = fields.Float("U eff", states=_states)
|
||||
t_student = fields.Float("T Student", states=_states)
|
||||
|
||||
uncertain_expanded = fields.Float("Uexpand", _digits, states=_states)
|
||||
|
||||
state = fields.Char('State')
|
||||
@ -723,6 +774,7 @@ class MaintenanceLine(ModelSQL, ModelView):
|
||||
if not self.unit or self.unit.category != category:
|
||||
self.unit = self.maintenance_activity.sale_uom
|
||||
|
||||
|
||||
class MaintenanceActivity(ModelView, ModelSQL):
|
||||
'Maintenance Activitys'
|
||||
__name__ = 'optical_equipment_maintenance.activity'
|
||||
@ -808,25 +860,6 @@ class CreateContract(Wizard):
|
||||
end_date=self.start.end_date,
|
||||
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):
|
||||
maintenance_service = self.records[0]
|
||||
|
@ -28,6 +28,8 @@
|
||||
<field name="t_student"/>
|
||||
<label name="uncertain_expanded"/>
|
||||
<field name="uncertain_expanded"/>
|
||||
<label name="graph_dates"/>
|
||||
<field name="graph_dates"/>
|
||||
<label name="state"/>
|
||||
<field name="state"/>
|
||||
</form>
|
||||
|
@ -49,6 +49,9 @@
|
||||
<field name="calibration_total"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Graph" id="graph">
|
||||
<field name="graph_calibration"/>
|
||||
</page>
|
||||
</notebook>
|
||||
<newline/>
|
||||
<label name="state"/>
|
||||
|
Loading…
Reference in New Issue
Block a user