retunk metrics
This commit is contained in:
parent
8d684856c9
commit
e8bed9a381
53
exporto.py
53
exporto.py
@ -1,32 +1,13 @@
|
||||
from sqlalchemy import create_engine, Integer, String, BIGINT, Column, DateTime
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy import select, update
|
||||
|
||||
|
||||
|
||||
from flask import Flask
|
||||
|
||||
#### https://docs.python-arango.com/en/main/
|
||||
from arango import ArangoClient
|
||||
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
engine = create_engine('postgresql+psycopg2://postgres:postgres@postgres.vdk2ch.ru:5432/jack_bot', echo=True)
|
||||
Session = sessionmaker(bind=engine)
|
||||
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
|
||||
class user(Base):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer)
|
||||
user_fullname = Column(String)
|
||||
dick_size = (Column(Integer))
|
||||
datetimes = (Column(DateTime))
|
||||
chat_id = Column(BIGINT)
|
||||
|
||||
|
||||
|
||||
@ -34,14 +15,21 @@ class user(Base):
|
||||
def get_top_dicks():
|
||||
|
||||
|
||||
session = Session()
|
||||
arango_client = ArangoClient(hosts='https://arango.vdk2ch.ru')
|
||||
pipisa_db = arango_client.db('pipisa', username='root', password='stolendick527')
|
||||
dicks_collection = pipisa_db.collection('dicks')
|
||||
|
||||
top = session.query(user.user_fullname, user.dick_size, user.user_id, user.chat_id).order_by(user.dick_size.desc()).all()
|
||||
dicks = dicks_collection.all( )
|
||||
dicks = [[
|
||||
d['user_fullname'],
|
||||
d['dick_size'],
|
||||
d['user_id'],
|
||||
d['chat_id'],
|
||||
d['attempts'],
|
||||
] for d in dicks]
|
||||
|
||||
|
||||
session.close()
|
||||
|
||||
return top
|
||||
return dicks
|
||||
|
||||
|
||||
|
||||
@ -56,6 +44,10 @@ def metrics():
|
||||
for dick in docks:
|
||||
metrics += 'pipisio{user="%s", user_id="%s", chat_id="%s"} %s\n' % (dick[0], dick[2], dick[3], dick[1])
|
||||
|
||||
# текущее число попыток
|
||||
for dick in docks:
|
||||
metrics += 'pipisio_attempto{user="%s", user_id="%s", chat_id="%s"} %s\n' % (dick[0], dick[2], dick[3], dick[4])
|
||||
|
||||
# расстояние до следующего впереди
|
||||
for k in range(len(docks)):
|
||||
|
||||
@ -75,6 +67,7 @@ def metrics():
|
||||
|
||||
return metrics
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=9992)
|
||||
engine.dispose()
|
Loading…
Reference in New Issue
Block a user