Skip to content

Commit 33f2879

Browse files
committed
Merge branch 'dev' of https://github.com/qiita-spots/qiita into auth_oidc
2 parents 19b4d7b + 83476d5 commit 33f2879

File tree

9 files changed

+493
-3
lines changed

9 files changed

+493
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ qiita_pet/*.conf
7272

7373
# jupyter notebooks input data
7474
notebooks/*/*.tsv.gz
75+
76+
# jupyter notebooks input data
77+
notebooks/resource-allocation/data

qiita_core/configuration_manager.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ class ConfigurationManager(object):
109109
The portal subdirectory used in the URL
110110
portal_fp : str
111111
The filepath to the portal styling config file
112+
stats_map_center_latitude : float
113+
The center latitude of the world map, shown on the Stats map.
114+
Defaults to 40.01027 (Boulder, CO, USA)
115+
stats_map_center_longitude : float
116+
The center longitude of the world map, shown on the Stats map.
117+
Defaults to -105.24827 (Boulder, CO, USA)
112118
qiita_env : str
113119
The script used to start the qiita environment
114120
private_launcher : str
@@ -368,6 +374,41 @@ def _get_portal(self, config):
368374
else:
369375
self.portal_dir = ""
370376

377+
msg = ("The value %s for %s you set in Qiita's configuration file "
378+
"(section 'portal') for the Stats world map cannot be "
379+
"intepreted as a float! %s")
380+
lat_default = 40.01027 # Boulder CO, USA
381+
try:
382+
self.stats_map_center_latitude = config.get(
383+
'portal', 'STATS_MAP_CENTER_LATITUDE', fallback=lat_default)
384+
if self.stats_map_center_latitude == '':
385+
self.stats_map_center_latitude = lat_default
386+
self.stats_map_center_latitude = float(
387+
self.stats_map_center_latitude)
388+
except ValueError as e:
389+
raise ValueError(msg % (self.stats_map_center_latitude,
390+
'STATS_MAP_CENTER_LATITUDE', e))
391+
392+
lon_default = -105.24827 # Boulder CO, USA
393+
try:
394+
self.stats_map_center_longitude = config.get(
395+
'portal', 'STATS_MAP_CENTER_LONGITUDE', fallback=lon_default)
396+
if self.stats_map_center_longitude == '':
397+
self.stats_map_center_longitude = lon_default
398+
self.stats_map_center_longitude = float(
399+
self.stats_map_center_longitude)
400+
except ValueError as e:
401+
raise ValueError(msg % (self.stats_map_center_longitude,
402+
'STATS_MAP_CENTER_LONGITUDE', e))
403+
for (name, val) in [('latitude', self.stats_map_center_latitude),
404+
('longitude', self.stats_map_center_longitude)]:
405+
msg = ("The %s of %s you set in Qiita's configuration file "
406+
"(section 'portal') for the Stats world map cannot be %s!")
407+
if val < -180:
408+
raise ValueError(msg % (name, val, 'smaller than -180°'))
409+
if val > 180:
410+
raise ValueError(msg % (name, val, 'larger than 180°'))
411+
371412
def _iframe(self, config):
372413
self.iframe_qiimp = config.get('iframe', 'QIIMP')
373414

qiita_core/support_files/config_test.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ PORTAL_DIR =
183183
# Full path to portal styling config file
184184
PORTAL_FP =
185185

186+
# The center latitude of the world map, shown on the Stats map.
187+
# Defaults to 40.01027 (Boulder, CO, USA)
188+
STATS_MAP_CENTER_LATITUDE =
189+
190+
# The center longitude of the world map, shown on the Stats map.
191+
# Defaults to -105.24827 (Boulder, CO, USA)
192+
STATS_MAP_CENTER_LONGITUDE =
186193

187194
# ----------------------------- iframes settings ---------------------------
188195
[iframe]

