2024-01-25

Goal

Finish the create_fighter() function in the Django Utils of the Fighters App of the HitHub App.

Notes

I was able to establish the lifestyle features through a series of rolls that look like the following:

is_enlightened = random.random() <= enlightenment_roll

where enlightenment_roll is the probability that the fighter gets that trait (in this case the trait of enlightenment). I also added multipliers to give an additional Conditional Probability based on certain traits. For instance, if the fighter is_derranged, it's also more likely that they have the fight is_offensive:

if is_derranged:
    is_offensive = random.random() <= offensive_roll * 1.5

which was fun to put together. Finally, I was able to run the create_fighter() function in the fighters/utils.py file via the Django Shell. Unfortunately though, I was unable to execute because the Cosmetic Django Model wasn't correctly linked to the appropriate cosmetic field. I was using the cosmetic_type as its reference for a kwarg (things like BEARD, FEET, EYE, etc.) and I wasn't quite sure what it wanted me to call these things. Thankfully ChatGPT gave me a really useful script that told me what the Fighter object called these cosmetic references:

from fighters.models import Fighter  # Import your Fighter model from your Django app

# Get the model's fields
fighter_fields = Fighter._meta.get_fields()

# Extract the names of the fields
field_names = [field.name for field in fighter_fields]

# Print the field names
print(field_names)

which helped me identify the name of the feature as cosmetic_{TYPE}, so I used the following string for the kwarg:

f"cosmetic_{cosmetic_type.lower()}"

This worked! I can now create fighters in my Fighters App just by executing the create_fighter() in the Django Shell. Nice!

I also verified that a fighter was created on CustomUser creation from the Accounts App so I know the accounts/signals.py file is working. Now I can associate many different apps / tables with one another. This is exciting!

At the end I started building Unit Tests with ChatGPT. This shouldn't be as bad as doing it on my own, and I can easily run the tests via

python manage.py test APPNAME

so I'm looking forward to seeing how broken my app really is!

Also at the end there I screwed up and merged the fighter-generator commit with the main branch... Gonna have to unscrew that one next time.

Results

  • Completed the create_fighter() function in fighters/utils.py
    • Now I can randomly generate fighters and associate them with all of my other data sources!

Next Time

  • Fix Git Branch
  • Figure out how to upload images to AWS so I can finally start seeing my fighters in my app.
  • Look into other quirky signals I could do on a timed basis
    • i.e random events at a given time interval
  • Could also start writing Unit Tests... Ahahaaaa...

Previous Note 2024-01-24 Next Note 2024-01-28