Created
September 19, 2015 23:54
-
-
Save Benhgift/71e854567f191bb8fb16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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