Skip to content

Config statsmap lat long #3388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions qiita_core/configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ class ConfigurationManager(object):
The portal subdirectory used in the URL
portal_fp : str
The filepath to the portal styling config file
stats_map_center_latitude : float
The center latitude of the world map, shown on the Stats map.
Defaults to 40.01027 (Boulder, CO, USA)
stats_map_center_longitude : float
The center longitude of the world map, shown on the Stats map.
Defaults to -105.24827 (Boulder, CO, USA)
qiita_env : str
The script used to start the qiita environment
private_launcher : str
Expand Down Expand Up @@ -347,5 +353,40 @@ def _get_portal(self, config):
else:
self.portal_dir = ""

msg = ("The value %s for %s you set in Qiita's configuration file "
"(section 'portal') for the Stats world map cannot be "
"intepreted as a float! %s")
lat_default = 40.01027 # Boulder CO, USA
try:
self.stats_map_center_latitude = config.get(
'portal', 'STATS_MAP_CENTER_LATITUDE', fallback=lat_default)
if self.stats_map_center_latitude == '':
self.stats_map_center_latitude = lat_default
self.stats_map_center_latitude = float(
self.stats_map_center_latitude)
except ValueError as e:
raise ValueError(msg % (self.stats_map_center_latitude,
'STATS_MAP_CENTER_LATITUDE', e))

lon_default = -105.24827 # Boulder CO, USA
try:
self.stats_map_center_longitude = config.get(
'portal', 'STATS_MAP_CENTER_LONGITUDE', fallback=lon_default)
if self.stats_map_center_longitude == '':
self.stats_map_center_longitude = lon_default
self.stats_map_center_longitude = float(
self.stats_map_center_longitude)
except ValueError as e:
raise ValueError(msg % (self.stats_map_center_longitude,
'STATS_MAP_CENTER_LONGITUDE', e))
for (name, val) in [('latitude', self.stats_map_center_latitude),
('longitude', self.stats_map_center_longitude)]:
msg = ("The %s of %s you set in Qiita's configuration file "
"(section 'portal') for the Stats world map cannot be %s!")
if val < -180:
raise ValueError(msg % (name, val, 'smaller than -180°'))
if val > 180:
raise ValueError(msg % (name, val, 'larger than 180°'))

def _iframe(self, config):
self.iframe_qiimp = config.get('iframe', 'QIIMP')
7 changes: 7 additions & 0 deletions qiita_core/support_files/config_test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ PORTAL_DIR =
# Full path to portal styling config file
PORTAL_FP =

# The center latitude of the world map, shown on the Stats map.
# Defaults to 40.01027 (Boulder, CO, USA)
STATS_MAP_CENTER_LATITUDE =

# The center longitude of the world map, shown on the Stats map.
# Defaults to -105.24827 (Boulder, CO, USA)
STATS_MAP_CENTER_LONGITUDE =

# ----------------------------- iframes settings ---------------------------
[iframe]
Expand Down
52 changes: 52 additions & 0 deletions qiita_core/tests/test_configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,50 @@ def test_get_portal(self):
obs._get_portal(self.conf)
self.assertEqual(obs.portal_dir, "/gold_portal")

def test_get_portal_latlong(self):
obs = ConfigurationManager()

# if parameters are given, but not set, they should default to Boulder
self.assertEqual(obs.stats_map_center_latitude, 40.01027)
self.assertEqual(obs.stats_map_center_longitude, -105.24827)

# a string cannot be parsed as a float
self.conf.set('portal', 'STATS_MAP_CENTER_LATITUDE', 'kurt')
with self.assertRaises(ValueError):
obs._get_portal(self.conf)

# check for illegal float values
self.conf.set('portal', 'STATS_MAP_CENTER_LATITUDE', "-200")
with self.assertRaises(ValueError):
obs._get_portal(self.conf)
self.conf.set('portal', 'STATS_MAP_CENTER_LATITUDE', "200")
with self.assertRaises(ValueError):
obs._get_portal(self.conf)

# check if value defaults if option is missing altogether
self.conf.remove_option('portal', 'STATS_MAP_CENTER_LATITUDE')
obs._get_portal(self.conf)
self.assertEqual(obs.stats_map_center_latitude, 40.01027)

# same as above, but for longitude
# a string cannot be parsed as a float
self.conf.set('portal', 'STATS_MAP_CENTER_LONGITUDE', 'kurt')
with self.assertRaises(ValueError):
obs._get_portal(self.conf)

# check for illegal float values
self.conf.set('portal', 'STATS_MAP_CENTER_LONGITUDE', "-200")
with self.assertRaises(ValueError):
obs._get_portal(self.conf)
self.conf.set('portal', 'STATS_MAP_CENTER_LONGITUDE', "200")
with self.assertRaises(ValueError):
obs._get_portal(self.conf)

# check if value defaults if option is missing altogether
self.conf.remove_option('portal', 'STATS_MAP_CENTER_LONGITUDE')
obs._get_portal(self.conf)
self.assertEqual(obs.stats_map_center_longitude, -105.24827)


CONF = """
# ------------------------------ Main settings --------------------------------
Expand Down Expand Up @@ -417,6 +461,14 @@ def test_get_portal(self):
# Full path to portal styling config file
PORTAL_FP = /tmp/portal.cfg

# The center latitude of the world map, shown on the Stats map.
# Defaults to 40.01027 (Boulder, CO, USA)
STATS_MAP_CENTER_LATITUDE =

# The center longitude of the world map, shown on the Stats map.
# Defaults to -105.24827 (Boulder, CO, USA)
STATS_MAP_CENTER_LONGITUDE =

# ----------------------------- iframes settings ---------------------------
[iframe]
QIIMP = https://localhost:8898/
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
vectorLayer
],
view: new ol.View({
center: ol.proj.fromLonLat([-105.24827, 40.01027]),
center: ol.proj.fromLonLat([{% raw qiita_config.stats_map_center_longitude %}, {% raw qiita_config.stats_map_center_latitude %}]),
zoom: 4
})
});
Expand Down