Skip to content

docs: add analysis module examples#113

Merged
mvanwyk merged 3 commits into
mainfrom
add_analysis_module_docs
Feb 28, 2025
Merged

docs: add analysis module examples#113
mvanwyk merged 3 commits into
mainfrom
add_analysis_module_docs

Conversation

@mvanwyk

@mvanwyk mvanwyk commented Feb 27, 2025

Copy link
Copy Markdown
Contributor

Added some docs examples and cleaned up some existing once to simplify/lint them.

Summary by CodeRabbit

  • New Features

    • Introduced new analysis modules covering topics such as cross-shop analysis, financial gain/loss, customer decision processes, revenue insights, segmentation stats, purchase patterns, and churn tracking—with practical usage examples.
  • Bug Fixes

    • Corrected the spelling of the parameter name from "cumlative" to "cumulative" in documentation and code examples, ensuring accurate functionality in plotting methods.
  • Documentation

    • Enhanced clarity and readability through restructured content, including added sections, clear descriptions, example code snippets, and improved formatting for easier understanding.

@mvanwyk mvanwyk requested review from Copilot and mayurkmmt February 27, 2025 08:15
@coderabbitai

coderabbitai Bot commented Feb 27, 2025

Copy link
Copy Markdown

Walkthrough

This pull request updates the documentation and public API definitions. The documentation in docs/analysis_modules.md has been significantly expanded with new sections describing several modules, including Cross Shop, Gain Loss, Customer Decision Hierarchy, Revenue Tree, Segmentation Stats, Purchases Per Customer, Days Between Purchases, and Transaction Churn. The content has been reformatted for improved clarity, with added example code snippets and tables. Additionally, new module declarations have been introduced across various namespaces to support these functionalities.

Changes

File(s) Change Summary
docs/analysis_modules.md Added new sections detailing modules (Cross Shop, Gain Loss, Customer Decision Hierarchy, Revenue Tree, Segmentation Stats, Purchases Per Customer, Days Between Purchases, Transaction Churn) along with example code snippets, tables, and restructured text for better readability.
pyretailscience/{cross_shop, gain_loss, range_planning, segmentation, customer} New public module declarations added: CrossShop, GainLoss, CustomerDecisionHierarchy, SegTransactionStats, PurchasesPerCustomer, DaysBetweenPurchases, and TransactionChurn.
README.md Corrected spelling of parameter cumlative to cumulative in dbp.plot() method call.
docs/examples/retention.ipynb Corrected typographical error from cumlative to cumulative in two instances within the code.
pyretailscience/customer.py Updated method signatures and documentation from cumlative to cumulative in classes PurchasesPerCustomer, DaysBetweenPurchases, and TransactionChurn.

Possibly related PRs

  • docs: updated analysis module docs #80 – Enhancements to the documentation of the "Customer Decision Hierarchy" module, related to the new sections and examples in this PR.
  • feat: updated docs and README.md #61 – Updates in the customer.py file, specifically modifications to the plot method signatures, which are also mentioned in this PR's documentation updates for customer analysis.

Suggested labels

documentation, enhancement, Review effort [1-5]: 3

Suggested reviewers

  • mayurkmmt

Poem

I'm a little rabbit hopping through the code,
New modules and docs light up my humble abode.
Cross Shop and Gain Loss dance in a cheerful spree,
Customer Decision Hierarchy and others join merrily.
In every line and snippet, joy and clarity overflow!
🐇💻 Happy hops to changes that help us grow!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mvanwyk mvanwyk self-assigned this Feb 27, 2025
@codecov

codecov Bot commented Feb 27, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pyretailscience/customer.py 0.00% 7 Missing ⚠️
Files with missing lines Coverage Δ
pyretailscience/customer.py 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
docs/analysis_modules.md (3)

62-65: Clarify Histogram Description Text.
The revised description explains how histograms visualize data distributions and group comparisons well. Consider a brief rephrasing to enhance readability (e.g., breaking up the long sentence) but overall it is clear.


621-626: Clarify Segmentation Stats Description and Punctuation.
The comprehensive description for the Segmentation Stats module is effective. Note that around line 625 there may be a missing comma; please review the sentence for proper punctuation to maximize clarity.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~625-~625: Possible missing comma found.
Context: ...l when combined with other segmentation approaches like HML segmentation. Example...

(AI_HYDRA_LEO_MISSING_COMMA)


662-668: Correct Typo in Purchases Per Customer Description.
The module description is informative; however, the word “deteriming” on line 667 appears to be a typo. It should be corrected to “determining” to ensure clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd3847f and 48aad39.

⛔ Files ignored due to path filters (5)
  • docs/assets/images/analysis_modules/cross_shop.svg is excluded by !**/*.svg
  • docs/assets/images/analysis_modules/days_between_purchases.svg is excluded by !**/*.svg
  • docs/assets/images/analysis_modules/gain_loss.svg is excluded by !**/*.svg
  • docs/assets/images/analysis_modules/purchases_per_customer.svg is excluded by !**/*.svg
  • docs/assets/images/analysis_modules/transaction_churn.svg is excluded by !**/*.svg
📒 Files selected for processing (1)
  • docs/analysis_modules.md (5 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/analysis_modules.md

[uncategorized] ~625-~625: Possible missing comma found.
Context: ...l when combined with other segmentation approaches like HML segmentation. Example...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~727-~727: The verb form ‘reveal’ does not appear to fit in this context.
Context: ... of purchases customers have made. This help reveal critical retention thresholds in the cu...

(SINGULAR_NOUN_VERB_AGREEMENT)

🔇 Additional comments (8)
docs/analysis_modules.md (8)

73-74: Review Customization Options Description.
The added text describing customizable legends, axes, and clipping options provides useful detail. The language is consistent with other sections.


114-117: Verify Bar Plot Description Clarity.
The updated description clearly covers grouping, stacking, and the ability to add data labels for bar plots. Minor wording adjustments could be considered for uniformity across sections, but the overall message is clear.


125-126: Check Consistency in Bar Plot Flexibility Description.
The text emphasizing flexibility in customizing legends and axes is clear and matches the style used in other plot sections.


355-368: Enhance Cross Shop Section Description.
The new Cross Shop module details—including the image and descriptive text—provide a clear overview of how Venn/Euler diagrams illustrate cross-purchasing behavior. It may be beneficial to note (or link to) any specific input data requirements if not documented elsewhere.


397-406: Review Gain Loss Module Description.
The explanation concisely outlines the key aspects of the Gain Loss analysis, with a clear bullet list that aids comprehension. Ensure terms like “Switching” are defined or linked to further details for new users.


443-445: Validate Image Path for Customer Decision Hierarchy.
The image inclusion for the Customer Decision Hierarchy is correctly formatted with proper attributes. Double-check the asset path and dimensions to ensure they align with design guidelines.


518-520: Confirm Revenue Tree Date Filters.
The updated example for the Revenue Tree module now uses clear date-based filters. Please verify that the cutoff dates accurately reflect the intended analysis period in production.


690-704: Assess Days Between Purchases Module Description.
The detailed explanation in this section effectively outlines the module’s benefits and uses clear bullet points. Verify that terms like “cumulative” (if used elsewhere) are consistently spelled throughout the document.

Comment thread docs/analysis_modules.md
Comment on lines +724 to 728
![Transaction Churn](assets/images/analysis_modules/transaction_churn.svg){align=right loading=lazy width="50%"}

PASTE TEXT HERE
The Transaction Churn module analyzes how customer churn rates vary based on the number of purchases customers have
made. This help reveal critical retention thresholds in the customer lifecycle when setting a churn window

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix Grammatical Agreement in Transaction Churn Description.
The sentence "This help reveal critical retention thresholds" should be revised to "This helps reveal critical retention thresholds" to ensure correct subject–verb agreement.

🧰 Tools
🪛 LanguageTool

[grammar] ~727-~727: The verb form ‘reveal’ does not appear to fit in this context.
Context: ... of purchases customers have made. This help reveal critical retention thresholds in the cu...

(SINGULAR_NOUN_VERB_AGREEMENT)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
docs/analysis_modules.md (3)

621-626: Solid Overview for Segmentation Stats
The added description for the Segmentation Stats module provides a concise summary of the metrics calculated by the module. For clarity, consider rephrasing “customer (or transactions or promotions) groups” into a more explicit enumeration.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~625-~625: Possible missing comma found.
Context: ...l when combined with other segmentation approaches like HML segmentation. Example...

(AI_HYDRA_LEO_MISSING_COMMA)


734-743: Typo in Transaction Churn Example Code
There is a minor typo in the parameter name: cumlative should be cumulative to correctly reflect its intent. Consider applying the following diff:

-    cumlative=True,
+    cumulative=True,

625-626: Suggestion: Add a Comma for Clarity
Static analysis tools flagged a potential missing comma around here. To improve readability, consider adding a comma before “like HML segmentation” in the sentence within the Segmentation Stats section.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~625-~625: Possible missing comma found.
Context: ...l when combined with other segmentation approaches like HML segmentation. Example...

(AI_HYDRA_LEO_MISSING_COMMA)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48aad39 and b2ef479.

📒 Files selected for processing (1)
  • docs/analysis_modules.md (5 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/analysis_modules.md

[uncategorized] ~625-~625: Possible missing comma found.
Context: ...l when combined with other segmentation approaches like HML segmentation. Example...

(AI_HYDRA_LEO_MISSING_COMMA)

🔇 Additional comments (10)
docs/analysis_modules.md (10)

62-65: Clear and Informative Histogram Description
The added text clearly explains how histograms visualize data distributions and support grouping. The description is detailed and enhances reader understanding.


73-74: Concise Customization Details
The explanation of customization options for legends, axes, and filtering is clear and useful. Great job outlining these features!


114-117: Enhanced Bar Plot Explanation
The revised text for bar plots effectively describes how metrics can be compared and how data labels are applied. The clarity in detailing grouping and stacking options is commendable.


355-360: Comprehensive Cross Shop Section
The new Cross Shop section now includes an illustrative image and a precise description of its functionality. This addition makes it easier for users to grasp how cross-purchasing behavior is visualized.


397-408: Detailed Gain Loss Module Explanation
The Gain Loss section now features an image and a well-structured breakdown of customer behavior changes (new, lost, spending changes, and switching). The step‐by‐step list is clear and beneficial for users.


443-445: Effective Customer Decision Hierarchy Image Inclusion
The inclusion of the image for the Customer Decision Hierarchy (CDH) with proper alignment and loading attributes improves visual appeal and clarity.


518-519: Revenue Tree Example Update
The updated example for the Revenue Tree module now clearly differentiates between the two transaction periods using date filters. Please verify that the selected date ranges align with the analytics requirements.


662-664: Appropriate Purchases Per Customer Image Integration
The image for the Purchases Per Customer module is correctly integrated with clear alignment and lazy loading. This enhances the aesthetics and readability of the section.


690-692: Well-Handled Days Between Purchases Image
The inclusion of the Days Between Purchases image with proper formatting and alignment effectively supports the content. It contributes to a better visual understanding of the module.


724-728: Accurate Transaction Churn Description
The Transaction Churn section now correctly uses “helps reveal” rather than “help reveal,” ensuring grammatical accuracy. The description and image integration effectively communicate the module’s purpose.

@mvanwyk mvanwyk requested a review from Copilot February 27, 2025 09:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR Overview

This PR updates the documentation for analysis modules by adding new examples and enhancing existing content for clarity and readability.

  • Added detailed usage examples for modules like Cross Shop, Gain Loss, Customer Decision Hierarchy, Purchases Per Customer, Days Between Purchases, and Transaction Churn.
  • Improved image and code snippet formatting for better visual presentation and consistency.

Reviewed Changes

File Description
docs/analysis_modules.md Updated example content and markdown formatting to improve clarity and readability.

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread docs/analysis_modules.md Outdated

tc.plot(
title="Churn Rate by Number of Purchases",
cumlative=True,

Copilot AI Feb 27, 2025

Copy link

Choose a reason for hiding this comment

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

Typo detected: 'cumlative' should be corrected to 'cumulative'.

Suggested change
cumlative=True,
cumulative=True,

Copilot uses AI. Check for mistakes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/analysis_modules.md (1)

621-627: Well-written documentation for the Segmentation Stats module.

The new Segmentation Stats section clearly explains the purpose and functionality of the module.

Consider adding a comma after "approaches" in the following sentence:

-This module calculates metrics such as total spend, number of transactions, average spend per customer, and transactions per customer for each segment. It's particularly useful when combined with other segmentation approaches like HML segmentation.
+This module calculates metrics such as total spend, number of transactions, average spend per customer, and transactions per customer for each segment. It's particularly useful when combined with other segmentation approaches, like HML segmentation.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~625-~625: Possible missing comma found.
Context: ...l when combined with other segmentation approaches like HML segmentation. Example...

(AI_HYDRA_LEO_MISSING_COMMA)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2ef479 and 0784787.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • docs/analysis_modules.md (5 hunks)
  • docs/examples/retention.ipynb (2 hunks)
  • pyretailscience/customer.py (11 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/examples/retention.ipynb
🧰 Additional context used
🪛 GitHub Check: codecov/patch
pyretailscience/customer.py

[warning] 91-91: pyretailscience/customer.py#L91
Added line #L91 was not covered by tests


[warning] 268-268: pyretailscience/customer.py#L268
Added line #L268 was not covered by tests

🪛 LanguageTool
docs/analysis_modules.md

[uncategorized] ~625-~625: Possible missing comma found.
Context: ...l when combined with other segmentation approaches like HML segmentation. Example...

(AI_HYDRA_LEO_MISSING_COMMA)

🔇 Additional comments (20)
README.md (1)

111-111: Parameter name spelling fix correctly applied.

The parameter name has been correctly updated from cumlative to cumulative, ensuring consistency with the underlying API changes in the customer.py file.

pyretailscience/customer.py (8)

46-46: Parameter name spelling correction in PurchasesPerCustomer class.

The parameter name has been correctly updated from cumlative to cumulative in both the method signature and docstring.

Also applies to: 59-59


73-74: Consistent parameter usage in conditional logic and method call.

The parameter name has been properly updated in both the conditional check and the method call to hist().

Also applies to: 81-81


90-92: Parameter name spelling correction in title logic.

The conditional check and default title logic now correctly use the cumulative parameter name.

The line is flagged as not covered by tests. Consider adding a test case that exercises the cumulative plotting functionality to ensure complete coverage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 91-91: pyretailscience/customer.py#L91
Added line #L91 was not covered by tests


224-224: Parameter name spelling correction in DaysBetweenPurchases class.

The parameter name has been correctly updated from cumlative to cumulative in both the method signature and docstring.

Also applies to: 237-237


251-252: Consistent parameter usage in conditional logic and method call.

The parameter name has been properly updated in both the conditional check and the method call to hist().

Also applies to: 256-256


267-268: Parameter name spelling correction in title logic.

The conditional check and default title logic now correctly use the cumulative parameter name.

The line is flagged as not covered by tests. Consider adding a test case that exercises the cumulative plotting functionality to ensure complete coverage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 268-268: pyretailscience/customer.py#L268
Added line #L268 was not covered by tests


373-373: Parameter name spelling correction in TransactionChurn class.

The parameter name has been correctly updated from cumlative to cumulative in both the method signature and docstring.

Also applies to: 384-384


395-396: Consistent parameter usage in conditional logic.

The parameter name has been properly updated in the conditional check that determines the plotting behavior.

docs/analysis_modules.md (11)

355-371: Well-structured documentation for the Cross Shop module.

The new Cross Shop section provides clear explanations of the module's functionality, applications, and usage. The example code demonstrates the correct API usage with appropriate parameter names.


397-437: Comprehensive documentation for the Gain Loss module.

The Gain Loss section effectively explains the module's purpose, key components, and practical applications. The example code is clear and demonstrates proper API usage.


518-520: Updated example code for the Revenue Tree module.

The example code for the Revenue Tree module has been updated with more realistic parameter values.


633-648: Clear example code for the Segmentation Stats module.

The example code effectively demonstrates how to use the SegTransactionStats class with an HML segmentation.


650-656: Helpful example output table for Segmentation Stats.

The example output table clearly shows what kind of information the module provides, making it easy for users to understand the expected results.


662-669: Concise documentation for the Purchases Per Customer module.

The Purchases Per Customer section provides a clear explanation of the module's purpose and benefits.


675-684: Straightforward example for the Purchases Per Customer module.

The example code demonstrates proper usage of the PurchasesPerCustomer class with appropriate parameters.


690-705: Detailed documentation for the Days Between Purchases module.

The Days Between Purchases section provides comprehensive information about the module's functionality and benefits, with clear applications for business use cases.


711-718: Clear example for the Days Between Purchases module.

The example code effectively demonstrates how to use the DaysBetweenPurchases class.


724-728: Brief but informative documentation for the Transaction Churn module.

The Transaction Churn section succinctly explains the module's purpose and key benefits.


734-743: Proper example for the Transaction Churn module with correct parameter name.

The example code demonstrates the correct usage of the TransactionChurn class with the properly spelled cumulative parameter.

@mvanwyk mvanwyk merged commit 1b6bea4 into main Feb 28, 2025
@mvanwyk mvanwyk deleted the add_analysis_module_docs branch February 28, 2025 09:20
@coderabbitai coderabbitai Bot mentioned this pull request Mar 18, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Apr 1, 2025
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.

3 participants