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
145 changes: 82 additions & 63 deletions src/assets/js/indicatorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,71 @@ class IndicatorHandler {
return request;
}

prepareDataLayerPayload(form_mode) {
var payload = {
event: "submitSelectedIndicators",
formMode: form_mode,
numIndicators: this.indicators.length,
numCovidcastIndicators: this.getCovidcastIndicators().length,
numFluviewIndicators: this.getFluviewIndicators().length,
numNIDSSFluIndicators: this.getNIDSSFluIndicators().length,
numNIDSSDengueIndicators: this.getNIDSSDengueIndicators().length,
numFlusurvIndicators: this.getFlusurvIndicators().length,
formStartDate: document.getElementById("start_date").value,
formEndDate: document.getElementById("end_date").value,
apiKey: document.getElementById("apiKey").value ? document.getElementById("apiKey").value : "Not provided",
clientId: clientId ? clientId : "Not available",
};
var covidcastGeoValues = $("#geographic_value").select2("data")
if (covidcastGeoValues !== undefined && covidcastGeoValues !== null) {
covidcastGeoValues = Object.values(
covidcastGeoValues
.flat()
.map(({ id }) => id
));
payload.covidcastGeoValues = covidcastGeoValues;
}
var fluviewGeoValues = $("#fluviewLocations").select2("data")
if (fluviewGeoValues !== undefined && fluviewGeoValues !== null) {
fluviewGeoValues = Object.values(
fluviewGeoValues
.flat()
.map(({ id }) => id
));
payload.fluviewGeoValues = fluviewGeoValues;
}
var nidssFluGeoValues = $("#nidssFluLocations").select2("data")
if (nidssFluGeoValues !== undefined && nidssFluGeoValues !== null) {
nidssFluGeoValues = Object.values(
nidssFluGeoValues
.flat()
.map(({ id }) => id
));
payload.nidssFluGeoValues = nidssFluGeoValues;
}
var nidssDengueGeoValues = $("#nidssDengueLocations").select2("data")
if (nidssDengueGeoValues !== undefined && nidssDengueGeoValues !== null) {
nidssDengueGeoValues = Object.values(
nidssDengueGeoValues
.flat()
.map(({ id }) => id
));
payload.nidssDengueGeoValues = nidssDengueGeoValues;
}
var flusurvGeoValues = $("#flusurvLocations").select2("data")
if (flusurvGeoValues !== undefined && flusurvGeoValues !== null) {
flusurvGeoValues = Object.values(
flusurvGeoValues
.flat()
.map(({ id }) => id
));
payload.flusurvGeoValues = flusurvGeoValues;
}

return payload;

}

showfluviewLocations() {
var fluviewLocationselect = `
<div class="row margin-top-1rem" id="fluviewDiv">
Expand Down Expand Up @@ -376,8 +441,8 @@ class IndicatorHandler {
nidssFluLocations: nidssFluLocations,
nidssDengueLocations: nidssDengueLocations,
flusurvLocations: flusurvLocations,
apiKey: document.getElementById("apiKey").value,
clientId: clientId,
apiKey: document.getElementById("apiKey").value ? document.getElementById("apiKey").value : "Not provided",
clientId: clientId ? clientId : "Not available",
};
const csrftoken = Cookies.get("csrftoken");
$.ajax({
Expand All @@ -388,19 +453,9 @@ class IndicatorHandler {
contentType: "application/json",
headers: { "X-CSRFToken": csrftoken },
data: JSON.stringify(submitData),
}).done(function (data) {
const payload = {
event: "submitSelectedIndicators",
formMode: "epivis",
covidcastGeoValues: JSON.stringify(submitData["covidCastGeographicValues"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewLocations"]),
nidssFluLocations: JSON.stringify(submitData["nidssFluLocations"]),
nidssDengueLocations: JSON.stringify(submitData["nidssDengueLocations"]),
flusurvLocations: JSON.stringify(submitData["flusurvLocations"]),
epivisUrl: data["epivis_url"],
apiKey: submitData["apiKey"] ? submitData["apiKey"] : "Not provided",
clientId: clientId ? clientId : "Not available",
}
}).done((data) => {
const payload = this.prepareDataLayerPayload("epivis");
console.log(payload);
dataLayerPush(payload);
window.open(data["epivis_url"], '_blank').focus();
});
Expand All @@ -425,8 +480,8 @@ class IndicatorHandler {
nidssFluLocations: nidssFluLocations,
nidssDengueLocations: nidssDengueLocations,
flusurvLocations: flusurvLocations,
apiKey: document.getElementById("apiKey").value,
clientId: clientId,
apiKey: document.getElementById("apiKey").value ? document.getElementById("apiKey").value : "Not provided",
clientId: clientId ? clientId : "Not available",
}
const csrftoken = Cookies.get("csrftoken");
$.ajax({
Expand All @@ -437,20 +492,8 @@ class IndicatorHandler {
contentType: "application/json",
headers: { "X-CSRFToken": csrftoken },
data: JSON.stringify(submitData),
}).done(function (data) {
const payload = {
event: "submitSelectedIndicators",
formMode: "export",
formStartDate: submitData["start_date"],
formEndDate: submitData["end_date"],
covidcastGeoValues: JSON.stringify(submitData["covidCastGeographicValues"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewLocations"]),
nidssFluLocations: JSON.stringify(submitData["nidssFluLocations"]),
nidssDengueLocations: JSON.stringify(submitData["nidssDengueLocations"]),
flusurvLocations: JSON.stringify(submitData["flusurvLocations"]),
apiKey: submitData["apiKey"] ? submitData["apiKey"] : "Not provided",
clientId: clientId ? clientId : "Not available",
}
}).done((data) => {
const payload = this.prepareDataLayerPayload("export");
dataLayerPush(payload);
$('#modeSubmitResult').html(data["data_export_block"]);
});
Expand All @@ -476,8 +519,8 @@ class IndicatorHandler {
nidssFluLocations: nidssFluLocations,
nidssDengueLocations: nidssDengueLocations,
flusurvLocations: flusurvLocations,
apiKey: document.getElementById("apiKey").value,
clientId: clientId,
apiKey: document.getElementById("apiKey").value ? document.getElementById("apiKey").value : "Not provided",
clientId: clientId ? clientId : "Not available",
}
const csrftoken = Cookies.get("csrftoken");
$.ajax({
Expand All @@ -487,20 +530,8 @@ class IndicatorHandler {
contentType: "application/json",
headers: { "X-CSRFToken": csrftoken },
data: JSON.stringify(submitData),
}).done(function (data) {
const payload = {
event: "submitSelectedIndicators",
formMode: "preview",
formStartDate: submitData["start_date"],
formEndDate: submitData["end_date"],
covidcastGeoValues: JSON.stringify(submitData["covidCastGeographicValues"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewLocations"]),
nidssFluLocations: JSON.stringify(submitData["nidssFluLocations"]),
nidssDengueLocations: JSON.stringify(submitData["nidssDengueLocations"]),
flusurvLocations: JSON.stringify(submitData["flusurvLocations"]),
apiKey: submitData["apiKey"] ? submitData["apiKey"] : "Not provided",
clientId: clientId ? clientId : "Not available",
}
}).done((data) => {
const payload = this.prepareDataLayerPayload("previewData");
dataLayerPush(payload);
$('#loader').hide();
$('#modeSubmitResult').html(JSON.stringify(data, null, 2));
Expand All @@ -527,8 +558,8 @@ class IndicatorHandler {
nidssFluLocations: nidssFluLocations,
nidssDengueLocations: nidssDengueLocations,
flusurvLocations: flusurvLocations,
apiKey: document.getElementById("apiKey").value,
clientId: clientId,
apiKey: document.getElementById("apiKey").value ? document.getElementById("apiKey").value : "Not provided",
clientId: clientId ? clientId : "Not available",
}
const csrftoken = Cookies.get("csrftoken");
var createQueryCodePython = `<h4>PYTHON PACKAGE</h4>`
Expand All @@ -546,20 +577,8 @@ class IndicatorHandler {
contentType: "application/json",
headers: { "X-CSRFToken": csrftoken },
data: JSON.stringify(submitData),
}).done(function (data) {
const payload = {
event: "submitSelectedIndicators",
formMode: "queryCode",
formStartDate: submitData["start_date"],
formEndDate: submitData["end_date"],
covidcastGeoValues: JSON.stringify(submitData["covidCastGeographicValues"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewLocations"]),
nidssFluLocations: JSON.stringify(submitData["nidssFluLocations"]),
nidssDengueLocations: JSON.stringify(submitData["nidssDengueLocations"]),
flusurvLocations: JSON.stringify(submitData["flusurvLocations"]),
apiKey: submitData["apiKey"] ? submitData["apiKey"] : "Not provided",
clientId: clientId ? clientId : "Not available",
}
}).done((data) => {
const payload = this.prepareDataLayerPayload("createQueryCode");
dataLayerPush(payload);
createQueryCodePython += data["python_code_blocks"].join("<br>");
createQueryCodeR += data["r_code_blocks"].join("<br>");
Expand Down
8 changes: 4 additions & 4 deletions src/indicatorsets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,9 @@ def log_form_stats(request, data, form_mode):
else []
),
"api_key_used": bool(data.get("api_key")),
"api_key": data.get("api_key", "")[:4] + "..." if data.get("api_key") else "",
"api_key": data.get("api_key", "Not provided"),
"user_ip": get_real_ip_addr(request),
"user_ga_id": data.get("clientId", "") if data.get("clientId") else "",
"user_ga_id": data.get("clientId", "Not available"),
}

form_stats_logger.info("form_stats", **log_data)
Expand Down Expand Up @@ -760,8 +760,8 @@ def log_form_data(request, data, form_mode):
"end_date": data.get("end_date", ""),
"epiweeks": get_epiweek(data.get("start_date", ""), data.get("end_date", "")) if data.get("start_date") and data.get("end_date") else [], # fmt: skip
"api_key_used": bool(data.get("apiKey")),
"api_key": data.get("apiKey", "") if data.get("apiKey") else "",
"api_key": data.get("apiKey", "Not provided"),
"user_ip": get_real_ip_addr(request),
"user_ga_id": data.get("clientId", "") if data.get("clientId") else "",
"user_ga_id": data.get("clientId", "Not available"),
}
form_data_logger.info("form_data", **log_data)
Loading