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

bug fixes #21

Merged
merged 1 commit into from
Oct 27, 2024
Merged

bug fixes #21

merged 1 commit into from
Oct 27, 2024

Conversation

leonvanbokhorst
Copy link
Owner

@leonvanbokhorst leonvanbokhorst commented Oct 27, 2024

Summary by Sourcery

Enhance emotional state processing and theme influence tracking, and fix unique interaction generation.

Bug Fixes:

  • Fix the generation of unique interactions by ensuring 'partner_id' is checked for existence and non-nullity.

Enhancements:

  • Improve emotional state description by stripping parentheses and converting to lowercase.
  • Add functionality to track and update theme influences in stories.

Copy link
Contributor

sourcery-ai bot commented Oct 27, 2024

Reviewer's Guide by Sourcery

This PR implements several bug fixes and enhancements to the narrative field simulation system. The changes focus on improving emotional state processing, adding theme influence tracking, fixing memory interaction handling, and adjusting simulation parameters.

Sequence diagram for process_interaction method

sequenceDiagram
    participant Story1
    participant Story2
    participant InteractionEngine
    InteractionEngine->>Story1: add_memory(memory)
    InteractionEngine->>Story2: add_memory(memory)
    loop for each shared theme
        InteractionEngine->>Story1: update_theme_influence(theme, resonance * 0.1)
        InteractionEngine->>Story2: update_theme_influence(theme, resonance * 0.1)
    end
Loading

Updated class diagram for Story class

classDiagram
    class Story {
        +theme_influences: dict
        +update_theme_influence(theme: str, influence: float)
    }
    note for Story "Added theme_influences attribute and update_theme_influence method"
Loading

File-Level Changes

Change Details Files
Enhanced emotional state processing in story updates
  • Modified prompt to request single-word emotional responses
  • Added string cleanup for emotional state descriptions
  • Implemented stripping of parentheses and lowercase conversion
src/nfd_three_story_evolve.py
Added theme influence tracking system
  • Introduced theme_influences dictionary to track theme impacts
  • Added method to update theme influences
  • Implemented theme influence updates during story interactions
  • Updated journey analytics to use new theme influence tracking
src/nfd_three_story_evolve.py
Fixed memory interaction handling
  • Improved unique interactions calculation
  • Added safer memory partner_id checking
  • Simplified unique interactions collection logic
src/nfd_three_story_evolve.py
Modified simulation parameters
  • Increased initial story count from 9 to 15
  • Reduced simulation loop iterations from 100 to 10
src/nfd_three_story_evolve.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leonvanbokhorst - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please use a more descriptive PR title and add details in the description about the specific bugs fixed and improvements made
  • The changes to simulation parameters (story count from 9->15 and iterations from 100->10) should be documented with rationale for the adjustments
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -261,6 +265,7 @@ def __init__(
self._field = None
if field:
self.set_field(field)
self.theme_influences = {} # Add this line to track theme influences
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider consolidating theme influence tracking into a single location within the Story class

The theme influence tracking is unnecessarily split between Story.theme_influences and the perspective object, creating confusing duplication. Consolidate this into the Story class since it's the natural owner of theme-related state.

# Remove theme_influences from perspective object
# Keep only in Story class:
class Story:
    def __init__(self, ...):
        self.theme_influences = {}  # Single source of truth

    def update_theme_influence(self, theme: str, influence: float):
        self.theme_influences[theme] = self.theme_influences.get(theme, 0) + influence

# Update get_journey_analytics() to use story.theme_influences directly
most_influential_themes = sorted(
    story.theme_influences.items(), 
    key=lambda x: x[1], 
    reverse=True
)[:3]

This removes the duplicate state while preserving all functionality.

Comment on lines 931 to +935
# Safely get unique interactions
unique_interactions = {
m["partner_id"] for m in story.memory_layer if "partner_id" in m
}
unique_interactions = set()
for memory in story.memory_layer:
if hasattr(memory, 'partner_id') and memory.partner_id is not None:
unique_interactions.add(memory.partner_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Convert for loop into set comprehension (set-comprehension)

Suggested change
# Safely get unique interactions
unique_interactions = {
m["partner_id"] for m in story.memory_layer if "partner_id" in m
}
unique_interactions = set()
for memory in story.memory_layer:
if hasattr(memory, 'partner_id') and memory.partner_id is not None:
unique_interactions.add(memory.partner_id)
unique_interactions = {
memory.partner_id
for memory in story.memory_layer
if hasattr(memory, 'partner_id') and memory.partner_id is not None
}

@leonvanbokhorst leonvanbokhorst merged commit ffeacfb into main Oct 27, 2024
1 check passed
@leonvanbokhorst leonvanbokhorst deleted the bug-fixes branch October 27, 2024 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant