Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deprecation check pipeline #49

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions .github/workflows/check_export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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 }}
Expand Down Expand Up @@ -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"
Expand All @@ -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
18 changes: 11 additions & 7 deletions ai_image_gen/ai_image_gen/backend/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions ci_template/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
assets/external/
*.db
*.py[cod]
.cursorignore
Expand Down
1 change: 1 addition & 0 deletions customer_data_app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
assets/external/
*.db
*.py[cod]
.web
Expand Down
147 changes: 89 additions & 58 deletions customer_data_app/customer_data_app/backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -36,7 +37,6 @@ class MonthValues(rx.Base):
num_delivers: int = 0



class State(rx.State):
"""The app state."""

Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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."""
Expand All @@ -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,
)
1 change: 1 addition & 0 deletions dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
assets/external/
*.db
*.py[cod]
.cursorignore
Expand Down
1 change: 1 addition & 0 deletions nba/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
assets/external/
*.db
*.py[cod]
.web
Expand Down
1 change: 1 addition & 0 deletions sales/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
assets/external/
*.db
*.py[cod]
.web
Expand Down