Esempio n. 1
0
    def POST(self):
        inp = web.input()
        try:
            wd = AgentBd.get(int(inp.get('pk')))
            wd.set(**{inp.get('name'): float(inp.get('value', 0))})
        except SQLObjectNotFound:
            return web.notfound()
        except ValueError:
            wd = AgentBd.get(int(inp.get('pk')))
            wd.set(**{inp.get('name'): inp.get('value', 0)})

        return {"Ok": "true"}
Esempio n. 2
0
    def GET(self, table_name):
        try:
            pos = AgentBd.get(BENDUNGAN_DICT.get(table_name))
        except:
            return web.notfound()
        tgl = datetime.date.today()
        asset = Asset.select(Asset.q.table_name == table_name)
        kerusakan = Kerusakan.select(Kerusakan.q.table_name == table_name)

        rusak_list = []
        for k in kerusakan:
            rusak_list.append(k.asset.id)

        data = open('asset.csv').readlines()
        flist = []
        for item in data:
            l = item.strip().split("_")
            s = str(l[0] + " > " + l[1])
            flist.append(s)

        fflist = []
        for kategori in flist:
            if kategori not in fflist:
                fflist.append(kategori)

        return render.adm.bendungan.asset.index({
            'pos': pos,
            'tgl': tgl,
            'asset': asset,
            'data': fflist,
            'rusak_list': rusak_list
        })
Esempio n. 3
0
 def GET(self, table_name):
     inp = web.input()
     ordering = '-waktu'
     try:
         pos = AgentBd.get(BENDUNGAN_DICT.get(table_name))
     except:
         return web.notfound()
     webinput = web.input(sampling=str(datetime.date.today()))
     tg = datetime.datetime.strptime(webinput.sampling, '%Y-%m-%d').date()
     #sql = "SELECT * FROM waduk_daily WHERE \
     #        pos_id=%s AND waktu='%s'" % (pos.id, tg)
     #rs = conn.queryAll(sql)
     if tg.month == datetime.date.today().month:
         rs = [
             r for r in WadukDaily.select(
                 WadukDaily.q.pos == pos).orderBy(ordering)
             if r.waktu.month == tg.month and r.waktu.year == tg.year
             and r.waktu.day <= tg.day
         ]
     else:
         rs = [
             r for r in WadukDaily.select(
                 WadukDaily.q.pos == pos).orderBy(ordering)
             if r.waktu.month == tg.month and r.waktu.year == tg.year
         ]
     msg = ''
     if session.has_key('err'):
         msg = session.pop('err')
     return render.adm.bendungan.keamanan({
         'bd': pos,
         'periodic': rs,
         'tanggal': tg,
         'msg': msg
     })
Esempio n. 4
0
    def GET(self, table_name):
        inp = web.input()
        csv = inp.get('csv')
        ordering = csv and 'waktu' or '-waktu'
        try:
            pos = AgentBd.get(BENDUNGAN_DICT.get(table_name))
        except:
            return web.notfound()
        webinput = web.input(sampling=str(datetime.date.today()))
        tg = datetime.datetime.strptime(webinput.sampling, '%Y-%m-%d').date()
        #sql = "SELECT * FROM waduk_daily WHERE \
        #        pos_id=%s AND waktu='%s'" % (pos.id, tg)
        #rs = conn.queryAll(sql)
        if tg.month == datetime.date.today().month:
            rs = [
                r for r in WadukDaily.select(
                    WadukDaily.q.pos == pos).orderBy(ordering)
                if r.waktu.month == tg.month and r.waktu.year == tg.year
                and r.waktu.day <= tg.day
            ]
        else:
            rs = [
                r for r in WadukDaily.select(
                    WadukDaily.q.pos == pos).orderBy(ordering)
                if r.waktu.month == tg.month and r.waktu.year == tg.year
            ]
        if csv:

            web.header('Content-Type', 'application/cnd.ms-excel')
            web.header('Content-Disposition',
                       'attachment; filename="' + table_name + '.csv"')
            cols = "waktu,curahhujan,tma6,vol6,tma12,vol12,tma18,vol18,inflow_q,inflow_v,intake_q,intake_v,outflow_q,outflow_v,spillway_q,spillway_v,vnotch_tin1,vnotch_q1,vnotch_tin2,vnotch_q2,vnotch_tin3,vnotch_q3,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5".split(
                ',')
            out = ",".join(cols)
            for r in rs:
                out += "\n" + ",".join([str(getattr(r, c)) for c in cols])
                #out += "\n"
            return out
        msg = ''
        if session.has_key('err'):
            msg = session.pop('err')
        return render.adm.bendungan.show({
            'bd': pos,
            'periodic': rs,
            'tanggal': tg,
            'msg': msg
        })
Esempio n. 5
0
    def GET(self, table_name, id=None):
        inp = web.input()
        tgl = to_date(
            inp.get('sampling',
                    datetime.date.today().strftime('%Y-%m-%d')))
        bd_id = BENDUNGAN_DICT.get(table_name)
        pos = AgentBd.get(int(bd_id))
        if id:
            kegiatan = Kegiatan.get(int(id))
            return render.adm.bendungan.kegiatan_show(kegiatan=kegiatan)
        if inp.get('sampling') and inp.get('paper'):
            sql = "SELECT k.id, k.petugas, k.uraian, f.id, f.filepath FROM \
                    kegiatan k, foto f \
                    WHERE f.obj_type='kegiatan' AND k.id=f.obj_id AND DATE(k.sampling)='%s' \
                    AND k.table_name='%s'" % (tgl.strftime('%Y-%m-%d'),
                                              table_name)
            rst = [{
                'kid': r[0],
                'p': r[1],
                'u': r[2],
                'fid': r[3],
                'f': r[4]
            } for r in conn.queryAll(sql)]
            print rst
            return render_plain.adm.bendungan.kegiatan_paper(pos, tgl, rst)

        sql = "SELECT k.petugas, DATE(k.sampling), k.uraian, k.id \
                FROM kegiatan k, foto f \
                WHERE f.obj_type='kegiatan' AND k.id=f.obj_id \
                AND k.table_name='%s' AND YEAR(k.sampling)=%s \
                AND MONTH(k.sampling)=%s \
                ORDER BY DATE(k.sampling) DESC" % (table_name, tgl.year,
                                                   tgl.month)
        rows = [r for r in conn.queryAll(sql)]
        tgls = list(set(r[1] for r in rows))
        result = dict([(t, {}) for t in tgls])
        for r in rows:
            if r[0] in result[r[1]]:
                result[r[1]][r[0]].append({'uraian': r[2], 'kid': r[3]})
            else:
                result[r[1]][r[0]] = [{'uraian': r[2], 'kid': r[3]}]
        return render.adm.bendungan.kegiatan(
            dict(pos=pos,
                 urutan_kegiatan=sorted(result, reverse=True),
                 petugas=PETUGAS_CHOICES,
                 kegiatan=result,
                 tgl=tgl))
Esempio n. 6
0
 def POST(self, table_name):
     fi = web.input(rtow_file={})
     data = fi['rtow_file'].file.read()
     fname = '/tmp/' + table_name + '.csv'
     with open(fname, 'w') as f:
         f.write(data)
     data_in = import_rtow(fname)
     pos_id = data_in.get('pos_id')
     pos = AgentBd.get(pos_id)
     date_list = ','.join(
         ["'" + str(d.get('waktu')) + "'" for d in data_in.get('object')])
     for d in data_in.get('object'):
         try:
             wd = WadukDaily.select(
                 AND(WadukDaily.q.pos == pos,
                     WadukDaily.q.waktu == d.get('waktu')))[0]
             wd.set(**d)
         except IndexError:
             wd = WadukDaily(**d)
     return web.redirect('/adm/bendungan/rotw', absolute=True)
Esempio n. 7
0
 def GET(self, table_name, id=None):
     kerusakan_id = id
     if kerusakan_id:
         return "Detail kerusakan dengan ID " + id
     else:
         try:
             pos = AgentBd.get(BENDUNGAN_DICT.get(table_name))
         except:
             return web.notfound()
         tgl = datetime.date.today()
         kerusakan = Kerusakan.select(Kerusakan.q.table_name == table_name)
         kf = Kerusakan
         if session.is_admin == 3:  #user petugas bendungan
             return render.adm.bendungan.kerusakan.index({
                 'pos': pos,
                 'tgl': tgl,
                 'kerusakan': kerusakan,
                 'kf': kf
             })
         elif session.is_admin == 3 and not session.table_name:  #user upb
             return render.adm.bendungan.kerusakan.index({
                 'pos': pos,
                 'tgl': tgl,
                 'kerusakan': kerusakan,
                 'kf': kf
             })
         elif session.is_admin == 4:  #user peltek
             return render_peltek.adm.bendungan.kerusakan.index({
                 'pos':
                 pos,
                 'tgl':
                 tgl,
                 'kerusakan':
                 kerusakan,
                 'kf':
                 kf
             })