Best Python code snippet using fMBT_python
models.py
Source:models.py
1"""Class for user and bookmark template"""2#from app import DB3def get_users(d_b):4 """This function fetches users table.5 Prevents a cyclical import"""6 class Users(d_b.Model):7 """Can create a Person with username and score. Letter won't be used"""8 id = d_b.Column(d_b.String(80), primary_key=True)9 email = d_b.Column(d_b.String(80), unique=True, nullable=False)10 firstName = d_b.Column(d_b.String, unique=False, nullable=False)11 familyName = d_b.Column(d_b.String(80), unique=False, nullable=False)12 imageURL = d_b.Column(d_b.String(80), unique=False, nullable=True)13 def __repr__(self):14 '''This function returns the users class'''15 return '<User %r>' % self.id16 return Users17def get_bookmarks(d_b):18 """Fetches Bookmarks Table"""19 class Bookmarks(d_b.Model):20 """Can create a Bookmark with username and event_id"""21 id = d_b.Column(d_b.Integer, primary_key=True)22 clientId = d_b.Column(d_b.String(80), unique=False, nullable=False)23 event_id = d_b.Column(d_b.String(80), unique=False, nullable=False)24 def __repr__(self):25 return '<Bookmark %r>' % self.id26 return Bookmarks27def get_likes_dislikes(d_b):28 '''Can create DB with eventID, num of likes and dislikes'''29 class LikesDislikes(d_b.Model):30 '''Can create DB with eventID, num of likes and dislikes'''31 eventID = d_b.Column(d_b.String(80), primary_key=True)32 likes = d_b.Column(d_b.Integer, nullable=False)33 dislikes = d_b.Column(d_b.Integer, nullable=False)34 def __repr__(self):35 return '<LikesDislikes %r>' % self.eventID36 return LikesDislikes37def get_comments(d_b):38 """ defines comment table"""39 class Comments(d_b.Model):40 """creates a comment"""41 commentId = d_b.Column(d_b.String(80), primary_key=True)42 event_id = d_b.Column(d_b.String(80), nullable=False)43 username = d_b.Column(d_b.String(80), nullable=False)44 text = d_b.Column(d_b.String(150), nullable=False)45 head = d_b.Column(d_b.String(80), nullable=True)46 tail = d_b.Column(d_b.String(80), nullable=True)47 depth = d_b.Column(d_b.Integer, nullable=False)48 def __repr__(self):49 return '<Comment %r>' % self.commentId...
plot.py
Source:plot.py
1import json2import numpy as np3from sklearn.linear_model import LinearRegression4from sklearn.ensemble import RandomForestRegressor5import joblib6from scipy.ndimage import median_filter as mf7f1 = open("input.json")8inputs = json.load(f1)9a_b = []10d_b = []11gt_theta = []12gt_dis = []13af = []14for i in inputs:15 a_b.append(i["angle_base"])16 d_b.append(i["distance"])17 gt_theta.append(i["sptheta"])18 gt_dis.append(i["spdis"])19 af.append(i["angleFiltered"])20d_b = np.asarray(d_b)21gt_dis = np.asarray(gt_dis)22a_b = np.asarray(a_b)23gt_dis = gt_dis[np.where(d_b > 0.7)[0]]24d_b = d_b[np.where(d_b > 0.7)[0]]25a_b = a_b[np.where(d_b > 0.7)[0]]26gt_dis = gt_dis[np.where(d_b < 4)[0]].reshape((-1, 1))27d_b = d_b[np.where(d_b < 4)[0]].reshape((-1, 1))28a_b = a_b[np.where(d_b < 4)[0]].reshape((-1, 1))29a_b = mf(a_b, size=10)30d_b = mf(d_b, size=10)31X = np.concatenate((d_b, a_b), 1)32reg = LinearRegression().fit(X, gt_dis)33d_pred = reg.predict(X)34regr = RandomForestRegressor(max_depth=10, random_state=0)35# regr = joblib.load('rf5.joblib')36regr.fit(X, gt_dis)37joblib.dump(regr, "rf10.joblib", protocol=2)38ranFor_pred = regr.predict(X)39L = np.linalg.norm(ranFor_pred.reshape((-1, 1)) - gt_dis)40print(L)41# plt.plot(ranFor_pred)42# # plt.plot(d_pred)43# plt.plot(gt_dis)44# # plt.plot(a_b)...
encr3pt.py
Source:encr3pt.py
1from PIL import Image, ImageDraw2import os3import sys4from random import SystemRandom5random = SystemRandom()6xrange = range7I3 = Image.open8if len(sys.argv) != 2:9 exit()10fl = str(sys.argv[1])11O1 = os.path.isfile12O2 = os.path.splitext13if not O1(fl):14 exit()15i = I3(fl)16f, e = O2(fl)17O_A = f+"_A.png"18O_B = f+"_B.png"19i = i.convert('1')20I1 = Image.new21I2 = ImageDraw.Draw22a = i.size[0]*223b = i.size[1]*224i_A = I1('1', (a, b))25d_A = I2(i_A)26i_B = I1('1', (a, b))27d_B = I2(i_B)28ps = ((1, 1, 0, 0), (1, 0, 1, 0), (1, 0, 0, 1),29 (0, 1, 1, 0), (0, 1, 0, 1), (0, 0, 1, 1))30for x in xrange(0, int(a/2)):31 for y in xrange(0, int(b/2)):32 pix = i.getpixel((x, y))33 p = random.choice(ps)34 d_A.point((x*2, y*2), p[0])35 d_A.point((x*2+1, y*2), p[1])36 d_A.point((x*2, y*2+1), p[2])37 d_A.point((x*2+1, y*2+1), p[3])38 if pix == 0:39 d_B.point((x*2, y*2), 1-p[0])40 d_B.point((x*2+1, y*2), 1-p[1])41 d_B.point((x*2, y*2+1), 1-p[2])42 d_B.point((x*2+1, y*2+1), 1-p[3])43 else:44 d_B.point((x*2, y*2), p[0])45 d_B.point((x*2+1, y*2), p[1])46 d_B.point((x*2, y*2+1), p[2])47 d_B.point((x*2+1, y*2+1), p[3])48i_A.save(O_A, 'PNG')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!