Skip to content

Instantly share code, notes, and snippets.

@Benhgift
Created September 19, 2015 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Benhgift/71e854567f191bb8fb16 to your computer and use it in GitHub Desktop.
Save Benhgift/71e854567f191bb8fb16 to your computer and use it in GitHub Desktop.
import sqlite3 as sq
import numpy as np
from scipy.interpolate import spline
from matplotlib import pylab
def insert_data(c):
c.execute('create table if not exists sleep (hours_slept INT)')
print("How much sleep did ya get")
user_input = input()
c.execute('insert into sleep values ({})'.format(user_input))
c.commit()
def plot_sleep(x, y):
pylab.plot(x, y)
pylab.xlabel('days')
pylab.ylabel('sleep (h)')
pylab.grid(True)
pylab.ylim(ymin=0, ymax=15)
pylab.show()
def run():
c = sq.connect('my_data.db')
insert_data(c)
points = [i[0] for i in c.execute('SELECT * FROM sleep')]
print(points)
x = np.linspace(0, len(points)-1, (len(points)-1)*1000)
y = spline(range(len(points)), points, x)
c.close()
plot_sleep(x, y)
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment