-
Notifications
You must be signed in to change notification settings - Fork 0
/
API report and Email
145 lines (103 loc) · 3.74 KB
/
API report and Email
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 23 11:03:50 2021
@author: wiesbrock
"""
import elabapy
import json
import numpy as np
from requests.exceptions import HTTPError
import pandas as pd
import datetime
date_cutoff=datetime.datetime.today()-datetime.timedelta(days=180)
date_cutoff=date_cutoff.strftime('%Y%m%d')
# initialize the manager with an endpoint and your token
manager = elabapy.Manager(endpoint="https://elablink/api/v1/", token="create user token in elab", verify=False)
all_exp = manager.get_all_experiments()
names=[]
status=[]
time_stamp=[]
date=[]
locked=[]
for i in range(len(all_exp)):
names.append(all_exp[i]['fullname'])
status.append(all_exp[i]['category'])
time_stamp.append(all_exp[i]['timestamped'])
date.append(all_exp[i]['date'])
locked.append(all_exp[i]['locked'])
date_int=np.array(date,dtype=int)
date_cutoff_int=np.array(date_cutoff,dtype=int)
insert_or_not=np.zeros((len(all_exp),1))
for i in range(len(all_exp)):
entry_date=date_int[i]
if entry_date>=date_cutoff_int:
insert_or_not[i]=1
all_exp=pd.DataFrame.from_dict(all_exp)
all_exp=all_exp[insert_or_not==1]
list_id=all_exp['id'].astype(int)
latest_id=list_id[0]
for i in (np.linspace(latest_id-599,latest_id+1,501)):
try:
exp=manager.get_experiment(i)
except:
print(i)
unique_names=np.unique(all_exp['fullname'])
all_exp['locked']=all_exp['locked'].astype(int)
all_exp['timestamped']=all_exp['timestamped'].astype(int)
all_exp['id']=all_exp['id'].astype(int)
timestamped=np.zeros((len(unique_names),2))
for i in range(len(unique_names)):
ind_exp=all_exp[all_exp['fullname']==unique_names[i]]
timestamped[i,0]=len(ind_exp[ind_exp['timestamped']==1])
timestamped[i,1]=len(ind_exp['timestamped'])
import matplotlib.pyplot as plt
# Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels = unique_names
sizes = timestamped[:,1]
fig1, ax1 = plt.subplots(dpi=200)
plt.title('Overall entries of last week: '+ str(len(all_exp)),fontsize=14)
ax1.pie(sizes, labels=labels, autopct='%1.1f%%',
startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
#plt.savefig(r'C:\Users\wiesbrock\Desktop\Neuer Ordner/Figure1.png')
labels = unique_names
sizes = timestamped[:,0]
fig1, ax1 = plt.subplots(dpi=200)
plt.title('Overall timestamped entries of last week: '+ str(np.sum(timestamped[:,0])),fontsize=14)
ax1.pie(sizes, labels=labels, autopct='%1.1f%%',
startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
#plt.savefig(r'C:\Users\wiesbrock\Desktop\Neuer Ordner/Figure2.png')
'''
import smtplib, ssl
port = 465 # For SSL
smtp_server = "smtp.gmail.com"
sender_email = "[email protected]"
receiver_email = "[email protected]"
password = 'YGt:+-Yk3nXu:sR3'
message = "Subject: Your grade Hi ${unique_names}, your grade is"
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)
print('finito')
'''
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
username = "[email protected]"
password = 'YGt:+-Yk3nXu:sR3'
mail_from = "[email protected]"
mail_to = "[email protected]"
mail_subject = "Test Subject"
mail_body = str(unique_names)
mimemsg = MIMEMultipart()
mimemsg['From']=mail_from
mimemsg['To']=mail_to
mimemsg['Subject']=mail_subject
mimemsg.attach(MIMEText(mail_body, 'plain'))
connection = smtplib.SMTP(host='smtp.gmail.com', port=587)
connection.starttls()
connection.login(username,password)
connection.send_message(mimemsg)
connection.quit()