From 206ac0e282384f61f4cf930293ee18259e7d8eb1 Mon Sep 17 00:00:00 2001 From: Thiago Coelho Date: Fri, 31 Mar 2023 09:06:33 -0300 Subject: [PATCH 1/2] Update Dockerfile to use HTTPS for cloning CasperJS repository Changed the git clone URL from git:// to https:// to resolve connection issues during the build process. --- docker/app/Dockerfile | 72 +++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile index 34554536..6a48395b 100644 --- a/docker/app/Dockerfile +++ b/docker/app/Dockerfile @@ -1,36 +1,36 @@ -FROM python:3.7-slim-buster - -RUN apt-get update \ - # dependencies for building Python packages - && apt-get install -y build-essential \ - && apt-get install -y python-dev \ - && apt-get install -y wget \ - && apt-get install -y zip unzip - -WORKDIR /usr/src/app - -COPY requirements.txt ./requirements.txt - -RUN pip install -r requirements.txt - -# Install PhantomJs and Casperjs for Testing -ENV PHANTOM_JS="phantomjs-1.9.8-linux-x86_64" -RUN apt-get install -y chrpath libssl-dev libxft-dev \ - && apt-get install -y libfreetype6 libfreetype6-dev \ - && apt-get install -y libfontconfig1 libfontconfig1-dev \ - && apt-get install -y git - -RUN cd ../ && wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2 -RUN mv ../$PHANTOM_JS.tar.bz2 /usr/local/share/ -RUN cd /usr/local/share/ && tar xvjf $PHANTOM_JS.tar.bz2 -RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/share/phantomjs -RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin/phantomjs -RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/bin/phantomjs -RUN rm -rf /usr/local/share/$PHANTOM_JS.tar.bz2 - -RUN cd ../ && git clone git://github.com/casperjs/casperjs.git \ - && cd casperjs && ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs - -ENV PYTHONPATH="/usr/src/app" -ENV PYTHONUNBUFFERED=1 -COPY . . +FROM python:3.7-slim-buster + +RUN apt-get update \ + # dependencies for building Python packages + && apt-get install -y build-essential \ + && apt-get install -y python-dev \ + && apt-get install -y wget \ + && apt-get install -y zip unzip + +WORKDIR /usr/src/app + +COPY requirements.txt ./requirements.txt + +RUN pip install -r requirements.txt + +# Install PhantomJs and Casperjs for Testing +ENV PHANTOM_JS="phantomjs-1.9.8-linux-x86_64" +RUN apt-get install -y chrpath libssl-dev libxft-dev \ + && apt-get install -y libfreetype6 libfreetype6-dev \ + && apt-get install -y libfontconfig1 libfontconfig1-dev \ + && apt-get install -y git + +RUN cd ../ && wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2 +RUN mv ../$PHANTOM_JS.tar.bz2 /usr/local/share/ +RUN cd /usr/local/share/ && tar xvjf $PHANTOM_JS.tar.bz2 +RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/share/phantomjs +RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin/phantomjs +RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/bin/phantomjs +RUN rm -rf /usr/local/share/$PHANTOM_JS.tar.bz2 + +RUN cd ../ && git clone https://github.com/casperjs/casperjs.git \ + && cd casperjs && ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs + +ENV PYTHONPATH="/usr/src/app" +ENV PYTHONUNBUFFERED=1 +COPY . . From 9d0080654f8605f2153c254e2b217c209552d234 Mon Sep 17 00:00:00 2001 From: Thiago Coelho Date: Tue, 4 Apr 2023 14:08:52 -0300 Subject: [PATCH 2/2] Refactor MultiResultCard to remove implicit state - Introduce a new CardResult class to encapsulate card evaluation results - Modify MultiResultCard's eval method to use CardResult instances - Update MultiResultCard's format_output method to handle CardResult instances --- app/logic/resultsets.py | 43 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/app/logic/resultsets.py b/app/logic/resultsets.py index c3f2cdf6..1795a2bd 100644 --- a/app/logic/resultsets.py +++ b/app/logic/resultsets.py @@ -11,6 +11,31 @@ from six.moves import map from six.moves import zip +class CardResult: + """ + A class to encapsulate the result of a card evaluation. + + This class holds the card, the evaluation result, the input representation, + and the components related to the card evaluation. It also implements an + equality check to compare CardResult instances based on their evaluation result. + + Attributes: + card (ResultCard): The card that was evaluated. + result (Any): The result of the card evaluation. + input_repr (str): The string representation of the input expression. + components (dict): The components related to the card evaluation. + """ + + def __init__(self, card, result, input_repr, components): + self.card = card + self.result = result + self.input_repr = input_repr + self.components = components + + def __eq__(self, other): + if not isinstance(other, CardResult): + return False + return self.result == other.result class ResultCard(object): """ @@ -113,20 +138,17 @@ def eval(self, evaluator, components, parameters): self.cards_used = [] results = [] - # TODO Implicit state is bad, come up with better API - # in particular a way to store variable, cards used for card in self.cards: try: result = card.eval(evaluator, components, parameters) except ValueError: continue - if result != None: - if not any(result == r[1] for r in results): + if result is not None: + card_result = CardResult(card, result, evaluator.get("input_evaluated"), components) + if card_result not in results: self.cards_used.append(card) - results.append((card, result)) + results.append(card_result) if results: - self.input_repr = evaluator.get("input_evaluated") - self.components = components return results return "None" @@ -137,17 +159,16 @@ def format_output(self, output, formatter): if not isinstance(output, list): return output html = ["") return "\n".join(html) - # Decide which result card set to use def is_derivative(input_evaluated):