qiita_core/tests/test_configuration_manager.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,50 @@ def test_get_portal(self):
245245
obs._get_portal(self.conf)
246246
self.assertEqual(obs.portal_dir, "/gold_portal")
247247

248+
def test_get_portal_latlong(self):
249+
obs = ConfigurationManager()
250+
251+
# if parameters are given, but not set, they should default to Boulder
252+
self.assertEqual(obs.stats_map_center_latitude, 40.01027)
253+
self.assertEqual(obs.stats_map_center_longitude, -105.24827)
254+
255+
# a string cannot be parsed as a float
256+
self.conf.set('portal', 'STATS_MAP_CENTER_LATITUDE', 'kurt')
257+
with self.assertRaises(ValueError):
258+
obs._get_portal(self.conf)
259+
260+
# check for illegal float values
261+
self.conf.set('portal', 'STATS_MAP_CENTER_LATITUDE', "-200")
262+
with self.assertRaises(ValueError):
263+
obs._get_portal(self.conf)
264+
self.conf.set('portal', 'STATS_MAP_CENTER_LATITUDE', "200")
265+
with self.assertRaises(ValueError):
266+
obs._get_portal(self.conf)
267+
268+
# check if value defaults if option is missing altogether
269+
self.conf.remove_option('portal', 'STATS_MAP_CENTER_LATITUDE')
270+
obs._get_portal(self.conf)
271+
self.assertEqual(obs.stats_map_center_latitude, 40.01027)
272+
273+
# same as above, but for longitude
274+
# a string cannot be parsed as a float
275+
self.conf.set('portal', 'STATS_MAP_CENTER_LONGITUDE', 'kurt')
276+
with self.assertRaises(ValueError):
277+
obs._get_portal(self.conf)
278+
279+
# check for illegal float values
280+
self.conf.set('portal', 'STATS_MAP_CENTER_LONGITUDE', "-200")
281+
with self.assertRaises(ValueError):
282+
obs._get_portal(self.conf)
283+
self.conf.set('portal', 'STATS_MAP_CENTER_LONGITUDE', "200")
284+
with self.assertRaises(ValueError):
285+
obs._get_portal(self.conf)
286+
287+
# check if value defaults if option is missing altogether
288+
self.conf.remove_option('portal', 'STATS_MAP_CENTER_LONGITUDE')
289+
obs._get_portal(self.conf)
290+
self.assertEqual(obs.stats_map_center_longitude, -105.24827)
291+
248292
def test_get_oidc(self):
249293
SECTION_NAME = 'oidc_academicid'
250294
obs = ConfigurationManager()
@@ -278,7 +322,6 @@ def test_get_oidc(self):
278322
obs._get_oidc(self.conf)
279323
self.assertEqual(obs.oidc['academicid']['label'], 'academicid')
280324

281-
282325
CONF = """
283326
# ------------------------------ Main settings --------------------------------
284327
[main]
@@ -450,6 +493,14 @@ def test_get_oidc(self):
450493
# Full path to portal styling config file
451494
PORTAL_FP = /tmp/portal.cfg
452495
496+
# The center latitude of the world map, shown on the Stats map.
497+
# Defaults to 40.01027 (Boulder, CO, USA)
498+
STATS_MAP_CENTER_LATITUDE =
499+
500+
# The center longitude of the world map, shown on the Stats map.
501+
# Defaults to -105.24827 (Boulder, CO, USA)
502+
STATS_MAP_CENTER_LONGITUDE =
503+
453504
# ----------------------------- iframes settings ---------------------------
454505
[iframe]
455506
QIIMP = https://localhost:8898/

qiita_db/study.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ def artifacts(self, dtype=None, artifact_type=None):
10921092

10931093
if artifact_type:
10941094
sql_args.append(artifact_type)
1095-
sql_where += "AND artifact_type = %s"
1095+
sql_where += " AND artifact_type = %s"
10961096

10971097
sql = """SELECT artifact_id
10981098
FROM qiita.artifact
7.17 MB
Binary file not shown.

qiita_db/test/test_util.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
from qiita_core.util import qiita_test_checker
2222
import qiita_db as qdb
2323

24+
from matplotlib.figure import Figure
25+
from matplotlib.axes import Axes
26+
import matplotlib.pyplot as plt
27+
2428

2529
@qiita_test_checker()
2630
class DBUtilTestsBase(TestCase):
@@ -1303,6 +1307,64 @@ def test_quick_mounts_purge(self):
13031307
qdb.util.quick_mounts_purge()
13041308

13051309

1310+
class ResourceAllocationPlotTests(TestCase):
1311+
def setUp(self):
1312+
1313+
self.PATH_TO_DATA = ('./qiita_db/test/test_data/'
1314+
'jobs_2024-02-21.tsv.gz')
1315+
self.CNAME = "Validate"
1316+
self.SNAME = "Diversity types - alpha_vector"
1317+
self.col_name = 'samples * columns'
1318+
self.df = pd.read_csv(self.PATH_TO_DATA, sep='\t',
1319+
dtype={'extra_info': str})
1320+
1321+
def test_plot_return(self):
1322+
# check the plot returns correct objects
1323+
fig1, axs1 = qdb.util.resource_allocation_plot(
1324+
self.PATH_TO_DATA, self.CNAME, self.SNAME, self.col_name)
1325+
self.assertIsInstance(
1326+
fig1, Figure,
1327+
"Returned object fig1 is not a Matplotlib Figure")
1328+
for ax in axs1:
1329+
self.assertIsInstance(
1330+
ax, Axes,
1331+
"Returned object axs1 is not a single Matplotlib Axes object")
1332+
1333+
def test_minimize_const(self):
1334+
self.df = self.df[
1335+
(self.df.cName == self.CNAME) & (self.df.sName == self.SNAME)]
1336+
self.df.dropna(subset=['samples', 'columns'], inplace=True)
1337+
self.df[self.col_name] = self.df.samples * self.df['columns']
1338+
fig, axs = plt.subplots(ncols=2, figsize=(10, 4), sharey=False)
1339+
1340+
bm, options = qdb.util._resource_allocation_plot_helper(
1341+
self.df, axs[0], self.CNAME, self.SNAME, 'MaxRSSRaw',
1342+
qdb.util.MODELS_MEM, self.col_name)
1343+
# check that the algorithm chooses correct model for MaxRSSRaw and
1344+
# has 0 failures
1345+
k, a, b = options.x
1346+
failures_df = qdb.util._resource_allocation_failures(
1347+
self.df, k, a, b, bm, self.col_name, 'MaxRSSRaw')
1348+
failures = failures_df.shape[0]
1349+
self.assertEqual(bm, qdb.util.mem_model4, msg="""Best memory model
1350+
doesn't match""")
1351+
self.assertEqual(failures, 0, "Number of failures must be 0")
1352+
1353+
# check that the algorithm chooses correct model for ElapsedRaw and
1354+
# has 1 failure
1355+
bm, options = qdb.util._resource_allocation_plot_helper(
1356+
self.df, axs[1], self.CNAME, self.SNAME, 'ElapsedRaw',
1357+
qdb.util.MODELS_TIME, self.col_name)
1358+
k, a, b = options.x
1359+
failures_df = qdb.util._resource_allocation_failures(
1360+
self.df, k, a, b, bm, self.col_name, 'ElapsedRaw')
1361+
failures = failures_df.shape[0]
1362+
1363+
self.assertEqual(bm, qdb.util.time_model1, msg="""Best time model
1364+
doesn't match""")
1365+
self.assertEqual(failures, 1, "Number of failures must be 1")
1366+
1367+
13061368
STUDY_INFO = {
13071369
'study_id': 1,
13081370
'owner': 'Dude',

0 commit comments

Comments
 (0)