-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_check_problems.py
81 lines (66 loc) · 2.97 KB
/
test_check_problems.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) Diego Gonzalez <[email protected]>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with This program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import MySQLdb
import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.dates import date2num, num2date, DateFormatter
from obspy.core import read, UTCDateTime, Trace, Stream
import time
import os, glob, itertools, shutil
from sys import path
path.append('src') # path to source folder of python functions
import imp
import asknow
imp.reload(asknow)
from asknow import asknow_humidity_fc28, asknow_photoresistor
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
host = "192.168.0.12"
user = "diego"
password = "None"
database = "test"
modname = "Exterior" # Indoor, Exterior
pause = 2
while 1 > 0:
now = UTCDateTime(datetime.datetime.now())
print("\n [ %s ]Last update for module %s" % ( now.strftime("%Y/%m/%d %H:%M:%S"), modname ))
# humidity threshold lower according to percentile 95
humidity_threshold_1 = [20, 60*5.] # humidity in %, time in seconds
t1 = now - humidity_threshold_1[1]
t2 = now
timeh, humidity, humidity_ohm = asknow_humidity_fc28(host, user, password, database, t1, t2, modname, verbose=False, doplot=False)
per95 = np.percentile(humidity, 95)
if per95<=humidity_threshold_1[0]:
print("[status] checking humidity threshold 1: ALARM ACTIVATE (H=%.1f; thrhld=%.1f)" % (per95, humidity_threshold_1[0]) )
else:
print("[status] checking humidity threshold 1: NOTHING HAPPENS(H=%.1f; thrhld=%.1f)" % (per95, humidity_threshold_1[0]) )
# lux threshold for night according to percentile 95
lux_threshold_night = [10, 60*10.] # lux in lux, time in seconds
t1 = now - lux_threshold_night[1]
t2 = now
timel, lux, lux_ohm = asknow_photoresistor(host, user, password, database, t1, t2, modname, verbose=False, doplot=False)
per95 = np.percentile(lux, 95)
if per95<=lux_threshold_night[0]:
print("[status] checking lux threshold night: ALARM ACTIVATE (L=%.1f; thrhld=%.1f)" % (per95, lux_threshold_night[0]) )
else:
print("[status] checking lux threshold night: NOTHING HAPPENS (L=%.1f; thrhld=%.1f)" % (per95, lux_threshold_night[0]) )
time.sleep(pause)