-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from JunAishima/remove-ispyb-user-controls
Remove ispyb user controls
- Loading branch information
Showing
2 changed files
with
6 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,151 +38,6 @@ def queryOneFromDB(q): | |
except TypeError: | ||
return 0 | ||
|
||
def personIdFromLogin(loginName): | ||
q = ("select personId from Person where login = \""+ loginName + "\"") | ||
return (queryOneFromDB(q)) | ||
|
||
def personIdFromProposal(propNum): | ||
q = ("select personId from Proposal where proposalNumber = " + str(propNum)) | ||
return (queryOneFromDB(q)) | ||
|
||
def proposalIdFromProposal(propNum): | ||
q = ("select proposalId from Proposal where proposalNumber = " + str(propNum)) | ||
return (queryOneFromDB(q)) | ||
|
||
def maxVisitNumfromProposal(propNum): | ||
propID = proposalIdFromProposal(propNum) | ||
q = ("select max(visit_number) from BLSession where proposalId = " + str(propID)) | ||
return (queryOneFromDB(q)) | ||
|
||
|
||
def createPerson(firstName,lastName,loginName): | ||
return | ||
params = core.get_person_params() | ||
params['given_name'] = firstName | ||
params['family_name'] = lastName | ||
params['login'] = loginName | ||
pid = core.upsert_person(list(params.values())) | ||
cnx.commit() | ||
|
||
|
||
def createProposal(propNum,PI_login="boaty"): | ||
return | ||
pid = personIdFromLogin(PI_login) | ||
if (pid == 0): | ||
createPerson("Not","Sure",PI_login) | ||
pid = personIdFromLogin(PI_login) | ||
params = core.get_proposal_params() | ||
params['proposal_code'] = 'mx' | ||
params['proposal_number'] = int(propNum) | ||
params['proposal_type'] = 'mx' | ||
params['person_id'] = pid | ||
params['title'] = 'SynchWeb Dev Proposal' | ||
proposal_id = core.upsert_proposal(list(params.values())) | ||
cnx.commit() #not sure why I needed to do this. Maybe mistake in stored proc? | ||
|
||
def createVisitName(propNum): # this is for the GUI to know what a datapath would be in row_clicked | ||
return | ||
logger.info("creating visit Name for propnum " + str(propNum)) | ||
propID = proposalIdFromProposal(propNum) | ||
if (propID == 0): #proposal doesn't exist, just create and assign to boaty | ||
createProposal(propNum) | ||
maxVis = maxVisitNumfromProposal(propNum) | ||
if (maxVis == None): #1st visit | ||
newVisitNum = 1 | ||
else: | ||
newVisitNum = 1 + maxVis | ||
logger.info('new visit number: %s' % newVisitNum) | ||
visitName = "mx"+str(propNum)+"-"+str(newVisitNum) | ||
return visitName, newVisitNum | ||
|
||
|
||
def createVisit(propNum): | ||
return | ||
visitName, newVisitNum = createVisitName(propNum) | ||
personID = personIdFromProposal(propNum) | ||
params = core.get_session_for_proposal_code_number_params() | ||
params['proposal_code'] = 'mx' | ||
params['proposal_number'] = propNum | ||
params['visit_number'] = newVisitNum | ||
params['beamline_name'] = daq_utils.beamline.upper() | ||
params['startdate'] = datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') | ||
params['enddate'] = datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') | ||
|
||
params['comments'] = 'For software testing' | ||
sid = core.upsert_session_for_proposal_code_number(list(params.values())) | ||
cnx.commit() | ||
assert sid is not None | ||
assert sid > 0 | ||
# Test upsert_person: | ||
# params = core.get_person_params() | ||
# params['given_name'] = 'Baldur' | ||
# params['family_name'] = 'Odinsson' | ||
# params['login'] = 'bo%s' % str(time.time()) # login must be unique | ||
# pid = core.upsert_person(list(params.values())) | ||
# assert pid is not None | ||
# assert pid > 0 | ||
|
||
# params = core.get_person_params() | ||
# params['id'] = pid | ||
# params['email_address'] = '[email protected]' | ||
# pid2 = core.upsert_person(list(params.values())) | ||
# assert pid2 is not None | ||
# assert pid2 == pid | ||
|
||
# Test upsert_session_has_person: | ||
params = core.get_session_has_person_params() | ||
params['session_id'] = sid | ||
params['person_id'] = personID | ||
params['role'] = 'Co-Investigator' | ||
params['remote'] = True | ||
core.upsert_session_has_person(list(params.values())) | ||
cnx.commit() | ||
try: | ||
personsOnProposalList = core.retrieve_persons_for_proposal("mx",propNum) | ||
logger.debug(f'list of all persons: {personsOnProposalList}') | ||
except: | ||
logger.error(f'exception when retrieving persons for proposal {propNum}') | ||
return visitName | ||
for i in range (0,len(personsOnProposalList)): | ||
personLogin = personsOnProposalList[i]["login"] | ||
personID = personIdFromLogin(personLogin) | ||
params = core.get_session_has_person_params() | ||
params['session_id'] = sid | ||
params['person_id'] = personID | ||
params['role'] = 'Co-Investigator' | ||
params['remote'] = True | ||
core.upsert_session_has_person(list(params.values())) | ||
cnx.commit() | ||
|
||
|
||
# Test upsert_proposal_has_person: | ||
# params = core.get_proposal_has_person_params() | ||
# params['proposal_id'] = 141666 | ||
# params['person_id'] = pid | ||
# params['role'] = 'Principal Investigator' | ||
# phpid = core.upsert_proposal_has_person(list(params.values())) | ||
# assert phpid is not None | ||
# assert phpid > 0 | ||
return visitName | ||
|
||
def addPersonToProposal(personLogin,propNum): | ||
return | ||
personID = personIdFromLogin(personLogin) | ||
if (personID == 0): | ||
createPerson("Not","Sure",personLogin) | ||
personID = personIdFromLogin(personLogin) | ||
propID = proposalIdFromProposal(propNum) | ||
if (propID == 0): | ||
createProposal(propNum,personLogin) | ||
propID = proposalIdFromProposal(propNum) | ||
params = core.get_proposal_has_person_params() | ||
params['proposal_id'] = propID | ||
params['role'] = 'Co-Investigator' | ||
params['personid'] = personID | ||
phpid = core.upsert_proposal_has_person(list(params.values())) | ||
cnx.commit() | ||
|
||
|
||
def insertPlotResult(dc_id,imageNumber,spotTotal,goodBraggCandidates,method2Res,totalIntegratedSignal): | ||
return | ||
|
@@ -203,9 +58,9 @@ def insertResult(result,resultType,request,visitName,dc_id=None,xmlFileName=None | |
try: | ||
sessionid = core.retrieve_visit_id(visitName) | ||
except ISPyBNoResultException as e: | ||
logger.error("insert result - caught ISPyBNoResultException: '%s'. make sure visit name is in the format mx999999-1234. NOT HAVING MX IN FRONT IS A SIGN OF PROBLEMS - try newVisit() in that case." % e) | ||
propNum = visitName.split('-')[0] | ||
sessionid = createVisit(propNum) | ||
message = f"insert result - caught ISPyBNoResultException: '{e}'." | ||
logger.exception(message) | ||
raise e | ||
request_type = request['request_type'] | ||
if request_type in('standard', 'vector') : | ||
sample = request['sample'] # this needs to be created and linked to a DC group | ||
|
@@ -397,8 +252,9 @@ def insertRasterResult(request,visitName): | |
try: | ||
sessionid = core.retrieve_visit_id(visitName) | ||
except ISPyBNoResultException as e: | ||
logger.error("insertRasterResult - caught ISPyBNoResultException: '%s'. make sure visit name is in the format mx999999-1234. NOT HAVING MX IN FRONT IS A SIGN OF PROBLEMS - try newVisit() in that case." % e) | ||
return | ||
message = f"insertRasterResult - caught ISPyBNoResultException: '{e}'." | ||
logger.error(message) | ||
raise e | ||
request = db_lib.getRequestByID(request_id) | ||
sample = request['sample'] # this needs to be created and linked to a DC group | ||
#result_obj = result['result_obj'] this doesn't appear to be used -DK | ||
|