Spaces:
Sleeping

Markishime commited on
Commit
329ee7f
·
1 Parent(s): 412d66d

Update results, pdf_utils, and translations

Browse files
Files changed (3) hide show
  1. modules/results.py +7 -12
  2. utils/pdf_utils.py +11 -13
  3. utils/translations.py +0 -18
modules/results.py CHANGED
@@ -10971,7 +10971,7 @@ def create_yield_projection_viz(yield_data):
10971
 
10972
  return {
10973
  'type': 'line_chart',
10974
- 'title': t('yield_forecast_by_scenario', '5-Year Yield Forecast by Investment Scenario'),
10975
  'subtitle': 'Projected yield increase over 5 years with different investment levels',
10976
  'data': {
10977
  'categories': [f'Year {year}' for year in years],
@@ -16588,12 +16588,9 @@ def display_forecast_graph_content(analysis_data, step_number=None, step_title=N
16588
  """Display Forecast Graph content with baseline - works for any step with yield forecast data"""
16589
  # Dynamic header based on step information
16590
  if step_number and step_title:
16591
- step_prefix = t('step_prefix', 'STEP')
16592
- forecast_header = t('yield_forecast_5_year_header', '5-Year Yield Forecast & Projections')
16593
- header_title = f"📈 {step_prefix} {step_number} — {step_title}: {forecast_header}"
16594
  else:
16595
- forecast_header = t('yield_forecast_5_year_header', '5-Year Yield Forecast & Projections')
16596
- header_title = f"📈 {forecast_header}"
16597
 
16598
  # Styled header with updated background color
16599
  st.markdown(
@@ -16770,7 +16767,7 @@ def display_forecast_graph_content(analysis_data, step_number=None, step_title=N
16770
  ))
16771
 
16772
  fig.update_layout(
16773
- title=t('yield_projection_from_baseline', '5-Year Yield Projection from Current Baseline'),
16774
  xaxis_title='Years',
16775
  yaxis_title='Yield (tons/ha)',
16776
  xaxis=dict(
@@ -16908,8 +16905,7 @@ def display_economic_forecast(economic_forecast):
16908
  # Display 5-year projection if available
16909
  five_year_projection = economic_forecast.get('five_year_projection', {})
16910
  if five_year_projection:
16911
- projection_title = t('yield_projection_from_baseline', '5-Year Yield Projection from Current Baseline')
16912
- st.markdown(f"### 📊 {t('yield_forecast_5_year', '5-Year Yield Forecast')}")
16913
 
16914
  # Create projection chart
16915
  years = list(range(1, 6))
@@ -16926,7 +16922,7 @@ def display_economic_forecast(economic_forecast):
16926
  ))
16927
 
16928
  fig.update_layout(
16929
- title=t('yield_projection_from_baseline', '5-Year Yield Projection from Current Baseline'),
16930
  xaxis_title="Year",
16931
  yaxis_title="Yield (tonnes/hectare)",
16932
  height=400
@@ -17084,8 +17080,7 @@ def display_forecast_visualization(analysis_data):
17084
  if not forecast_data:
17085
  return
17086
 
17087
- forecast_title = t('yield_forecast_5_year', '5-Year Yield Forecast')
17088
- st.markdown(f"### 📈 {forecast_title}")
17089
 
17090
  # Create interactive Plotly chart
17091
  years = list(range(2024, 2029))
 
10971
 
10972
  return {
10973
  'type': 'line_chart',
10974
+ 'title': '5-Year Yield Forecast by Investment Scenario',
10975
  'subtitle': 'Projected yield increase over 5 years with different investment levels',
10976
  'data': {
10977
  'categories': [f'Year {year}' for year in years],
 
16588
  """Display Forecast Graph content with baseline - works for any step with yield forecast data"""
16589
  # Dynamic header based on step information
16590
  if step_number and step_title:
16591
+ header_title = f"📈 STEP {step_number} — {step_title}: 5-Year Yield Forecast & Projections"
 
 
16592
  else:
16593
+ header_title = "📈 5-Year Yield Forecast & Projections"
 
16594
 
16595
  # Styled header with updated background color
16596
  st.markdown(
 
16767
  ))
16768
 
16769
  fig.update_layout(
16770
+ title='5-Year Yield Projection from Current Baseline',
16771
  xaxis_title='Years',
16772
  yaxis_title='Yield (tons/ha)',
16773
  xaxis=dict(
 
16905
  # Display 5-year projection if available
16906
  five_year_projection = economic_forecast.get('five_year_projection', {})
16907
  if five_year_projection:
16908
+ st.markdown("### 📊 5-Year Yield Projection")
 
16909
 
16910
  # Create projection chart
16911
  years = list(range(1, 6))
 
16922
  ))
16923
 
16924
  fig.update_layout(
16925
+ title="5-Year Yield Projection",
16926
  xaxis_title="Year",
16927
  yaxis_title="Yield (tonnes/hectare)",
16928
  height=400
 
17080
  if not forecast_data:
17081
  return
17082
 
17083
+ st.markdown("### 📈 5-Year Yield Forecast")
 
17084
 
17085
  # Create interactive Plotly chart
17086
  years = list(range(2024, 2029))
utils/pdf_utils.py CHANGED
@@ -1049,7 +1049,7 @@ class PDFReportGenerator:
1049
  executive_sections.append(f"Year 5 projections: Low {year5_row[1]}, Medium {year5_row[2]}, High {year5_row[3]}")
1050
 
1051
  if not any("year" in section.lower() or "projection" in section.lower() for section in executive_sections[-5:]):
1052
- executive_sections.append(self._t('yield_projections_sustainable', '5-year yield projections indicate sustainable production improvements with proper nutrient management.'))
1053
  executive_sections.append("")
1054
 
1055
  # 7. REGENERATIVE AGRICULTURE - Pull from Step 4
@@ -4051,8 +4051,7 @@ class PDFReportGenerator:
4051
  logger.info("🔍 DEBUG Step 6 - Chart is None, adding failure message")
4052
  story.append(Paragraph(f"📈 {step_prefix} 6 — {forecast_title}", self.styles['Heading3']))
4053
  story.append(Spacer(1, 8))
4054
- error_msg = self._t('yield_forecast_5_year', '5-Year Yield Forecast') + " (t/ha) - Chart generation failed"
4055
- story.append(Paragraph(error_msg, self.styles['Normal']))
4056
 
4057
  except Exception as e:
4058
  logger.error(f"❌ Step 6: Error adding yield forecast chart: {str(e)}")
@@ -4062,8 +4061,7 @@ class PDFReportGenerator:
4062
  forecast_title = self._t('pdf_forecast_graph_title', 'Forecast Graph: 5-Year Yield Forecast & Projections')
4063
  story.append(Paragraph(f"📈 {step_prefix} 6 — {forecast_title}", self.styles['Heading3']))
4064
  story.append(Spacer(1, 8))
4065
- error_msg = self._t('yield_forecast_5_year', '5-Year Yield Forecast') + " (t/ha) - Chart generation error"
4066
- story.append(Paragraph(error_msg, self.styles['Normal']))
4067
 
4068
  # Visualizations and Charts - ONLY Step 1 bar graphs; remove charts for Steps 2-6
4069
  try:
@@ -4341,7 +4339,7 @@ class PDFReportGenerator:
4341
 
4342
  return {
4343
  'type': 'line_chart',
4344
- 'title': self._t('yield_forecast_by_scenario', '5-Year Yield Forecast by Investment Scenario'),
4345
  'subtitle': 'Projected yield increase over 5 years with different investment levels',
4346
  'data': {
4347
  'categories': [f'Year {year}' for year in years],
@@ -6077,7 +6075,7 @@ class PDFReportGenerator:
6077
 
6078
  # Yield Projections Table
6079
  if 'yield_projections' in step and step['yield_projections']:
6080
- story.append(Paragraph(self._t('pdf_yield_projections', '5-Year Yield Projections'), self.styles['Heading3']))
6081
  projections = step['yield_projections']
6082
 
6083
  years = list(range(2025, 2030))
@@ -6712,7 +6710,7 @@ class PDFReportGenerator:
6712
 
6713
  ax.set_xlabel('Year')
6714
  ax.set_ylabel('Yield (tonnes/hectare)')
6715
- ax.set_title(self._t('yield_projections_by_level', '5-Year Yield Projections by Investment Level'))
6716
  ax.legend()
6717
  ax.grid(True, alpha=0.3)
6718
  ax.set_xticks(years)
@@ -7008,7 +7006,7 @@ class PDFReportGenerator:
7008
  story = []
7009
 
7010
  # 5-Year Yield Forecast header
7011
- story.append(Paragraph(self._t('yield_forecast_5_year', '5-Year Yield Forecast'), self.styles['Heading1']))
7012
  story.append(Spacer(1, 12))
7013
 
7014
  # Find yield forecast data from multiple possible locations
@@ -7136,7 +7134,7 @@ class PDFReportGenerator:
7136
  # Customize the graph
7137
  ax.set_xlabel('Years', fontsize=12, fontweight='bold')
7138
  ax.set_ylabel('Yield (tons/ha)', fontsize=12, fontweight='bold')
7139
- ax.set_title(self._t('yield_forecast_from_baseline', '5-Year Yield Forecast from Current Baseline'), fontsize=14, fontweight='bold')
7140
  ax.legend(fontsize=10)
7141
  ax.grid(True, alpha=0.3)
7142
  ax.set_xticks(years)
@@ -7191,7 +7189,7 @@ class PDFReportGenerator:
7191
  # Customize the graph
7192
  ax.set_xlabel('Years', fontsize=12, fontweight='bold')
7193
  ax.set_ylabel('Yield (tons/ha)', fontsize=12, fontweight='bold')
7194
- ax.set_title(self._t('yield_forecast_sample_projections', '5-Year Yield Forecast - Sample Projections'), fontsize=14, fontweight='bold')
7195
  ax.legend(fontsize=10)
7196
  ax.grid(True, alpha=0.3)
7197
  ax.set_xticks(years)
@@ -8071,7 +8069,7 @@ class PDFReportGenerator:
8071
  # Set chart properties - IMPROVED TO MATCH RESULTS PAGE
8072
  ax.set_xlabel('Years', fontsize=12, fontweight='bold')
8073
  ax.set_ylabel('Yield (tons/ha)', fontsize=12, fontweight='bold')
8074
- ax.set_title(self._t('yield_projection_from_baseline', '5-Year Yield Projection from Current Baseline'), fontsize=14, fontweight='bold', pad=20)
8075
 
8076
  # Position legend at top right - EXACT SAME AS RESULTS PAGE
8077
  ax.legend(loc='upper right', bbox_to_anchor=(1.0, 1.0), framealpha=0.8)
@@ -8245,7 +8243,7 @@ class PDFReportGenerator:
8245
 
8246
  ax.set_xlabel('Year')
8247
  ax.set_ylabel('Yield (tonnes/hectare)')
8248
- ax.set_title(self._t('yield_forecast_tha', '5-Year Yield Forecast (t/ha)'))
8249
  ax.legend()
8250
  ax.grid(True, alpha=0.3)
8251
 
 
1049
  executive_sections.append(f"Year 5 projections: Low {year5_row[1]}, Medium {year5_row[2]}, High {year5_row[3]}")
1050
 
1051
  if not any("year" in section.lower() or "projection" in section.lower() for section in executive_sections[-5:]):
1052
+ executive_sections.append("5-year yield projections indicate sustainable production improvements with proper nutrient management.")
1053
  executive_sections.append("")
1054
 
1055
  # 7. REGENERATIVE AGRICULTURE - Pull from Step 4
 
4051
  logger.info("🔍 DEBUG Step 6 - Chart is None, adding failure message")
4052
  story.append(Paragraph(f"📈 {step_prefix} 6 — {forecast_title}", self.styles['Heading3']))
4053
  story.append(Spacer(1, 8))
4054
+ story.append(Paragraph("5-Year Yield Forecast (t/ha) - Chart generation failed", self.styles['Normal']))
 
4055
 
4056
  except Exception as e:
4057
  logger.error(f"❌ Step 6: Error adding yield forecast chart: {str(e)}")
 
4061
  forecast_title = self._t('pdf_forecast_graph_title', 'Forecast Graph: 5-Year Yield Forecast & Projections')
4062
  story.append(Paragraph(f"📈 {step_prefix} 6 — {forecast_title}", self.styles['Heading3']))
4063
  story.append(Spacer(1, 8))
4064
+ story.append(Paragraph("5-Year Yield Forecast (t/ha) - Chart generation error", self.styles['Normal']))
 
4065
 
4066
  # Visualizations and Charts - ONLY Step 1 bar graphs; remove charts for Steps 2-6
4067
  try:
 
4339
 
4340
  return {
4341
  'type': 'line_chart',
4342
+ 'title': '5-Year Yield Forecast by Investment Scenario',
4343
  'subtitle': 'Projected yield increase over 5 years with different investment levels',
4344
  'data': {
4345
  'categories': [f'Year {year}' for year in years],
 
6075
 
6076
  # Yield Projections Table
6077
  if 'yield_projections' in step and step['yield_projections']:
6078
+ story.append(Paragraph("5-Year Yield Projections", self.styles['Heading3']))
6079
  projections = step['yield_projections']
6080
 
6081
  years = list(range(2025, 2030))
 
6710
 
6711
  ax.set_xlabel('Year')
6712
  ax.set_ylabel('Yield (tonnes/hectare)')
6713
+ ax.set_title('5-Year Yield Projections by Investment Level')
6714
  ax.legend()
6715
  ax.grid(True, alpha=0.3)
6716
  ax.set_xticks(years)
 
7006
  story = []
7007
 
7008
  # 5-Year Yield Forecast header
7009
+ story.append(Paragraph("5-Year Yield Forecast", self.styles['Heading1']))
7010
  story.append(Spacer(1, 12))
7011
 
7012
  # Find yield forecast data from multiple possible locations
 
7134
  # Customize the graph
7135
  ax.set_xlabel('Years', fontsize=12, fontweight='bold')
7136
  ax.set_ylabel('Yield (tons/ha)', fontsize=12, fontweight='bold')
7137
+ ax.set_title('5-Year Yield Forecast from Current Baseline', fontsize=14, fontweight='bold')
7138
  ax.legend(fontsize=10)
7139
  ax.grid(True, alpha=0.3)
7140
  ax.set_xticks(years)
 
7189
  # Customize the graph
7190
  ax.set_xlabel('Years', fontsize=12, fontweight='bold')
7191
  ax.set_ylabel('Yield (tons/ha)', fontsize=12, fontweight='bold')
7192
+ ax.set_title('5-Year Yield Forecast - Sample Projections', fontsize=14, fontweight='bold')
7193
  ax.legend(fontsize=10)
7194
  ax.grid(True, alpha=0.3)
7195
  ax.set_xticks(years)
 
8069
  # Set chart properties - IMPROVED TO MATCH RESULTS PAGE
8070
  ax.set_xlabel('Years', fontsize=12, fontweight='bold')
8071
  ax.set_ylabel('Yield (tons/ha)', fontsize=12, fontweight='bold')
8072
+ ax.set_title('5-Year Yield Projection from Current Baseline', fontsize=14, fontweight='bold', pad=20)
8073
 
8074
  # Position legend at top right - EXACT SAME AS RESULTS PAGE
8075
  ax.legend(loc='upper right', bbox_to_anchor=(1.0, 1.0), framealpha=0.8)
 
8243
 
8244
  ax.set_xlabel('Year')
8245
  ax.set_ylabel('Yield (tonnes/hectare)')
8246
+ ax.set_title('5-Year Yield Forecast (t/ha)')
8247
  ax.legend()
8248
  ax.grid(True, alpha=0.3)
8249
 
utils/translations.py CHANGED
@@ -266,15 +266,6 @@ TRANSLATIONS = {
266
 
267
  # Yield Forecast
268
  'yield_forecast_title': 'Yield Forecast & Projections',
269
- 'yield_forecast_5_year_header': '5-Year Yield Forecast & Projections',
270
- 'yield_forecast_5_year': '5-Year Yield Forecast',
271
- 'yield_projection_from_baseline': '5-Year Yield Projection from Current Baseline',
272
- 'yield_forecast_from_baseline': '5-Year Yield Forecast from Current Baseline',
273
- 'yield_forecast_sample_projections': '5-Year Yield Forecast - Sample Projections',
274
- 'yield_forecast_tha': '5-Year Yield Forecast (t/ha)',
275
- 'yield_forecast_by_scenario': '5-Year Yield Forecast by Investment Scenario',
276
- 'yield_projections_by_level': '5-Year Yield Projections by Investment Level',
277
- 'yield_projections_sustainable': '5-year yield projections indicate sustainable production improvements with proper nutrient management.',
278
  'baseline_yield': 'Baseline Yield',
279
  'projected_yield': 'Projected Yield',
280
  'year_1': 'Year 1',
@@ -684,15 +675,6 @@ TRANSLATIONS = {
684
 
685
  # Yield Forecast (Malaysian)
686
  'yield_forecast_title': 'Ramalan & Unjuran Hasil',
687
- 'yield_forecast_5_year_header': 'Ramalan & Unjuran Hasil 5 Tahun',
688
- 'yield_forecast_5_year': 'Ramalan Hasil 5 Tahun',
689
- 'yield_projection_from_baseline': 'Unjuran Hasil 5 Tahun dari Asas Semasa',
690
- 'yield_forecast_from_baseline': 'Ramalan Hasil 5 Tahun dari Asas Semasa',
691
- 'yield_forecast_sample_projections': 'Ramalan Hasil 5 Tahun - Unjuran Sampel',
692
- 'yield_forecast_tha': 'Ramalan Hasil 5 Tahun (t/ha)',
693
- 'yield_forecast_by_scenario': 'Ramalan Hasil 5 Tahun mengikut Senario Pelaburan',
694
- 'yield_projections_by_level': 'Unjuran Hasil 5 Tahun mengikut Tahap Pelaburan',
695
- 'yield_projections_sustainable': 'Unjuran hasil 5 tahun menunjukkan peningkatan pengeluaran mampan dengan pengurusan nutrien yang betul.',
696
  'baseline_yield': 'Hasil Asas',
697
  'projected_yield': 'Hasil Unjuran',
698
  'year_1': 'Tahun 1',
 
266
 
267
  # Yield Forecast
268
  'yield_forecast_title': 'Yield Forecast & Projections',
 
 
 
 
 
 
 
 
 
269
  'baseline_yield': 'Baseline Yield',
270
  'projected_yield': 'Projected Yield',
271
  'year_1': 'Year 1',
 
675
 
676
  # Yield Forecast (Malaysian)
677
  'yield_forecast_title': 'Ramalan & Unjuran Hasil',
 
 
 
 
 
 
 
 
 
678
  'baseline_yield': 'Hasil Asas',
679
  'projected_yield': 'Hasil Unjuran',
680
  'year_1': 'Tahun 1',