Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. __author__ = 'kozi'
  4.  
  5. import pymysql.cursors
  6. import pymysql
  7. import time
  8.  
  9. class Numeron():
  10.  
  11.     sensor_id = []
  12.     measurement_time = []
  13.  
  14.     DATABASE_HOST = "db1.l"
  15.     DATABASE_USER = "control"
  16.     DATABASE_PASSWD = "dair4Ohsae1k"
  17.     DATABASE_NAME = "control_production"
  18.     DATABASE_PORT = 3306
  19.  
  20.     db = pymysql.connect(
  21.         host=DATABASE_HOST,
  22.         user=DATABASE_USER,
  23.         passwd=DATABASE_PASSWD,
  24.         db=DATABASE_NAME,
  25.         port=int(DATABASE_PORT))
  26.     dbconn = db.cursor()
  27.     dbconn.execute("SELECT VERSION()")
  28.     ver = dbconn.fetchone()
  29.  
  30.     dbconn.execute('SET NAMES utf8;')
  31.     dbconn.execute('SET CHARACTER SET utf8;')
  32.     dbconn.execute('SET character_set_connection=utf8;')
  33.  
  34.     #szukaj po 1.5.0 i 1.8.0 OBIS
  35.     dbconn.execute("SELECT * FROM `measurement_device_sensor` WHERE `measurement_device_model_register_id` IN (1313,1343) AND `virtual_calculation` IS NOT NULL")
  36.     time.sleep(0.1)
  37.     rows = dbconn.fetchall()
  38.     for row in rows:
  39.         sensor_id.append(row[0])
  40.         #print row[0]
  41.  
  42.     #db.close()
  43.  
  44.     print "ilosc sensorów 1.5.0 oraz 1.8.0 :", len(sensor_id)
  45.     print "======================================"
  46.  
  47.     for i in range(len(sensor_id)):
  48.         dbconn.execute("SELECT *  FROM `energy_measurement` WHERE `measurement_device_sensor_id` = %d ORDER BY `energy_measurement`.`measurement_time` DESC LIMIT 1" % (sensor_id[i]))
  49.         time.sleep(0.1)
  50.         rows2 = dbconn.fetchall()
  51.         for row2 in rows2:
  52.             #measurement_time.append((sensor_id[i], row[2]))
  53.             #print sensor_id[i], row2[2]
  54.             measurement_time.append((sensor_id[i], str(row2[7])))
  55.  
  56.     print "======================================"
  57.     db.close()
  58.  
  59.     #print sorted(measurement_time, key=lambda l:l[1])
  60.  
  61.     for x in range(len(sorted(measurement_time, key=lambda l:l[1]))):
  62.         print sorted(measurement_time, key=lambda l:l[1])[x]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement