示例#1
0
    def GET(self):
        #return "development test"
        tanggal = web.input().get('d')
        if not tanggal:
            tanggal = datetime.date.today()
        else:
            try:
                tanggal = datetime.datetime.strptime(tanggal,
                                                     "%Y-%m-%d").date()
            except:
                tanggal = datetime.datetime.strptime(tanggal,
                                                     "%d %b %y").date()
        HIDE_THIS = [
            a.strip() for a in open('HIDE_AWLR.txt').read().split(',')
        ]
        agents = Agent.select(
            AND(OR(Agent.q.AgentType == HIDROLOGI, Agent.q.AgentType == 0),
                Agent.q.expose == True)).orderBy(["wilayah", "urutan"])
        agents = [a for a in agents if a.table_name not in HIDE_THIS]
        data = [
            Struct(**{
                'pos': a,
                'tma': Struct(**a.get_segmented_wl(tanggal))
            }) for a in agents
        ]
        js = """
        <script type="text/javascript">
        $(function(){
            $('.tanggal').datepicker({dateFormat: 'd M y'});
            $('.show-current-date').bind('change', function () {
             $(this).parent().submit()});
        });
        </script>"""
        sebelum = tanggal - datetime.timedelta(days=1)
        sesudah = tanggal + datetime.timedelta(days=1)

        # water level tertinggi
        sql = "SELECT MAX(pagi), agent_id, waktu FROM tma"
        res = Agent._connection.queryAll(sql)
        if res:
            try:
                (total, agent_id, waktu) = res[0]
                tertinggi = Struct(**{
                    'agent': Agent.get(agent_id),
                    'total': total,
                    'waktu': waktu
                })
            except IndexError:
                tertinggi = Struct()

        return render.tma.tma_diff(tma=data,
                                   meta={
                                       'now': tanggal.strftime('%d %b %y'),
                                       'before': sebelum.strftime('%d %b %y'),
                                       'after': sesudah.strftime('%d %b %y'),
                                       'tertinggi': tertinggi
                                   },
                                   wilayah=WILAYAH,
                                   js=js)
示例#2
0
    def GET(self):
        tanggal = web.input().get('d')
        if not tanggal:
            tanggal = datetime.date.today()
        else:
            try:
                tanggal = datetime.datetime.strptime(tanggal,
                                                     "%Y-%m-%d").date()
            except:
                tanggal = datetime.datetime.strptime(tanggal,
                                                     "%d %b %y").date()
        HIDE_THIS = [
            a.strip() for a in open('HIDE_AWLR.txt').read().split(',')
        ]
        agents = Agent.select(
            AND(OR(Agent.q.AgentType == HIDROLOGI, Agent.q.AgentType == 0),
                Agent.q.expose == True)).orderBy(["wilayah", "urutan"])
        agents = [a for a in agents if a.table_name not in HIDE_THIS]
        data = [
            Struct(**{
                'pos': a,
                'tma': Struct(**a.get_segmented_wl(tanggal))
            }) for a in agents
        ]
        js = """
        <script type="text/javascript">
        $(function(){
            $('.tanggal').datepicker({dateFormat: 'd M y'});
            $('.show-current-date').bind('change', function () {
             $(this).parent().submit()});
        });
        </script>"""
        sebelum = tanggal - datetime.timedelta(days=1)
        sesudah = tanggal + datetime.timedelta(days=1)
        if web.ctx.env.get('HTTP_X_PJAX') is not None:
            return render_plain.tma.index_table(
                tma=data,
                meta={
                    'now': tanggal.strftime('%d %b %y'),
                    'before': sebelum.strftime('%d %b %y'),
                    'after': sesudah.strftime('%d %b %y')
                },
                wilayah=WILAYAH)

        return render.tma.index(tma=data,
                                meta={
                                    'now': tanggal.strftime('%d %b %y'),
                                    'before': sebelum.strftime('%d %b %y'),
                                    'after': sesudah.strftime('%d %b %y')
                                },
                                wilayah=WILAYAH,
                                js=js)
示例#3
0
    def GET(self):
        tanggal = web.input().get('d')
        paper = web.input().get('paper', False)
        if not tanggal:
            tanggal = datetime.date.today()
        else:
            try:
                tanggal = datetime.datetime.strptime(tanggal,
                                                     "%Y-%m-%d").date()
            except:
                tanggal = datetime.datetime.strptime(tanggal,
                                                     "%d %b %y").date()
        BENDUNGAN = 3.0
        agents = Agent.select(Agent.q.AgentType == BENDUNGAN).orderBy(
            ('wilayah', 'urutan'))

        # Menambah field Kondisi bendungan
        #for a in agents:
        #    a.get_segmented_tma_bendungan(tanggal)

        data = [
            Struct(**{
                'pos': a,
                'tma': Struct(**a.get_segmented_tma_bendungan(tanggal))
            }) for a in agents
        ]
        js = """
        <script type="text/javascript">
        $(function(){
            $('.tanggal').datepicker({dateFormat: 'd M y'});
            $('.show-current-date').bind('change', function () {
                $(this).parent().submit()});
        });
        </script>"""
        sebelum = tanggal - datetime.timedelta(days=1)
        sesudah = tanggal + datetime.timedelta(days=1)

        template_render = render.bendungan.index
        if paper:
            template_render = render_plain.bendungan.harian_paper
        return template_render(bendungan=data,
                               meta={
                                   'now': tanggal.strftime('%d %b %y'),
                                   'before': sebelum.strftime('%d %b %y'),
                                   'after': sesudah.strftime('%d %b %y')
                               },
                               wilayah=WILAYAH,
                               js=js)
示例#4
0
    def GET(self, tahun=None, bulan=None):
        skr = datetime.date.today()
        data = []
        try:
            tahun = int(tahun)
        except:
            tahun = skr.year

        try:
            bulan = int(bulan)
        except:
            bulan = skr.month
        (a, z) = calendar.monthrange(tahun, bulan)
        next_month = datetime.date(tahun, bulan,
                                   z) + datetime.timedelta(days=1)
        prev_month = datetime.date(tahun, bulan,
                                   1) - datetime.timedelta(days=2)

        tdata = dict([(i, dict(telemetri=None, total=None, manual=None))
                      for i in range(0, z)])
        for a in AgentCh.select(
                AND(
                    OR(AgentCh.q.AgentType == KLIMATOLOGI,
                       AgentCh.q.AgentType == 0),
                    AgentCh.q.expose == True)).orderBy(["wilayah", "cname"]):
            sql = "SELECT DAY(waktu), pagi+sore+malam AS telemetri, total, manual \
                FROM curahhujan WHERE agent_id=%s AND \
                YEAR(waktu)=%s AND MONTH(waktu)=%s" % (a.AgentId, tahun, bulan)
            rst = AgentCh._connection.queryAll(sql)
            tdata.update(
                dict([(r[0],
                       Struct(**dict(telemetri=r[1], total=r[2], manual=r[3])))
                      for r in rst]))
            data.append(
                Struct(**dict(
                    AgentName=a.AgentName, wilayah=a.wilayah, data=tdata)))
        ctx = dict(curr_month=datetime.date(tahun, bulan, 1),
                   data=data,
                   wilayah=WILAYAH,
                   numdays=z + 1,
                   prev_month=prev_month,
                   next_month=next_month)
        return render_fluid.curahhujan.human.index(ctx)
示例#5
0
    def curah_hujan_pos(self,
                        pos_id,
                        tahun=datetime.date.today().year,
                        bulan=''):
        '''
        Jika bulan valid, otomatis tahun juga valid,
          tampilkan curah hujan setiap hari pada bulan terpilih
          sumbu mendatar berisi tanggal
        Jika tahun valid, bulan kosong, tampilkan curah hujan 3 tahun lalu,
          dari tahun terpilih, sumbu mendatar berisi bulan-bulan
        '''
        try:
            agent = AgentCh.get(pos_id)
        except SQLObjectNotFound:
            return web.notfound()
        if agent.AgentType not in (1.0, 0.0):
            return web.notfound()
        ch = agent.get_ch(tahun, bulan)
        data = []
        for a in ch:
            try:
                data.append((a[0], a[2] or 0))
            except:
                data.append((a[0], 0))
        series = {}
        to_render = render.curahhujan.bulanan
        if bulan:
            # hujan per hari pada 'bulan'
            series = [
                0 for r in range(calendar.monthrange(tahun, int(bulan))[1])
            ]
            sql = "SELECT waktu, manual, pagi, sore, malam, tmalam FROM curahhujan \
                    WHERE agent_id=%s AND YEAR(waktu)=%s AND MONTH(waktu)=%s" % (
                pos_id, tahun, bulan)

            for d in conn.queryAll(sql):
                series[d[0].day - 1] = d[1]
            data = Struct(
                **{
                    'series': series,
                    'categories': [s + 1 for s in range(len(series))],
                    'bulan': datetime.date(tahun, int(bulan), 1)
                })
            to_render = render.curahhujan.harian
        elif data:
            print data
            # hujan per bulan pada 'tahun'
            th = data[0][0].year
            series[th] = [0 for r in range(0, 12)]
            for d in data:
                if d[0].year != th:
                    th = d[0].year
                    series[th] = [0 for r in range(0, 12)]
                    series[th][d[0].month - 1] = d[1]
                else:
                    series[th][d[0].month - 1] = d[1]
            data = [
                Struct(**{
                    'tahun': k,
                    'series': v
                }) for k, v in sorted(series.items())
            ]
        ctx = {'pos': agent, 'data': data}
        return to_render(ctx)
示例#6
0
    def curah_hujan_pos(self,
                        pos_id,
                        tahun=datetime.date.today().year,
                        bulan=''):
        '''
        Jika bulan valid, otomatis tahun juga valid,
          tampilkan curah hujan setiap hari pada bulan terpilih
          sumbu mendatar berisi tanggal
        Jika tahun valid, bulan kosong, tampilkan curah hujan 3 tahun lalu,
          dari tahun terpilih, sumbu mendatar berisi bulan-bulan
        '''
        try:
            agent = AgentCh.get(pos_id)
        except SQLObjectNotFound:
            return web.notfound()
        if agent.AgentType not in (1.0, 0.0):
            return web.notfound()
        HIDE_THIS = [a.strip() for a in open('HIDE_ARR.txt').read().split(',')]
        agents = AgentCh.select(
            AND(
                OR(AgentCh.q.AgentType == KLIMATOLOGI,
                   AgentCh.q.AgentType == 0.0),
                AgentCh.q.expose == True)).orderBy((
                    'wilayah',
                    'urutan',
                ))
        agents = [a for a in agents if a.table_name not in HIDE_THIS]
        ch = agent.get_ch(tahun, bulan)
        data = []
        for a in ch:
            try:
                data.append((a[0], a[2] or 0))
            except:
                data.append((a[0], 0))
        series = {}
        to_render = render.curahhujan.bulanan
        if bulan:
            # hujan per hari pada 'bulan'
            series = [
                0 for r in range(calendar.monthrange(tahun, int(bulan))[1])
            ]
            sql = "SELECT waktu, manual, pagi, sore, malam, tmalam FROM curahhujan \
                    WHERE agent_id=%s AND YEAR(waktu)=%s AND MONTH(waktu)=%s" % (
                pos_id, tahun, bulan)

            for d in conn.queryAll(sql):
                series[d[0].day - 1] = d[1]
            data = Struct(
                **{
                    'series': series,
                    'categories': [s + 1 for s in range(len(series))],
                    'bulan': datetime.date(tahun, int(bulan), 1)
                })
            to_render = render.curahhujan.harian
        elif data:
            # hujan per bulan pada 'tahun'
            th = data[0][0].year
            series[th] = [0 for r in range(0, 12)]
            for d in data:
                if d[0].year != th:
                    th = d[0].year
                    series[th] = [0 for r in range(0, 12)]
                    series[th][d[0].month - 1] = d[1]
                else:
                    series[th][d[0].month - 1] = d[1]
            data = [
                Struct(**{
                    'tahun': k,
                    'series': v
                }) for k, v in sorted(series.items())
            ]
        ctx = {'pos': agent, 'data': data, 'poses': agents, 'wilayah': WILAYAH}
        return to_render(ctx)