Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
node-bigstream
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bs
node-bigstream
Commits
6a03e3f8
Commit
6a03e3f8
authored
Dec 20, 2016
by
project
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
c4543a8a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
230 additions
and
0 deletions
+230
-0
index.js
plugins/dt/dt-agritronics/index.js
+13
-0
package.json
plugins/dt/dt-agritronics/package.json
+18
-0
agri_parser_factory.js
plugins/dt/dt-agritronics/parser/agri_parser_factory.js
+9
-0
image_parser.js
plugins/dt/dt-agritronics/parser/image_parser.js
+71
-0
simple_parser.js
plugins/dt/dt-agritronics/parser/simple_parser.js
+27
-0
wind_direction_parser.js
plugins/dt/dt-agritronics/parser/wind_direction_parser.js
+27
-0
perform.js
plugins/dt/dt-agritronics/perform.js
+65
-0
No files found.
plugins/dt/dt-agritronics/index.js
0 → 100644
View file @
6a03e3f8
var
util
=
require
(
'util'
);
var
DTPlugin
=
require
(
'../dt-plugin'
);
function
DTTask
(
context
,
request
){
DTPlugin
.
call
(
this
,
context
,
request
);
this
.
name
=
"noop"
;
this
.
output_type
=
""
;
}
util
.
inherits
(
DTTask
,
DTPlugin
);
DTTask
.
prototype
.
perform
=
require
(
'./perform'
);
module
.
exports
=
DTTask
;
plugins/dt/dt-agritronics/package.json
0 → 100644
View file @
6a03e3f8
{
"name"
:
"dt-agritronics-ibitz"
,
"version"
:
"0.0.1"
,
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"keywords"
:
[
"bigstream"
],
"author"
:
"lsr.bigstream"
,
"license"
:
"ISC"
,
"dependencies"
:
{
"async"
:
"^2.1.2"
,
"xml2json"
:
"^0.10.0"
}
}
plugins/dt/dt-agritronics/parser/agri_parser_factory.js
0 → 100644
View file @
6a03e3f8
var
simpleParser
=
require
(
'./simple_parser'
);
var
windDirParser
=
require
(
'./wind_direction_parser'
);
var
imageParser
=
require
(
'./image_parser'
);
exports
.
getParser
=
function
(
type
){
if
(
type
===
"Camera"
)
return
imageParser
;
else
if
(
type
===
"Wind Direction Degree"
)
return
windDirParser
;
else
return
simpleParser
;
}
\ No newline at end of file
plugins/dt/dt-agritronics/parser/image_parser.js
0 → 100644
View file @
6a03e3f8
var
fs
=
require
(
'fs'
);
var
request
=
require
(
'request'
);
var
async
=
require
(
'async'
);
exports
.
getValues
=
function
(
json
,
cb
){
let
dataTemplate
=
{
"type"
:
json
.
xhr
.
IO
.
Type
,
"unit"
:
json
.
xhr
.
IO
.
Unit
,
"value_type"
:
json
.
xhr
.
IO
.
ValueType
,
"image_type"
:
json
.
xhr
.
IO
.
Name
,
"values"
:
[]
};
let
values
=
[];
if
(
typeof
json
.
xhr
.
IO
.
Data
.
length
===
"undefined"
){
getImage
(
json
.
xhr
.
IO
.
Data
.
Value
).
then
((
data
)
=>
{
values
.
push
({
"observeddatetime"
:
json
.
xhr
.
IO
.
Data
.
IODateTime
,
"value"
:
data
});
if
(
values
.
length
>
0
){
dataTemplate
.
values
=
values
;
cb
(
dataTemplate
);
}
else
cb
(
null
);
}).
catch
((
err
)
=>
{
cb
(
err
);
})
}
else
{
var
idx
=
0
;
async
.
whilst
(
function
()
{
return
idx
<
json
.
xhr
.
IO
.
Data
.
length
;},
function
(
callback
)
{
let
d
=
json
.
xhr
.
IO
.
Data
[
idx
];
idx
++
;
getImage
(
d
.
Value
).
then
((
data
)
=>
{
values
.
push
({
"observeddatetime"
:
d
.
IODateTime
,
"value"
:
data
});
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
getImage
(
url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
request
(
url
,
function
(
error
,
resp
,
body
)
{
if
(
!
error
&&
resp
.
statusCode
==
200
)
{
resolve
(
"data:"
+
resp
.
headers
[
"content-type"
]
+
";base64,"
+
new
Buffer
(
body
).
toString
(
'base64'
));
}
else
{
return
reject
(
error
);
}
})
})
}
\ No newline at end of file
plugins/dt/dt-agritronics/parser/simple_parser.js
0 → 100644
View file @
6a03e3f8
exports
.
getValues
=
function
(
json
,
callback
){
let
dataTemplate
=
{
"type"
:
json
.
xhr
.
IO
.
Type
,
"unit"
:
json
.
xhr
.
IO
.
Unit
,
"value_type"
:
json
.
xhr
.
IO
.
ValueType
,
"values"
:
[]
};
let
values
=
[];
if
(
typeof
json
.
xhr
.
IO
.
Data
.
length
===
"undefined"
){
values
.
push
({
"observeddatetime"
:
json
.
xhr
.
IO
.
Data
.
IODateTime
,
"value"
:
json
.
xhr
.
IO
.
Data
.
Value
});
}
else
{
for
(
var
i
=
0
;
i
<
json
.
xhr
.
IO
.
Data
.
length
;
i
++
)
{
let
d
=
json
.
xhr
.
IO
.
Data
[
i
];
values
.
push
({
"observeddatetime"
:
d
.
IODateTime
,
"value"
:
d
.
Value
});
}
}
//console.log("values.langth >>>" + values.length);
if
(
values
.
length
>
0
){
dataTemplate
.
values
=
values
;
callback
(
dataTemplate
);
}
else
callback
(
null
);
}
\ No newline at end of file
plugins/dt/dt-agritronics/parser/wind_direction_parser.js
0 → 100644
View file @
6a03e3f8
exports
.
getValues
=
function
(
json
,
callback
){
let
dataTemplate
=
{
"type"
:
json
.
xhr
.
IO
.
Type
,
"unit"
:
json
.
xhr
.
IO
.
Unit
,
"value_type"
:
json
.
xhr
.
IO
.
ValueType
,
"values"
:
[]
};
let
values
=
[];
if
(
typeof
json
.
xhr
.
IO
.
Data
.
length
===
"undefined"
){
values
.
push
({
"observeddatetime"
:
json
.
xhr
.
IO
.
Data
.
IODateTime
,
"value"
:
json
.
xhr
.
IO
.
Data
.
Value
});
}
else
{
for
(
var
i
=
0
;
i
<
json
.
xhr
.
IO
.
Data
.
length
;
i
++
)
{
let
d
=
json
.
xhr
.
IO
.
Data
[
i
];
values
.
push
({
"observeddatetime"
:
d
.
IODateTime
,
"value"
:
d
.
Value
,
"direction"
:
d
.
Direction
});
}
}
//console.log("values.langth >>>" + values.length);
if
(
values
.
length
>
0
){
dataTemplate
.
values
=
values
;
callback
(
dataTemplate
);
}
else
callback
(
null
);
}
\ No newline at end of file
plugins/dt/dt-agritronics/perform.js
0 → 100644
View file @
6a03e3f8
function
perform_function
(
context
,
request
,
response
){
var
job_id
=
context
.
jobconfig
.
job_id
;
var
transaction_id
=
context
.
transaction
.
id
;
var
param
=
context
.
jobconfig
.
data_transform
.
param
;
var
memstore
=
context
.
task
.
memstore
var
output_type
=
request
.
input_type
;
var
di_data
=
request
.
data
;
var
agriParser
=
require
(
'./parser/agri_parser_factory'
);
var
async
=
require
(
'async'
);
var
parser
=
require
(
'xml2json'
);
var
fs
=
require
(
'fs'
);
let
idx
=
0
;
let
result
=
{
"station_id"
:
di_data
.
station_id
,
"latitude"
:
""
,
"longitude"
:
""
,
"data"
:[]
};
//console.log(json_table.length);
async
.
whilst
(
function
()
{
return
idx
<
di_data
.
data
.
length
;},
function
(
callback
)
{
let
json
=
parser
.
toJson
(
di_data
.
data
[
idx
].
value
,
{
object
:
true
});
idx
++
;
if
(
typeof
json
.
xhr
.
IO
.
Data
!==
'undefined'
)
{
agriParser
.
getParser
(
json
.
xhr
.
IO
.
Type
).
getValues
(
json
,
(
values
)
=>
{
if
(
values
!==
null
){
result
.
latitude
=
json
.
xhr
.
IO
.
Latitude
;
result
.
longitude
=
json
.
xhr
.
IO
.
Longitude
;
result
.
data
.
push
(
values
);
callback
();
}
});
}
},
function
(
err
)
{
console
.
log
(
"CB"
);
if
(
err
)
{
console
.
log
(
err
);
}
else
{
console
.
log
(
'data out...'
);
fs
.
writeFileSync
(
"./result.json"
,
JSON
.
stringify
(
result
));
console
.
log
(
JSON
.
stringify
(
result
));
}
});
// memstore.setItem('lasttransaction',transaction_id,function(err){
// response.success(data);
// });
// memstore.getItem('lasttransaction',function(err,value){
// response.success(value);
// });
//data = data + "--DT--"
response
.
success
(
result
,
output_type
);
//response.reject();
//response.error("error message")
}
module
.
exports
=
perform_function
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment