Skip to content

Commit

Permalink
email changes 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon Joseph Leadman committed Oct 23, 2024
1 parent b6efc98 commit 2b29ea4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
31 changes: 8 additions & 23 deletions RDAS_MEMGRAPH_APP/Alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def send_email(self,subject,html,recipient):
Destination={'ToAddresses': recipient},
Message=message
)
print("Email sent successfully.")
print(f"Email sent successfully to {recipient}.")

def send_mail(self,data):
# Add tabs and type to the data dictionary
Expand All @@ -82,34 +82,25 @@ def send_mail(self,data):
def get_stats(self, type, gard, date_start, date_end):
# print("master get_stats----start::",date_start, "end::",date_end)
db = AlertCypher(type)
return_data = dict()
# date_start_string = date_start
# date_end_string = date_end
#date_start_obj = datetime.strptime(date_start, '%m/%d/%y')
#date_end_obj = datetime.strptime(date_end, '%m/%d/%y')

date_list = pd.date_range(date_start, date_end, freq='D').strftime('%m/%d/%y').to_list()
# print("date_list::",date_list)

convert = {sysvars.ct_db:['ClinicalTrial','GARD','GardId'], sysvars.pm_db:['Article','GARD','GardId'], sysvars.gnt_db:['Project','GARD','GardId']}
connect_to_gard = {sysvars.ct_db:'--',sysvars.pm_db:'--',sysvars.gnt_db:'--'}

# query = 'MATCH (x:{node}){connection}(y:{gardnode}) WHERE x.DateCreatedRDAS IN {date_list} AND y.{property} IN {list} RETURN COUNT(x)'.format(node=convert[type][0], gardnode=convert[type][1], property=convert[type][2], list=list(gards.keys()), date_list=date_list, connection=connect_to_gard[type])
query = 'MATCH (x:{node}){connection}(y:{gardnode}) WHERE x.DateCreatedRDAS IN {date_list} AND y.{property} = \"{gard}\" RETURN COUNT(x)'.format(node=convert[type][0], gardnode=convert[type][1], property=convert[type][2], gard=gard, date_list=date_list, connection=connect_to_gard[type])
# print("query::",query)
response = db.run(query)
result = response.single()
# print("total_query count::",result['COUNT(x)'])

return result['COUNT(x)']

def trigger_email(self,has_updates,date_start=datetime.today().strftime('%m/%d/%y'), date_end=datetime.today().strftime('%m/%d/%y')):
print("start_date",date_start, " end date:: ",date_end)
print(has_updates)
#obtain users contact information
txt_tabs_1 = {'trials':sysvars.ct_db, 'grants':sysvars.gnt_db, 'articles':sysvars.pm_db}
#tabs = {prefix +sysvars.ct_db_name: 'trials', prefix +sysvars.gf_db_name: 'grants', prefix +sysvars.pa_db_name: 'articles'}
users = auth.list_users()
user_info={}

if users:
users = users.iterate_all()
for user in users:
Expand All @@ -127,38 +118,32 @@ def trigger_email(self,has_updates,date_start=datetime.today().strftime('%m/%d/%
print('Document Doesnt Exist')

for uid, subscript in user_data.items():
# print(uid,subscript,"\n")
user=user_info.get(uid,None)

if user:
# print("user contact info: ",user.email)
subscript_gard={}
query_results={}
total=0
query_results = {}
uniques=set()

for subs in subscript["subscriptions"]:# for each gard id
# print("subs::",subs)
if "gardID" in subs and len(subs["alerts"])>0 and subs["alerts"][0] and "diseaseName" in subs:

subscript_gard[subs["gardID"]]=subs["diseaseName"]
# query databases
query_results[subs["gardID"]]={}


for dtype in subs["alerts"]:
print(dtype,txt_tabs_1 [dtype],has_updates)
uniques.add(dtype)
if txt_tabs_1 [dtype] in has_updates and txt_tabs_1[dtype] in has_updates:

# print("dtype::",dtype)
update_count = self.get_stats(txt_tabs_1 [dtype], subs["gardID"], date_start, date_end)
query_results[subs["gardID"]][dtype]=update_count
total+=update_count

else:
query_results[subs["gardID"]][dtype]=0

uniques=list(uniques)
# if len(uniques)<3:
# print("len < 3")
query_results["datasets"]=uniques
query_results['email'] = [user.email]
query_results['name'] = user_data[uid].get('displayName',"")
Expand All @@ -167,7 +152,7 @@ def trigger_email(self,has_updates,date_start=datetime.today().strftime('%m/%d/%
query_results["update_date_start"]=date_start
query_results["update_date_end"]=date_end
print("total updates::",total)
# print("query_results::",query_results,"\n")

if total>0:
self.send_mail( query_results)
print("\n")
Expand Down
4 changes: 0 additions & 4 deletions RDAS_MEMGRAPH_APP/Transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def seed(self, dump_name, dump_folder):
def detect(self, path):
server = None
config_title = None
#transfer_detection = {k:False for k in sysvars.dump_dirs}
transfer_detection = list()
last_updates = {k:str() for k in sysvars.dump_dirs}

Expand All @@ -75,10 +74,8 @@ def detect(self, path):
last_mod_date = self.db.getConf(f'{server}_{config_title}_DETECTION', db_name)
# stores value to return later
last_updates[db_name] = last_mod_date
print(f'{db_name} last mod:: {last_mod_date}')
# Gets current modification timestamp of the targeted database dump file
cur_mod_date = os.path.getmtime(f"{path}{db_name}.dump")
print(f'{db_name} cur mod:: {cur_mod_date}')
cur_mod_date = str(cur_mod_date)

# If the config file last update and the current last modification date is different, detect as new transfer and update the config
Expand All @@ -87,6 +84,5 @@ def detect(self, path):
self.db.setConf(f'{server}_{config_title}_DETECTION', db_name, cur_mod_date)
except Exception as e:
print(e)
#transfer_detection[db_name] = False

return [transfer_detection,last_updates]
17 changes: 11 additions & 6 deletions start_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
transfer_detection,lastupdates = transfer_module.detect(sysvars.approved_path)

while True:
print('[RDAS] Checking for new database files in the transfer folder')
# Detects all new dump files in the transfer folder of the TEST server
transfer_detection,lastupdates = transfer_module.detect(sysvars.transfer_path)
new_dumps = transfer_detection
Expand All @@ -48,10 +49,11 @@
<p>Run the following Cypher Query:</p>
<p>MATCH (x:UserTesting) SET x.Approved = \"True\"</p>'''
email_client.send_email(sub,html,recip)
print(f'Notification email sent to {recip}')
print(f'Notification emails sent to {recip}')

print('Waiting for 1 minute before checking for approval...')
sleep(60)
print('[RDAS] Waiting for 15 seconds before checking for approval...')
sleep(15)
print('[RDAS] Checking Neo4j for recently approved databases')

for db_name in sysvars.dump_dirs:
db = AlertCypher(db_name)
Expand All @@ -72,7 +74,9 @@
except Exception as e:
print(e)

sleep(60)
print('[RDAS] Waiting for 15 seconds before checking if new database files are in the approved folder')
sleep(15)
print('[RDAS] Checking approved folder for recently approved dump files')

# Detects if a new dump file was loaded into the approved folder
transfer_detection,lastupdates = transfer_module.detect(sysvars.approved_path)
Expand All @@ -95,8 +99,9 @@
<p>Database effected: {db_name}</p>
<p>There are no other actions required on your end</p>'''
email_client.send_email(sub,html,recip)
print(f'Notification email sent to {recip}')
print(f'Notification emails sent to {recip}')

# Waits one minute before restarting checks
sleep(60)
print('[RDAS] Waiting 15 seconds before restarting all checks')
sleep(15)

0 comments on commit 2b29ea4

Please sign in to comment.