Example #1
0
async def get_map(request):
    uid = uuid.UUID(hex=request.match_info["session"])
    try:
        presenter = request.app["sessions"][uid]
    except KeyError:
        raise web.HTTPUnauthorized(
            reason="Session {0!s} not found.".format(uid))
    narrator = presenter.ensemble[-1]
    matcher = MultiMatcher(request.app["folders"])
    folders = matcher.options(t=narrator.clock)

    pathways = {p for f in folders for p in f.metadata.get("pathways", [])}
    presenter.log.debug("Pathways: {0}".format(pathways))

    spots = list(
        filter(None,
               (i.get_state(Spot)
                for i in presenter.ensemble if not isinstance(i, Location))))
    presenter.log.debug("Spots: {0}".format(spots))

    hots = [i for i in spots if i.value in pathways]
    presenter.log.debug("Hots: {0}".format(hots))

    return web.Response(
        text=bluemonday78.render.body_html(refresh=None).format(
            bluemonday78.render.dict_to_css(presenter.definitions),
            bluemonday78.render.ensemble_to_html(presenter.ensemble,
                                                 hots,
                                                 here=True)),
        content_type="text/html")
Example #2
0
async def get_frame(request):
    uid = uuid.UUID(hex=request.match_info["session"])
    try:
        presenter = request.app["sessions"][uid]
    except KeyError:
        raise web.HTTPUnauthorized(
            reason="Session {0!s} not found.".format(uid))

    if not presenter.pending:
        presenter.log.debug("No frames pending. Finding new dialogue.")
        narrator = presenter.ensemble[-1]
        pathway = narrator.get_state(Spot).value
        matcher = MultiMatcher(request.app["folders"])
        folders = list(matcher.options(pathways=set([pathway])))
        dialogue = presenter.dialogue(folders, presenter.ensemble)
        request.app["sessions"][uid] = presenter = Presenter(
            dialogue, presenter.ensemble)

    try:
        frame = presenter.frame()
    except IndexError:
        raise web.HTTPFound("/{0.hex}/map".format(uid))

    pending = presenter.pending
    return web.Response(text=bluemonday78.render.body_html(
        refresh=Presenter.refresh_animations(frame)
        if pending else None, ).format(
            bluemonday78.render.dict_to_css(presenter.definitions),
            bluemonday78.render.frame_to_html(frame, presenter.ensemble,
                                              not pending)),
                        content_type="text/html")
Example #3
0
async def post_hop(request):
    uid = uuid.UUID(hex=request.match_info["session"])
    try:
        presenter = request.app["sessions"][uid]
    except KeyError:
        raise web.HTTPUnauthorized(
            reason="Session {0!s} not found.".format(uid))

    data = await request.post()
    location_id = uuid.UUID(hex=data["location_id"])
    location = next(
        bluemonday78.story.search(presenter.ensemble, id=location_id))
    spot = location.get_state(Spot)

    narrator = presenter.ensemble[-1]
    narrator.set_state(spot)
    presenter.log.debug("Hopped to {0}".format(spot))

    pathway = spot.value
    matcher = MultiMatcher(request.app["folders"])
    folders = list(matcher.options(pathways=set([pathway])))
    dialogue = presenter.dialogue(folders, presenter.ensemble)
    if dialogue is None:
        request.app["log"].info("No new dialogue cast. Check selection.")
    else:
        request.app["sessions"][uid] = Presenter(dialogue, presenter.ensemble)
    raise web.HTTPFound("/{0.hex}".format(uid))
Example #4
0
    def test_match_by_pathway(self):
        matcher = MultiMatcher(self.folders)

        rv = list(matcher.options(pathways=set([("w12_latimer", "lockup")])))
        self.assertEqual(3, len(rv), rv)
        self.assertEqual("a_01", rv[0].metadata["arc"])
        self.assertEqual("a_11", rv[1].metadata["arc"])
        self.assertEqual("a_12", rv[2].metadata["arc"])
Example #5
0
    def test_match_by_datetime(self):
        matcher = MultiMatcher(self.folders)

        for d in range(1, 4):
            t = datetime.date(2020, 5, d)
            with self.subTest(t=t):
                rv = list(matcher.options(t=t))
                self.assertEqual(2, len(rv), rv)
                self.assertEqual("a_01", rv[0].metadata["arc"])
                self.assertEqual("a_10", rv[1].metadata["arc"])
Example #6
0
    def test_match_by_tnteger(self):
        matcher = MultiMatcher(self.folders)

        rv = list(matcher.options(t=0))
        self.assertEqual(1, len(rv), rv)
        self.assertEqual("a_10", rv[0].metadata["arc"])

        rv = list(matcher.options(t=1))
        self.assertEqual(2, len(rv), rv)
        self.assertEqual("a_10", rv[0].metadata["arc"])
        self.assertEqual("a_12", rv[1].metadata["arc"])
Example #7
0
def frame_to_html(frame, ensemble=[], final=False):
    narrator = ensemble[-1] if ensemble else None
    ts = narrator and MultiMatcher.parse_timespan(str(narrator.state))[0]
    spot = narrator.get_state(Spot) if narrator else None
    dialogue = "\n".join(animated_line_to_html(i) for i in frame[Model.Line])
    stills = "\n".join(animated_still_to_html(i) for i in frame[Model.Still])
    audio = "\n".join(animated_audio_to_html(i) for i in frame[Model.Audio])
    return f"""
Example #8
0
    def test_match_by_arc(self):
        matcher = MultiMatcher(self.folders)

        rv = list(matcher.options(arc="a_11"))
        self.assertEqual(1, len(rv), rv)
        self.assertEqual("a_11", rv[0].metadata["arc"])
Example #9
0
def prepare_folders(pkg="bluemonday78", path="dialogue", min_t=None, max_t=None):
    return [
        MultiMatcher.decorate_folder(f, min_t, max_t)
        for f in generate_folders(pkg, path)
    ]