def fit(self, csv_file):
    db = sqlite3.connect(':memory:')
    c = db.cursor()
    try:
        c.execute('CREATE TABLE data (loc TEXT, mac TEXT, val INTEGER, count INTEGER)')
        db.commit()
    except sqlite3.OperationalError:
        pass
    headers = []
    with open(csv_file, 'r') as f:
        for (i, line) in enumerate(tqdm(f, total=get_num_lines(csv_file))):
            line = line.strip()
            if (i == 0):
                headers = line.split(',')
                continue
            loc = ''
            for (j, signal) in enumerate(line.split(',')):
                if (j == 0):
                    loc = signal
                    continue
                if (signal.strip() == ''):
                    continue
                mac = headers[j]
                val = int(round(float(signal.strip())))
                c.execute('SELECT count FROM data WHERE loc = ? AND mac = ? AND val = ?', (loc, mac, val))
                count = c.fetchone()
                if (count == None):
                    c.execute('INSERT INTO data(loc,mac,val,count)\n                          VALUES(?,?,?,?)', (loc, mac, val, 1))
                else:
                    c.execute('UPDATE data SET count = ? WHERE loc = ? AND mac = ? AND val = ?', ((count[0] + 1), loc, mac, val))
                db.commit()
    f = tempfile.TemporaryFile()
    for line in db.iterdump():
        f.write('{}\n'.format(line).encode('utf-8'))
    db.close()
    try:
        os.remove(self.db_name)
    except:
        pass
    db = sqlite3.connect(self.db_name)
    c = db.cursor()
    f.seek(0)
    c.executescript(f.read().decode('utf-8'))
    f.close()
    db.commit()
    db.close()
def fit(self, csv_file):
    db = sqlite3.connect(':memory:')
    c = db.cursor()
    try:
        c.execute('CREATE TABLE data (loc TEXT, mac TEXT, val INTEGER, count INTEGER)')
        db.commit()
    except sqlite3.OperationalError:
        pass
    headers = []
    with open(csv_file, 'r') as f:
        for (i, line) in enumerate(tqdm(f, total=get_num_lines(csv_file))):
            line = line.strip()
            if (i == 0):
                headers = line.split(',')
                continue
            loc = 
            for (j, signal) in enumerate(line.split(',')):
                if (j == 0):
                    loc = signal
                    continue
                if (signal.strip() == ):
                    continue
                mac = headers[j]
                val = int(round(float(signal.strip())))
                c.execute('SELECT count FROM data WHERE loc = ? AND mac = ? AND val = ?', (loc, mac, val))
                count = c.fetchone()
                if (count == None):
                    c.execute('INSERT INTO data(loc,mac,val,count)\n                          VALUES(?,?,?,?)', (loc, mac, val, 1))
                else:
                    c.execute('UPDATE data SET count = ? WHERE loc = ? AND mac = ? AND val = ?', ((count[0] + 1), loc, mac, val))
                db.commit()
    f = tempfile.TemporaryFile()
    for line in db.iterdump():
        f.write('{}\n'.format(line).encode('utf-8'))
    db.close()
    try:
        os.remove(self.db_name)
    except:
        pass
    db = sqlite3.connect(self.db_name)
    c = db.cursor()
    f.seek(0)
    c.executescript(f.read().decode('utf-8'))
    f.close()
    db.commit()
    db.close()