Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- __author__ = 'kozi'
- import pymysql.cursors
- import pymysql
- import time
- class Numeron():
- sensor_id = []
- measurement_time = []
- DATABASE_HOST = "db1.l"
- DATABASE_USER = "control"
- DATABASE_PASSWD = "dair4Ohsae1k"
- DATABASE_NAME = "control_production"
- DATABASE_PORT = 3306
- db = pymysql.connect(
- host=DATABASE_HOST,
- user=DATABASE_USER,
- passwd=DATABASE_PASSWD,
- db=DATABASE_NAME,
- port=int(DATABASE_PORT))
- dbconn = db.cursor()
- dbconn.execute("SELECT VERSION()")
- ver = dbconn.fetchone()
- dbconn.execute('SET NAMES utf8;')
- dbconn.execute('SET CHARACTER SET utf8;')
- dbconn.execute('SET character_set_connection=utf8;')
- #szukaj po 1.5.0 i 1.8.0 OBIS
- dbconn.execute("SELECT * FROM `measurement_device_sensor` WHERE `measurement_device_model_register_id` IN (1313,1343) AND `virtual_calculation` IS NOT NULL")
- time.sleep(0.1)
- rows = dbconn.fetchall()
- for row in rows:
- sensor_id.append(row[0])
- #print row[0]
- #db.close()
- print "ilosc sensorów 1.5.0 oraz 1.8.0 :", len(sensor_id)
- print "======================================"
- for i in range(len(sensor_id)):
- dbconn.execute("SELECT * FROM `energy_measurement` WHERE `measurement_device_sensor_id` = %d ORDER BY `energy_measurement`.`measurement_time` DESC LIMIT 1" % (sensor_id[i]))
- time.sleep(0.1)
- rows2 = dbconn.fetchall()
- for row2 in rows2:
- #measurement_time.append((sensor_id[i], row[2]))
- #print sensor_id[i], row2[2]
- measurement_time.append((sensor_id[i], str(row2[7])))
- print "======================================"
- db.close()
- #print sorted(measurement_time, key=lambda l:l[1])
- for x in range(len(sorted(measurement_time, key=lambda l:l[1]))):
- print sorted(measurement_time, key=lambda l:l[1])[x]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement