Exemplo n.º 1
0
 def kwh(self, meter, start_date, finish_date):
     sum_kwh = 0
     code = 'complete-data'
     first_read = Read.gql("""where meter = :1 and read_date <= :2 order by
             read_date desc""", meter, start_date).get()
     if first_read is None:
         code = 'partial-data'
     last_read = Read.gql("""where meter = :1 and read_date >= :2 order by
             read_date""", meter, finish_date).get()
     if last_read is None:
         code = 'partial-data'
         q_finish = finish_date
     else:
         q_finish = last_read.read_date
     for read in Read.gql(
             "where meter = :1 and read_date > :2 and read_date <= :3 "
             "order by read_date", meter, start_date, q_finish):
         if first_read is not None:
             rate = (read.value - first_read.value) / \
                 self.total_seconds(read.read_date - first_read.read_date)
             sum_kwh += rate * max(
                 self.total_seconds(
                     min(read.read_date, finish_date) -
                     max(first_read.read_date, start_date)), 0)
         first_read = read
     return {'kwh': sum_kwh, 'code': code, 'start_date': start_date,
             'finish_date': finish_date}
Exemplo n.º 2
0
    def page_fields(self, meter, current_reader, message=None):
        reads = Read.gql(
            "where meter = :1 order by read_date desc", meter).fetch(30)
        now = meter.get_tzinfo().localize(datetime.datetime.now())

        return {'meter': meter, 'reads': reads, 'now': now,
                'candidate_customer_read': meter.candidate_customer_read(),
                'message': message}
Exemplo n.º 3
0
    def get(self):
        meter_key = self.get_str("meter_key")
        meter = Meter.get_meter(meter_key)
        if meter.is_public:
            current_reader = self.find_current_reader()
        else:
            current_reader = self.require_current_reader()
            if current_reader.key() != meter.reader.key():
                self.return_forbidden()

        reads = Read.gql(
            "where meter = :1 order by read_date desc", meter).fetch(1000)
        self.return_ok(
            {
                'reads': reads,
                'template_name': 'export_reads.csv',
                'content_disposition': 'attachment; filename=reads.csv;'})
Exemplo n.º 4
0
    def get(self):
        meters = {}
        public_reads = []

        for read in Read.gql("order by read_date desc limit 50"):
            meter = read.meter
            if not meter.is_public or str(meter.key()) in meters:
                continue
            meters[str(meter.key())] = meter
            public_reads.append(read)
            if len(public_reads) > 20:
                break

        fields = {'public_reads': public_reads}
        current_reader = self.find_current_reader()
        if current_reader is not None:
            reader_meters = Meter.gql(
                "where reader = :1", current_reader).fetch(10)
            fields['meters'] = reader_meters
            fields['candidate_customer_reads'] = [
                cand for cand in [
                    mtr.candidate_customer_read() for mtr in reader_meters]
                if cand is not None]
        self.return_ok(fields)