From c4def899c78548c87ea7d8bf5661475dbea80879 Mon Sep 17 00:00:00 2001 From: Alex Danamir Date: Fri, 31 May 2024 22:12:59 +0300 Subject: [PATCH] add pereodic func --- app.py | 6 ++- migrations/README | 1 + migrations/versions/b52c8dd65906_.py | 46 ++++++++++++++++++ models.py | 15 ++++++ pereodicFunc.py | 43 +++++++++++++++++ templates/index.html | 71 +++++++++++++++++++++++++++- 6 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 migrations/README create mode 100644 migrations/versions/b52c8dd65906_.py create mode 100644 pereodicFunc.py diff --git a/app.py b/app.py index fbb4d50..f284241 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,7 @@ from flask import Flask, render_template, request, redirect, url_for from flask_migrate import Migrate from models import db, Data - +from threading import Timer app = Flask(__name__) @@ -15,6 +15,10 @@ db.init_app(app) migrate = Migrate(app, db) + +def calculateAverageper(): + pass + def createDb(): with app.app_context(): db.create_all() diff --git a/migrations/README b/migrations/README new file mode 100644 index 0000000..0e04844 --- /dev/null +++ b/migrations/README @@ -0,0 +1 @@ +Single-database configuration for Flask. diff --git a/migrations/versions/b52c8dd65906_.py b/migrations/versions/b52c8dd65906_.py new file mode 100644 index 0000000..8af4545 --- /dev/null +++ b/migrations/versions/b52c8dd65906_.py @@ -0,0 +1,46 @@ +"""empty message + +Revision ID: b52c8dd65906 +Revises: +Create Date: 2024-05-31 11:30:48.526961 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'b52c8dd65906' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('averageperday', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('temp1', sa.Float(), nullable=False), + sa.Column('vlaz1', sa.Float(), nullable=False), + sa.Column('temp2', sa.Float(), nullable=False), + sa.Column('vlaz2', sa.Float(), nullable=False), + sa.Column('addTime', sa.DateTime(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('averageperhour', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('temp1', sa.Float(), nullable=False), + sa.Column('vlaz1', sa.Float(), nullable=False), + sa.Column('temp2', sa.Float(), nullable=False), + sa.Column('vlaz2', sa.Float(), nullable=False), + sa.Column('addTime', sa.DateTime(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('averageperhour') + op.drop_table('averageperday') + # ### end Alembic commands ### diff --git a/models.py b/models.py index 84ef6f9..ea9bd11 100644 --- a/models.py +++ b/models.py @@ -11,3 +11,18 @@ class Data(db.Model): temp2 = db.Column(db.Float, nullable=False) vlaz2 = db.Column(db.Float, nullable=False) addTime = db.Column(db.DateTime, nullable=False) + +class averageperhour(db.Model): + id = db.Column(db.Integer, primary_key=True) + temp1 = db.Column(db.Float, nullable=False) + vlaz1 = db.Column(db.Float, nullable=False) + temp2 = db.Column(db.Float, nullable=False) + vlaz2 = db.Column(db.Float, nullable=False) + + +class averageperday(db.Model): + id = db.Column(db.Integer, primary_key=True) + temp1 = db.Column(db.Float, nullable=False) + vlaz1 = db.Column(db.Float, nullable=False) + temp2 = db.Column(db.Float, nullable=False) + vlaz2 = db.Column(db.Float, nullable=False) \ No newline at end of file diff --git a/pereodicFunc.py b/pereodicFunc.py new file mode 100644 index 0000000..87e1381 --- /dev/null +++ b/pereodicFunc.py @@ -0,0 +1,43 @@ +from models import db, Data, averageperhour, averageperday +from app import app +import statistics + + +def avph(offset, count): + offset = int(offset) + count = int(count) + + for i in range(100): + offset = i*6 + print(offset) + with app.app_context(): + data = db.session.query(Data).order_by(Data.id.desc()).slice(offset, offset + count).all() + print(data) + tmp1dict = [] + hum1dict = [] + tmp2dict = [] + hum2dict = [] + + for item in data: + tmp1dict.append(item.temp1) + hum1dict.append(item.vlaz1) + tmp2dict.append(item.temp2) + hum2dict.append(item.vlaz2) + + temp1average = statistics.mean(tmp1dict) + hum1average = statistics.mean(hum1dict) + temp2average = statistics.mean(tmp2dict) + hum2average = statistics.mean(hum2dict) + + newData = db.session.add(averageperhour( + temp1=temp1average, + vlaz1=hum1average, + temp2=temp2average, + vlaz2=hum2average + )) + db.session.commit() + print(i) + + +if __name__ == '__main__': + avph(6, 6) diff --git a/templates/index.html b/templates/index.html index aaebc11..330ea65 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,7 +4,76 @@ Метостанция + + + + + + + + + + + + + + + + + + +
Column 1Column 2
Row 1, Col 1Row 1, Col 2
Row 2, Col 1Row 2, Col 2
Row 3, Col 1Row 3, Col 2
+
+ + + + + + + + + + + + + + + + + +
Column 1Column 2
Row 1, Col 1Row 1, Col 2
Row 2, Col 1Row 2, Col 2
Row 3, Col 1Row 3, Col 2
+ + + + + + + + + + Two Tables + + - \ No newline at end of file +