Skip to content

Instantly share code, notes, and snippets.

View masasa27's full-sized avatar

masasa masasa27

View GitHub Profile
@masasa27
masasa27 / alpha_beta_filter.py
Last active February 2, 2020 22:11
AlphaBetaFilter example
class Sample:
def __init__(self, x, t):
self.location = x
self.time = t
def __repr__(self):
return f"Sample({self.location}, {self.time})"
class AlphaBetaFilter:
@masasa27
masasa27 / Sample.py
Created February 2, 2020 22:09
Sample Class Exanple
class Sample:
def __init__(self, x, t):
self.location = x
self.time = t
def __repr__(self):
return f"Sample({self.location}, {self.time})"
@masasa27
masasa27 / samples.py
Created February 2, 2020 22:14
alpha_beta_data
import numpy as np
pie_x = np.linspace(0, np.pi * 3, 50)
t_loc = np.sin(pie_x)
error_loc = t_loc * (np.random.randint(950, 1050, 50) / 1000.0) # creates error in data
samples = [Sample(loc, t) for t, loc in enumerate(error_loc)] # create samples list
@masasa27
masasa27 / tracker.py
Created February 2, 2020 22:15
tracket.py
tracker = AlphaBetaFilter(samples[0], alpha=0.85, beta=0.5, velocity=0.5) # initiate a tracker
for sample in samples[1:]:
tracker.add_sample(sample) # tracking in "real time"
@masasa27
masasa27 / sqlite3_python.py
Created February 2, 2020 22:18
sqlite init
import sqlite3
import pandas as pd
with sqlite3.connect('example.db') as conn:
cursor = conn.cursor()
@masasa27
masasa27 / insert_sqllite3.py
Created February 2, 2020 22:19
insert staement
fields = "id, street, size, number_of_rooms, parking, price"
query = f"create TABLE HOME_PRICES ({fields})"
cursor.execute(query)
houses = [
(1, 'first', 110, 4, 1, 100000),
(2, 'second', 90, 3, 0, 65000),
(3, 'second', 90, 3, 1, 72000)
]
cursor.executemany('insert into HOME_PRICES values (?, ?, ?, ?, ?, ?)', houses)
#cursor.executemany receives an iterable for multiple executions
with sqlite3.connect('example.db') as conn:
cursor = conn.cursor()
# Changed inside the Database
conn.commit()
with sqlite3.connect('example.db') as conn:
df = pd.read_sql("select * from HOME_PRICES", conn)
print(df)
with sqlite3.connect('example.db') as conn:
# creating a cursor
cursor = conn.cursor()
# reading your own data
df = pd.read_csv("your_csv.csv")
# inserting data
rows = [row for name, row in df.iterrows()]