def requested_plot(request): plotdate = datetime.date.fromtimestamp(dt.now()) if (request.method == 'POST' and 'dateselected' in request.form and len(request.form['dateselected'].split('/')) == 3): pdate = time.strptime(request.form['dateselected'], '%m/%d/%Y') if dt.valid_date(pdate.tm_year, pdate.tm_mon, pdate.tm_mday): plotdate = datetime.date.fromtimestamp(time.mktime(pdate)) return plotdate
def _get_today(self): ''' retrieve all of the readings for today formatted for json file''' if self.db is None: return res = [] today = dt.timestamp_day(dt.now()) with sqlite.connect(os.environ['PIMMS_DB']) as con: cur = con.cursor() cur.execute("SELECT * FROM readings " "WHERE timestamp > {ts} AND timestamp < {te} " "ORDER BY timestamp ASC;".format(ts = today.start, te = today.end)) res = cur.fetchall() return JSONTemps.dbval2json(res)
def main_func(): print 'Monitor Running.' (options, args) = parser.parse_args() log_int = options.logint # Log Interval lastlog = 0 # Time we last logged to the db wire = Wire() temps = [] # current loop temperatures jsonf = jsonT(os.path.join(os.path.dirname(os.path.abspath(__file__)), options.jsonf, 'today.json'), os.environ['PIMMS_DB']) while True: t = now() if t >= lastlog + log_int: lastlog = t if len(temps) > 0: temp = sum(temps) / len(temps) log_avg(temp, t, os.environ['PIMMS_DB']) jsonf.add_val(t, temp/1000.0) temps = [] wire.detect_devices() else: temps.append(get_temps(wire))