add pereodic func

This commit is contained in:
2024-05-31 22:12:59 +03:00
parent 85d6145df2
commit c4def899c7
6 changed files with 180 additions and 2 deletions

6
app.py
View File

@@ -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()

1
migrations/README Normal file
View File

@@ -0,0 +1 @@
Single-database configuration for Flask.

View File

@@ -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 ###

View File

@@ -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)

43
pereodicFunc.py Normal file
View File

@@ -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)

View File

@@ -4,6 +4,75 @@
<meta charset="UTF-8">
<title>Метостанция </title>
</head>
<body>
<table>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
<tr>
<td>Row 1, Col 1</td>
<td>Row 1, Col 2</td>
</tr>
<tr>
<td>Row 2, Col 1</td>
<td>Row 2, Col 2</td>
</tr>
<tr>
<td>Row 3, Col 1</td>
<td>Row 3, Col 2</td>
</tr>
</table>
<br>
<table>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
<tr>
<td>Row 1, Col 1</td>
<td>Row 1, Col 2</td>
</tr>
<tr>
<td>Row 2, Col 1</td>
<td>Row 2, Col 2</td>
</tr>
<tr>
<td>Row 3, Col 1</td>
<td>Row 3, Col 2</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Two Tables</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
table {
margin: 0 auto;
border-collapse: collapse;
background-color: #fff;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
</body>