diff --git a/.github/workflows/check_export.yml b/.github/workflows/check_export.yml index 227180e..219f7b0 100644 --- a/.github/workflows/check_export.yml +++ b/.github/workflows/check_export.yml @@ -18,7 +18,7 @@ jobs: outputs: examples: ${{ steps.generate-matrix.outputs.examples }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Generate Matrix id: generate-matrix run: | @@ -31,10 +31,13 @@ jobs: strategy: matrix: example: ${{ fromJSON(needs.list-examples.outputs.examples) }} + fail-fast: false runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.9 - id: export-check run: | f=${{ matrix.example }} @@ -63,7 +66,7 @@ jobs: export OPENAI_API_KEY="dummy" reflex init - reflex export + reflex export | tee export_logs.txt for a in frontend.zip backend.zip; do if unzip -t "$a"; then echo "$a prepared as expected" @@ -75,9 +78,12 @@ jobs: - name: Check for DeprecationWarning in logs run: | - if grep -q "DeprecationWarning:" <<< "${{ steps.export-check.outputs.stdout }}"; then - echo "Found a Deprecation warning, please fix." - exit 1 - else - echo "No deprecated code, all good." - fi + cd ${{ matrix.example }} + dep_lines=$(grep -i "DeprecationWarning:" export_logs.txt || true) + if [ -n "$dep_lines" ]; then + echo "Found Deprecation warning:" + echo "$dep_lines" + exit 1 + else + echo "No deprecated code, all good." + fi diff --git a/ai_image_gen/ai_image_gen/backend/options.py b/ai_image_gen/ai_image_gen/backend/options.py index d41d5bc..a8447ba 100644 --- a/ai_image_gen/ai_image_gen/backend/options.py +++ b/ai_image_gen/ai_image_gen/backend/options.py @@ -46,31 +46,35 @@ class OptionsState(rx.State): advanced_options_open: bool = False # Generation options prompt: str = "" - negative_prompt: str = ( - "deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, text, watermark, signature" - ) + negative_prompt: str = "deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, text, watermark, signature" num_outputs: int = 1 seed: int = 0 steps: int = 4 scheduler: str = "K_EULER" guidance_scale: float = 0 - def set_tick(self, value: int): + @rx.event + def set_tick(self, value: list): self.slider_tick = value[0] self.selected_dimensions = self.dimensions[self.slider_tick] + @rx.event def set_hover(self, value: bool): self.hover = value - def set_num_outputs(self, value: int): + @rx.event + def set_num_outputs(self, value: list): self.num_outputs = value[0] - def set_steps(self, value: int): + @rx.event + def set_steps(self, value: list): self.steps = value[0] - def set_guidance_scale(self, value: float): + @rx.event + def set_guidance_scale(self, value: list): self.guidance_scale = value[0] + @rx.event def randomize_prompt(self): self.prompt = random.choice(prompt_list) diff --git a/ci_template/.gitignore b/ci_template/.gitignore index 5fc7223..6177310 100644 --- a/ci_template/.gitignore +++ b/ci_template/.gitignore @@ -1,3 +1,4 @@ +assets/external/ *.db *.py[cod] .cursorignore diff --git a/customer_data_app/.gitignore b/customer_data_app/.gitignore index e97bb37..84a3ecc 100644 --- a/customer_data_app/.gitignore +++ b/customer_data_app/.gitignore @@ -1,3 +1,4 @@ +assets/external/ *.db *.py[cod] .web diff --git a/customer_data_app/customer_data_app/backend/backend.py b/customer_data_app/customer_data_app/backend/backend.py index 89edcfa..4933ee8 100644 --- a/customer_data_app/customer_data_app/backend/backend.py +++ b/customer_data_app/customer_data_app/backend/backend.py @@ -4,18 +4,19 @@ from datetime import datetime, timedelta - -def _get_percentage_change(value: Union[int, float], prev_value: Union[int, float]) -> float: +def _get_percentage_change( + value: Union[int, float], prev_value: Union[int, float] +) -> float: percentage_change = ( round(((value - prev_value) / prev_value) * 100, 2) if prev_value != 0 - else 0 + else 0.0 if value == 0 - else - float("inf") + else float("inf") ) return percentage_change + class Customer(rx.Model, table=True): """The customer model.""" @@ -36,7 +37,6 @@ class MonthValues(rx.Base): num_delivers: int = 0 - class State(rx.State): """The app state.""" @@ -49,77 +49,96 @@ class State(rx.State): current_month_values: MonthValues = MonthValues() previous_month_values: MonthValues = MonthValues() - def load_entries(self) -> list[Customer]: - """Get all users from the database.""" - with rx.session() as session: - query = select(Customer) - if self.search_value: - search_value = f"%{str(self.search_value).lower()}%" - query = query.where( - or_( - *[ - getattr(Customer, field).ilike(search_value) - for field in Customer.get_fields() - if field not in ["id", "payments"] - ], - # ensures that payments is cast to a string before applying the ilike operator - cast(Customer.payments, String).ilike(search_value) - ) + """Get all users from the database.""" + with rx.session() as session: + query = select(Customer) + if self.search_value: + search_value = f"%{str(self.search_value).lower()}%" + query = query.where( + or_( + *[ + getattr(Customer, field).ilike(search_value) + for field in Customer.get_fields() + if field not in ["id", "payments"] + ], + # ensures that payments is cast to a string before applying the ilike operator + cast(Customer.payments, String).ilike(search_value), ) + ) + + if self.sort_value: + sort_column = getattr(Customer, self.sort_value) + if self.sort_value == "payments": + order = desc(sort_column) if self.sort_reverse else asc(sort_column) + else: + order = ( + desc(func.lower(sort_column)) + if self.sort_reverse + else asc(func.lower(sort_column)) + ) + query = query.order_by(order) - if self.sort_value: - sort_column = getattr(Customer, self.sort_value) - if self.sort_value == "payments": - order = desc(sort_column) if self.sort_reverse else asc(sort_column) - else: - order = desc(func.lower(sort_column)) if self.sort_reverse else asc(func.lower(sort_column)) - query = query.order_by(order) - - self.users = session.exec(query).all() - - self.get_current_month_values() - self.get_previous_month_values() + self.users = session.exec(query).all() + self.get_current_month_values() + self.get_previous_month_values() def get_current_month_values(self): """Calculate current month's values.""" now = datetime.now() start_of_month = datetime(now.year, now.month, 1) - + current_month_users = [ - user for user in self.users if datetime.strptime(user.date, '%Y-%m-%d %H:%M:%S') >= start_of_month + user + for user in self.users + if datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") >= start_of_month ] num_customers = len(current_month_users) total_payments = sum(user.payments for user in current_month_users) - num_delivers = len([user for user in current_month_users if user.status == "Delivered"]) - self.current_month_values = MonthValues(num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers) - + num_delivers = len( + [user for user in current_month_users if user.status == "Delivered"] + ) + self.current_month_values = MonthValues( + num_customers=num_customers, + total_payments=total_payments, + num_delivers=num_delivers, + ) def get_previous_month_values(self): """Calculate previous month's values.""" now = datetime.now() first_day_of_current_month = datetime(now.year, now.month, 1) last_day_of_last_month = first_day_of_current_month - timedelta(days=1) - start_of_last_month = datetime(last_day_of_last_month.year, last_day_of_last_month.month, 1) - + start_of_last_month = datetime( + last_day_of_last_month.year, last_day_of_last_month.month, 1 + ) + previous_month_users = [ - user for user in self.users - if start_of_last_month <= datetime.strptime(user.date, '%Y-%m-%d %H:%M:%S') <= last_day_of_last_month + user + for user in self.users + if start_of_last_month + <= datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") + <= last_day_of_last_month ] # We add some dummy values to simulate growth/decline. Remove them in production. num_customers = len(previous_month_users) + 3 total_payments = sum(user.payments for user in previous_month_users) + 240 - num_delivers = len([user for user in previous_month_users if user.status == "Delivered"]) + 5 - - self.previous_month_values = MonthValues(num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers) + num_delivers = ( + len([user for user in previous_month_users if user.status == "Delivered"]) + + 5 + ) + self.previous_month_values = MonthValues( + num_customers=num_customers, + total_payments=total_payments, + num_delivers=num_delivers, + ) def sort_values(self, sort_value: str): self.sort_value = sort_value self.load_entries() - def toggle_sort(self): self.sort_reverse = not self.sort_reverse self.load_entries() @@ -131,7 +150,6 @@ def filter_values(self, search_value): def get_user(self, user: Customer): self.current_user = user - def add_customer_to_db(self, form_data: dict): self.current_user = form_data self.current_user["date"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") @@ -144,8 +162,9 @@ def add_customer_to_db(self, form_data: dict): session.add(Customer(**self.current_user)) session.commit() self.load_entries() - return rx.toast.info(f"User {self.current_user['name']} has been added.", position="bottom-right") - + return rx.toast.info( + f"User {self.current_user['name']} has been added.", position="bottom-right" + ) def update_customer_to_db(self, form_data: dict): self.current_user.update(form_data) @@ -159,8 +178,10 @@ def update_customer_to_db(self, form_data: dict): session.add(customer) session.commit() self.load_entries() - return rx.toast.info(f"User {self.current_user['name']} has been modified.", position="bottom-right") - + return rx.toast.info( + f"User {self.current_user['name']} has been modified.", + position="bottom-right", + ) def delete_customer(self, id: int): """Delete a customer from the database.""" @@ -169,17 +190,27 @@ def delete_customer(self, id: int): session.delete(customer) session.commit() self.load_entries() - return rx.toast.info(f"User {customer.name} has been deleted.", position="bottom-right") - - + return rx.toast.info( + f"User {customer.name} has been deleted.", position="bottom-right" + ) + @rx.var(cache=True) def payments_change(self) -> float: - return _get_percentage_change(self.current_month_values.total_payments, self.previous_month_values.total_payments) + return _get_percentage_change( + self.current_month_values.total_payments, + self.previous_month_values.total_payments, + ) @rx.var(cache=True) def customers_change(self) -> float: - return _get_percentage_change(self.current_month_values.num_customers, self.previous_month_values.num_customers) + return _get_percentage_change( + self.current_month_values.num_customers, + self.previous_month_values.num_customers, + ) @rx.var(cache=True) def delivers_change(self) -> float: - return _get_percentage_change(self.current_month_values.num_delivers, self.previous_month_values.num_delivers) + return _get_percentage_change( + self.current_month_values.num_delivers, + self.previous_month_values.num_delivers, + ) diff --git a/dashboard/.gitignore b/dashboard/.gitignore index 5fc7223..6177310 100644 --- a/dashboard/.gitignore +++ b/dashboard/.gitignore @@ -1,3 +1,4 @@ +assets/external/ *.db *.py[cod] .cursorignore diff --git a/nba/.gitignore b/nba/.gitignore index e97bb37..84a3ecc 100644 --- a/nba/.gitignore +++ b/nba/.gitignore @@ -1,3 +1,4 @@ +assets/external/ *.db *.py[cod] .web diff --git a/sales/.gitignore b/sales/.gitignore index 575e538..939e365 100644 --- a/sales/.gitignore +++ b/sales/.gitignore @@ -1,3 +1,4 @@ +assets/external/ *.db *.py[cod] .web