JC321 commited on
Commit
8a99c90
·
verified ·
1 Parent(s): 852ab2d

Upload financial_analyzer.py

Browse files
Files changed (1) hide show
  1. financial_analyzer.py +7 -3
financial_analyzer.py CHANGED
@@ -146,12 +146,13 @@ class FinancialAnalyzer:
146
  break # Found revenue tag, no need to check more
147
 
148
  # Step 5: Generate period list for target years
 
149
  periods = []
150
  for file_year in target_years:
151
  # Try to get fiscal year from mapping, otherwise use filing year
152
  fiscal_year = filing_to_fiscal_year.get(file_year, file_year)
153
 
154
- # Add annual data for this fiscal year
155
  periods.append({
156
  'period': str(fiscal_year),
157
  'type': 'annual',
@@ -159,7 +160,7 @@ class FinancialAnalyzer:
159
  'filing_year': file_year
160
  })
161
 
162
- # Add quarterly data for this fiscal year
163
  for quarter in range(4, 0, -1):
164
  periods.append({
165
  'period': f"{fiscal_year}Q{quarter}",
@@ -169,7 +170,7 @@ class FinancialAnalyzer:
169
  })
170
 
171
  # Step 6: Get financial data for each period
172
- for period_info in periods:
173
  period = period_info['period']
174
  fiscal_year = period_info['fiscal_year']
175
 
@@ -180,6 +181,9 @@ class FinancialAnalyzer:
180
  if period_info['type'] == 'annual':
181
  data["period"] = f"FY{fiscal_year}"
182
 
 
 
 
183
  financial_data.append(data)
184
 
185
  return financial_data
 
146
  break # Found revenue tag, no need to check more
147
 
148
  # Step 5: Generate period list for target years
149
+ # For each year: FY -> Q4 -> Q3 -> Q2 -> Q1 (descending order)
150
  periods = []
151
  for file_year in target_years:
152
  # Try to get fiscal year from mapping, otherwise use filing year
153
  fiscal_year = filing_to_fiscal_year.get(file_year, file_year)
154
 
155
+ # First add annual data for this fiscal year
156
  periods.append({
157
  'period': str(fiscal_year),
158
  'type': 'annual',
 
160
  'filing_year': file_year
161
  })
162
 
163
+ # Then add quarterly data in descending order: Q4, Q3, Q2, Q1
164
  for quarter in range(4, 0, -1):
165
  periods.append({
166
  'period': f"{fiscal_year}Q{quarter}",
 
170
  })
171
 
172
  # Step 6: Get financial data for each period
173
+ for idx, period_info in enumerate(periods):
174
  period = period_info['period']
175
  fiscal_year = period_info['fiscal_year']
176
 
 
181
  if period_info['type'] == 'annual':
182
  data["period"] = f"FY{fiscal_year}"
183
 
184
+ # Add sequence number to maintain order
185
+ data["_sequence"] = idx
186
+
187
  financial_data.append(data)
188
 
189
  return financial_data