def post_ch(self, data): data["obj"]["mtime_manual"] = datetime.datetime.strptime( data["obj"]["mtime_manual"][0:19], "%Y-%m-%dT%H:%M:%S") data["obj"]["waktu"] = datetime.datetime.strptime( data["obj"]["waktu"], "%Y-%m-%d") try: ch = CurahHujan.selectBy(agentID=data["obj"]["agentID"], waktu=data["obj"]["waktu"])[0] ch.manual = data["obj"]["manual"] ch.syncUpdate() except IndexError: CurahHujan(**data["obj"])
def POST(self): inp = web.input() try: ch = CurahHujan.get(int(inp.get('pk'))) ch.set(**{inp.get('name'): float(inp.get('value', 0))}) ch.syncUpdate() except SQLObjectNotFound: return web.notfound() return {"Ok": "true"}
def POST(self): inp = web.input() try: km = KlimatManual.get(int(inp.get('pk'))) km.set(**{inp.get('name'): float(inp.get('value',0))}) km.syncUpdate() except SQLObjectNotFound: return web.notfound() if inp.get('name') == 'ch_m': ch = CurahHujan.select(AND(CurahHujan.q.agent==km.agent, CurahHujan.q.waktu == km.sampling.date())) if ch.count(): ch[0].set(**{'manual': float(inp.get('value', 0))}) ch[0].syncUpdate() else: ch = CurahHujan(**{'waktu': km.sampling, 'manual': float(inp.get('value', 0)), 'agent': km.agent}) return {"Ok": "true"}
def POST(self, table_name): try: pos = [a for a in AgentCh.select(AgentCh.q.AgentType==1) if a.table_name == table_name][0] except IndexError: return web.notfound() inp = web.input() sql = "SELECT id FROM curahhujan WHERE agent_id=%s AND waktu='%s'" % (pos.id, to_date(inp.waktu)) rs = conn.queryAll(sql) if not rs: ch = CurahHujan(agent=pos, waktu=to_date(inp.waktu), manual=float(inp.hujan)) # publish to MQTT Broker #pub_object(ch) return web.redirect('/adm/ch/' + table_name, absolute=True)
def GET(self): web.header('Content-Type', 'application/json') web.header('Access-Control-Allow-Origin', '*') inp = web.input() sampling = inp.get('sampling') n = datetime.datetime.now() waktu = n.replace(hour=0, minute=0, second=0, microsecond=0).date() if sampling: d = to_date(sampling) waktu = datetime.datetime(d.year, d.month, d.day).date() rst = [ c.sqlmeta.asDict() for c in CurahHujan.select(CurahHujan.q.waktu == waktu) ] return json.dumps(rst, default=json_serialize)
def POST(self, table_name): agent_id = dict([a.split('\t') for a in open('agent_table.txt').readlines()]).get(table_name) pos = Agent.get(agent_id) try: pos = [a for a in AgentCh.select(AgentCh.q.AgentType==1) if a.table_name == table_name][0] except IndexError: return web.notfound() inp = web.input() float_list = 'ch_m,temp_min_m,temp_max_m,humi_m,kec_angin_m,penguapan_m'.split(',') for kol in float_list: if inp.get(kol): inp.update({kol: float(inp.get(kol))}) else: inp.update({kol: None}) inp.update({'penyinaran_m': inp.get('penyinaran_m') and int(inp.get('penyinaran_m')) or None}) inp.update({'agentID': pos.id, 'cuser': session.username, 'cdate': datetime.datetime.now()}) inp.update({'sampling': to_date(inp.get('sampling'))}) if 'csrf_token' in inp: del inp['csrf_token'] rst = KlimatManual.select(AND(KlimatManual.q.agent==pos, func.DATE(KlimatManual.q.sampling)==inp.get('sampling'))) if rst.count(): rst[0].set(**inp) else: km = KlimatManual(**inp) # table curahhujan perlu ditambah/update ch = CurahHujan.select(AND(CurahHujan.q.agent==pos, func.DATE(CurahHujan.q.waktu) == inp.get('sampling'))) if ch.count(): ch[0].set(**{'manual': float(inp.get('ch_m', 0))}) else: ch = CurahHujan(**{'waktu': inp.get('sampling'), 'manual': float(inp.get('ch_m', 0)), 'agent': pos}) return web.redirect('/adm/klimatologi/' + table_name, absolute=True)