def parse_headerline(self, line): #Process incoming header line """11/03/2014 14:46:46 PANalytical Results quantitative - Omnian 2013, Selected archive:,Omnian 2013 Number of results selected:,4 """ # Save each header field (that we know) and its own value in the dict if line.startswith('Results quantitative'): line = to_unicode(line) if len(self._header) == 0: self.err("Unexpected header format", numline=self._numline) return -1 line = line.replace(',', "") splitted = line.split(' - ') self._header['Quantitative'] = splitted[1] return 1 if line.startswith('Selected archive'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Archive'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Number of'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['NumResults'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Seq.'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 #Grab column names self._columns = line.split(',') self._end_header = True return 1 else: self._header['Date'] = line return 1
def __call__(self): CheckAuthenticator(self.request) uid = self.request.get('UID', '') title = self.request.get('Title', '') ret = { 'UID': '', 'Title': '', 'Prefix': '', 'Hazardous': '', 'SampleMatrixUID': '', 'SampleMatrixTitle': '', 'MinimumVolume': '', 'ContainerTypeUID': '', 'ContainerTypeTitle': '', 'SamplePoints': ('', ), 'StorageLocations': ('', ), } proxies = None if uid: try: bsc = getToolByName(self.context, 'bika_setup_catalog') proxies = bsc(UID=uid) except ParseError: pass elif title: try: bsc = getToolByName(self.context, 'bika_setup_catalog') proxies = bsc(portal_type='SampleType', title=to_unicode(title)) except ParseError: pass if proxies and len(proxies) == 1: st = proxies[0].getObject() ret = { 'UID': st.UID(), 'Title': st.Title(), 'Prefix': st.getPrefix(), 'Hazardous': st.getHazardous(), 'SampleMatrixUID': st.getSampleMatrix() and \ st.getSampleMatrix().UID() or '', 'SampleMatrixTitle': st.getSampleMatrix() and \ st.getSampleMatrix().Title() or '', 'MinimumVolume': st.getMinimumVolume(), 'ContainerTypeUID': st.getContainerType() and \ st.getContainerType().UID() or '', 'ContainerTypeTitle': st.getContainerType() and \ st.getContainerType().Title() or '', 'SamplePoints': dict((sp.UID(),sp.Title()) for sp in st.getSamplePoints()), 'StorageLocations': dict((sp.UID(),sp.Title()) for sp in st.getStorageLocations()), } return json.dumps(ret)
def __call__(self): CheckAuthenticator(self.request) uid = self.request.get('UID', '') title = self.request.get('Title', '') ret = { 'UID': '', 'Title': '', 'Prefix': '', 'Hazardous': '', 'SampleMatrixUID': '', 'SampleMatrixTitle': '', 'MinimumVolume': '', 'ContainerTypeUID': '', 'ContainerTypeTitle': '', 'SamplePoints': ('',), 'StorageLocations': ('',), } proxies = None if uid: try: bsc = getToolByName(self.context, 'bika_setup_catalog') proxies = bsc(UID=uid) except ParseError: pass elif title: try: bsc = getToolByName(self.context, 'bika_setup_catalog') proxies = bsc(portal_type='SampleType', title=to_unicode(title)) except ParseError: pass if proxies and len(proxies) == 1: st = proxies[0].getObject(); ret = { 'UID': st.UID(), 'Title': st.Title(), 'Prefix': st.getPrefix(), 'Hazardous': st.getHazardous(), 'SampleMatrixUID': st.getSampleMatrix() and \ st.getSampleMatrix().UID() or '', 'SampleMatrixTitle': st.getSampleMatrix() and \ st.getSampleMatrix().Title() or '', 'MinimumVolume': st.getMinimumVolume(), 'ContainerTypeUID': st.getContainerType() and \ st.getContainerType().UID() or '', 'ContainerTypeTitle': st.getContainerType() and \ st.getContainerType().Title() or '', 'SamplePoints': dict((sp.UID(),sp.Title()) for sp in st.getSamplePoints()), 'StorageLocations': dict((sp.UID(),sp.Title()) for sp in st.getStorageLocations()), } return json.dumps(ret)
def setSamplePoint(self, value, **kw): """ Accept Object, Title or UID, and convert SampleType title to UID before saving. """ if hasattr(value, "portal_type") and value.portal_type == "SamplePoint": pass else: bsc = getToolByName(self, 'bika_setup_catalog') sampletypes = bsc(portal_type='SamplePoint', title=to_unicode(value)) if sampletypes: value = sampletypes[0].UID else: sampletypes = bsc(portal_type='SamplePoint', UID=value) if sampletypes: value = sampletypes[0].UID else: value = None for ar in self.getAnalysisRequests(): ar.Schema()['SamplePoint'].set(ar, value) return self.Schema()['SamplePoint'].set(self, value)
def parse_headerline(self, line): #Process incoming header line """ 29/11/2013 10:15:44 PANalytical "Quantification of sample ESFERA CINZA - 1g H3BO3 - 1:0,5 - NO PPC", R.M.S.:,"0,035" Result status:, Sum before normalization:,"119,5 %" Normalised to:,"100,0 %" Sample type:,Pressed powder Initial sample weight (g):,"2,000" Weight after pressing (g):,"3,000" Correction applied for medium:,No Correction applied for film:,No Used Compound list:,Oxides Results database:,omnian 2013 Results database in:,c:\panalytical\superq\userdata """ if line.startswith('"Quantification of sample') or line.startswith( 'Quantification of sample'): line = to_unicode(line) if len(self._header) == 0: self.warn('Unexpected header format', numline=self._numline) return -1 # Remove non important string and double comas to obtein # the sample name free line = line.replace("Quantification of sample ", "") line = line.replace('"', "") splitted = line.split(' - ') if len( splitted ) > 3: # Maybe we don't need this, i could be all the sample's identifier... self._header['Sample'] = splitted[0].strip(' ') self._header['Quantity'] = splitted[1] self._header['????'] = splitted[2] # At present we # don't know what # is that self._header['PPC'] = splitted[3] elif len(splitted) == 1: self._header['Sample'] = splitted[0].replace( 'Quantification of sample', '').strip(' ') else: self.warn('Unexpected header format', numline=self._numline) return 1 # Save each header field (that we know) and its own value in the dict if line.startswith('R.M.S.'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['R.M.S.'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Result status'): if len(self._header) == 0: self.err("No header found", numline=self._numline) splitted = self.splitLine(line) if len(splitted) > 1: self._header['Result status'] = splitted[1].replace( '"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Sum before normalization'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Sum'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Normalised to'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Normalized'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Sample type'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Sample type'] = splitted[1].strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Initial sample weight (g)'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Initial sample weight'] = splitted[1].replace( '"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Weight after pressing (g)'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Weight after pressing'] = splitted[1].replace( '"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Correction applied for medium'): if len(self._header) == 0: self.warn('Unexpected header format', numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Correction medium'] = splitted[1].replace( '"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Correction applied for film'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Correction film'] = splitted[1].replace( '"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Used Compound list'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Used compound'] = splitted[1].replace( '"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Results database:'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Result database'] = splitted[1].replace( '"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if self.columns_name: if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 #Grab column names self._end_header = True self._columns = self.splitLine(line) return 1 if line.startswith('Results database in'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Database path'] = splitted[1] + splitted[2] self.columns_name = True else: self.warn('Unexpected header format', numline=self._numline) return 1 else: self._header['Date'] = line return 1
def __call__(self): CheckAuthenticator(self.request) bsc = getToolByName(self.context, 'bika_setup_catalog') uc = getToolByName(self.context, 'uid_catalog') service_title = self.request.get('service_title', '').strip() if not service_title: return '' analysis = uc(UID=self.request.get('analysis_uid', None)) if analysis: analysis = analysis[0].getObject() self.request['ajax_load'] = 1 tmp = LogView(analysis, self.request) self.log = tmp.folderitems() self.log.reverse() else: self.log = [] brains = bsc(portal_type="AnalysisService", title=to_unicode(service_title)) if not brains: return '' self.service = brains[0].getObject() self.calc = self.service.getCalculation() self.partsetup = self.service.getPartitionSetup() # convert uids to comma-separated list of display titles for i, ps in enumerate(self.partsetup): self.partsetup[i]['separate'] = \ ps.has_key('separate') and _('Yes') or _('No') if type(ps['sampletype']) == str: ps['sampletype'] = [ ps['sampletype'], ] sampletypes = [] for st in ps['sampletype']: res = bsc(UID=st) sampletypes.append(res and res[0].Title or st) self.partsetup[i]['sampletype'] = ", ".join(sampletypes) if ps.has_key('container'): if type(ps['container']) == str: self.partsetup[i]['container'] = [ ps['container'], ] try: containers = [bsc(UID=c)[0].Title for c in ps['container']] except IndexError: containers = [c for c in ps['container']] self.partsetup[i]['container'] = ", ".join(containers) else: self.partsetup[i]['container'] = '' if ps.has_key('preservation'): if type(ps['preservation']) == str: ps['preservation'] = [ ps['preservation'], ] try: preservations = [ bsc(UID=c)[0].Title for c in ps['preservation'] ] except IndexError: preservations = [c for c in ps['preservation']] self.partsetup[i]['preservation'] = ", ".join(preservations) else: self.partsetup[i]['preservation'] = '' return self.template()
def parse_headerline(self, line): #Process incoming header line """ 29/11/2013 10:15:44 PANalytical "Quantification of sample ESFERA CINZA - 1g H3BO3 - 1:0,5 - NO PPC", R.M.S.:,"0,035" Result status:, Sum before normalization:,"119,5 %" Normalised to:,"100,0 %" Sample type:,Pressed powder Initial sample weight (g):,"2,000" Weight after pressing (g):,"3,000" Correction applied for medium:,No Correction applied for film:,No Used Compound list:,Oxides Results database:,omnian 2013 Results database in:,c:\panalytical\superq\userdata """ if line.startswith('"Quantification of sample') or line.startswith('Quantification of sample'): line = to_unicode(line) if len(self._header) == 0: self.warn('Unexpected header format', numline=self._numline) return -1 # Remove non important string and double comas to obtein # the sample name free line = line.replace("Quantification of sample ", "") line = line.replace('"', "") splitted = line.split(' - ') if len(splitted) > 3:# Maybe we don't need this, i could be all the sample's identifier... self._header['Sample'] = splitted[0].strip(' ') self._header['Quantity'] = splitted[1] self._header['????'] = splitted[2]# At present we # don't know what # is that self._header['PPC'] = splitted[3] elif len(splitted) == 1: self._header['Sample'] = splitted[0].replace('Quantification of sample','').strip(' ') else: self.warn('Unexpected header format', numline=self._numline) return 1 # Save each header field (that we know) and its own value in the dict if line.startswith('R.M.S.'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['R.M.S.'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Result status'): if len(self._header) == 0: self.err("No header found", numline=self._numline) splitted = self.splitLine(line) if len(splitted) > 1: self._header['Result status'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Sum before normalization'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Sum'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Normalised to'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Normalized'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Sample type'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Sample type'] = splitted[1].strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Initial sample weight (g)'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Initial sample weight'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Weight after pressing (g)'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Weight after pressing'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Correction applied for medium'): if len(self._header) == 0: self.warn('Unexpected header format', numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Correction medium'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Correction applied for film'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Correction film'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Used Compound list'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Used compound'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if line.startswith('Results database:'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Result database'] = splitted[1].replace('"', '').strip() else: self.warn('Unexpected header format', numline=self._numline) return 0 if self.columns_name: if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 #Grab column names self._end_header = True self._columns = self.splitLine(line) return 1 if line.startswith('Results database in'): if len(self._header) == 0: self.err("No header found", numline=self._numline) return -1 splitted = self.splitLine(line) if len(splitted) > 1: self._header['Database path'] = splitted[1]+splitted[2] self.columns_name = True else: self.warn('Unexpected header format', numline=self._numline) return 1 else: self._header['Date'] = line return 1
def __call__(self): CheckAuthenticator(self.request) bsc = getToolByName(self.context, 'bika_setup_catalog') uc = getToolByName(self.context, 'uid_catalog') service_title = self.request.get('service_title', '').strip() if not service_title: return '' analysis = uc(UID=self.request.get('analysis_uid', None)) if analysis: analysis = analysis[0].getObject() self.request['ajax_load'] = 1 tmp = LogView(analysis, self.request) self.log = tmp.folderitems() self.log.reverse() else: self.log = [] brains = bsc(portal_type="AnalysisService", title=to_unicode(service_title)) if not brains: return '' self.service = brains[0].getObject() self.calc = self.service.getCalculation() self.partsetup = self.service.getPartitionSetup() # convert uids to comma-separated list of display titles for i,ps in enumerate(self.partsetup): self.partsetup[i]['separate'] = \ ps.has_key('separate') and _('Yes') or _('No') if type(ps['sampletype']) == str: ps['sampletype'] = [ps['sampletype'],] sampletypes = [] for st in ps['sampletype']: res = bsc(UID=st) sampletypes.append(res and res[0].Title or st) self.partsetup[i]['sampletype'] = ", ".join(sampletypes) if ps.has_key('container'): if type(ps['container']) == str: self.partsetup[i]['container'] = [ps['container'],] try: containers = [bsc(UID=c)[0].Title for c in ps['container']] except IndexError: containers = [c for c in ps['container']] self.partsetup[i]['container'] = ", ".join(containers) else: self.partsetup[i]['container'] = '' if ps.has_key('preservation'): if type(ps['preservation']) == str: ps['preservation'] = [ps['preservation'],] try: preservations = [bsc(UID=c)[0].Title for c in ps['preservation']] except IndexError: preservations = [c for c in ps['preservation']] self.partsetup[i]['preservation'] = ", ".join(preservations) else: self.partsetup[i]['preservation'] = '' return self.template()