kopia lustrzana https://github.com/glidernet/ogn-python
Fixed SenderPositionStatistic
rodzic
f29e2a49be
commit
6648311a4f
|
@ -230,9 +230,10 @@ def sender_position_csv_strings_to_db(lines):
|
|||
|
||||
# Update sender position statistics
|
||||
cursor.execute(f"""
|
||||
INSERT INTO sender_position_statistics AS sps (date, dstcall, address_type, aircraft_type, stealth, software_version, hardware_version, messages_count)
|
||||
INSERT INTO sender_position_statistics AS sps (date, sender_id, dstcall, address_type, aircraft_type, stealth, software_version, hardware_version, messages_count)
|
||||
SELECT
|
||||
tmp.reference_timestamp::DATE AS date,
|
||||
s.id AS sender_id,
|
||||
tmp.dstcall,
|
||||
tmp.address_type,
|
||||
tmp.aircraft_type,
|
||||
|
@ -241,8 +242,9 @@ def sender_position_csv_strings_to_db(lines):
|
|||
tmp.hardware_version,
|
||||
COUNT(tmp.*) AS messages_count
|
||||
FROM {tmp_tablename} AS tmp
|
||||
GROUP BY date, dstcall, address_type, aircraft_type, stealth, software_version, hardware_version
|
||||
ON CONFLICT (date, dstcall, address_type, aircraft_type, stealth, software_version, hardware_version) DO UPDATE
|
||||
INNER JOIN senders AS s ON tmp.name = s.name
|
||||
GROUP BY date, sender_id, tmp.dstcall, tmp.address_type, tmp.aircraft_type, tmp.stealth, tmp.software_version, tmp.hardware_version
|
||||
ON CONFLICT (date, sender_id, dstcall, address_type, aircraft_type, stealth, software_version, hardware_version) DO UPDATE
|
||||
SET
|
||||
messages_count = EXCLUDED.messages_count + sps.messages_count;
|
||||
""")
|
||||
|
|
|
@ -21,4 +21,8 @@ class SenderPositionStatistic(db.Model):
|
|||
|
||||
messages_count = db.Column(db.Integer)
|
||||
|
||||
__table_args__ = (db.Index('idx_sender_position_statistics_uc', 'date', 'dstcall', 'address_type', 'aircraft_type', 'stealth', 'software_version', 'hardware_version', unique=True), )
|
||||
# Relations
|
||||
sender_id = db.Column(db.Integer, db.ForeignKey("senders.id", ondelete="CASCADE"), index=True)
|
||||
sender = db.relationship("Sender", foreign_keys=[sender_id], backref=db.backref("position_statistics", order_by=date.desc()))
|
||||
|
||||
__table_args__ = (db.Index('idx_sender_position_statistics_uc', 'date', 'sender_id', 'dstcall', 'address_type', 'aircraft_type', 'stealth', 'software_version', 'hardware_version', unique=True), )
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
"""Fix SenderPositionStatistic
|
||||
|
||||
Revision ID: eb571174e4b2
|
||||
Revises: 0dff4f629978
|
||||
Create Date: 2020-12-04 19:09:41.947668
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'eb571174e4b2'
|
||||
down_revision = '0dff4f629978'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('sender_position_statistics', sa.Column('sender_id', sa.Integer(), nullable=True))
|
||||
op.create_index(op.f('ix_sender_position_statistics_sender_id'), 'sender_position_statistics', ['sender_id'], unique=False)
|
||||
op.drop_index('idx_sender_position_statistics_uc', table_name='sender_position_statistics')
|
||||
op.create_index('idx_sender_position_statistics_uc', 'sender_position_statistics', ['date', 'sender_id', 'dstcall', 'address_type', 'aircraft_type', 'stealth', 'software_version', 'hardware_version'], unique=True)
|
||||
op.create_foreign_key(None, 'sender_position_statistics', 'senders', ['sender_id'], ['id'], ondelete='CASCADE')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'sender_position_statistics', type_='foreignkey')
|
||||
op.drop_index('idx_sender_position_statistics_uc', table_name='sender_position_statistics')
|
||||
op.create_index('idx_sender_position_statistics_uc', 'sender_position_statistics', ['date', 'dstcall', 'address_type', 'aircraft_type', 'stealth', 'software_version', 'hardware_version'], unique=True)
|
||||
op.drop_index(op.f('ix_sender_position_statistics_sender_id'), table_name='sender_position_statistics')
|
||||
op.drop_column('sender_position_statistics', 'sender_id')
|
||||
# ### end Alembic commands ###
|
Ładowanie…
Reference in New Issue