Ejemplo n.º 1
0
    def add(self, device):
        try:
            data = watch.get_data(device)
        except serial.serialutil.SerialException as err:
            print ('SerialException: '), err
            raise DataError("no data received")
        except watch.CommunicationsException as err:
            print ("CommunicationsException: "), err
            raise DataError("no data received")
        else:
            if double_entry(data, self.list(1)):
                raise DataError("the entry has already been added.")

            if not check_data(data):
                raise DataError("received data not valid.")

            cur = self.con.cursor()
            cur.execute(self._sql_insert_table1
                        % (data.year, data.month, data.day, data.alarm[0],
                          data.alarm[1], data.window, data.tobed[0],
                          data.tobed[1], -1.0))
            rowid = cur.lastrowid
            for i in range(len(data.awakemoments[0])):
                cur.execute(self._sql_insert_table2
                            % (rowid, data.awakemoments[0][i],
                              data.awakemoments[1][i]))
                cur.execute(self._sql_update_table1_dataa
                            % (compute_dataA(data.tobed[0], data.tobed[1],
                                            data.awakemoments), rowid))
                self.con.commit()

            return(self.list(1))
Ejemplo n.º 2
0
    def load_data():
        data = watch.get_data()
        # removing temporal generated data
        remove_pyc = os.system('rm src/*.pyc')
        print data

        return data
Ejemplo n.º 3
0
def main():
    print "CS 434 Final"

    # Example of reading training data
    X = get_data((1, 4))
    # print np.asmatrix(X[198][0:35]).reshape(7,5)

    # Example of reading samples
    # samples = get_samples((5,))
    # print np.asmatrix(samples[0][0:35]).reshape(7,5)

    # Example of reading testing data
    # T = get_testing_data('general')
    # print np.asmatrix(T[3][0:35]).reshape(7,5)

    # -------

    tree = DecisionTree(X, 6)
    tree.print_tree()

    my_knn = KNN(X)
    predictions = my_knn.get_predictions(X)

    X = get_data((1, 4, 6, 9))
    training = get_subsample(X, 1000, 9000)
    validation = get_subsample(X, 100, 900)

    # perceptron = Perceptron(sub_x)
    # write_predictions(perceptron.training_predictions)
    # print len([p[0,1] for p in perceptron.training_predictions if p[0,1] > 0])

    # lr = logistic_regression.LogisticRegression(X)
    # lr.run()

    samples = get_samples((1, 2, 3, 4, 5))
    predictions = tree.get_predictions(samples)
Ejemplo n.º 4
0
  def GET(self):
    params = web.input(refresh=False, suffix='')
    global CACHE, LAST_CACHE_UPDATE, CACHE_VALIDITY
    cache_expired = (datetime.utcnow() - LAST_CACHE_UPDATE).seconds/60 >= CACHE_VALIDITY if LAST_CACHE_UPDATE else False
    if params.refresh or not CACHE or cache_expired:
      if cache_expired:
        print('cache expired (' + str(CACHE_VALIDITY) + ' min), last updated at ' + str(LAST_CACHE_UPDATE))
      # TO-DO: install/use postgres client and directly query/return this data
      if 0 != subprocess.call(os.getcwd() + '/export_data.sh ' + params.suffix, shell=True):
        print('error refreshing data')
        raise Exception
      CACHE = format_data.get_data(suffix=params.suffix)
      LAST_CACHE_UPDATE = datetime.utcnow()
    else:
      print('using cache from ' + str(LAST_CACHE_UPDATE))

    return json.dumps(CACHE, sort_keys=True)
Ejemplo n.º 5
0
print 'http://launchpad.net/~PySleep-Devs'
print 'This program comes with ABSOLUTELY NO WARRANTY; see COPYRIGHT for more information'
print 'This is free software, and you are welcome to redistribute it under certain conditions; see COPYING for more information'
print

logging_in = login()
del logging_in

print
print _('Fetching data from the watch...')
print

gotData = False
while not gotData:
    try:
        data = watch.get_data()
        remove_pyc = os.system('rm src/*.pyc')

        print
        print _('Transferring data to browser...')
        print
        submit_to_browser = submit_data(data.alarm, data.window, data.tobed, data.awakemoments)
        del submit_to_browser
        print '-------------------------------'
        print '----------- PySleep -----------'
        print '-------------------------------'

        gotData = True

    except serial.SerialException as detail:
        print _('Error:'), detail
Ejemplo n.º 6
0
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>
#
######################################################################
#
# You can purchase your Sleeptracker from
#
# http://www.sleeptracker.de
# http://www.sleeptracker.fr
# ... and some other stores
#

import format_data as fd
test = fd.get_data()
print "Datum: %.2d.%.2d.%.4d" % (test.day, test.month, test.year)
print "Weckzeit: %.2d:%.2d" % (test.alarm[0], test.alarm[1])
print "Weckfenster: %.2d" % test.window
print "ToBed-Zeit: %.2d:%.2d" % (test.tobed[0], test.tobed[1])
if len(test.awakemoments[0]) == 0:
    print "Keine Wachmomente aufgezeichnet."
else:
    for i, x in enumerate(test.awakemoments[0]):
        print "Data %.2d: %.2d:%.2d" % (i, x, test.awakemoments[1][i])