Commit 221e9b4e authored by project's avatar project

--no commit message

--no commit message
parent a02953f6
...@@ -15,62 +15,53 @@ exports.getValues = function(dataSet, cb){ ...@@ -15,62 +15,53 @@ exports.getValues = function(dataSet, cb){
let values = []; let values = [];
//console.log(dataSet.length); //console.log(dataSet.length);
var i = 0; let json = parser.toJson(dataSet, {object: true});
async.whilst(function() { return i < dataSet.length;}, function(callbackFn) {
let json = parser.toJson(dataSet[i], {object: true});
i++;
dataTemplate.type = json.xhr.IO.Type;
dataTemplate.unit = json.xhr.IO.Unit;
dataTemplate.value_type = json.xhr.IO.ValueType;
dataTemplate.image_type = json.xhr.IO.Name;
if(parseInt(json.xhr.IO.Record) > 0){ dataTemplate.type = json.xhr.IO.Type;
if(parseInt(json.xhr.IO.Record) === 1){ dataTemplate.unit = json.xhr.IO.Unit;
getImage(json.xhr.IO.Data.Value).then((data) =>{ dataTemplate.value_type = json.xhr.IO.ValueType;
values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": data}); dataTemplate.image_type = json.xhr.IO.Name;
}).catch((err) => {
cb(err);
})
callbackFn();
}
else{
var idx = 0;
async.whilst(function() { return idx < json.xhr.IO.Data.length;}, function(callback) {
let d = json.xhr.IO.Data[idx];
idx++;
//console.log(d.Value);
getImage(d.Value).then((data) =>{
values.push({"observeddatetime": d.IODateTime, "value": data});
//var bitmap = new Buffer(data, 'base64');
//fs.writeFileSync("./result.jpg", bitmap);
callback();
}).catch((err) => {
callback(err);
});
}, function(err) { if(parseInt(json.xhr.IO.Record) > 0){
if( err ) { if(parseInt(json.xhr.IO.Record) === 1){
console.log(err); getImage(json.xhr.IO.Data.Value).then((data) =>{
} values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": data});
callbackFn(); }).catch((err) => {
}); cb(err);
})
}
} }
else callbackFn(); else{
var idx = 0;
async.whilst(function() { return idx < json.xhr.IO.Data.length;}, function(callback) {
let d = json.xhr.IO.Data[idx];
idx++;
//console.log(d.Value);
getImage(d.Value).then((data) =>{
values.push({"observeddatetime": d.IODateTime, "value": data});
//var bitmap = new Buffer(data, 'base64');
//fs.writeFileSync("./result.jpg", bitmap);
callback();
}).catch((err) => {
callback(err);
});
}, function(err) { }, function(err) {
if( err ) { if( err ) {
console.log(err); console.log(err);
} else { }
if(values.length > 0){ if(values.length > 0){
dataTemplate.values = values; dataTemplate.values = values;
cb(dataTemplate); cb(dataTemplate);
} }
else cb(null); else cb(null);
});
} }
}); }
else cb(null);
......
...@@ -11,26 +11,25 @@ exports.getValues = function(dataSet, callback){ ...@@ -11,26 +11,25 @@ exports.getValues = function(dataSet, callback){
let values = []; let values = [];
for (var i = 0; i < dataSet.length; i++) {
let json = parser.toJson(dataSet[i], {object: true}); let json = parser.toJson(dataSet, {object: true});
dataTemplate.type = json.xhr.IO.Type; dataTemplate.type = json.xhr.IO.Type;
dataTemplate.unit = json.xhr.IO.Unit; dataTemplate.unit = json.xhr.IO.Unit;
dataTemplate.value_type = json.xhr.IO.ValueType; dataTemplate.value_type = json.xhr.IO.ValueType;
if(parseInt(json.xhr.IO.Record) > 0){ if(parseInt(json.xhr.IO.Record) > 0){
if(parseInt(json.xhr.IO.Record) === 1){ if(parseInt(json.xhr.IO.Record) === 1){
values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": json.xhr.IO.Data.Value}); values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": json.xhr.IO.Data.Value});
} }
else{ else{
for (var j = 0; j < json.xhr.IO.Data.length; j++) { for (var j = 0; j < json.xhr.IO.Data.length; j++) {
let d = json.xhr.IO.Data[j]; let d = json.xhr.IO.Data[j];
values.push({"observeddatetime": d.IODateTime, "value": d.Value}); values.push({"observeddatetime": d.IODateTime, "value": d.Value});
}
} }
} }
} }
if(values.length > 0){ if(values.length > 0){
dataTemplate.values = values; dataTemplate.values = values;
......
...@@ -12,24 +12,22 @@ exports.getValues = function(dataSet, callback){ ...@@ -12,24 +12,22 @@ exports.getValues = function(dataSet, callback){
let values = []; let values = [];
let json = parser.toJson(dataSet, {object: true});
for (var i = 0; i < dataSet.length; i++) { dataTemplate.type = json.xhr.IO.Type;
let json = parser.toJson(dataSet[i], {object: true}); dataTemplate.unit = json.xhr.IO.Unit;
dataTemplate.type = json.xhr.IO.Type; dataTemplate.value_type = json.xhr.IO.ValueType;
dataTemplate.unit = json.xhr.IO.Unit; if(parseInt(json.xhr.IO.Record) > 0){
dataTemplate.value_type = json.xhr.IO.ValueType; if(parseInt(json.xhr.IO.Record) === 1){
if(parseInt(json.xhr.IO.Record) > 0){ values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": json.xhr.IO.Data.Value, "direction": json.xhr.IO.Data.Direction});
if(parseInt(json.xhr.IO.Record) === 1){ }
values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": json.xhr.IO.Data.Value, "direction": json.xhr.IO.Data.Direction}); else{
} for (var j = 0; j < json.xhr.IO.Data.length; j++) {
else{ let d = json.xhr.IO.Data[j];
for (var j = 0; j < json.xhr.IO.Data.length; j++) { values.push({"observeddatetime": d.IODateTime, "value": d.Value, "direction": d.Direction});
let d = json.xhr.IO.Data[j];
values.push({"observeddatetime": d.IODateTime, "value": d.Value, "direction": d.Direction});
}
} }
} }
} }
if(values.length > 0){ if(values.length > 0){
dataTemplate.values = values; dataTemplate.values = values;
callback(dataTemplate); callback(dataTemplate);
......
...@@ -13,23 +13,35 @@ function perform_function(context,request,response){ ...@@ -13,23 +13,35 @@ function perform_function(context,request,response){
var output_type = "object/sds"; var output_type = "object/sds";
var di_data = request.data; var di_data = request.data;
let idx = 0;
let result = { let out = [];
"object_type": 'iBitz',
"station_id": di_data.station_id,
"latitude": "",
"longitude": "",
"altitude": "",
"data":[]
};
async.whilst(function() { return idx < di_data.data.length;}, function(callback) { var dataKeySeries = Object.keys(di_data.data);
let dtype = di_data.data[idx].data_types;
//console.log('[DT] di_data length = ' + di_data.data[idx].value.length); // for (var i = 0; i < dataKeySeries.length; i++) {
if(typeof di_data.data[idx].value.length !== "undefined"){ // console.log(di_data.data[dataKeySeries[i]]);
//console.log('data = ' + di_data.data[idx].value[0]); // }
let json = parser.toJson(di_data.data[idx].value[0], {object: true}); let i = 0;
agriParser.getParser(json.xhr.IO.Type).getValues(di_data.data[idx].value, function(values) { async.whilst(function() { return i < dataKeySeries.length;}, function(cb) {
let result = {
"object_type": 'iBitz',
"station_id": di_data.station_id,
"latitude": "",
"longitude": "",
"altitude": "",
"data":[]
};
let vals = di_data.data[dataKeySeries[i]];
i++;
let idx = 0;
async.whilst(function() { return idx < vals.length;}, function(callback) {
let dtype = vals[idx].data_types;
//console.log('[DT] di_data length = ' + vals[idx].value.length);
let json = parser.toJson(vals[idx].value, {object: true});
//console.log('Type = ' + json.xhr.IO.Type);
agriParser.getParser(json.xhr.IO.Type).getValues(vals[idx].value, function(values) {
//console.log('data = ' + vals[idx].value);
idx++; idx++;
if(values !== null){ if(values !== null){
result.latitude = json.xhr.IO.Latitude; result.latitude = json.xhr.IO.Latitude;
...@@ -37,32 +49,41 @@ function perform_function(context,request,response){ ...@@ -37,32 +49,41 @@ function perform_function(context,request,response){
result.data.push(values); result.data.push(values);
//console.log(`STAMP : ${di_data.station_id}-${dtype} = `+ values.values[values.values.length-1].observeddatetime); //console.log(`STAMP : ${di_data.station_id}-${dtype} = `+ values.values[values.values.length-1].observeddatetime);
memstore.setItem(`${di_data.station_id}-${dtype}`, values.values[values.values.length-1].observeddatetime, (err) =>{ memstore.setItem(`${di_data.station_id}-${dtype}`, values.values[values.values.length-1].observeddatetime, (err) =>{
if(err) throw err; if(err){
callback(err); throw err;
callback(err);
}
else callback();
}); });
} }
else callback(); else callback();
}); });
}
else{
idx++;
callback();
}
}, function(err) {
if( err ) {
console.log(err);
cb(err);
//response.error(err);
} else {
if(result.data.length > 0){
out.push(result);
}
cb();
}
});
}, function(err) { }, function(err) {
if( err ) { if( err ) {
console.log(err); console.log(err);
//response.error(err); //response.error(err);
} else { } else {
//fs.writeFileSync("./result.json", JSON.stringify(result)); //fs.writeFileSync("./result.json", JSON.stringify(out));
//console.log(JSON.stringify(result)); //console.log(JSON.stringify(out));
if(result.data.length > 0) if(out.length > 0)
response.success(result, output_type); response.success(out, output_type);
else response.reject(); else response.reject();
} }
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment