Skip to content
Snippets Groups Projects
Commit dd9723db authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Fixing modifications of JSON objects from source (VIPSLogic)

parent 5ac271f9
No related branches found
No related tags found
No related merge requests found
...@@ -140,6 +140,7 @@ INSTALLED_APPS = ( ...@@ -140,6 +140,7 @@ INSTALLED_APPS = (
'applefruitmoth', 'applefruitmoth',
'fusarium', 'fusarium',
'security', 'security',
'mock',
'VIPSWeb' 'VIPSWeb'
) )
......
...@@ -319,4 +319,34 @@ function getMultipleSelectedValues(list) ...@@ -319,4 +319,34 @@ function getMultipleSelectedValues(list)
} }
} }
return retVal; return retVal;
}
function getJSON(ambiguousVar)
{
try
{
// Is it a JSON string?
return JSON.parse(ambiguousVar);
}
catch(e)
{
return isDict(ambiguousVar) ? ambiguousVar : null;
}
}
function isDict(v){
return typeof v==='object' && v!==null && !(v instanceof Array) && !(v instanceof Date);
}
function getUnixTimestampFromJSON(ambiguousValue)
{
var possibleDateObject = new Date(ambiguousValue);
if(possibleDateObject.getTime() === NaN && typeof parseInt(ambiguousValue) === "number")
{
return parseInt(ambiguousValue);
}
else
{
return possibleDateObject.getTime();
}
} }
\ No newline at end of file
...@@ -56,6 +56,7 @@ else: ...@@ -56,6 +56,7 @@ else:
url(r'^security/', include('security.urls', namespace = "security")), url(r'^security/', include('security.urls', namespace = "security")),
url(r'^fusarium/', include('fusarium.urls', namespace = "fusarium")), url(r'^fusarium/', include('fusarium.urls', namespace = "fusarium")),
url(r'^applefruitmoth/', include('applefruitmoth.urls', namespace = "applefruitmoth")), url(r'^applefruitmoth/', include('applefruitmoth.urls', namespace = "applefruitmoth")),
url(r'^mock/', include('mock.urls', namespace = "mock")),
# Uncomment the next line to enable the admin: # Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
url(r'^tinymce/', include('tinymce.urls')), url(r'^tinymce/', include('tinymce.urls')),
......
...@@ -244,8 +244,8 @@ function getWarningStatusPlotBandData(forecastResults) ...@@ -244,8 +244,8 @@ function getWarningStatusPlotBandData(forecastResults)
if (forecastResults != null && forecastResults.length >=2) if (forecastResults != null && forecastResults.length >=2)
{ {
// Replace with Moment.js // Replace with Moment.js
var start = forecastResults[0]["validTimeStart"]; var start = getUnixTimestampFromJSON(forecastResults[0]["validTimeStart"]);
var end = forecastResults[1]["validTimeStart"]; var end = getUnixTimestampFromJSON(forecastResults[1]["validTimeStart"]);
bandOffset = (end - start) / 2; bandOffset = (end - start) / 2;
//console.log("bandOffset=" + bandOffset); //console.log("bandOffset=" + bandOffset);
...@@ -259,13 +259,13 @@ function getWarningStatusPlotBandData(forecastResults) ...@@ -259,13 +259,13 @@ function getWarningStatusPlotBandData(forecastResults)
if(plotBand != null) if(plotBand != null)
{ {
// Moment.js needed! // Moment.js needed!
plotBand["to"] = forecastResult["validTimeStart"] - bandOffset; plotBand["to"] = getUnixTimestampFromJSON(forecastResult["validTimeStart"]) - bandOffset;
plotBands.push(plotBand); plotBands.push(plotBand);
} }
plotBand = { plotBand = {
"color": warningStatuses[forecastResult["warningStatus"]].color, "color": warningStatuses[forecastResult["warningStatus"]].color,
// Moment.js!! // Moment.js!!
"from" : forecastResult["validTimeStart"] - bandOffset "from" : getUnixTimestampFromJSON(forecastResult["validTimeStart"]) - bandOffset
}; };
} }
previousForecastResult = forecastResult; previousForecastResult = forecastResult;
...@@ -275,7 +275,7 @@ function getWarningStatusPlotBandData(forecastResults) ...@@ -275,7 +275,7 @@ function getWarningStatusPlotBandData(forecastResults)
if(plotBand != null && plotBand["to"] == null) if(plotBand != null && plotBand["to"] == null)
{ {
// Moment.js!!! // Moment.js!!!
plotBand.to = forecastResults[forecastResults.length -1]["validTimeStart"] + bandOffset; plotBand.to = getUnixTimestampFromJSONforecastResults([forecastResults.length -1]["validTimeStart"]) + bandOffset;
plotBands.push(plotBand); plotBands.push(plotBand);
} }
...@@ -305,11 +305,12 @@ function getHighChartsSeries(forecastResults, yAxisList, parameterList) ...@@ -305,11 +305,12 @@ function getHighChartsSeries(forecastResults, yAxisList, parameterList)
for(var i in forecastResults) for(var i in forecastResults)
{ {
var forecastResult = forecastResults[i]; var forecastResult = forecastResults[i];
var allValues = getJSON(forecastResult["allValues"]);
for(var j in parameterList) for(var j in parameterList)
{ {
var parameter = parameterList[j]; var parameter = parameterList[j];
var value = parseFloat(forecastResult["allValues"][parameter.key]); var value = parseFloat(allValues[parameter.key]);
chartSeries.series[parameter.key].data.push([forecastResult.validTimeStart,value]); chartSeries.series[parameter.key].data.push([getUnixTimestampFromJSON(forecastResult.validTimeStart),value]);
} }
} }
......
...@@ -193,7 +193,8 @@ var renderNutritionModelResults = function(data,textStatus, jqXHR) ...@@ -193,7 +193,8 @@ var renderNutritionModelResults = function(data,textStatus, jqXHR)
for(var i in charts) for(var i in charts)
{ {
var lines = [{key: charts[i].key, type: "spline", color: "red", name: charts[i].name, showInLegend: false, yAxis: 0}]; var lines = [{key: charts[i].key, type: "spline", color: "red", name: charts[i].name, showInLegend: false, yAxis: 0}];
if(data[0].keys.indexOf(charts[i].key + normalValueKeySuffix) >= 0)
if(getJSON(data[0].keys).indexOf(charts[i].key + normalValueKeySuffix) >= 0)
{ {
lines.push({key: charts[i].key + normalValueKeySuffix, type: "spline", color: "green", name: charts[i].name + "_NORMAL", showInLegend: true, yAxis: 0}) lines.push({key: charts[i].key + normalValueKeySuffix, type: "spline", color: "green", name: charts[i].name + "_NORMAL", showInLegend: true, yAxis: 0})
} }
...@@ -340,7 +341,7 @@ function renderResultTable(tableId, data) ...@@ -340,7 +341,7 @@ function renderResultTable(tableId, data)
{ {
var theTable=document.getElementById(tableId); var theTable=document.getElementById(tableId);
//console.log(data); //console.log(data);
var headingData = data[0].keys; var headingData = getJSON(data[0].keys);
var headerRowHTML = "<thead>" var headerRowHTML = "<thead>"
+ " <tr>" + " <tr>"
+ " <th>" + gettext("Date") + "</th>"; + " <th>" + gettext("Date") + "</th>";
...@@ -355,9 +356,10 @@ function renderResultTable(tableId, data) ...@@ -355,9 +356,10 @@ function renderResultTable(tableId, data)
for(var i=0; i<data.length; i++) for(var i=0; i<data.length; i++)
{ {
dataRowsHTML += "<tr><td>" + moment.tz(data[i].validTimeStart, "Europe/Oslo").format("YYYY-MM-DD") + "</td>"; dataRowsHTML += "<tr><td>" + moment.tz(data[i].validTimeStart, "Europe/Oslo").format("YYYY-MM-DD") + "</td>";
var allValues = getJSON(data[i].allValues);
for(var j=0;j<headingData.length;j++) for(var j=0;j<headingData.length;j++)
{ {
dataRowsHTML += "<td>" + data[i].allValues[headingData[j]] + "</td>"; dataRowsHTML += "<td>" + allValues[headingData[j]] + "</td>";
} }
dataRowsHTML += "</tr>"; dataRowsHTML += "</tr>";
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment