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){
let values = [];
//console.log(dataSet.length);
var i = 0;
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;
let json = parser.toJson(dataSet, {object: true});
if(parseInt(json.xhr.IO.Record) > 0){
if(parseInt(json.xhr.IO.Record) === 1){
getImage(json.xhr.IO.Data.Value).then((data) =>{
values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": data});
}).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);
});
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;
}, function(err) {
if( err ) {
console.log(err);
}
callbackFn();
});
}
if(parseInt(json.xhr.IO.Record) > 0){
if(parseInt(json.xhr.IO.Record) === 1){
getImage(json.xhr.IO.Data.Value).then((data) =>{
values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": data});
}).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) {
if( err ) {
console.log(err);
} else {
if(values.length > 0){
dataTemplate.values = values;
cb(dataTemplate);
}
else cb(null);
}, function(err) {
if( err ) {
console.log(err);
}
if(values.length > 0){
dataTemplate.values = values;
cb(dataTemplate);
}
else cb(null);
});
}
});
}
else cb(null);
......
......@@ -11,26 +11,25 @@ exports.getValues = function(dataSet, callback){
let values = [];
for (var i = 0; i < dataSet.length; i++) {
let json = parser.toJson(dataSet[i], {object: true});
dataTemplate.type = json.xhr.IO.Type;
dataTemplate.unit = json.xhr.IO.Unit;
dataTemplate.value_type = json.xhr.IO.ValueType;
let json = parser.toJson(dataSet, {object: true});
dataTemplate.type = json.xhr.IO.Type;
dataTemplate.unit = json.xhr.IO.Unit;
dataTemplate.value_type = json.xhr.IO.ValueType;
if(parseInt(json.xhr.IO.Record) > 0){
if(parseInt(json.xhr.IO.Record) === 1){
values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": json.xhr.IO.Data.Value});
}
else{
for (var j = 0; j < json.xhr.IO.Data.length; j++) {
let d = json.xhr.IO.Data[j];
values.push({"observeddatetime": d.IODateTime, "value": d.Value});
}
if(parseInt(json.xhr.IO.Record) > 0){
if(parseInt(json.xhr.IO.Record) === 1){
values.push({"observeddatetime": json.xhr.IO.Data.IODateTime, "value": json.xhr.IO.Data.Value});
}
else{
for (var j = 0; j < json.xhr.IO.Data.length; j++) {
let d = json.xhr.IO.Data[j];
values.push({"observeddatetime": d.IODateTime, "value": d.Value});
}
}
}
if(values.length > 0){
dataTemplate.values = values;
......
......@@ -12,24 +12,22 @@ exports.getValues = function(dataSet, callback){
let values = [];
for (var i = 0; i < dataSet.length; i++) {
let json = parser.toJson(dataSet[i], {object: true});
dataTemplate.type = json.xhr.IO.Type;
dataTemplate.unit = json.xhr.IO.Unit;
dataTemplate.value_type = json.xhr.IO.ValueType;
if(parseInt(json.xhr.IO.Record) > 0){
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++) {
let d = json.xhr.IO.Data[j];
values.push({"observeddatetime": d.IODateTime, "value": d.Value, "direction": d.Direction});
}
let json = parser.toJson(dataSet, {object: true});
dataTemplate.type = json.xhr.IO.Type;
dataTemplate.unit = json.xhr.IO.Unit;
dataTemplate.value_type = json.xhr.IO.ValueType;
if(parseInt(json.xhr.IO.Record) > 0){
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++) {
let d = json.xhr.IO.Data[j];
values.push({"observeddatetime": d.IODateTime, "value": d.Value, "direction": d.Direction});
}
}
}
if(values.length > 0){
dataTemplate.values = values;
callback(dataTemplate);
......
......@@ -13,23 +13,35 @@ function perform_function(context,request,response){
var output_type = "object/sds";
var di_data = request.data;
let idx = 0;
let result = {
"object_type": 'iBitz',
"station_id": di_data.station_id,
"latitude": "",
"longitude": "",
"altitude": "",
"data":[]
};
let out = [];
async.whilst(function() { return idx < di_data.data.length;}, function(callback) {
let dtype = di_data.data[idx].data_types;
//console.log('[DT] di_data length = ' + di_data.data[idx].value.length);
if(typeof di_data.data[idx].value.length !== "undefined"){
//console.log('data = ' + di_data.data[idx].value[0]);
let json = parser.toJson(di_data.data[idx].value[0], {object: true});
agriParser.getParser(json.xhr.IO.Type).getValues(di_data.data[idx].value, function(values) {
var dataKeySeries = Object.keys(di_data.data);
// for (var i = 0; i < dataKeySeries.length; i++) {
// console.log(di_data.data[dataKeySeries[i]]);
// }
let i = 0;
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++;
if(values !== null){
result.latitude = json.xhr.IO.Latitude;
......@@ -37,32 +49,41 @@ function perform_function(context,request,response){
result.data.push(values);
//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) =>{
if(err) throw err;
callback(err);
if(err){
throw err;
callback(err);
}
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) {
if( err ) {
console.log(err);
//response.error(err);
} else {
//fs.writeFileSync("./result.json", JSON.stringify(result));
//console.log(JSON.stringify(result));
if(result.data.length > 0)
response.success(result, output_type);
else response.reject();
}
});
if( err ) {
console.log(err);
//response.error(err);
} else {
//fs.writeFileSync("./result.json", JSON.stringify(out));
//console.log(JSON.stringify(out));
if(out.length > 0)
response.success(out, output_type);
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