3
3
# Copyright 2011-2016 by it's authors.
4
4
# Some rights reserved. See LICENSE.txt, AUTHORS.txt.
5
5
6
+ import json
7
+ import math
8
+ import plone
9
+
10
+ from zope .component import adapts
11
+ from zope .component import getAdapters
12
+ from zope .interface import implements
13
+
14
+ from Products .Archetypes .config import REFERENCE_CATALOG
15
+ from Products .CMFCore .utils import getToolByName
16
+ from Products .PythonScripts .standard import html_quote
17
+
18
+ from bika .lims import bikaMessageFactory as _
6
19
from bika .lims .browser import BrowserView
7
20
from bika .lims .interfaces import IAnalysis
8
21
from bika .lims .interfaces import IFieldIcons
9
- from bika .lims import bikaMessageFactory as _
10
22
from bika .lims .utils import t , isnumber
11
- from bika .lims import logger
12
- from bika .lims .utils import to_utf8
13
- from Products .Archetypes .config import REFERENCE_CATALOG
14
- from Products .CMFCore .utils import getToolByName
15
- from Products .PythonScripts .standard import html_quote
16
23
from bika .lims .utils .analysis import format_numeric_result
17
- from zope .component import adapts
18
- from zope .component import getAdapters
19
- from zope .interface import implements
20
-
21
- import json
22
- import math
23
- import plone
24
24
25
25
26
26
class CalculationResultAlerts (object ):
27
-
28
27
"""This uses IAnalysis.ResultOutOfRange on values in request.
28
+
29
29
To validate results at ajax calculation time, make more adapters like this
30
30
one, from IFieldIcons. Any existing IAnalysis/IFieldIcon adapters
31
31
(AnalysisOutOfRange) have already been called.
32
32
"""
33
-
34
33
adapts (IAnalysis )
35
34
implements (IFieldIcons )
36
35
@@ -62,10 +61,9 @@ def __call__(self, result=None, specification=None, **kwargs):
62
61
63
62
64
63
class ajaxCalculateAnalysisEntry (BrowserView ):
65
-
66
- """ This view is called by javascript when an analysis' result or interim
67
- field value is entered. Returns a JSON dictionary, or None if no
68
- action is required or possible.
64
+ """This view is called by javascript when an analysis' result or interim
65
+ field value is entered.
66
+ Returns a JSON dictionary, or None if no action is required or possible.
69
67
"""
70
68
71
69
def __init__ (self , context , request ):
@@ -94,18 +92,17 @@ def calculate(self, uid=None):
94
92
Result ['result' ] = ""
95
93
96
94
if calculation :
95
+ """We need first to create the map of available parameters
96
+ acording to the interims, analyses and wildcards:
97
97
98
- '''
99
- We need first to create the map of available parameters
100
- acording to the interims, analyses and wildcards:
101
98
params = {
102
99
<as-1-keyword> : <analysis_result>,
103
100
<as-1-keyword>.<wildcard-1> : <wildcard_1_value>,
104
101
<as-1-keyword>.<wildcard-2> : <wildcard_2_value>,
105
102
<interim-1> : <interim_result>,
106
103
...
107
104
}
108
- '''
105
+ """
109
106
110
107
# Get dependent analyses results and wildcard values to the
111
108
# mapping. If dependent analysis without result found,
@@ -124,17 +121,17 @@ def calculate(self, uid=None):
124
121
else :
125
122
# Retrieve the result and DLs from the analysis
126
123
analysisvalues = {
127
- 'keyword' : dependency .getKeyword (),
128
- 'result' : dependency .getResult (),
129
- 'ldl' : dependency .getLowerDetectionLimit (),
130
- 'udl' : dependency .getUpperDetectionLimit (),
124
+ 'keyword' : dependency .getKeyword (),
125
+ 'result' : dependency .getResult (),
126
+ 'ldl' : dependency .getLowerDetectionLimit (),
127
+ 'udl' : dependency .getUpperDetectionLimit (),
131
128
'belowldl' : dependency .isBelowLowerDetectionLimit (),
132
129
'aboveudl' : dependency .isAboveUpperDetectionLimit (),
133
130
}
134
- if analysisvalues ['result' ]== '' :
131
+ if analysisvalues ['result' ] == '' :
135
132
unsatisfied = True
136
- break ;
137
- key = analysisvalues .get ('keyword' ,dependency .getKeyword ())
133
+ break
134
+ key = analysisvalues .get ('keyword' , dependency .getKeyword ())
138
135
139
136
# Analysis result
140
137
# All result mappings must be float, or they are ignored.
@@ -215,7 +212,7 @@ def calculate(self, uid=None):
215
212
'context' : self .context },
216
213
{'mapping' : mapping })
217
214
# calculate
218
- result = eval (formula )
215
+ result = eval (formula , calculation . _getGlobals () )
219
216
Result ['result' ] = result
220
217
self .current_results [uid ]['result' ] = result
221
218
except TypeError as e :
@@ -258,18 +255,6 @@ def calculate(self, uid=None):
258
255
else :
259
256
self .alerts [uid ] = [alert , ]
260
257
261
- if analysis .portal_type == 'ReferenceAnalysis' :
262
- # The analysis is a Control or Blank. We might use the
263
- # reference results instead other specs
264
- _uid = analysis .getServiceUID ()
265
- specs = analysis .aq_parent .getResultsRangeDict ().get (_uid , {})
266
-
267
- else :
268
- # Get the specs directly from the analysis. The getResultsRange
269
- # function already takes care about which are the specs to be used:
270
- # AR, client or lab.
271
- specs = analysis .getResultsRange ()
272
-
273
258
# format result
274
259
try :
275
260
Result ['formatted_result' ] = format_numeric_result (analysis ,
@@ -322,8 +307,8 @@ def calculate(self, uid=None):
322
307
anvals = self .current_results [uid ]
323
308
isldl = anvals .get ('isldl' , False )
324
309
isudl = anvals .get ('isudl' , False )
325
- ldl = anvals .get ('ldl' ,0 )
326
- udl = anvals .get ('udl' ,0 )
310
+ ldl = anvals .get ('ldl' , 0 )
311
+ udl = anvals .get ('udl' , 0 )
327
312
ldl = float (ldl ) if isnumber (ldl ) else 0
328
313
udl = float (udl ) if isnumber (udl ) else 10000000
329
314
belowldl = (isldl or flres < ldl )
0 commit comments