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-05-16 16:22:54 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a2022c025aa172f0748052b57050563da89e9c1c
a2022c02
1 parent
3d41d6d0
feat. balance Factoring
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
4 deletions
server/src/lib/DataProcess.js
server/src/lib/DataProcess.js
View file @
a2022c0
...
...
@@ -12,14 +12,19 @@ exports.dataPublish = async (topic, message) => {
const
result
=
await
transPublishingTopicAndMessage
(
bottleId
);
return
result
;
};
//Hub topic : bottle/bottleId
//Hub로부터 받은 message : 개폐여부/온도/습도/초음파센서
const
factoring
=
(
topic
,
message
)
=>
{
const
factoring
=
async
(
topic
,
message
)
=>
{
const
bottleId
=
parseInt
(
topic
.
split
(
'/'
)[
1
]);
const
data
=
message
.
split
(
'/'
);
const
[
isOpen
,
temperature
,
humidity
,
balance
]
=
data
;
let
[
isOpen
,
temperature
,
humidity
,
balance
]
=
data
;
if
(
isOpen
===
'0'
)
balance
=
await
balanceFactoring
(
balance
);
else
balance
=
'-1'
;
const
openDate
=
new
Date
();
...
...
@@ -31,23 +36,48 @@ const factoring = (topic, message) => {
humidity
,
balance
};
}
const
balanceFactoring
=
(
balance
)
=>
{
const
max
=
11
;
const
slicingBalance
=
max
/
5
;
if
(
parseInt
(
balance
)
<
slicingBalance
||
parseInt
(
balance
)
>
max
*
2
)
return
'100'
;
else
if
(
parseInt
(
balance
)
<
slicingBalance
*
2
)
return
'80'
;
else
if
(
parseInt
(
balance
)
<
slicingBalance
*
3
)
return
'60'
;
else
if
(
parseInt
(
balance
)
<
slicingBalance
*
4
)
return
'40'
;
else
if
(
parseInt
(
balance
)
<
slicingBalance
*
5
)
return
'20'
;
else
return
'0'
;
}
//bottleId가 포함된 data를 받아서 해당 약병의 data를 업데이트한다.
const
bottleInfoUpdate
=
async
(
data
)
=>
{
const
{
bottleId
,
isOpen
,
openDate
,
temperature
,
humidity
,
balance
}
=
data
;
if
(
isOpen
===
'1'
)
{
await
Bottle
.
findOneAndUpdate
({
bottleId
},
{
recentOpen
:
openDate
});
}
if
(
balance
!==
'-1'
)
{
await
Bottle
.
findOneAndUpdate
({
bottleId
},
{
balance
})
}
await
Bottle
.
findOneAndUpdate
({
bottleId
},
{
temperature
,
humidity
,
balance
humidity
});
}
...
...
Please
register
or
login
to post a comment