AutoSkill firestore_expenses_lifecycle_and_charting
Manages the full lifecycle of Firestore expense data, including date-based initialization, additive array updates across time granularities, and time-series visualization using Jetpack Compose and Vico.
git clone https://github.com/ECNU-ICALK/AutoSkill
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/firestore_expenses_lifecycle_and_charting" ~/.claude/skills/ecnu-icalk-autoskill-firestore-expenses-lifecycle-and-charting && rm -rf "$T"
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/firestore_expenses_lifecycle_and_charting/SKILL.mdfirestore_expenses_lifecycle_and_charting
Manages the full lifecycle of Firestore expense data, including date-based initialization, additive array updates across time granularities, and time-series visualization using Jetpack Compose and Vico.
Prompt
Role & Objective
Act as an Android/Kotlin developer specializing in Jetpack Compose and Firestore. Your task is to provide a complete solution for managing expenses, including date formatting utilities, database initialization with parallel arrays, additive updates, and time-series chart visualization.
Operational Rules & Constraints
1. Date Utilities
Create a Kotlin object named
DateUtils containing helper functions for date formatting. The date formats must use underscores for readability and follow these specific patterns:
- Year:
(e.g., 2023)yyyy - Month:
(e.g., Apr_2023)MMM_yyyy - Week:
(e.g., Week_2_Apr_2023)Week_{weekNum}_MMM_yyyy - Day:
(e.g., Sunday_09_Apr_2023)EEEE_dd_MMM_yyyy
2. Data Structure
All Firestore documents under the
yearly, monthly, weekly, and daily subcollections must adhere to the following parallel array structure:
: List<String> (Item names)name
: List<Int> (Item quantities)quantity
: List<Double> (Item costs)expenses
: Double (Sum of thetotalExpenses
array)expenses
3. Data Initialization
Create a function
initUserExpenses that accepts userId, name, quantity, and expenses.
- The function must write to Firestore subcollections:
,yearly
,monthly
, andweekly
under thedaily
collection for the given user.expenses - The document ID for each subcollection must correspond to the formatted date string from
.DateUtils - The document data must initialize the parallel arrays with the provided values and calculate the initial
.totalExpenses
4. Update Logic (Additive)
Create a function
updateUserExpenses that accepts userId, itemName, quantity, and expense.
- Target Collections: Update the four subcollections (
,yearly
,monthly
,weekly
) underdaily
.db.collection("expenses").document(userId) - Retrieve & Cast: Fetch the document and safely cast array fields to mutable lists using
.as? List<Type> ?: mutableListOf() - Merge Logic: Iterate through the
list.name- If item exists: Increment the corresponding
andquantity
values.expenses - If item does not exist: Append the new item data to the lists.
- If item exists: Increment the corresponding
- Aggregation: Recalculate
as the sum of the updatedtotalExpenses
list.expenses - Write: Construct an update map using the mutable lists and write back to Firestore. Use
andaddOnSuccessListener
for result handling.addOnFailureListener
5. Charting & Visualization
Implement a time-series chart component that fetches data from the Firestore subcollections, parses document IDs as dates, and filters data based on relative timeframes.
- Firestore Structure: Assume a parent collection containing a document (e.g., entity ID), which contains the subcollections.
- Date Parsing: Document IDs serve as timestamps. Parse them using
with the patterns defined inSimpleDateFormat
.DateUtils - Timeframe Logic: Implement filtering logic based on the selected button:
- Daily: Show data for the current week (7 days).
- Weekly: Show data for the current month (4 weeks).
- Monthly: Show data for the current year (12 months).
- Yearly: Show all available data.
- Data Mapping: Retrieve the numeric value from the
field.totalExpenses - Chart Integration: Use the Vico chart library. Resolve
ambiguity by mapping values to Pairs (e.g.,entriesOf
).it to 0
Anti-Patterns
- Do not rely on a
field; use the document ID.timestamp - Do not hardcode specific entity names (like "Kantin"); use generic parameters or variables.
- Do not use the character 'e' inside the
pattern string for the week format to avoidSimpleDateFormat
errors; use string concatenation for the week number prefix if necessary.Illegal pattern character - Do not hardcode specific dates; use
.Calendar.getInstance() - Do not use read-only lists for the update map; ensure lists are mutable before updating.
Triggers
- create firestore expenses database
- update firestore expenses arrays
- format date strings for firestore
- implement time series chart filtering
- sync daily weekly monthly expenses