aditya-me13 commited on
Commit
39ab179
Β·
1 Parent(s): b395e0e

Checkpoint on 9th Oct - Everything Working

Browse files
Files changed (3) hide show
  1. app.py +90 -10
  2. templates/gallery.html +2 -2
  3. templates/view_interactive.html +17 -5
app.py CHANGED
@@ -524,16 +524,39 @@ def gallery():
524
 
525
  # Try to parse metadata from filename
526
  try:
527
- # Example: PM2_5_India_viridis_20200824_1200.png
528
  name_parts = filename.replace(plot_file.suffix, '').split('_')
529
- if len(name_parts) >= 3:
530
- file_info['variable'] = name_parts[0].replace('_', '.')
531
- file_info['region'] = name_parts[1] if len(name_parts) > 1 else 'Unknown'
532
- file_info['theme'] = name_parts[-2] if len(name_parts) > 2 else 'Unknown'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
533
  except:
534
  file_info['variable'] = 'Unknown'
535
  file_info['region'] = 'Unknown'
536
  file_info['theme'] = 'Unknown'
 
 
537
 
538
  plot_files.append(file_info)
539
 
@@ -552,15 +575,39 @@ def gallery():
552
 
553
  # Try to parse metadata from filename
554
  try:
 
555
  name_parts = filename.replace('.html', '').split('_')
556
- if len(name_parts) >= 3:
557
- file_info['variable'] = name_parts[0].replace('_', '.')
558
- file_info['region'] = name_parts[1] if len(name_parts) > 1 else 'Unknown'
559
- file_info['theme'] = name_parts[-2] if len(name_parts) > 2 else 'Unknown'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560
  except:
561
  file_info['variable'] = 'Unknown'
562
  file_info['region'] = 'Unknown'
563
  file_info['theme'] = 'Unknown'
 
 
564
 
565
  plot_files.append(file_info)
566
 
@@ -594,14 +641,47 @@ def view_interactive_plot(filename):
594
  with open(plot_path, 'r', encoding='utf-8') as f:
595
  html_content = f.read()
596
 
597
- # Create plot info from filename
598
  plot_info = {
599
  'variable': 'Unknown',
 
 
 
600
  'generated_time': datetime.fromtimestamp(plot_path.stat().st_mtime).strftime('%Y-%m-%d %H:%M:%S'),
601
  'is_interactive': True,
602
  'filename': filename
603
  }
604
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
605
  return render_template('view_interactive.html',
606
  plot_html=html_content,
607
  plot_info=plot_info)
 
524
 
525
  # Try to parse metadata from filename
526
  try:
527
+ # Example: PM2_5_India_viridis_20200824_1200.png or PM2_5_India_850hPa_viridis_20200824_1200.png
528
  name_parts = filename.replace(plot_file.suffix, '').split('_')
529
+ if len(name_parts) >= 4:
530
+ # Extract variable name (everything before _India)
531
+ var_parts = []
532
+ for i, part in enumerate(name_parts):
533
+ if part == 'India':
534
+ break
535
+ var_parts.append(part)
536
+
537
+ file_info['variable'] = '_'.join(var_parts).replace('_', '.')
538
+ file_info['region'] = 'India'
539
+ file_info['plot_type'] = 'Static'
540
+
541
+ # Check if there's pressure level (contains 'hPa')
542
+ pressure_level = None
543
+ theme_color = 'Unknown'
544
+ for part in name_parts:
545
+ if 'hPa' in part:
546
+ pressure_level = part
547
+ elif part not in var_parts and part != 'India' and not part.isdigit():
548
+ # This is likely the color theme
549
+ theme_color = part
550
+ break
551
+
552
+ file_info['pressure_level'] = pressure_level
553
+ file_info['theme'] = theme_color
554
  except:
555
  file_info['variable'] = 'Unknown'
556
  file_info['region'] = 'Unknown'
557
  file_info['theme'] = 'Unknown'
558
+ file_info['pressure_level'] = None
559
+ file_info['plot_type'] = 'Static'
560
 
561
  plot_files.append(file_info)
562
 
 
575
 
576
  # Try to parse metadata from filename
577
  try:
578
+ # Example: PM2_5_India_interactive_viridis_20200824_1200.html or PM2_5_India_interactive_850hPa_viridis_20200824_1200.html
579
  name_parts = filename.replace('.html', '').split('_')
580
+ if len(name_parts) >= 5:
581
+ # Extract variable name (everything before _India)
582
+ var_parts = []
583
+ for i, part in enumerate(name_parts):
584
+ if part == 'India':
585
+ break
586
+ var_parts.append(part)
587
+
588
+ file_info['variable'] = '_'.join(var_parts).replace('_', '.')
589
+ file_info['region'] = 'India'
590
+ file_info['plot_type'] = 'Interactive'
591
+
592
+ # Check if there's pressure level (contains 'hPa')
593
+ pressure_level = None
594
+ theme_color = 'Unknown'
595
+ for part in name_parts:
596
+ if 'hPa' in part:
597
+ pressure_level = part
598
+ elif part not in var_parts and part not in ['India', 'interactive'] and not part.isdigit():
599
+ # This is likely the color theme
600
+ theme_color = part
601
+ break
602
+
603
+ file_info['pressure_level'] = pressure_level
604
+ file_info['theme'] = theme_color
605
  except:
606
  file_info['variable'] = 'Unknown'
607
  file_info['region'] = 'Unknown'
608
  file_info['theme'] = 'Unknown'
609
+ file_info['pressure_level'] = None
610
+ file_info['plot_type'] = 'Interactive'
611
 
612
  plot_files.append(file_info)
613
 
 
641
  with open(plot_path, 'r', encoding='utf-8') as f:
642
  html_content = f.read()
643
 
