async def load_location(sid: int, location: Location): pr: PlayerRoom = game_state.get(sid) if pr.active_location != location: pr.active_location = location pr.save() data = {} data["locations"] = [ {"id": l.id, "name": l.name} for l in pr.room.locations.order_by(Location.index) ] data["floors"] = [ f.as_dict(pr.player, pr.player == pr.room.creator) for f in location.floors.order_by(Floor.index) ] client_options = pr.player.as_dict() client_options.update( **LocationUserOption.get(user=pr.player, location=location).as_dict() ) await sio.emit("Board.Set", data, room=sid, namespace=GAME_NS) await sio.emit("Location.Set", location.as_dict(), room=sid, namespace=GAME_NS) await sio.emit("Client.Options.Set", client_options, room=sid, namespace=GAME_NS) await sio.emit( "Notes.Set", [ note.as_dict() for note in Note.select().where( (Note.user == pr.player) & (Note.room == pr.room) ) ], room=sid, namespace=GAME_NS, ) await sio.emit( "Markers.Set", [ marker.as_string() for marker in Marker.select(Marker.shape_id).where( (Marker.user == pr.player) & (Marker.location == location) ) ], room=sid, namespace=GAME_NS, ) location_data = InitiativeLocationData.get_or_none(location=location) if location_data: await send_client_initiatives(pr, pr.player) await sio.emit( "Initiative.Round.Update", location_data.round, room=sid, namespace=GAME_NS, ) await sio.emit( "Initiative.Turn.Set", location_data.turn, room=sid, namespace=GAME_NS )
def image_markers(image_id, stack_id, project_id): with DATABASE.transaction(): project_stack = models.ProjectStack.get(models.ProjectStack.project == project_id, models.ProjectStack.stack == stack_id) stack_image = models.StackImage.get(models.StackImage.stack == stack_id, models.StackImage.image == image_id) user = models.AppUser.get(models.AppUser.id == g.user_id) markers = (Marker.select().where( Marker.app_user == g.user_id, Marker.stack_image == stack_image.id, Marker.project_stack == project_stack.id) ) return jsonify({ 'markers': [marker.serialized for marker in markers] })
def generate_report_xlsx(self, project_id, report_type): project = Project.get(Project.id == project_id) total_probes = len([p for p in project.project_stacks]) project_users = AppUser.select().join(ProjectUser).where(ProjectUser.project == project) project_info = project.title.split('_') report = {} total_iteration = 0 for iteration, project_stack in enumerate(project.project_stacks): stack = {} stack_images = StackImage.select().where(StackImage.stack == project_stack.stack.id) for stack_image in stack_images: users = {} for user in project_users: markers = Marker.select().where( Marker.app_user == user.id, Marker.stack_image == stack_image.id, Marker.project_stack == project_stack.id ) user_markers = [m.serialized for m in markers] if user_markers: users[user.email] = user_markers stack[stack_image.image.name] = users report[project_stack.stack.title] = stack self.update_state(state='PROGRESS', meta={ 'current': iteration, 'total': total_probes, 'projectId': project_id, 'reportType': report_type }) total_iteration += 1 return { 'current': total_iteration, 'total': total_probes, 'status': 'Task complete', 'projectId': project_id, 'report': report, 'reportType': report_type }
async def load_location(sid: str, location: Location, *, complete=False): pr: PlayerRoom = game_state.get(sid) if pr.active_location != location: pr.active_location = location pr.save() # 1. Load client options client_options = pr.player.as_dict() client_options["location_user_options"] = LocationUserOption.get( user=pr.player, location=location).as_dict() client_options["default_user_options"] = pr.player.default_options.as_dict( ) if pr.user_options: client_options["room_user_options"] = pr.user_options.as_dict() await sio.emit("Client.Options.Set", client_options, room=sid, namespace=GAME_NS) # 2. Load room info if complete: await sio.emit( "Room.Info.Set", { "name": pr.room.name, "creator": pr.room.creator.name, "invitationCode": str(pr.room.invitation_code), "isLocked": pr.room.is_locked, "default_options": pr.room.default_options.as_dict(), "players": [{ "id": rp.player.id, "name": rp.player.name, "location": rp.active_location.id, "role": rp.role, } for rp in pr.room.players], "publicName": config.get("General", "public_name", fallback=""), }, room=sid, namespace=GAME_NS, ) # 3. Load location await sio.emit("Location.Set", location.as_dict(), room=sid, namespace=GAME_NS) # 4. Load all location settings (DM) if complete and pr.role == Role.DM: await sio.emit( "Locations.Settings.Set", { l.id: {} if l.options is None else l.options.as_dict() for l in pr.room.locations }, room=sid, namespace=GAME_NS, ) # 5. Load Board locations = [{ "id": l.id, "name": l.name, "archived": l.archived } for l in pr.room.locations.order_by(Location.index)] await sio.emit("Board.Locations.Set", locations, room=sid, namespace=GAME_NS) floors = [floor for floor in location.floors.order_by(Floor.index)] if "active_floor" in client_options["location_user_options"]: index = next(i for i, f in enumerate(floors) if f.name == client_options["location_user_options"]["active_floor"]) lower_floors = floors[index - 1::-1] if index > 0 else [] higher_floors = floors[index + 1:] if index < len(floors) else [] floors = [floors[index], *lower_floors, *higher_floors] for floor in floors: await sio.emit( "Board.Floor.Set", floor.as_dict(pr.player, pr.role == Role.DM), room=sid, namespace=GAME_NS, ) # 6. Load Initiative location_data = Initiative.get_or_none(location=location) if location_data: await sio.emit("Initiative.Set", location_data.as_dict(), room=sid, namespace=GAME_NS) # 7. Load labels if complete: labels = Label.select().where((Label.user == pr.player) | (Label.visible == True)) label_filters = LabelSelection.select().where( (LabelSelection.user == pr.player) & (LabelSelection.room == pr.room)) await sio.emit( "Labels.Set", [l.as_dict() for l in labels], room=sid, namespace=GAME_NS, ) await sio.emit( "Labels.Filters.Set", [l.label.uuid for l in label_filters], room=sid, namespace=GAME_NS, ) # 8. Load Notes await sio.emit( "Notes.Set", [ note.as_dict() for note in Note.select().where((Note.user == pr.player) & (Note.room == pr.room)) ], room=sid, namespace=GAME_NS, ) # 9. Load Markers await sio.emit( "Markers.Set", [ marker.as_string() for marker in Marker.select(Marker.shape_id).where( (Marker.user == pr.player) & (Marker.location == location)) ], room=sid, namespace=GAME_NS, ) # 10. Load Assets if complete: await sio.emit( "Asset.List.Set", Asset.get_user_structure(pr.player), room=sid, namespace=GAME_NS, )
def get_project_report_user(project_id, user_id): markers = Marker.select().join(ProjectStack).join(Project).where( ProjectStack.project == project_id, Marker.app_user == user_id) markers = [m.marker_type for m in markers] return jsonify({ 'markers': [markers] })