Last active
October 13, 2015 20:28
-
-
Save hackolite/4251843 to your computer and use it in GitHub Desktop.
OOB : python toolbox for bioreactor management
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
import smtplib | |
from email.mime.image import MIMEImage | |
from email.mime.multipart import MIMEMultipart | |
import os | |
import Image | |
from PIL import Image | |
import random | |
import time | |
import pylab | |
import time | |
import matplotlib.pyplot as plt | |
def send_mail(image_file,passwd): | |
# email conf | |
#image_file = "index.png" | |
fromaddr = '[email protected]' | |
toaddrs = '[email protected]' | |
msg = 'YOUR BIOREACTOR STATS' | |
username = '[email protected]' | |
password = passwd | |
collaborators = ['[email protected]'] | |
COMMASPACE = ', ' | |
# Create the container (outer) email message. | |
msg = MIMEMultipart() | |
msg['Subject'] = 'Our bioreactor week stats' | |
# me == sender | |
# collaborators = receiver list | |
msg['From'] = '[email protected]' | |
msg['To'] = COMMASPACE.join(collaborators) | |
msg.preamble = 'Our family reunion' | |
files=[image_file] | |
# jpeg pics, attachement in files | |
for file in files: | |
# Open the files in binary mode. Let the MIMEImage class automatically | |
# guess the specific image type. | |
fp = open(file,'rb') | |
img = MIMEImage(fp.read()) | |
fp.close() | |
msg.attach(img) | |
#action on server and send server datas | |
server = smtplib.SMTP('smtp.gmail.com:587') | |
server.starttls() | |
server.login(username,password) | |
server.sendmail(fromaddr, toaddrs, msg.as_string()) | |
server.quit() | |
#photos generation | |
def photo_cam(count) : | |
projet_name = 'My projetc' | |
os.popen("export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so") | |
os.popen("streamer -o images/"+str(count)+".jpeg") | |
#quantifiy luminosity | |
#link = 'index.png' | |
def photo_quantify(): | |
count_idate = 0 | |
liste_data = [] | |
listex = [] | |
liste = os.listdir('images') | |
liste.sort() | |
print liste | |
for i in liste : | |
if i.count("jpeg")> 0: | |
countj = count_idate+1 | |
pixi_list = [] | |
img = Image.open('images/'+i) | |
pix = img.load() | |
intensity = 0 | |
# multiply each pixel by 1.2 | |
#pix = img.getpixel((x,y)) | |
x,y = img.size | |
#rouge[0],vert[1],bleu[2]' | |
for i in range(x): | |
for j in range(y): | |
intensity = intensity + pix[i,j][1] | |
print 'intensity',intensity | |
liste_data.append(intensity/100000) | |
listex.append(count_idate) | |
os.popen("rm images/*.jpeg") | |
return listex,liste_data | |
#graph drawing | |
def graph(listeX,listeY) : | |
now = time.localtime(time.time()) | |
print time.strftime("%Y-%m-%d %H:%M:%S %Z", now) | |
# import the Matplotlib module | |
grap_name = str(time.strftime("%Y-%m-%d %H:%M:%S %Z", now)) | |
#pylab.plot(listeX, listeY) | |
plt.plot(listeY) | |
plt.title('variation d intensite') | |
plt.grid(True) | |
plt.ylabel('Bioreactor Intensity variation') | |
plt.axis([0, (len(listeY)-1),0, 200 ]) | |
plt.savefig(grap_name+'.png') | |
plt.close() | |
return grap_name+'.png' | |
#count deltas time | |
def main(delta_capture,delta_sendmail): | |
start_time_capture = time.time() | |
start_time_mail = time.time() | |
count = 0 | |
while 1==1 : | |
elapsed_time_mail = int(time.time()) - int(start_time_mail) | |
elapsed_time_capture = int(time.time()) - int(start_time_capture) | |
print elapsed_time_capture, elapsed_time_mail | |
#les captures de photos | |
if elapsed_time_capture >= delta_capture: | |
count = count + 1 | |
print 'capture de photos' | |
start_time_capture = time.time() | |
photo_cam(count) | |
# l'envoie de mail periodique | |
if elapsed_time_mail >= delta_sendmail: | |
print 'MAIL' | |
start_time_mail = time.time() | |
x,y = photo_quantify() | |
name = graph(x,y) | |
send_mail(name,'passwd') | |
if __name__ == '__main__': | |
intervalle_capture= 10 | |
intervalle_send_mail = 1000 | |
#day = 86400 | |
#minute = 60 | |
#week = 604800 | |
#capture,send_mail | |
#photo_cam(1) | |
main(intervalle_capture,intervalle_send_mail) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it works only on debian/ubuntu, you have to install streamer, if capture doesn't work type : 'export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so'