644
+ # Create plot info from filename parsing
645
  plot_info = {
646
  'variable': 'Unknown',
647
+ 'pressure_level': None,
648
+ 'theme': 'Unknown',
649
+ 'plot_type': 'Interactive',
650
  'generated_time': datetime.fromtimestamp(plot_path.stat().st_mtime).strftime('%Y-%m-%d %H:%M:%S'),
651
  'is_interactive': True,
652
  'filename': filename
653
  }
654
 
655
+ # Try to parse metadata from filename
656
+ try:
657
+ # Example: PM2_5_India_interactive_850hPa_viridis_20200824_1200.html
658
+ name_parts = filename.replace('.html', '').split('_')
659
+ if len(name_parts) >= 5:
660
+ # Extract variable name (everything before _India)
661
+ var_parts = []
662
+ for i, part in enumerate(name_parts):
663
+ if part == 'India':
664
+ break
665
+ var_parts.append(part)
666
+
667
+ plot_info['variable'] = '_'.join(var_parts).replace('_', '.')
668
+
669
+ # Check if there's pressure level (contains 'hPa')
670
+ pressure_level = None
671
+ theme_color = 'Unknown'
672
+ for part in name_parts:
673
+ if 'hPa' in part:
674
+ pressure_level = part
675
+ elif part not in var_parts and part not in ['India', 'interactive'] and not part.isdigit():
676
+ # This is likely the color theme
677
+ theme_color = part
678
+ break
679
+
680
+ plot_info['pressure_level'] = pressure_level
681
+ plot_info['theme'] = theme_color
682
+ except:
683
+ pass # Keep defaults
684
+
685
  return render_template('view_interactive.html',
686
  plot_html=html_content,
687
  plot_info=plot_info)
templates/gallery.html CHANGED
@@ -288,7 +288,7 @@
288
  🌍
289
  </div>
290
  <div class="plot-info">
291
- <h3>{{ plot.variable|title }} - {{ plot.region|title }}</h3>
292
  <div class="plot-meta">
293
  <span>πŸ“… {{ plot.created.strftime('%Y-%m-%d %H:%M') }}</span>
294
  <span>🎨 {{ plot.theme|title }}</span>
@@ -328,7 +328,7 @@
328
  onerror="this.style.display='none'; this.parentElement.innerHTML='<div style=\'color: #e74c3c; text-align: center;\'>πŸ“·<br>Preview unavailable</div>'">
329
  </div>
330
  <div class="plot-info">
331
- <h3>{{ plot.variable|title }} - {{ plot.region|title }}</h3>
332
  <div class="plot-meta">
333
  <span>πŸ“… {{ plot.created.strftime('%Y-%m-%d %H:%M') }}</span>
334
  <span>🎨 {{ plot.theme|title }}</span>
 
288
  🌍
289
  </div>
290
  <div class="plot-info">
291
+ <h3>{{ plot.variable|title }} - {{ plot.region|title }}{{ ' (' + plot.plot_type + ')' if plot.plot_type else '' }}</h3>
292
  <div class="plot-meta">
293
  <span>πŸ“… {{ plot.created.strftime('%Y-%m-%d %H:%M') }}</span>
294
  <span>🎨 {{ plot.theme|title }}</span>
 
328
  onerror="this.style.display='none'; this.parentElement.innerHTML='<div style=\'color: #e74c3c; text-align: center;\'>πŸ“·<br>Preview unavailable</div>'">
329
  </div>
330
  <div class="plot-info">
331
+ <h3>{{ plot.variable|title }} - {{ plot.region|title }}{{ ' (' + plot.plot_type + ')' if plot.plot_type else '' }}</h3>
332
  <div class="plot-meta">
333
  <span>πŸ“… {{ plot.created.strftime('%Y-%m-%d %H:%M') }}</span>
334
  <span>🎨 {{ plot.theme|title }}</span>
templates/view_interactive.html CHANGED
@@ -165,19 +165,31 @@
165
  <p>{{ plot_info.variable }}</p>
166
  </div>
167
 
 
168
  <div class="info-item">
169
- <h3>⏰ Generated</h3>
170
- <p>{{ plot_info.generated_time }}</p>
171
  </div>
 
172
 
173
  <div class="info-item">
174
- <h3>πŸ“ Filename</h3>
175
- <p>{{ plot_info.filename }}</p>
 
 
 
 
 
176
  </div>
177
 
178
  <div class="info-item">
179
  <h3>🎯 Type</h3>
180
- <p>Interactive Plot</p>
 
 
 
 
 
181
  </div>
182
  </div>
183
  </div>
 
165
  <p>{{ plot_info.variable }}</p>
166
  </div>
167
 
168
+ {% if plot_info.pressure_level %}
169
  <div class="info-item">
170
+ <h3>🌑️ Pressure Level</h3>
171
+ <p>{{ plot_info.pressure_level }}</p>
172
  </div>
173
+ {% endif %}
174
 
175
  <div class="info-item">
176
+ <h3>🎨 Color Theme</h3>
177
+ <p>{{ plot_info.theme }}</p>
178
+ </div>
179
+
180
+ <div class="info-item">
181
+ <h3>⏰ Generated</h3>
182
+ <p>{{ plot_info.generated_time }}</p>
183
  </div>
184
 
185
  <div class="info-item">
186
  <h3>🎯 Type</h3>
187
+ <p>{{ plot_info.plot_type }} Plot</p>
188
+ </div>
189
+
190
+ <div class="info-item" style="grid-column: 1 / -1;">
191
+ <h3>πŸ“ Filename</h3>
192
+ <p style="font-family: monospace; background: #f8f9fa; padding: 8px; border-radius: 4px; word-break: break-all;">{{ plot_info.filename }}</p>
193
  </div>
194
  </div>
195
  </div>