def index(): """Show user's grades for selected trimester""" if request.method == "POST": trimester = request.form.get("trimester") user = session["user_id"] index = db.execute( "SELECT * FROM grades WHERE id=:user AND trimester=:trimester ORDER BY subject ASC", user=user, trimester=trimester) for subject in index: test = subject["test"] cg1 = subject["cg1"] cg2 = subject["cg2"] cg3 = subject["cg3"] cg4 = subject["cg4"] cg5 = subject["cg5"] cgs = [cg1, cg2, cg3, cg4, cg5] if subject["subject"] in ["RE", "Sociology", "Philosophy"]: if test: average = (test + cgavg(add(cgs), count(cgs))) / 2 else: average = cgavg(add(cgs), count(cgs)) / 2 else: if test: average = test * 0.4 + cgavg(add(cgs), count(cgs)) * 0.6 else: average = cgavg(add(cgs), count(cgs)) * 0.6 rounded = approx(average) subject.update({"average": round(average, 5)}) subject.update({"approx": rounded}) return render_template("grades.html", trimester=trimester, index=index) else: return render_template("index.html")
def plotSets(quantizedSets, means, pausebuffer): count = 1 base = (0.31, 0.53, 0.87) colour = (0.0, 0.0, 0.0) fig = plt.figure() ax = fig.gca(projection='3d') for cluster in quantizedSets: colour = helpers.add(colour, base) colour = helpers.mod(1, colour) pointsX = [x[0] for x in cluster.keys()] pointsY = [y[1] for y in cluster.keys()] pointsZ = [z[2] for z in cluster.keys()] ax.scatter(pointsX, pointsY, pointsZ, c=colour, marker='+') count = count + 1 colour = helpers.add(colour, base) colour = helpers.mod(1, colour) pointsX = [x[0] for x in means] pointsY = [y[1] for y in means] pointsZ = [z[2] for z in means] ax.scatter(pointsX, pointsY, pointsZ, c='r', marker='o') ax.invert_yaxis() if pausebuffer <= 0: plt.show() elif pausebuffer > 0: plt.show(block=False) plt.pause(pausebuffer) plt.close()
def main(numSets,accuracy,flag,length=3): if flag == 2: n = int(sanitizeInput("Input the block size here:")) mostRandom = int(sanitizeInput("Print 1 for purely random, 0 for predefined clusters")) increaseN(n,mostRandom,numSets) return elif flag == 1: n = int(sanitizeInput("Input the sample size here:") ) low = float(sanitizeInput("Input the range minimum here:")) high = float(sanitizeInput("Input the range maximum here:")) points = [] theRange = high - low spacing = float(theRange)/numSets means = [] thePoint = () midpoint = () for j in range(length-1): thePoint = thePoint + (0,) midpoint = midpoint + (1/(numSets-1)**0.5,) thePoint = thePoint + (1,) midpoint = midpoint + (0,) increment = helpers.add(thePoint,helpers.mult(-1,midpoint)) for i in range(numSets): means.append(helpers.add(thePoint,helpers.mult(float(i+0.5)/numSets,increment))) for i in range(n): thePoint = () j = 0 while j < length: thePoint = thePoint + (rand.uniform(low,high),) j = j + 1 points.append(thePoint) else: testnum = sanitizeInput("Input the test number here:") filepath = "../Testing/test"+testnum+".csv" points = fileio.readFile(filepath) # low = helpers.theMin(points) # high = helpers.theMax(points) # spacing = () # for i in range(length): # spacing = spacing + ((high[i]-low[i])/numSets,) means = [] n = len(points) thePoint = () midpoint = () for j in range(length-1): thePoint = thePoint + (0,) midpoint = midpoint + (1/float(length-1),) thePoint = thePoint + (1,) midpoint = midpoint + (0,) increment = helpers.add(midpoint,helpers.mult(-1,thePoint)) # print thePoint, midpoint, increment thePoint = helpers.add(thePoint,helpers.mult(0.25,increment)) increment = helpers.mult(0.5,increment) # print thePoint, increment for i in range(numSets): means.append(helpers.add(thePoint,helpers.mult(float(i+0.5)/numSets,increment))) # print means doKMeans(points,means)
def get(self, paths=['/'], flat=True): paginator = self.ssm.get_paginator('get_parameters_by_path') output = {} for path in paths: for page in paginator.paginate(Path=path, Recursive=True, WithDecryption=True): for param in page['Parameters']: add(obj=output, path=param['Name'], value=self._read_param(param['Value'], param['Type'])) return flatten(output) if flat else output
def generateBall(num, n, center, radius): points = generatePoints(num, n, radius) ball = [] for i in range(len(points)): ball.append(helpers.add(center, points[i])) # plotting.plotPointsWithCenter(ball,center) return ball
def plotSets12(quantizedSets, means, length, pausebuffer): base = (0.31, 0.53, 0.87) colour = (0.0, 0.0, 0.0) for cluster in quantizedSets: colour = helpers.add(colour, base) colour = helpers.mod(1, colour) pointsX = [x[0] for x in cluster.keys()] if length == 2: pointsY = [y[0] for y in cluster.keys()] elif length == 1: pointsY = [1 for y in cluster.keys()] plt.plot(pointsX, pointsY, c=colour, marker='+') if length == 2: pointsX = [x[0] for x in means] pointsY = [y[1] for y in means] elif length == 1: pointsX = means pointsY = [1 for y in means] plt.plot(pointsX, pointsY, c='r', marker='o') if pausebuffer <= 0: plt.show() else: plt.show(block=False) plt.pause(pausebuffer) plt.close()
def main(): # add two numbers using imported function print(add(10,20)) # create single line functions using lambda print((lambda x: (x * 5) - 5) (10)) print((lambda x, y: x + y) (10,20)) # check if s is in string using function print(isIn("y", "bcdefghijklmnopqrstuvwxy"))
def main(numSets, accuracy, flag, length=3): if flag == 2: n = int(allio.sanitizeInput("Input the block size here:")) mostRandom = int( allio.sanitizeInput( "Print 1 for purely random, 0 for predefined clusters")) increaseN(n, mostRandom, numSets) return else: testnum = allio.sanitizeInput("Input the test number here:") filepath = "../Testing/test" + testnum + ".csv" points = allio.readFile(filepath) # low = helpers.theMin(points) # high = helpers.theMax(points) # spacing = () # for i in range(length): # spacing = spacing + ((high[i]-low[i])/numSets,) means = [] n = len(points) thePoint = () midpoint = () for j in range(length - 1): thePoint = thePoint + (0, ) midpoint = midpoint + (1 / float(length - 1), ) thePoint = thePoint + (1, ) midpoint = midpoint + (0, ) increment = helpers.add(midpoint, helpers.mult(-1, thePoint)) # print thePoint, midpoint, increment thePoint = helpers.add(thePoint, helpers.mult(0.25, increment)) increment = helpers.mult(0.5, increment) # print thePoint, increment for i in range(numSets): means.append( helpers.add(thePoint, helpers.mult(float(i + 0.5) / numSets, increment))) means = gen.meanInit(numSets) # print means pausebuffer = float(allio.sanitizeInput("Input the pause buffer here:")) means, sets = doKMeans3(points, means, pausebuffer)
def plotLists(lists): fig = plt.figure() ax = fig.gca(projection='3d') base = (0.13, 0.73, 0.35) colour = base # print len(lists) for i in range(len(lists)): pointsX = [x[0] for x in lists[i]] pointsY = [y[1] for y in lists[i]] pointsZ = [z[2] for z in lists[i]] ax.scatter(pointsX, pointsY, pointsZ, c=colour, marker='o') colour = helpers.mod(1, helpers.add(colour, base)) ax.invert_yaxis() plt.show()
def calculator(): """Calculate necessary score on an activity based on inputted values""" if request.method == "POST": subject = request.form.get("subject") test = request.form.get("test") cg1 = request.form.get("cg1") cg2 = request.form.get("cg2") cg3 = request.form.get("cg3") cg4 = request.form.get("cg4") cg5 = request.form.get("cg5") cgs = [cg1, cg2, cg3, cg4, cg5] average = float(request.form.get("average")) if subject == "1": if test: test = float(test) grade = ((count(cgs) + 1) * (average - 0.24 - (test * 0.4))) / 0.6 - add(cgs) evaluation = "test" else: grade = (average - 0.24 - cgavg(add(cgs), count(cgs)) * 0.6) / 0.4 evaluation = "class grade" else: if test: test = float(test) grade = (count(cgs) + 1) * (2 * (average - 0.24) - test) - add(cgs) evaluation = "test" else: grade = 2 * (average - 0.24) - cgavg(add(cgs), count(cgs)) evaluation = "class grade" return render_template("calculated.html", grade=round(grade, 3), evaluation=evaluation) else: return render_template("calculator.html")
def main(): number1 = float(input('Enter the first number: ')) number2 = float(input('Enter the second number: ')) print(helpers.add(number1, number2))
def _move(self): self._acc = add(self._acc, self.brain.dirs[self.brain.step]) self.brain.step += 1 self._vel = add(self._vel, self._acc) self._vel = limit(self._vel, Dot._MAX_VEL) self._pos = add(self._pos, self._vel)
# coding=utf-8 import helpers print(helpers.__author__) print(helpers.add(15, 16))