def createDefaultRequest(sample_id): """ Doesn't really create a request, just returns a dictionary with the default parameters that can be passed to addRequesttoSample(). But note that these then get overwritten anyway, and I no longer expose them in screen params dialog """ sample = db_lib.getSampleByID(sample_id) try: propNum = sample["proposalID"] except KeyError: propNum = 999999 if (propNum == None): propNum = 999999 if (propNum != getProposalID()): setProposalID(propNum) screenPhist = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_phist")) screenPhiend = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_phi_end")) screenWidth = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_width")) screenDist = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_dist")) screenExptime = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_time")) screenReso = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_reso")) screenWave = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_wave")) screenEnergy = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_energy")) screenbeamWidth = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_beamWidth")) screenbeamHeight = float(db_lib.getBeamlineConfigParam(beamline,"screen_default_beamHeight")) screenTransmissionPercent = float(db_lib.getBeamlineConfigParam(beamline,"screen_transmission_percent")) sampleName = str(db_lib.getSampleNamebyID(sample_id)) basePath = os.getcwd() runNum = db_lib.getSampleRequestCount(sample_id) (puckPosition,samplePositionInContainer,containerID) = db_lib.getCoordsfromSampleID(beamline,sample_id) request = {"sample": sample_id} request["beamline"] = beamline requestObj = { "sample": sample_id, "sweep_start": screenPhist, "sweep_end": screenPhiend, "img_width": screenWidth, "exposure_time": screenExptime, "protocol": "standard", "detDist": screenDist, "parentReqID": -1, "basePath": basePath, "file_prefix": sampleName, "directory": basePath+"/" + str(getVisitName()) + "/"+sampleName+"/" + str(runNum) + "/" +db_lib.getContainerNameByID(containerID)+"_"+str(samplePositionInContainer+1)+"/", # "directory": basePath+"/" + str(getProposalID()) + "/"+sampleName+"/" + str(runNum) + "/" +db_lib.getContainerNameByID(containerID)+"_"+str(samplePositionInContainer+1)+"/", "file_number_start": 1, "energy":screenEnergy, "wavelength": energy2wave(screenEnergy), "resolution": screenReso, "slit_height": screenbeamHeight, "slit_width": screenbeamWidth, "attenuation": screenTransmissionPercent, "pos_x": -999, "pos_y": 0, "pos_z": 0, "pos_type": 'A', "gridStep": 30} request["request_obj"] = requestObj return request
def getSampleReqRes(reqid): """ this function is used in the getVisitSummary. the requestid is present in the request and in the results if you don't have a list of requestid , you can try : reqid = db_lib.getRequestsBySampleID(value, active_only=False :params reqid is a list of requestid per sample """ # reqid = db_lib.getRequestsBySampleID(value, active_only=False print('**New sample**') if reqid != []: print('{:12} {:15} {:10}'.format('ProposalID', 'Sample Name', 'Sample ID')) for r in reqid: if r is not None: print('{:_>50}'.format('')) sample_name = db_lib.getSampleNamebyID(r['sample']) print('{:12} {:15} {:10}'.format(r['proposalID'], sample_name, r['uid'])) reqRes = db_lib.getRequestByID(str(r['uid']), active_only=False) FASTDP = 'no' # default try: FASTDP == reqRes['request_obj']['fastDP'] except KeyError as e: print(" no FASTDP key " + repr(e)) print('{:>20} {:6} {:12} {:12}{:6} {:>6}-{:6}'.format( 'requests', 'FastDP', 'wavelength A', 'DetDist mm', 'width (Deg)', 'Start', 'End')) print('{:>20} {:<6} {:10} {:10}{:6} {:>10}-{:6}'.format( r['request_type'], FASTDP, reqRes['request_obj']['wavelength'], reqRes['request_obj']['detDist'], reqRes['request_obj']['img_width'], reqRes['request_obj']['sweep_start'], reqRes['request_obj']['sweep_end'])) print('{:*>20}'.format('Results')) try: reqres = db_lib.getResultsforRequest(r['uid']) for rr in reqres: print('{:>20}'.format(rr['result_type'])) # eventually it might be important to show what kind of results was obtained from the raster if rr['result_type'] == 'rasterResult': print('{:>38}'.format( rr['result_obj']['rasterCellResults']['type'])) except Exception as e: print('in 2nd exception') print('{:20}'.format('none'))
def createDefaultRequest(sample_id): """ Doesn't really create a request, just returns a dictionary with the default parameters that can be passed to addRequesttoSample(). """ # beamlineConfig = db_lib.getAllBeamlineConfigParams(**searchParams) beamlineConfig = getAllBeamlineConfigParams() screenPhist = float(beamlineConfig["screen_default_phist"]) screenPhiend = float(beamlineConfig["screen_default_phi_end"]) screenWidth = float(beamlineConfig["screen_default_width"]) screenDist = float(beamlineConfig["screen_default_dist"]) screenExptime = float(beamlineConfig["screen_default_time"]) screenReso = float(beamlineConfig["screen_default_reso"]) screenWave = float(beamlineConfig["screen_default_wave"]) screenEnergy = float(beamlineConfig["screen_default_energy"]) screenbeamWidth = float(beamlineConfig["screen_default_beamWidth"]) screenbeamHeight = float(beamlineConfig["screen_default_beamHeight"]) screenTransmissionPercent = float(beamlineConfig["screen_transmission_percent"]) sampleName = str(db_lib.getSampleNamebyID(sample_id)) basePath = os.getcwd() runNum = db_lib.getSampleRequestCount(sample_id) request = {"sample_id": sample_id} requestObj = { "sample_id": sample_id, "sweep_start": screenPhist, "sweep_end": screenPhiend, "img_width": screenWidth, "exposure_time": screenExptime, "protocol": "standard", "parentReqID": -1, "basePath": basePath, "file_prefix": sampleName, "directory": basePath+"/projID/"+sampleName+"/" + str(runNum) + "/", "file_number_start": 1, "energy":screenEnergy, "wavelength": energy2wave(screenEnergy), "resolution": screenReso, "slit_height": screenbeamHeight, "slit_width": screenbeamWidth, "attenuation": screenTransmissionPercent, "pos_x": 0, "pos_y": 0, "pos_z": 0, "pos_type": 'A', "gridStep": 30} request["request_obj"] = requestObj return request
def getShortVisitSummary(start_thuman, end_thuman=None): """ Get more generic statistics, on the mx beamlines, get a printed summary of what was done :param start_thuman: :param end_thuman: :return: a list of dict for each proposalid worked on. This is for both beamlines (amx fmx) """ # get the headers sampleid_dict = getSamplesByTimeInterval(start_thuman, end_thuman) visits = [] # will have the stats for a visit according to proposalid. # headers for the print print('{:25} {:10} {:10} {:^10}{:^10} {:^10} {:^10} {:10}'.format( 'Name', 'proposalid', 'standard', 'raster', 'snapshot', 'vector', 'escan', 'sample ID')) for pid, sid in sampleid_dict.items(): num_samples = (len(sid)) # define timestamps for now start-end p_stime = time.time() p_etime = 1451624400.0 # '2016-01-01T00:00' num_datacol = 0 for value in sid: # getting the name of the samples sample_name = db_lib.getSampleNamebyID(value) # getting a flavor of the request type list_type = [] srt = db_lib.getRequestsBySampleID( value, active_only=False ) # at this point it's not discriminating with time num_datacol += len(srt) # find the request_type for each header for i in srt: try: req_type = i['request_type'] except Exception as e: req_type = 'none' # set the time period for a proposal start_thuman = validate_date(start_thuman) start_t = time.mktime( datetime.strptime(start_thuman, '%Y-%m-%dT%H:%M:%S').timetuple()) if end_thuman is None: now = datetime.now() end_t = time.mktime(now.timetuple()) else: end_thuman = validate_date(end_thuman) end_t = time.mktime( datetime.strptime(end_thuman, '%Y-%m-%dT%H:%M:%S').timetuple()) if i['time'] >= start_t and i['time'] <= end_t: # set the time period for a proposal if i['time'] <= p_stime: p_stime = i['time'] if i['time'] >= p_etime: p_etime = i['time'] list_type.append(req_type) # print(list_type) p_stime2 = datetime.fromtimestamp(p_stime).strftime( '%Y-%m-%dT%H:%M:%S') p_etime2 = datetime.fromtimestamp(p_etime).strftime( '%Y-%m-%dT%H:%M:%S') visit = { 'pid': pid, 'num_datacol': num_datacol, 'beamline': 'amx', 'num_samples': num_samples, 'start': p_stime2, 'end': p_etime2 } list_type = Counter(list_type) # print(list_type) standard = '' raster = '' escan = '' vector = '' snapshot = '' if 'standard' in list_type: standard = list_type['standard'] # print(standard) if 'raster' in list_type: raster = list_type['raster'] if 'vector' in list_type: vector = list_type['vector'] if 'snapshot' in list_type: snapshot = list_type['snapshot'] if 'escan' in list_type: escan = list_type['escan'] print( '{:25} {:^10} {:^10} {:^10} {:^10} {:^10} {:^10}{:10}'.format( sample_name, pid, standard, raster, snapshot, vector, escan, value)) visits.append(visit) print('----------{} samples, {} requests from {} to {} '.format( num_samples, num_datacol, p_stime2, p_etime2)) return visits
def createDefaultRequest(sample_id, createVisit=True): """ Doesn't really create a request, just returns a dictionary with the default parameters that can be passed to addRequesttoSample(). But note that these then get overwritten anyway, and I no longer expose them in screen params dialog """ sample = db_lib.getSampleByID(sample_id) try: propNum = sample["proposalID"] except KeyError: propNum = 999999 if (propNum == None): propNum = 999999 if (propNum != getProposalID()): setProposalID(propNum, createVisit) screenDist, screenEnergy, screenExptime, screenPhiend, screenPhist, screenReso, screenTransmissionPercent, screenWidth, screenbeamHeight, screenbeamWidth = getScreenDefaultParams( ) sampleName = str(db_lib.getSampleNamebyID(sample_id)) basePath = os.getcwd() runNum = db_lib.getSampleRequestCount(sample_id) (puckPosition, samplePositionInContainer, containerID) = db_lib.getCoordsfromSampleID(beamline, sample_id) request = {"sample": sample_id} request["beamline"] = beamline requestObj = { "sample": sample_id, "sweep_start": screenPhist, "sweep_end": screenPhiend, "img_width": screenWidth, "exposure_time": screenExptime, "protocol": "standard", "detDist": screenDist, "parentReqID": -1, "basePath": basePath, "file_prefix": sampleName, "directory": basePath + "/" + str(getVisitName()) + "/" + sampleName + "/" + str(runNum) + "/" + db_lib.getContainerNameByID(containerID) + "_" + str(samplePositionInContainer + 1) + "/", "file_number_start": 1, "energy": screenEnergy, "wavelength": energy2wave(screenEnergy), "resolution": screenReso, "slit_height": screenbeamHeight, "slit_width": screenbeamWidth, "attenuation": screenTransmissionPercent, "pos_x": -999, "pos_y": 0, "pos_z": 0, "pos_type": 'A', "gridStep": 20 } request["request_obj"] = requestObj return request