def insert_stack(self): s = Stack() s.title = "Example Stack" s.image_base = "http://incf.ini.uzh.ch/image-stack-fib/" s.trakem2_project = False s.dimension = Integer3D(x=2048, y=1536, z=460) s.resolution = Double3D(x=5.0001, y = 5.0002, z=9.0003) s.save() return s
def get_contents(self): db_id = Directory.get(Directory.key == self.key).id directories = Directory.select().where(Directory.parent_directory == db_id) has_probes = False try: has_probes = Directory.get(Directory.key == directories .first().key).images.first() except: pass if has_probes: directories = [DirectoryTree(d.name, d.key).get_contents() for d in directories] self.directories = [d.serialized for d in directories] else: self.directories = [DirectoryTree(d.name, d.key).serialized for d in directories] self.images = [image.serialized for image in Image.select().where(Image.directory == db_id)] if self.images: stack_title = self.key[:-1] try: stack_id = Stack.get(Stack.title == stack_title).id except models.DoesNotExist: images = Image.select().where(Image.directory == db_id) stack = models.Stack.create(title=stack_title) for image in images: try: models.StackImage.create(stack=stack, image = image.id) except Exception as ex: print ex stack_id = stack.id self.stack_id = stack_id return self
def decorated_function(*args, **kwargs): if 'username' not in session or session['username'] is None or session['username'] == '': #This bypasses the actual set cookie for angularAuthentication in the notes route. So call it here! resp = make_response(render_template('app.html')) set_user_cookie(resp) return resp, 401 #Check if this user already has a floating stack try: user = User.objects.get(username=session['username']) # @UndefinedVariable except DoesNotExist: return dumps({'error':'could not retrieve user object while creating floating stack'}), 500 try: #does the stack exist already, if not, create it stack = Stack.objects.get(title='Floating', owner=user) # @UndefinedVariable except DoesNotExist: try: stack = Stack( title='Floating', owner = user, createdat = datetime.now().strftime('%Y%m%d%H%M%S') ) stack.save() except: return dumps({'error':'could not create floating stack'}), 500 #Remove floating 'new' atts attinstorage = Attachment.objects.filter(cardid__startswith='new') for att in attinstorage: if 'file' in att: att.file.delete() else: att.image.delete att.delete() linksinstorage = UrlAttachment.objects.filter(cardid__startswith='new') for att in linksinstorage: att.delete() return function(*args, **kwargs)
def stacks(): req = request.get_json() message = "" if request.method == 'POST': page = 1 page_size = 10 try: request_error = False title = req['title'] image_ids = req['imageIds'] except KeyError: request_error = True if request_error: return jsonify({ 'message': 'Insufficient data to create stack' }), 400 try: stack = models.Stack.create(title=title) for id in image_ids: try: models.StackImage.create(stack=stack, image = id) except Exception as ex: print ex message = "Stack created" except IntegrityError: return jsonify({ 'message': 'Stack already exists with title {}'.format(title) }), 400 stacks = (Stack.select() .order_by(Stack.created_date.desc()) .paginate(page, page_size)) if request.method == 'GET': page = int(request.args.get('page')) page_size = 10 stacks = (Stack.select() .order_by(Stack.created_date.desc()) .paginate(page, page_size)) stack_count = SelectQuery(models.Stack).count() return jsonify({ 'message': message, 'stacks': [stack.serialized for stack in stacks], 'totalStacks': stack_count, 'pages': [stack + 1 for stack in range(int(math.ceil(float(stack_count)/float(page_size))))] }), 201
def project_stack_images(project_id, stack_id): first_image = Image.select().join(StackImage).where(StackImage.stack == stack_id).get().key last_underscore = first_image.rfind('_') stack_title = first_image[:last_underscore] project_stack = ProjectStack.get(ProjectStack.project == project_id, ProjectStack.stack == stack_id) project_stack_user_data = project_stack.project_stack_data.where(ProjectStackDatum.user == g.user_id) probe_type = project_stack.project.probe_type probe_settings = project_stack.probe_setting.get() images = (Image.select().join(StackImage).where(StackImage.stack == stack_id) .order_by(Image.name)) project_stacks = Stack.select().join(ProjectStack).where(ProjectStack.project == project_id).order_by(Stack.id) marker_options = MarkerOption.select().join(ProjectMarkerOption).where(ProjectMarkerOption.project == project_id) return jsonify({ 'images': [image.stack_image_serialized for image in images], 'data': [d.serialized for d in project_stack_user_data], 'probeSettings': probe_settings.serialized, 'stackTitle': stack_title, 'probeType': probe_type, 'markerOptions': [marker_option.name for marker_option in marker_options], 'projectStackIds': [stack.id for stack in project_stacks] })
def create_stack(): new_id = str(uuid.uuid4()) posted = request.json decoded = base64.b64decode(posted['composeYml']).decode('utf-8') newstack = Stack(id=new_id, name=str(posted['name'].lower()), compose_yml=posted['composeYml']) db.session.add(newstack) db.session.commit() # run docker compose results = subprocess.run([ 'docker-compose', '-p', str(posted['name'].lower()), '-f', '-', 'up', '-d' ], input=bytes(decoded, encoding='utf-8'), capture_output=True) # docker compose status goes on stderr? return jsonify({'result': str(results.stderr)})
def message(bot, update): chat_id = update.message.chat_id user_id = update.message.from_user.id msg = update.message.text username = update.message.from_user.username fullname = " ".join([ update.message.from_user.first_name, update.message.from_user.last_name ]) chat_type = update.message.chat.type chat_title = update.message.chat.title # If message from group if chat_type == 'group' or chat_type == 'supergroup': # Add chat and user to DB User().add(user_id, username, fullname) Chat().add(chat_id, chat_title, bot.getChat(chat_id).username) if update.message.photo: Entity().add(chat_id, 'photo', None) if update.message.video: Entity().add(chat_id, 'video', None) if update.message.audio: Entity().add(chat_id, 'audio', None) if update.message.voice: Entity().add(chat_id, 'voice', None) if update.message.document: Entity().add(chat_id, 'document', None) for entity in update.message.entities: # http://link.com if entity['type'] == 'url': link = msg[entity['offset']:entity['offset'] + entity['length']] link = re.sub('(.*)://', '', link) link = link.split('/')[0] Entity().add(cid=chat_id, type='url', title=link) # /command if entity['type'] == 'bot_command': title = msg[entity['offset']:entity['offset'] + entity['length']] Entity().add(cid=chat_id, type='bot_command', title=title) # #hashtag if entity['type'] == 'hashtag': title = msg[entity['offset']:entity['offset'] + entity['length']] Entity().add(cid=chat_id, type='hashtag', title=title) # @username if entity['type'] == 'mention': title = msg[entity['offset']:entity['offset'] + entity['length']] Entity().add(cid=chat_id, type='mention', title=title) user_stat = UserStat.get(user_id, chat_id) # If user already in group if user_stat: today = datetime.today().day last_activity = datetime.fromtimestamp( timestamp=user_stat.last_activity).day # If last activity was not today if (timedelta(today).days - timedelta(last_activity).days) != 0: Stack().add({'cid': chat_id, 'msg_count': 1, 'users_count': 1}) else: Stack().add({'cid': chat_id, 'msg_count': 1, 'users_count': 0}) else: Stack().add({'cid': chat_id, 'msg_count': 1, 'users_count': 1}) # Update user messages count UserStat().add(user_id, chat_id) else: # If message from user pass
def job(bot): Stack().send()
def start(player): """ Attempts creating a new game session for the given player. """ if not player: return None # Initialize all the stacks. room_stack = Stack() room_stack.save() you_stack = Stack() you_stack.save() equipment_stack = Stack() equipment_stack.save() forge_stack = Stack() forge_stack.save() treasure_stack = Stack() treasure_stack.save() discard_stack = Stack() discard_stack.save() # Begin a new session. session = Session( health=HEALTH_CAPACITY, # Important to note that a session has to be tied to a player. Same goes for # cards and stacks; they must, ultimately, be tied to a session. Otherwise # it would be possible to move cards between sessions. belongs_to_player=player, room_stack=room_stack, you_stack=you_stack, equipment_stack=equipment_stack, forge_stack=forge_stack, treasure_stack=treasure_stack, discard_stack=discard_stack) session.save() # Draw the first 5 cards. initial_room_cards = draw(session, ROOM_CAPACITY) # Put the initial cards in place. room_stack.push_many(initial_room_cards) # If everything went as expected, activate the session by hooking it up to the player. player.active_session = session player.save() return session
def __init__(self): self.og = Stack() self.max = Stack()
class StackWithMax: def __init__(self): self.og = Stack() self.max = Stack() def push(self, item): if self.og.size() == 0: self.og.push(item) self.max.push(item) else: if item >= self.max.peek(): self.max.push(item) self.og.push(item) def pop(self): if self.og.size == 0: print("Empty stack error") else: result = self.og.pop() if result == self.max.peek(): self.max.pop() return result def show(self): print(self.og.show()) def getMax(self): print(str(self.max.peek()))