nouamanetazi HF staff commited on
Commit
df311b6
1 Parent(s): 9786630

better coors parsing

Browse files
Files changed (2) hide show
  1. app.py +1 -2
  2. src/utils.py +16 -17
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import os
2
  import time
3
  from datetime import datetime
4
- import uuid
5
 
6
  import folium
7
  import pandas as pd
@@ -192,7 +191,7 @@ def show_verified_requests(filtered_verified_df):
192
  )
193
 
194
  # mark as solved button
195
- id_in_sheet = row["id"]+2
196
  display_text += f"<a href='https://docs.google.com/forms/d/e/1FAIpQLSdyAcOAULumk4A1DsfrwUsGdZ-9G5xOUuD3vHdQOp3nGNAZXw/viewform?usp=pp_url&entry.1499427789={id_in_sheet}&entry.1666684596={datetime.now().strftime('%Y-%m-%d')}' target='_blank' rel='noopener noreferrer'><b>Mark as solved</b></a><br>"
197
 
198
  icon_name = ICON_MAPPING.get(request_type, "list")
 
1
  import os
2
  import time
3
  from datetime import datetime
 
4
 
5
  import folium
6
  import pandas as pd
 
191
  )
192
 
193
  # mark as solved button
194
+ id_in_sheet = row["id"] + 2
195
  display_text += f"<a href='https://docs.google.com/forms/d/e/1FAIpQLSdyAcOAULumk4A1DsfrwUsGdZ-9G5xOUuD3vHdQOp3nGNAZXw/viewform?usp=pp_url&entry.1499427789={id_in_sheet}&entry.1666684596={datetime.now().strftime('%Y-%m-%d')}' target='_blank' rel='noopener noreferrer'><b>Mark as solved</b></a><br>"
196
 
197
  icon_name = ICON_MAPPING.get(request_type, "list")
src/utils.py CHANGED
@@ -3,7 +3,6 @@ from typing import Union
3
  import folium
4
  import pandas as pd
5
  from folium import plugins
6
- import streamlit as st
7
 
8
  EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
9
  BORDER_COLOR = "black"
@@ -64,27 +63,27 @@ def add_latlng_col(df, process_column: Union[str, int]):
64
  def parse_latlng(latlng):
65
  if pd.isna(latlng):
66
  return None
67
- # lat, lng = latlng.split(",")
68
- # return [float(lat), float(lng)]
69
-
70
  try:
71
- # check if it matches (30.9529832, -7.1010705) or (30.9529832,-7.1010705)
72
- if re.match(r"\(\d+\.\d+,\s?-\d+\.\d+\)", latlng):
73
- lat, lng = latlng[1:-1].split(",")
74
- return [float(lat), float(lng)]
75
- # check of it matches 30.9529832, -7.1010705 or 30.9529832,-7.1010705 or 30.9529832 ,-7.10107050
76
- elif re.match(r"\d+\.\d+\s?,\s?-\d+\.\d+", latlng):
77
- lat, lng = latlng.split(",")
78
- return [float(lat), float(lng)]
79
- # check if it matches 30,9529832, -7,1010705 or 30,9529832,-7,1010705, match1=30,9529832 and match2=-7,1010705
80
- elif re.match(r"\d+,\d+,\s?-\d+,\d+", latlng):
81
- d1, d2, d3, d4 = latlng.split(",")
82
  return [float(".".join([d1, d2])), float(".".join([d3, d4]))]
 
 
 
 
 
 
 
 
83
  except Exception as e:
84
  print(f"Error parsing latlng: {latlng} Reason: {e}")
85
  return None
86
- print(f"Error parsing latlng: {latlng}")
87
- return None
88
 
89
  def add_epicentre_to_map(fg):
90
  # Removed the spinner to not confuse the users as the map is already loaded
 
3
  import folium
4
  import pandas as pd
5
  from folium import plugins
 
6
 
7
  EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
8
  BORDER_COLOR = "black"
 
63
  def parse_latlng(latlng):
64
  if pd.isna(latlng):
65
  return None
 
 
 
66
  try:
67
+ # case where there more than one comma 30,98 , -7,10
68
+ if latlng.count(',') > 2:
69
+ d1, d2, d3, d4 = latlng.split(",")[:4]
70
+ return [float(".".join([d1, d2])), float(".".join([d3, d4]))]
71
+
72
+ # case of more than one dot 30.98. -7.10
73
+ if latlng.count('.') > 2:
74
+ d1, d2, d3, d4 = latlng.split(".")[:4]
 
 
 
75
  return [float(".".join([d1, d2])), float(".".join([d3, d4]))]
76
+
77
+ # case where there is only one comma 30,98 , -7,10
78
+ lat, lng = latlng.split(",")[:2]
79
+ # remove anything that is not a digit or a dot or a minus sign
80
+ lat = re.sub(r"[^\d\.\-]", "", lat)
81
+ lng = re.sub(r"[^\d\.\-]", "", lng)
82
+ return [float(lat), float(lng)]
83
+
84
  except Exception as e:
85
  print(f"Error parsing latlng: {latlng} Reason: {e}")
86
  return None
 
 
87
 
88
  def add_epicentre_to_map(fg):
89
  # Removed the spinner to not confuse the users as the map is already loaded