Skip to content

Commit 7043b7f

Browse files
authored
Merge pull request #251 from cmu-delphi/staging
Staging
2 parents 96ae695 + 05ce682 commit 7043b7f

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

src/alternative_interface/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def alternative_interface_view(request):
9999
else []
100100
),
101101
}
102-
print(ctx["available_geos"])
103102
ctx["current_year"] = datetime.now().year
104103

105104
return render(

src/assets/css/custom_styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,9 @@ tr:not(.odd-row) > .dtfc-fixed-end {
257257
font-size: 0.85em;
258258
margin-right: 0.4em;
259259
margin-bottom: 0.25em;
260+
}
261+
262+
.table-stats-info {
263+
font-size: 20px;
264+
margin-bottom: 10px;
260265
}

src/indicatorsets/utils.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def get_real_ip_addr(req): # `req` should be a Flask.request object
692692
# a negative proxy depth is a special case to trust the whole chain -- not generally recommended unless the
693693
# most-external proxy is configured to disregard "X-Forwarded-For" from outside.
694694
# really, ONLY trust the following headers if reverse proxied!!!
695-
x_forwarded_for = req.META.get('HTTP_X_FORWARDED_FOR')
695+
x_forwarded_for = req.META.get("HTTP_X_FORWARDED_FOR")
696696

697697
if x_forwarded_for:
698698
full_proxy_chain = x_forwarded_for.split(",")
@@ -707,12 +707,12 @@ def get_real_ip_addr(req): # `req` should be a Flask.request object
707707
return trusted_proxy_chain[0].strip()
708708

709709
# fall back to "X-Real-Ip" if "X-Forwarded-For" isnt present
710-
x_real_ip = req.META.get('HTTP_X_REAL_IP')
710+
x_real_ip = req.META.get("HTTP_X_REAL_IP")
711711
if x_real_ip:
712712
return x_real_ip
713713

714714
# if we are not proxied (or we are proxied but the headers werent present and we fell through to here), just use the remote ip addr as the true client address
715-
return req.META.get('REMOTE_ADDR')
715+
return req.META.get("REMOTE_ADDR")
716716

717717

718718
def log_form_stats(request, data, form_mode):
@@ -813,3 +813,17 @@ def log_form_data(request, data, form_mode):
813813
"user_ga_id": data.get("clientId", "Not available"),
814814
}
815815
form_data_logger.info("form_data", **log_data)
816+
817+
818+
def get_num_locations_from_meta(indicators):
819+
timeseries_count = 0
820+
indicators = set(
821+
(indicator["source"], indicator["name"]) for indicator in indicators
822+
)
823+
metadata = requests.get(
824+
"https://api.delphi.cmu.edu/epidata/covidcast_meta/"
825+
).json()["epidata"]
826+
for r in metadata:
827+
if (r["data_source"], r["signal"]) in indicators:
828+
timeseries_count += r["num_locations"]
829+
return timeseries_count

src/indicatorsets/views.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
log_form_data,
4040
log_form_stats,
4141
get_grouped_original_data_provider_choices,
42+
get_num_locations_from_meta,
4243
)
4344

4445
from delphi_utils import get_structured_logger
@@ -156,7 +157,10 @@ def get_url_params(self):
156157
else ""
157158
),
158159
"hosted_by_delphi": (
159-
str(self.request.GET.get("hosted_by_delphi") in ["True", "true", "on", "1"]).lower()
160+
str(
161+
self.request.GET.get("hosted_by_delphi")
162+
in ["True", "true", "on", "1"]
163+
).lower()
160164
if self.request.GET.get("hosted_by_delphi")
161165
else "false"
162166
),
@@ -212,7 +216,9 @@ def get_context_data(self, **kwargs):
212216
# Convert hosted_by_delphi string back to boolean for form initialization
213217
form_initial = url_params_dict.copy()
214218
if "hosted_by_delphi" in form_initial:
215-
form_initial["hosted_by_delphi"] = form_initial["hosted_by_delphi"] == "true"
219+
form_initial["hosted_by_delphi"] = (
220+
form_initial["hosted_by_delphi"] == "true"
221+
)
216222
context["form"] = IndicatorSetFilterForm(initial=form_initial)
217223
context["filter"] = filter
218224
context["APP_VERSION"] = settings.APP_VERSION
@@ -244,11 +250,16 @@ def get_context_data(self, **kwargs):
244250
output_field=IntegerField(),
245251
),
246252
).order_by("beta_last", "-is_ongoing", "-is_dua_required", "name")
247-
context["related_indicators"] = json.dumps(
248-
self.get_related_indicators(
249-
filter.indicators_qs, filter.qs.values_list("id", flat=True)
250-
)
253+
related_indicators = self.get_related_indicators(
254+
filter.indicators_qs, filter.qs.values_list("id", flat=True)
255+
)
256+
context["related_indicators"] = json.dumps(related_indicators)
257+
context["num_of_timeseries"] = get_num_locations_from_meta(
258+
related_indicators
251259
)
260+
print(get_num_locations_from_meta(
261+
related_indicators
262+
))
252263
context["filters_descriptions"] = (
253264
FilterDescription.get_all_descriptions_as_dict()
254265
)

src/templates/indicatorsets/indicatorSetsTable.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,14 @@
346346
<script src="{% static 'js/pluralize_word.js' %}"></script>
347347
<script>
348348
var relatedIndicators = JSON.parse(JSON.stringify({{ related_indicators|safe }}));
349+
var numOfTimeseries = {{ num_of_timeseries }};
349350

350351

351352
$(document).ready(function() {
352353
table.columns.adjust();
353354
const totalRowsSpan = document.createElement("span");
354-
totalRowsSpan.textContent = `Showing ${table.page.info().recordsTotal} indicator ${pluralize(table.page.info().recordsTotal, 'set')} containing ${relatedIndicators.length} individual ${pluralize(relatedIndicators.length, 'indicator')}`;
355+
totalRowsSpan.classList.add("table-stats-info");
356+
totalRowsSpan.innerHTML = `Showing <b>${table.page.info().recordsTotal}</b> indicator ${pluralize(table.page.info().recordsTotal, 'set')} containing <b>${relatedIndicators.length}</b> individual ${pluralize(relatedIndicators.length, 'indicator')} for total of <b>${numOfTimeseries}</b> time series across numerous locations.`;
355357
const refElement = document.getElementById("indicatorSetsTable_wrapper");
356358
refElement.before(totalRowsSpan);
357359
});

0 commit comments

Comments
 (0)