def dumplol(data, table_name = None, footer_str = None): if data == []: return t = Table() for (row_index, row) in enumerate(data): t.set_row('row' + str(row_index), dict(map(lambda (col_index, col_val): ('col' + str(col_index), col_val), enumerate(row)))) t_print(t, table_name, footer_str, col_sort_function = lambda c1, c2: int(c1[3:]) - int(c2[3:]))
def dumplod(data, table_name = None, footer_str = None, show_col = False ,col_sort_function = None): if data == []: return t = Table() for (row_index, row) in enumerate(data): t.set_row('row' + str(row_index), dict([(str(col), val) for (col, val) in row.iteritems()])) t_print(t, table_name, footer_str, show_col = show_col, col_sort_function = col_sort_function)
def post(self): #TODO consistency on the redirect name = self.request.get('name') if not name: return "You need to post the 'name' field" new_table = Table(name=name) new_table.put() self.redirect('/')
def main(): ATM( menu, Accounts( Table( File('accounts.txt') ) ), History( Table( File('transactions.txt') ) ) ).start()
def handle(self): p = float(self.request.get("p")) SEATS_PER_TABLE = 10 for price in [p]: t = Table(price=btc2satoshi(price)) t.put() for n in xrange(SEATS_PER_TABLE): seat = Seat(table=t, number=n, purchase_addr=new_address(), state=EMPTY) seat.table = t seat.put() from time import sleep sleep(1) return {"success":True}
def get(self, table_id=None): if not table_id: return "You need to have a table_id" try: table = Table.get_by_id(int(table_id)) if not table: raise Exception("No table retrieved") except Exception as e: logging.exception(e) return "invalid table_id specified" result = "" if table.hasResolved: for participant in table.users: if participant.user == users.get_current_user().email(): result = participant.result return { 'name': table.name, 'participants': table.users, 'resolved': table.hasResolved, 'table_id': table_id, 'result': result }
def table_view(): s = bottle.request.environ.get('beaker.session') t = s.get('table', None) if t is None: t = Table(5, 5, 7) s['table'] = t s.save() return dict(table=t)
def handle(self): price = int(self.request.get("price")) if not price: return {"success": False, "error": "price parameter not found"} table = Table.get(price).to_dict_with_seats() if not table: return {"success": False, "error": "table not found"} return {"success":True, "table": table}
def handle(self): price = int(self.request.get("price")) if not price: return {"success": False, "error": "price parameter not found"} table = Table.get(price).to_dict_with_seats() if not table: return {"success": False, "error": "table not found"} return {"success": True, "table": table}
def handle(self): p = float(self.request.get("p")) SEATS_PER_TABLE = 10 for price in [p]: t = Table(price=btc2satoshi(price)) t.put() for n in xrange(SEATS_PER_TABLE): seat = Seat(table=t, number=n, purchase_addr=new_address(), state=EMPTY) seat.table = t seat.put() from time import sleep sleep(1) return {"success": True}
def click(): s = bottle.request.environ.get('beaker.session') x = int(request.forms.get('size_x')) y = int(request.forms.get('size_y')) num = int(request.forms.get('num_mines')) t = Table(num, x, y) s['table'] = t s.save() redirect('/game')
def tablename_intent(req): # get model by username data = getUserData(req.user) # create table and add to user data data.db.table = table.Table(req.tablename, '', None) # generate response text = "Ok, saved!\nNow I need the csv url of '" + req.tablename + "' table." r = response.Response(text, None, [], [], None) res = r.response return res
def create_tables(num_tables, num_people): """Create 'num_tables' Table objects that can hold 'num_people' on each Table - commit to database.""" for i in range(num_tables): current = Table(people_count=num_people) db.session.add(current) db.session.commit()
def endElement(self, tag): if tag == "o:Table" and self.current_table is not None: if "code" in self.current_table.keys(): t = Table() for key, val in self.current_table.items(): t.__setattr__(key, val) self.tables.append(t) self.current_table = None self.table_map[t.id] = t elif tag == "o:Column": if "name" in self.current_column.keys(): c = Column() for key, val in self.current_column.items(): if key == 'col_type': c.col_type = PdmColumnType[val.upper()] else: c.__setattr__(key, val) self.current_table['columns'].append(c) self.current_column = None elif tag == "a:Name": self.current_attr = None elif tag == "a:Code": self.current_attr = None elif tag == "a:DataType": self.current_attr = None elif tag == "a:Comment": self.current_attr = None elif tag == "o:Reference" and 'child' in self.current_ref.keys( ) and 'parent' in self.current_ref.keys(): if self.current_ref['child'] not in self.refs.keys(): self.refs[self.current_ref['child']] = [] ref = self.refs[self.current_ref['child']] ref.append(self.current_ref['parent']) self.current_ref = None elif self.current_ref is not None and tag == "c:ParentTable": self.current_ref['parent'] = self.current_parent_table self.current_parent_table = None elif self.current_ref is not None and tag == "c:ChildTable": self.current_ref['child'] = self.current_child_table self.current_child_table = None
def handle(self): for table in Table.all(): if table.is_ready(): gh = table.pick_random() players = gh.players winner_address = players[gh.winner] # TODO: should separate payment from table restart total_satoshis = table.price * len(players) payout = int(total_satoshis * (1 - HOUSE_EDGE)) sendmany([(winner_address, payout), (HOUSE_ADDRESS, total_satoshis - payout)]) return {"success": True}
def handle(self): for table in Table.all(): if table.is_ready(): gh = table.pick_random() players = gh.players winner_address = players[gh.winner] # TODO: should separate payment from table restart total_satoshis = table.price * len(players) payout = int(total_satoshis * (1 - HOUSE_EDGE)) sendmany([ (winner_address, payout), (HOUSE_ADDRESS, total_satoshis - payout) ]) return {"success":True}
def get(self, table_id=None): if not table_id: return "You need to have a table_id" try: table = Table.get_by_id(int(table_id)) if not table: raise Exception("No table retrieved") except Exception as e: logging.exception(e) return "invalid table_id specified" if table.hasResolved: self.redirect_to('details',table_id=table_id) return { 'name': table.name }
def post(self, table_id=None): if not table_id: self.response.write("You need to have a table_id") return try: table = Table.get_by_id(int(table_id)) if not table: raise Exception("No table retrieved") except Exception as e: logging.exception(e) self.response.write("invalid table_id specified") return cash = int(self.request.get("cash", None)) credit = self.request.get("credit", None) everything = self.request.get("everything", None) cost = int(self.request.get("cost", None)) if not cash: self.response.write("You must specify how much cash you have") return if not cost: self.response.write("You must specify how much your meal costed") return @ndb.transactional def add_participant(table_key, cash, credit, everything, cost): table = table_key.get() table.users.append(Participant( user=users.get_current_user().email(), cash=cash, hasCredit=True if credit else False, wantsToPayForEverything=True if everything else False, costOfMeal=cost, result="")) table.put() add_participant(table.key, cash, credit, everything, cost) self.redirect_to('details',table_id=table_id)
def register(): form = RegisterForm(request.form) if form.validate_on_submit(): gmail.mail(form.email.data, form.username.data) newUser = Table(username=form.username.data, email=form.email.data, password=form.password.data, phoneNo=form.number.data) try: db.session.add(newUser) db.session.commit() flash( "You are Registered Server Side. Please check your mail for further instructions." ) return redirect('/login') except: return 'error saving name' return render_template('register.html', form=form)
def create_tables(event_id): '''create tables''' if is_not_logged_in(): return redirect('/') # retrieve values from the form table_name = request.form['table-name'] max_seats = int(request.form['max-seats']) event_id = event_id # add the table to the database table = Table(event_id=event_id, table_name=table_name, max_seats=max_seats) db.session.add(table) db.session.commit() return redirect('/event={}/event-info'.format(event_id))
def test_table(self): u = Table(id=1, size=3, time1=datetime.datetime(2005, 7, 14, 12, 30)) db.session.add(u) db.session.commit()
class PoolWindow(pyglet.window.Window): ZOOM_SCROLL_STEP = 5 BALL_MAX_SPEED = 7500 def __init__(self, *args, **kwargs): super(PoolWindow, self).__init__(*args, **kwargs) self.set_size(1680, 1000) #self.set_fullscreen() self.keys = key.KeyStateHandler() self.push_handlers(self.keys) # Setup GL self.set_vsync(True) glClearColor(.15, .15, .15, 1) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glShadeModel(GL_SMOOTH) self.lpos1 = (0, 0.5 * SCALE_FACTOR, 1 * SCALE_FACTOR, 0) self.lpos2 = (0, -0.5 * SCALE_FACTOR, 1 * SCALE_FACTOR, 0) glLightfv(GL_LIGHT0, GL_POSITION, vec(*self.lpos1)) glLightfv(GL_LIGHT1, GL_POSITION, vec(*self.lpos2)) glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_LIGHT1) # Scroll zoom self.wheel_step = PoolWindow.ZOOM_SCROLL_STEP # Setup view self.view = View(eye=(0, -3 * SCALE_FACTOR, .75 * SCALE_FACTOR), center=(0, 0, -SCALE_FACTOR)) self.view.set_distance(SCALE_FACTOR) # The scene self.table = Table('obj/table.obj', self.view) self.rails = Rails('obj/rails.obj', self.view) self.ball = {} self.ball['cue'] = CueBall('obj/ball.obj', self.view, .260) self.ball['red'] = CueBall('obj/red.obj', self.view, .260, eVector3(0, 0.5 * SCALE_FACTOR, 0)) self.ball['yellow'] = CueBall('obj/yellow.obj', self.view, .260, eVector3(0, -0.5 * SCALE_FACTOR, 0)) self.cue = CueStick('obj/cue.obj', self.view, self.ball['cue'].radius) self.table.body.setUserPointer("Table") self.rails.body.setUserPointer("Rails") self.cue.body.setUserPointer("Cue") self.ball['cue'].body.setUserPointer("Cue Ball") self.ball['red'].body.setUserPointer("Red") self.ball['yellow'].body.setUserPointer("Yellow") # Set view center pos = self.ball['cue'].motion.getWorldTransform().getOrigin() self.view.set_center(eVector3(pos.x, pos.y, pos.z)) # Setup cue (position and orient) self._reset_cue() # Initialize physics self.world = DiscreteDynamicsWorld() self.debug = DebugDraw() self.world.setDebugDrawer(self.debug) self.world.addRigidBody(self.table.body) self.world.addRigidBody(self.cue.body) self.world.addRigidBody(self.rails.body) for ball in self.ball.values(): self.world.addRigidBody(ball.body) self.world.setGravity(bVector3(0, 0, -9.81 * SCALE_FACTOR)) # Register call-backs # A 1/60 call-back to run physics (the same as render) pyglet.clock.schedule(self._step) # Physic clock callback (usually few times faster than render clock) self.world.setInternalTickCallback(self.internal_tick_callback, True) self._setup_pan() self.topview = False self.helper = True self.push_handlers(on_key_press=self._on_key_press) def _setup_pan(self): self.view.pan(0, - self.width / 5.0) def internal_tick_callback(self, timeStep): if self._cue_ball_rest(): disp = self.world.getDispatcher() n = disp.getNumManifolds() for i in xrange(n): cm = disp.getManifoldByIndexInternal(i) contacts = cm.getNumContacts() for c in xrange(contacts): obA = cm.getBody0().getUserPointer() obB = cm.getBody1().getUserPointer() if obA == 'Cue' and obB == 'Cue Ball' \ or obA == 'Cue Ball' and obB == 'Cue': p = cm.getContactPoint(c) if p.getDistance() < 0.0: # test for penetration # The cue's strike force is calculated from actual # linear velocity applied to the cues orientation vector b = self.cue.body.getLinearVelocity() v = eVector3(b.x, b.y, b.z) d = self.cue.direction if hasattr(self.cue, 'direction') \ else self.view.dir # get force impuls = v.magnitude() * SCALE_FACTOR * 25. force = bVector3(d.x * impuls, d.y * impuls, 0.0) # span offset to [0..1] offset = eVector3(self.cue.dx * 4., 0., self.cue.dy * 4.) # calculate offset from cue's position [convert from eye into object space] # TODO: (rewrite this in compact form of vector vs. matrix multiplication) moffset = self.view.orient.inverse() * Matrix4.new_translate(*offset) offset = eVector3(moffset.d, moffset.h, moffset.l) cue = self.ball['cue'] cue.body.clearForces() cue.body.applyGravity() cue.body.applyForce(force, bVector3(offset.x, offset.y, offset.z)) # Restore cue self._reset_cue() def ball_cant_fly(ball): # check for flying pos = ball.motion.getWorldTransform().getOrigin() if pos.z > ball.radius: ball.body.applyCentralForce(bVector3(0, 0, -15 * SCALE_FACTOR)) # check for ball speed v = ball.body.getLinearVelocity() vel = eVector3(v.x, v.y, v.z) if vel.magnitude_squared() > PoolWindow.BALL_MAX_SPEED: ball.body.setLinearVelocity(v * 0.9) for ball in self.ball.values(): ball_cant_fly(ball) def on_mouse_press(self, x, y, button, modifiers): if button & mouse.RIGHT: self.view.zoom_distance = y def on_mouse_motion(self, x, y, dx, dy): if self.keys[key.LCTRL] and self._cue_ball_rest(): self.cue.delta = dy * -0.01 * SCALE_FACTOR def on_mouse_drag(self, x, y, dx, dy, button, modifiers): if button & mouse.LEFT: if modifiers & key.MOD_WINDOWS: self.view.rotate(dx, dy) else: self.view.rotate(dx, dy) pos = self.ball['cue'].motion.getWorldTransform().getOrigin() self.view.set_center(eVector3(pos.x, pos.y, pos.z)) self.cue.set_position(eVector3(pos.x, pos.y, pos.z + self.cue.pivot.z)) self.cue.orient_from_direction() self._setup_pan() elif button & mouse.RIGHT: pos = self.ball['cue'].motion.getWorldTransform().getOrigin() self.view.set_center(eVector3(pos.x, pos.y, pos.z)) self.view.zoom(y) self._setup_pan() elif button & mouse.MIDDLE: if modifiers & key.MOD_SHIFT: self.cue.move(dx, dy) else: self.view.pan(dx, dy) def _update_scroll(self, dt): distance = self.view.distance * self.zmul self.view.set_distance(distance) pos = self.ball['cue'].motion.getWorldTransform().getOrigin() self.view.set_center(eVector3(pos.x, pos.y, pos.z)) self._setup_pan() self.wheel_step -= 1 if self.wheel_step == 0: pyglet.clock.unschedule(self._update_scroll) def on_mouse_scroll(self, x, y, scroll_x, scroll_y): # Regulate zooming direction depending on scroll wheel direction # Schedule scroll update self.zmul = .98 if scroll_y > 0 else 1.02 self.wheel_step += 2 if self.wheel_step > 0 else PoolWindow.ZOOM_SCROLL_STEP pyglet.clock.schedule(self._update_scroll) def _on_key_press(self, symbol, modifiers): if symbol == key.TAB: self.topview = not self.topview if symbol == key.H: self.helper = not self.helper def on_resize(self, width, height): glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(40., width / float(height), .01, 1000.) self.view.load_matrix() glMatrixMode(GL_MODELVIEW) return pyglet.event.EVENT_HANDLED def on_draw(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glViewport(0, 0, self.width, self.height) def redraw_scene(self, debug=False): # table self.table.render() # rails self.rails.render() # balls for ball in self.ball.values(): p = ball.motion.getWorldTransform().getOrigin() q = ball.motion.getWorldTransform().getRotation() a = q.getAxis() ball.set_position((p.x, p.y, p.z)) ball.orient_from_axis_angle(q.getAngle(), eVector3(a.x, a.y, a.z)) ball.render() # cue stick (only if cue ball is resting) if self._cue_ball_rest(): self.cue.render() # debug draw if debug: self.debug.reset() self.world.debugDrawWorld() glDisable(GL_LIGHTING) glBegin(GL_LINES) for line in self.debug.lines: glColor3f(*line[6:]) glVertex3f(*line[:3]) glVertex3f(*line[3:6]) glEnd() glEnable(GL_LIGHTING) def render_top_cue(self): # Redraw helper top-right (top view) glViewport(self.width - self.width / 3, self.height - self.height / 3, self.width / 3, self.height / 3) glLoadIdentity() # top-view pos = self.ball['cue'].position gluLookAt(pos.x, pos.y, pos.z + SCALE_FACTOR / 2, pos.x, pos.y, pos.z, 1., 0., 0.) redraw_scene(self) def render_front_cue(self): # Redraw helper top-right (front view) glViewport(self.width - self.width / 3, self.height - self.height / 3, self.width / 3, self.height / 3) glLoadIdentity() eye = eVector3(self.cue.mtransform.d, self.cue.mtransform.h, self.cue.mtransform.l) eye += self.cue.direction * 6. # render front pos = self.ball['cue'].position gluLookAt(eye.x, eye.y, eye.z, pos.x, pos.y, pos.z, 0., 0., 1.) redraw_scene(self, True) def render_top_table(self): # render top glLoadIdentity() gluLookAt(0, 0, 3 * SCALE_FACTOR, 0, 0, 0, 1, 0., 0.) redraw_scene(self) # render table if not self.topview: self.view.load_matrix() redraw_scene(self) else: render_top_table(self) # render helper windows (for aim and shoot) if self._cue_ball_rest() and self.helper: if self.keys[key.LSHIFT]: render_front_cue(self) elif not self.topview: render_top_cue(self) def _step(self, dt): timeStep = fixedTimeStep = 1.0 / 300.0 self.world.stepSimulation(dt, 5, fixedTimeStep) now = time.time() delay = now % timeStep time.sleep(delay) # Cancel cue stick motion self.cue.delta = 0.0 def _cue_ball_rest(self): vel = self.ball['cue'].body.getLinearVelocity() mag = eVector3(vel.x, vel.y, vel.z).magnitude() return mag < 0.001 def _reset_cue(self): # Position and orient the cue pos = self.ball['cue'].motion.getWorldTransform().getOrigin() p = self.cue.org_pivot self.cue.set_pivot(eVector3(p.x, p.y, p.z + SCALE_FACTOR * 0.1)) self.cue.set_position(eVector3(pos.x, pos.y, pos.z + self.cue.pivot.z)) self.cue.orient_from_direction()
app = Flask(__name__) app.secret_key = os.urandom(12) app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///allData.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) # # if 'userData.db' is None: # print('Creating Database') # db.create_all() from model import Table if Table.query.filter_by(username='******', password='******').first() is None: admin = Table(username='******', password='******', email='*****@*****.**', phoneNo='123456789') db.session.add(admin) db.session.commit() def login_required(f): @wraps(f) def wrap(*args, **kwargs): if "logged_in" in session: return f(*args, **kwargs) else: flash("You need to LogIn First") return redirect("/") return wrap
def __init__(self, *args, **kwargs): super(PoolWindow, self).__init__(*args, **kwargs) self.set_size(1680, 1000) #self.set_fullscreen() self.keys = key.KeyStateHandler() self.push_handlers(self.keys) # Setup GL self.set_vsync(True) glClearColor(.15, .15, .15, 1) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glShadeModel(GL_SMOOTH) self.lpos1 = (0, 0.5 * SCALE_FACTOR, 1 * SCALE_FACTOR, 0) self.lpos2 = (0, -0.5 * SCALE_FACTOR, 1 * SCALE_FACTOR, 0) glLightfv(GL_LIGHT0, GL_POSITION, vec(*self.lpos1)) glLightfv(GL_LIGHT1, GL_POSITION, vec(*self.lpos2)) glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_LIGHT1) # Scroll zoom self.wheel_step = PoolWindow.ZOOM_SCROLL_STEP # Setup view self.view = View(eye=(0, -3 * SCALE_FACTOR, .75 * SCALE_FACTOR), center=(0, 0, -SCALE_FACTOR)) self.view.set_distance(SCALE_FACTOR) # The scene self.table = Table('obj/table.obj', self.view) self.rails = Rails('obj/rails.obj', self.view) self.ball = {} self.ball['cue'] = CueBall('obj/ball.obj', self.view, .260) self.ball['red'] = CueBall('obj/red.obj', self.view, .260, eVector3(0, 0.5 * SCALE_FACTOR, 0)) self.ball['yellow'] = CueBall('obj/yellow.obj', self.view, .260, eVector3(0, -0.5 * SCALE_FACTOR, 0)) self.cue = CueStick('obj/cue.obj', self.view, self.ball['cue'].radius) self.table.body.setUserPointer("Table") self.rails.body.setUserPointer("Rails") self.cue.body.setUserPointer("Cue") self.ball['cue'].body.setUserPointer("Cue Ball") self.ball['red'].body.setUserPointer("Red") self.ball['yellow'].body.setUserPointer("Yellow") # Set view center pos = self.ball['cue'].motion.getWorldTransform().getOrigin() self.view.set_center(eVector3(pos.x, pos.y, pos.z)) # Setup cue (position and orient) self._reset_cue() # Initialize physics self.world = DiscreteDynamicsWorld() self.debug = DebugDraw() self.world.setDebugDrawer(self.debug) self.world.addRigidBody(self.table.body) self.world.addRigidBody(self.cue.body) self.world.addRigidBody(self.rails.body) for ball in self.ball.values(): self.world.addRigidBody(ball.body) self.world.setGravity(bVector3(0, 0, -9.81 * SCALE_FACTOR)) # Register call-backs # A 1/60 call-back to run physics (the same as render) pyglet.clock.schedule(self._step) # Physic clock callback (usually few times faster than render clock) self.world.setInternalTickCallback(self.internal_tick_callback, True) self._setup_pan() self.topview = False self.helper = True self.push_handlers(on_key_press=self._on_key_press)
def get(self): tables = Table.query().fetch(100) return { 'tables': tables }
def create_example_data(): # add fake users to database store_users() # grab the first user event_owner = User.query.first() # add a fake event to the database gala_dinner = Event(event_name='Gala Dinner', event_description='Fundraiser', location='Four Seasons') # match the user id to the event gala_dinner.user_id = event_owner.user_id # add attendees to the event store_attendees(gala_dinner) # commit our changes and add the event db.session.add(gala_dinner) db.session.commit() t_one = Table(table_name='Test Table', max_seats=10, event_id=gala_dinner.event_id) t_two = Table(table_name='Test Table Two', max_seats=10, event_id=gala_dinner.event_id) t_three = Table(table_name='Test Table Three', max_seats=10, event_id=gala_dinner.event_id) t_four = Table(table_name='Test Table Four', max_seats=10, event_id=gala_dinner.event_id) t_five = Table(table_name='Test Table Five', max_seats=10, event_id=gala_dinner.event_id) db.session.add_all([t_one, t_two, t_three, t_four, t_five]) db.session.commit() r_one = SeatingRelationship(primary_attendee=1, secondary_attendee=2, relationship_code='must') db.session.add(r_one) db.session.commit() r_two = SeatingRelationship(primary_attendee=3, secondary_attendee=4, relationship_code='must') db.session.add(r_two) db.session.commit() r_three = SeatingRelationship(primary_attendee=5, secondary_attendee=6, relationship_code='must') db.session.add(r_three) db.session.commit() r_four = SeatingRelationship(primary_attendee=8, secondary_attendee=9, relationship_code='must') db.session.add(r_four) db.session.commit() r_five = SeatingRelationship(primary_attendee=6, secondary_attendee=7, relationship_code='must_not') db.session.add(r_five) db.session.commit() r_six = SeatingRelationship(primary_attendee=7, secondary_attendee=4, relationship_code='want') db.session.add(r_six) db.session.commit()
def get(self, table_id=None): if not table_id: return "You need to have a table_id" try: table = Table.get_by_id(int(table_id)) if not table: raise Exception("No table retrieved") except Exception as e: logging.exception(e) return "invalid table_id specified" @ndb.transactional def resolve(table_key): table = table_key.get() # First, calculate the total cost: cost = 0 for participant in table.users: cost += participant.costOfMeal # and the tip tip = cost * 0.2 total_cost = tip + cost generous_users = [] # Next, see if anyone wants to pay for everything for participant in table.users: if participant.wantsToPayForEverything: if participant.hasCredit or participant.cash >= cost: generous_users.append(participant.user) if len(generous_users) >= 2: random.shuffle(generous_users) cost_payer = generous_users[0] tip_payer = generous_users[1] for participant in table.users: if participant.user == cost_payer: participant.result = "You pay for everyone's meal. It costs {}".format( cost) elif participant.user == tip_payer: participant.result = "You pay the tip. It costs {}".format( tip) else: participant.result = "You don't have to pay. Thanks, {} and {}!".format( cost_payer, tip_payer) elif len(generous_users) == 1: random.shuffle(generous_users) cost_payer = generous_users[0] for participant in table.users: if participant.user == cost_payer: participant.result = "You pay for everyone's meal and the tip. It costs {}".format( total_cost) else: participant.result = "You don't have to pay. Thanks, {}!".format( cost_payer) else: for participant in table.users: if participant.cash > participant.costOfMeal: participant.result = "You pay for your own meal with cash" elif participant.hasCredit: participant.result = "You pay for your own meal with credit" else: participant.result = "You're broke! You end up doing dishes all night." table.hasResolved = True table.put() resolve(table.key) self.redirect_to('details',table_id=table_id)
def handle(self): return {"success": True, "list": Table.get_all()}
tableList = [] for i, r in dataFrame.iterrows(): name = r['name'] dataType = r['type'] notNull = r['not null'] unique = r['unique'] composite = r['composite'] default = r['default'] if pd.isna(name): continue if dataType == 'TABLE': if isOk: table = Table(name=tableName, columns=columns) tableList.append(table) isOk = True columns = [] tableName = name elif dataType == 'composite': # todo: need to handle composite key continue elif notNull != 'yes': continue else: columns.append(Column(name=name, type=dataType, defaultValue=default)) table = Table(name=tableName, columns=columns) tableList.append(table) for t in tableList:
def handle(self): return {"success":True, "list": Table.get_all()}