コード例 #1
0
def webreq():

    cfg = pconfig.read("rb_preserve.cfg")
    first_value, last_value = plot.data_span()

    return """
function min_secs(){
    return %f;
}

function max_secs(){
    return %f;
}

function default_begin(){
    return %s;
}

function config_json(){
    return %s;
}
""" % (
        first_value * 1000,
        last_value * 1000,
        cfg.get("settings", "default_view_hours"),
        pconfig.json_out(),
    )
コード例 #2
0
ファイル: plot.py プロジェクト: nuess0r/raspberry_preserve
def draw_svg(begin, end, width, height):

    cfg = pconfig.read("rb_preserve.cfg")

    uid_fbase = "%s/%s" % (cfg.get("settings", "tmp_dir"), str(uuid.uuid4()))

    # write data file
    with open("%s.tdata" % uid_fbase, "w") as dfo:
        dfo.write(
            "".join(
                get_lines(
                    begin,
                    end,
                    int(cfg.get("settings", "max_plot_points")),
                    int(cfg.get("settings", "sample_period")) * 60,
                )
            )
        )
    # write gnuplot cfg file
    write_gpcfg(width, height, uid_fbase, cfg)

    # make gnuplot generate the svg file
    outp = check_output(["gnuplot", "%s.gp" % uid_fbase])

    # clean up tmp files
    os.remove("%s.gp" % uid_fbase)
    os.remove("%s.tdata" % uid_fbase)

    return outp
コード例 #3
0
ファイル: mail.py プロジェクト: nuess0r/raspberry_preserve
def webreq(form):
    cfg = pconfig.read('rb_preserve.cfg')
    try:
        sndto = form.getvalue('alarm_to_addresses')
        send_warning("Test", "-1.0", cfg, toaddrs=sndto)
        return "".join([ "Test mail successfully sent to the following recipients:\n",
        sndto.replace(";", "\n")])
    except Exception as e:
        return str(e)
コード例 #4
0
def main(argv=None):    
    cfg = pconfig.read('rb_preserve.cfg')

    ddir = cfg.get('settings', 'data_dir')
    timeformat = pconfig.dformat();
    pwd = os.path.dirname(os.path.realpath(__file__))
    
    #sample sensor
    humidity = None
    temperature = None
    
    while humidity == None and temperature == None:
        humidity, temperature = poll()

    # see if 
    tmpfn = os.path.join(cfg.get('settings', 'tmp_dir'), "intermediary.data")

    if os.path.exists(tmpfn):
        with open(tmpfn, 'r') as pd:
            lines = pd.readlines()
    else:
        lines = []
    
    lines.append("%.2f,%.02f\n" % (humidity, temperature))
    
    if len(lines) >= int(cfg.get('settings', 'sample_period')):        
        avg_hum, avg_temp = condense(lines)
        warning_test(avg_hum, avg_temp, cfg)
        lines = []   # zerro tmp file
        
        #store in persistent file
        pfname = "%s/%s/%s.data" % (pwd, ddir, time.strftime(pconfig.dfilename_fmt()))
        pstr = "%s,%.2f,%.02f\n" % (time.strftime(timeformat), avg_hum, avg_temp)
        with open(pfname, "a") as outfile:
            outfile.write(pstr)

    #overwrite existing tmp file with current data
    with open(tmpfn, 'w') as pd:
        pd.write("".join(lines))
コード例 #5
0
def webreq(form):
  cfg = pconfig.read('rb_preserve.cfg')

  #default time is past 24 hours
  firstvalue, lastvalue = plot.data_span()
  
  tend =   lastvalue
  deftimeview = 60*60*int(cfg.get('settings', 'default_view_hours'))

  timeformat = pconfig.dformat()

  getvals = {
    'begin': time.strftime(timeformat, time.localtime(tend - deftimeview)),
    'end': time.strftime(timeformat, time.localtime(tend)),
    'width': 960,
    'height' : 720,
    'origin' : ""
  }

  for k,v in getvals.iteritems():
    getvals[k] = cond_read(k, v, form)

  #try parsing string values 
  try:
    getvals['end'] = time.mktime(time.strptime(getvals['end'], timeformat))
  except:
    getvals['end'] = tend

  try:
    getvals['begin'] = time.mktime(time.strptime(getvals['begin'], timeformat)) 
  except:
    getvals['begin'] = tend - deftimeview

    
  # test that begin is before end
  if getvals['begin'] >= getvals['end']:
      if getvals['origin'] == "end":
        getvals['begin'] = getvals['end'] - deftimeview
      elif getvals['end'] >= tend:
        getvals['begin'] = tend - deftimeview
        getvals['end'] = tend
      else:
        getvals['end'] = getvals['begin'] + deftimeview

  if getvals['end'] >= tend:
    getvals['end'] = tend
  elif getvals['end'] <= firstvalue:
    getvals['end'] = firstvalue + deftimeview
    getvals['begin'] = firstvalue
    
  if getvals['begin'] < firstvalue:
    getvals['begin'] = firstvalue

  return plot.draw_svg(getvals['begin'], getvals['end'], 
                      int(getvals['width']), int(getvals['height'])).replace("</svg>","""
  <script type="text/javascript">
    top.max_secs = function(){return %f;};
    top.show_range();
    top.set_time_pickers(%f, %f);
  </script>
</svg>""" % (lastvalue *1000, getvals['begin']*1000, getvals['end']*1000))
コード例 #6
0
                    tmplnes = []
                    if date != None:
                        th = 0.0;
                        tt = 0.0;
                        for i in range(len(td)):
                            th += td[i][0]
                            tt += td[i][1]

                        date = time.strftime(cfg.get('settings', 'timeformat'), date)
                        th /= len(td)
                        tt /= len(td)
                        lines.append("%s,%.2f,%.02f\n" % (date, th, tt))
    return lines

if __name__ == "__main__":
    cfg = pconfig.read('rb_preserve.cfg')
    # print "".join(get_lines(cfg.get('settings', 'timeformat'), 10))

    with  open("data/2014-09.data", 'r') as f:
        lines = f.readlines()

    endtime = time.time() #+ time.timezone
    begintime = endtime - len(lines)*600

    outlines = []

    for l in lines:
        _, h, t = l.split(',')
        ttime = time.localtime(begintime)
        ttime = time.strftime(cfg.get('settings', 'timeformat'), ttime)
        begintime += 600