Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-10-16 16:17:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8be7ce15b8665891ae1cde0cc5ec9b08f65a73ac
8be7ce15
1 parent
7775c289
fix. data processing
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
server/src/util/DataProcess.js
server/src/util/DataProcess.js
View file @
8be7ce1
...
...
@@ -5,7 +5,6 @@ const TakeMedicineHist = require('../models/takeMedicineHistory');
//message subscribe 후 message를 가공한 이후 해당 데이터를 보낼 topic과 message를 리턴하는 함수
exports
.
dataPublish
=
async
(
topic
,
message
)
=>
{
if
(
message
.
includes
(
'weight'
))
{
console
.
log
(
'무게 갱신중'
);
//무게 갱신
const
result
=
await
updateBottleMedicineWeight
(
topic
,
message
);
...
...
@@ -29,7 +28,7 @@ exports.dataPublish = async (topic, message) => {
const
factoring
=
async
(
topic
,
message
)
=>
{
const
bottleId
=
parseInt
(
topic
.
split
(
'/'
)[
1
]);
const
data
=
message
.
split
(
'/'
);
const
[
isOpen
,
humidity
,
totalWeight
,
temperature
]
=
data
;
const
[
isOpen
,
temperature
,
totalWeight
,
humidity
]
=
data
;
return
{
bottleId
,
...
...
@@ -45,21 +44,21 @@ const factoring = async (topic, message) => {
const
bottleInfoUpdate
=
async
(
data
)
=>
{
let
{
bottleId
,
isOpen
,
temperature
,
humidity
,
totalWeight
}
=
data
;
if
(
!
parseInt
(
isOpen
))
{
bottleId
=
parseInt
(
bottleId
);
isOpen
=
parseInt
(
isOpen
);
temperature
=
parseFloat
(
temperature
).
toFixed
(
1
);
humidity
=
parseFloat
(
humidity
).
toFixed
(
1
);
totalWeight
=
parseFloat
(
totalWeight
).
toFixed
(
2
);
temperature
=
parseFloat
(
temperature
);
humidity
=
parseFloat
(
humidity
);
totalWeight
=
parseFloat
(
totalWeight
);
const
bottleMedicine
=
await
BottleMedicine
.
findOne
({
bottleId
,
useYn
:
'Y'
});
if
(
bottleMedicine
)
{
const
lastTotalWeight
=
parseFloat
(
bottleMedicine
.
totalWeight
);
if
(
isOpen
)
{
const
{
eachWeight
}
=
bottleMedicine
;
const
dosage
=
Math
.
round
((
lastTotalWeight
-
totalWeight
)
/
parseFloat
(
eachWeight
));
if
(
dosage
>
0
)
{
const
takeMedicineHist
=
new
TakeMedicineHist
({
bmId
:
bottleMedicine
.
_id
,
temperature
,
...
...
@@ -72,6 +71,7 @@ const bottleInfoUpdate = async(data) => {
await
bottleMedicine
.
setTotalWeight
(
totalWeight
);
await
bottleMedicine
.
save
();
}
}
}
//해당 MQTT Broker(client)에 bottleId의 정보에 관한 topic과 message를 리턴한다.
...
...
@@ -83,7 +83,9 @@ const transPublishingTopicAndMessage = async(bottleId) => {
bmId
:
bottleMedicine
.
_id
}).
sort
({
takeDate
:
'desc'
}).
limit
(
1
);
const
message
=
'res/'
+
await
transDate
(
takeMedicineHistList
[
0
].
takeDate
)
+
'/'
+
takeMedicineHistList
[
0
].
dosage
;
const
message
=
takeMedicineHistList
&&
takeMedicineHistList
[
0
]
?
'res/'
+
await
transDate
(
takeMedicineHistList
[
0
].
takeDate
)
+
'/'
+
takeMedicineHistList
[
0
].
dosage
:
'res/'
+
await
transDate
(
new
Date
())
+
'/'
+
0
;
return
{
topic
,
...
...
Please
register
or
login
to post a comment