-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgendata.py
More file actions
42 lines (29 loc) · 883 Bytes
/
gendata.py
File metadata and controls
42 lines (29 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Generate some data and put in it a database.
This is to have a data source from which to then run a bokeh visualization.
"""
from time import sleep
from sqlalchemy import create_engine, Column, Integer, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import numpy as np
engine = create_engine("sqlite:///test.sqlite")
Session = sessionmaker(engine)
session = Session()
Base = declarative_base()
class DataPt(Base):
__tablename__ = "testdata"
idx = Column(Integer, primary_key=True)
val = Column(Float)
Base.metadata.create_all(engine)
def main():
index = 0
value = 0.0
while True:
index += 1
value += np.random.uniform(0, 1)
dat = DataPt(idx=index, val=value)
session.add(dat)
session.commit()
sleep(1)
if __name__ == "__main__":
main()