Skip to content

Instantly share code, notes, and snippets.

View prfraser's full-sized avatar
🎯
Focusing

Philip Fraser prfraser

🎯
Focusing
  • Brisbane, Australia
View GitHub Profile

Performance Optimization ELI5: Single Stat by Time Report 🚀

The Old Way (Slow) 🐌

Imagine you're organizing a huge toy box with 1000 toys, and you want to sort them by color and put them in different rooms.

Old way was like this:

  1. "Where's the red car?" - You look through ALL 1000 toys to find red cars
  2. "Where's the blue car?" - You look through ALL 1000 toys AGAIN to find blue cars
  3. "Where's the green car?" - You look through ALL 1000 toys AGAIN...
You are a product management assistant specialized in creating Shape Up methodology documents. Your task is to help create a comprehensive "shape doc" (pitch) for the following topic:
<new_shape_topic>
{{new_shape_topic}}
</new_shape_topic>
Shape docs are crucial in the Shape Up development methodology for presenting problems and solutions to the betting table, providing clear direction to development teams, and setting appropriate boundaries and expectations for the work.
Your goal is to create a shape doc that follows the Structure Up template and adheres to the following principles:

⏺ How Automatic Sales Predictions Work with the "Average of Dates" Strategy

Overview

When an organisation uses the "average of dates" forecasting strategy, the system automatically creates sales predictions to help with roster planning. These predictions are generated intelligently and stored in the database, but the process happens "on-demand" rather than through scheduled background tasks.

The Complete Chain of Events

1. Initial Setup

You are an expert in Ruby on Rails, Sorbet, PostgreSQL, Hotwire (Turbo and Stimulus) and Tailwind CSS.
Code Style and Structure
- Write concise, idiomatic Ruby code with accurate examples.
- Follow Rails conventions and best practices.
- Use object-oriented and functional programming patterns as appropriate.
- Prefer iteration and modularization over code duplication.
- Use descriptive variable and method names (e.g., user_signed_in?, calculate_total).
- Structure files according to Rails conventions (MVC, concerns, helpers, etc.).
@prfraser
prfraser / base.rb
Last active September 30, 2024 06:13
class WorkforceReport::Base
# ... existing code ...
sig { returns(T::Boolean) }
def sortable_columns?
is_a?(WorkforceReport::Concerns::Sortable)
end
# Remove the reports_with_sortable_columns method
end
def save_report
result = SaveReportService.call(@report_params)
if result.success?
redirect_to workforce_report_path(result.report.report_key, params: { saved_report_id: result.report.id }),
notice: "Report saved successfully"
else
redirect_to workforce_report_path(params[:id]), alert: result.error_message
end
end