Skip to content
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
1 change: 0 additions & 1 deletion src/alternative_interface/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def alternative_interface_view(request):
else []
),
}
print(ctx["available_geos"])
ctx["current_year"] = datetime.now().year

return render(
Expand Down
5 changes: 5 additions & 0 deletions src/assets/css/custom_styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,9 @@ tr:not(.odd-row) > .dtfc-fixed-end {
font-size: 0.85em;
margin-right: 0.4em;
margin-bottom: 0.25em;
}

.table-stats-info {
font-size: 20px;
margin-bottom: 10px;
}
20 changes: 17 additions & 3 deletions src/indicatorsets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def get_real_ip_addr(req): # `req` should be a Flask.request object
# a negative proxy depth is a special case to trust the whole chain -- not generally recommended unless the
# most-external proxy is configured to disregard "X-Forwarded-For" from outside.
# really, ONLY trust the following headers if reverse proxied!!!
x_forwarded_for = req.META.get('HTTP_X_FORWARDED_FOR')
x_forwarded_for = req.META.get("HTTP_X_FORWARDED_FOR")

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

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

# 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
return req.META.get('REMOTE_ADDR')
return req.META.get("REMOTE_ADDR")


def log_form_stats(request, data, form_mode):
Expand Down Expand Up @@ -813,3 +813,17 @@ def log_form_data(request, data, form_mode):
"user_ga_id": data.get("clientId", "Not available"),
}
form_data_logger.info("form_data", **log_data)


def get_num_locations_from_meta(indicators):
timeseries_count = 0
indicators = set(
(indicator["source"], indicator["name"]) for indicator in indicators
)
metadata = requests.get(
"https://api.delphi.cmu.edu/epidata/covidcast_meta/"
).json()["epidata"]
for r in metadata:
if (r["data_source"], r["signal"]) in indicators:
timeseries_count += r["num_locations"]
return timeseries_count
23 changes: 17 additions & 6 deletions src/indicatorsets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
log_form_data,
log_form_stats,
get_grouped_original_data_provider_choices,
get_num_locations_from_meta,
)

from delphi_utils import get_structured_logger
Expand Down Expand Up @@ -156,7 +157,10 @@ def get_url_params(self):
else ""
),
"hosted_by_delphi": (
str(self.request.GET.get("hosted_by_delphi") in ["True", "true", "on", "1"]).lower()
str(
self.request.GET.get("hosted_by_delphi")
in ["True", "true", "on", "1"]
).lower()
if self.request.GET.get("hosted_by_delphi")
else "false"
),
Expand Down Expand Up @@ -212,7 +216,9 @@ def get_context_data(self, **kwargs):
# Convert hosted_by_delphi string back to boolean for form initialization
form_initial = url_params_dict.copy()
if "hosted_by_delphi" in form_initial:
form_initial["hosted_by_delphi"] = form_initial["hosted_by_delphi"] == "true"
form_initial["hosted_by_delphi"] = (
form_initial["hosted_by_delphi"] == "true"
)
context["form"] = IndicatorSetFilterForm(initial=form_initial)
context["filter"] = filter
context["APP_VERSION"] = settings.APP_VERSION
Expand Down Expand Up @@ -244,11 +250,16 @@ def get_context_data(self, **kwargs):
output_field=IntegerField(),
),
).order_by("beta_last", "-is_ongoing", "-is_dua_required", "name")
context["related_indicators"] = json.dumps(
self.get_related_indicators(
filter.indicators_qs, filter.qs.values_list("id", flat=True)
)
related_indicators = self.get_related_indicators(
filter.indicators_qs, filter.qs.values_list("id", flat=True)
)
context["related_indicators"] = json.dumps(related_indicators)
context["num_of_timeseries"] = get_num_locations_from_meta(
related_indicators
)
print(get_num_locations_from_meta(
related_indicators
))
context["filters_descriptions"] = (
FilterDescription.get_all_descriptions_as_dict()
)
Expand Down
4 changes: 3 additions & 1 deletion src/templates/indicatorsets/indicatorSetsTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,14 @@
<script src="{% static 'js/pluralize_word.js' %}"></script>
<script>
var relatedIndicators = JSON.parse(JSON.stringify({{ related_indicators|safe }}));
var numOfTimeseries = {{ num_of_timeseries }};


$(document).ready(function() {
table.columns.adjust();
const totalRowsSpan = document.createElement("span");
totalRowsSpan.textContent = `Showing ${table.page.info().recordsTotal} indicator ${pluralize(table.page.info().recordsTotal, 'set')} containing ${relatedIndicators.length} individual ${pluralize(relatedIndicators.length, 'indicator')}`;
totalRowsSpan.classList.add("table-stats-info");
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.`;
const refElement = document.getElementById("indicatorSetsTable_wrapper");
refElement.before(totalRowsSpan);
});
Expand Down
Loading