Toggle navigation
Toggle navigation
This project
Loading...
Sign in
유희정
/
fwiot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이윤영
2019-12-17 11:52:25 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
73cb7ecbe69614e131ec5e0e6dde9a64840391bc
73cb7ecb
1 parent
f963efab
Modify DBhelper and Tab
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
119 additions
and
93 deletions
source/AppTabNavigator/HistoryTab.js
source/AppTabNavigator/HomeTab.js
source/AppTabNavigator/SettingTab.js
source/Login.js
source/component/DBhelper.js
source/component/HistoryGraph.js
source/AppTabNavigator/HistoryTab.js
View file @
73cb7ec
...
...
@@ -3,6 +3,8 @@ import { View, Text, StyleSheet,ScrollView, RefreshControl } from 'react-native'
import
{
BarChart
,
Grid
}
from
'react-native-svg-charts'
import
HistoryGraph
from
'../component/HistoryGraph'
import
SegmentedControlTab
from
"react-native-segmented-control-tab"
;
import
{
add_data
}
from
'../component/DBhelper.js'
;
const
data1
=
[
{
label
:
'MON'
,
value
:
1.8
},
{
label
:
'TUE'
,
value
:
4.2
},
...
...
@@ -61,7 +63,8 @@ export default class HomeTab extends Component {
_onRefresh
=
()
=>
{
this
.
setState
({
refresing
:
true
});
this
.
setState
({
data
:
data4
})
// this.setState({data: data4})
this
.
get_diff_data
();
this
.
setState
({
refreshing
:
false
});
}
...
...
@@ -81,21 +84,21 @@ export default class HomeTab extends Component {
};
get_diff_data
(){
return
fetch
(
'http://
10.0.2.2:3000
/app/get_diff_data/'
,{
return
fetch
(
'http://
testloadbalancer-1847561458.ap-northeast-2.elb.amazonaws.com
/app/get_diff_data/'
,{
method
:
'POST'
,
headers
:
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
},
body
:
JSON
.
stringify
({
ras_id
:
this
.
state
.
ID
,
date
:
this
.
state
.
today
,
ras_id
:
"pi1"
,
date
:
"1576339901541"
,
}),
})
.
then
((
response
)
=>
console
.
log
(
response
.
json
()))
.
then
((
response
)
=>
response
.
json
())
.
then
((
responseJson
)
=>
{
console
.
log
(
responseJson
)
a
lert
(
responseJson
[
0
].
ras_id
.
S
);
a
dd_data
(
responseJson
)
},
function
(){
})
.
catch
((
error
)
=>
{
...
...
@@ -114,29 +117,33 @@ export default class HomeTab extends Component {
// );
return
(
<
ScrollView
<
ScrollView
style
=
{
style
.
container
}
refreshControl
=
{
<
RefreshControl
refreshing
=
{
this
.
state
.
refreshing
}
onRefresh
=
{
this
.
_onRefresh
}
tintColor
=
"#
ff
0000"
tintColor
=
"#
00
0000"
title
=
"Loading..."
titleColor
=
"#00
ff00
"
colors
=
{[
"#ff
0000"
,
'#00ff00'
,
'#0000
ff'
]}
progressBackgroundColor
=
"#
ffff00
"
titleColor
=
"#00
66cc
"
colors
=
{[
"#ff
ffff"
,
'#0066cc'
,
'#ffff
ff'
]}
progressBackgroundColor
=
"#
0066cc
"
/>
}
>
<
View
style
=
{
style
.
container
}
>
<
View
style
=
{
style
.
header
}
>
<
Text
style
=
{
style
.
tabName
}
>
History
<
/Text
>
<
/View
>
<
Text
>
{
this
.
state
.
title
}
<
/Text
>
<
View
style
=
{{
flex
:
8
,
justifyContent
:
'center'
}}
>
<
Text
style
=
{
style
.
date_text
}
>
{
this
.
state
.
title
}
<
/Text
>
<
/View>
<
SegmentedControlTab
values
=
{[
"Week"
,
"Month"
,
"Year"
]}
selectedIndex
=
{
this
.
state
.
selectedIndex
}
onTabPress
=
{
this
.
handleIndexChange
}
/
>
<
HistoryGraph
data
=
{
this
.
state
.
data
}
round
=
{
100
}
unit
=
"kg"
/>
<
/View
>
<
/ScrollView
>
)
}
...
...
@@ -145,12 +152,11 @@ export default class HomeTab extends Component {
const
style
=
StyleSheet
.
create
({
container
:
{
flex
:
1
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
},
header
:
{
flex
:
1
,
flex
:
2
,
justifyContent
:
'center'
,
padding
:
10
,
},
tabName
:{
marginStart
:
10
,
...
...
@@ -158,5 +164,10 @@ const style = StyleSheet.create({
fontSize
:
20
,
color
:
"#0066cc"
,
fontWeight
:
'bold'
,
},
date_text
:{
fontSize
:
20
,
marginStart
:
5
,
textAlignVertical
:
'center'
}
})
\ No newline at end of file
...
...
source/AppTabNavigator/HomeTab.js
View file @
73cb7ec
...
...
@@ -2,56 +2,52 @@ import React, { Component } from 'react';
import
{
View
,
Text
,
StyleSheet
,
SafeAreaView
,
ScrollView
,
Image
}
from
'react-native'
;
import
Circle
from
'../component/circle_component'
import
{
Table
,
TableWrapper
,
Row
,
Rows
}
from
'react-native-table-component'
import
{
get_now_weight
,
get_today_data
}
from
'../component/DBhelper.js'
;
import
{
get_now_weight
,
get_today_data
,
add_data
}
from
'../component/DBhelper.js'
;
var
date
=
new
Date
();
date
.
setHours
(
date
.
getHours
()
+
9
);
var
month
=
date
.
getMonth
()
+
1
;
if
(
month
==
11
){
month
=
12
}
export
default
class
HomeTab
extends
Component
{
}
export
default
class
HomeTab
extends
Component
{
constructor
(
props
){
super
(
props
);
this
.
state
=
{
ID
:
this
.
props
.
navigation
.
getParam
(
'id'
,
'pi1'
),
// today : date.getFullYear() + "." + month + "." + date.getDate(),
today
:
"1576237044146.4011"
,
today
:
date
.
getFullYear
()
+
"."
+
month
+
"."
+
date
.
getDate
(),
current_weight
:
get_now_weight
()
,
table_contents
:
get_today_data
()
}
}
get_diff_data
(){
return
fetch
(
'http://
10.0.2.2:3000
/app/get_diff_data/'
,{
return
fetch
(
'http://
testloadbalancer-1847561458.ap-northeast-2.elb.amazonaws.com
/app/get_diff_data/'
,{
method
:
'POST'
,
headers
:
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
},
body
:
JSON
.
stringify
({
ras_id
:
this
.
state
.
ID
,
//date : date,
date
:
"1576237047226.6567"
ras_id
:
"pi1"
,
date
:
"1576339901541"
,
}),
})
.
then
((
response
)
=>
console
.
log
(
response
.
json
()))
.
then
((
response
)
=>
response
.
json
())
.
then
((
responseJson
)
=>
{
//alert(responseJson[0][0].ras_id.S);
console
.
log
(
responseJson
)
add_data
(
responseJson
);
},
function
(){
})
.
catch
((
error
)
=>
{
console
.
error
(
error
);
})
}
render
()
{
return
(
<
View
style
=
{
style
.
container
}
>
<
View
style
=
{
style
.
header
}
>
<
Text
style
=
{
style
.
tabName
}
>
Home
<
/Text
>
<
Text
style
=
{
style
.
tabName
}
>
Home
<
/Text
>
<
/View
>
<
View
style
=
{{
flexDirection
:
'row'
,
flex
:
0.8
,
backgroundColor
:
"rgba(230,230,230,0.5)"
}}
>
<
View
style
=
{{
flex
:
1
,
justifyContent
:
'center'
}}
>
...
...
@@ -64,7 +60,7 @@ export default class HomeTab extends Component {
<
/View
>
<
View
style
=
{
this
.
state
.
current_weight
}
>
<
Circle
title
=
{
this
.
state
.
current_weight
}
title
=
{
this
.
state
.
current_weight
/
1000
}
onPress
=
{()
=>
{
this
.
get_diff_data
()}}
>
<
/Circle
>
<
/View
>
...
...
@@ -87,7 +83,6 @@ export default class HomeTab extends Component {
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
...
...
source/AppTabNavigator/SettingTab.js
View file @
73cb7ec
...
...
@@ -31,7 +31,6 @@ export default class SettingTab extends Component {
.
then
((
response
)
=>
console
.
log
(
response
.
json
()))
.
then
((
responseJson
)
=>
{
console
.
log
(
responseJson
)
},
function
(){
})
.
catch
((
error
)
=>
{
console
.
error
(
error
);
...
...
@@ -40,7 +39,7 @@ export default class SettingTab extends Component {
delete_id
(){
this
.
setState
({
ID
:
''
})
save_app_data
()
//
save_app_data()
delete_all_data
()
}
render
()
{
...
...
@@ -81,7 +80,7 @@ export default class SettingTab extends Component {
onChangeText
=
{(
text
)
=>
this
.
setState
({
ID
:
text
})}
/
>
<
/View
>
<
AddButton
onPress
=
{()
=>
{
this
.
save_app_data
()
}}
/
>
onPress
=
{()
=>
{
this
.
save_app_data
}}
/
>
<
/View
>
<
/View
>
<
/View
>
...
...
source/Login.js
View file @
73cb7ec
...
...
@@ -16,11 +16,9 @@ export default class Login extends Component {
};
getdata
()
{
return
fetch
(
'http://
10.0.2.2:3000/app/get_data/uid
1'
)
return
fetch
(
'http://
testloadbalancer-1847561458.ap-northeast-2.elb.amazonaws.com/app/get_data/pi
1'
)
.
then
((
response
)
=>
response
.
json
())
.
then
((
responseJson
)
=>
{
// alert(responseJson[0].ras_id.S);
//alert(responseJson.length)
add_data
(
responseJson
);
})
.
catch
((
error
)
=>
{
...
...
@@ -28,6 +26,10 @@ export default class Login extends Component {
});
}
navigate
(){
}
render
()
{
return
(
<
View
style
=
{
styles
.
container
}
>
...
...
@@ -55,8 +57,9 @@ export default class Login extends Component {
onChangeText
=
{(
text
)
=>
{
this
.
setState
({
ID
:
text
})}}
/
>
<
LoginButton
// onPress={()=>getdata}
onPress
=
{()
=>
{
this
.
getdata
().
then
(
this
.
props
.
navigation
.
navigate
(
'MainScreen'
,
{
ID
:
this
.
state
.
ID
}))
}}
//onPress={()=>{this.getdata}}
onPress
=
{()
=>
{
this
.
props
.
navigation
.
navigate
(
'MainScreen'
,
{
ID
:
this
.
state
.
ID
});}}
//onPress={() =>{ this.getdata().then(()=>{this.props.navigation.navigate('MainScreen', { ID: this.state.ID })}) }}
/
>
<
/View
>
<
/View
>
...
...
source/component/DBhelper.js
View file @
73cb7ec
...
...
@@ -14,54 +14,35 @@ Waste.schema = {
// Get the default Realm with support for our objects
let
realm
=
new
Realm
({
schema
:
[
Waste
]});
// // Create Realm objects and write to local storage
// realm.write(() => {
// let myWaste = realm.create('Waste', {
// weight: 1655,
// diff: 500,
// date: '1576236841329.253',
// });
// // myWaste.miles += 2SS0; // Update a property value
// });
// // Query Realm for all cars with a high mileage
// let wastes = realm.objects('Waste').filtered('weight > 1000');
// // Will return a Results object with our 1 car
// cars.length // => 1
// // Add another car
// realm.write(() => {
// let myCar = realm.create('Car', {
// make: 'Ford',
// model: 'Focus',
// miles: 2000,
// });
// });
// // Query results are updated in realtime
// cars.length // => 2
export
function
add_data
(
responseJson
){
for
(
i
=
0
;
i
<
responseJson
.
length
;
i
++
){
for
(
i
=
0
;
i
<
responseJson
.
length
;
i
++
){
realm
.
write
(()
=>
{
// responseJson[0].ras_id.S
let
myWaste
=
realm
.
create
(
'Waste'
,
{
weight
:
Number
(
responseJson
[
i
].
weight
.
N
),
diff
:
Number
(
responseJson
[
i
].
diff
.
N
),
date
:
Number
(
responseJson
[
i
].
save_date
.
S
),
weight
:
parseFloat
(
responseJson
[
i
].
weight
.
N
),
diff
:
parseFloat
(
responseJson
[
i
].
diff
.
N
),
date
:
parseFloat
(
responseJson
[
i
].
save_date
.
S
),
});
});
console
.
log
(
responseJson
[
i
].
save_date
.
S
)
}
return
responseJson
.
length
;
}
}
export
function
get_now_weight
(){
let
wastes
=
realm
.
objects
(
'Waste'
);
let
recent
=
realm
.
objects
(
'Waste'
).
max
(
'date'
).
date
;
let
recentWeight
=
wastes
.
filtered
(
'date = 1576223063238.5166'
);
//"id == %@", id!
console
.
log
(
String
(
wastes
.
lenth
));
let
recent
=
wastes
.
max
(
'date'
);
var
recentWeight
=
wastes
.
filtered
(
'date = $0'
,
recent
);
console
.
log
(
"now_weight"
,
recentWeight
)
return
recentWeight
[
0
].
weight
;
}
export
function
get_last_update
(){
let
recent
=
realm
.
objects
(
'Waste'
).
max
(
'date'
);
let
recentWeight
=
wastes
.
filtered
(
'date = %0'
,
recent
);
console
.
log
(
recentWeight
[
0
].
weight
)
return
recentWeight
[
0
].
weight
;
}
...
...
@@ -70,23 +51,49 @@ export function get_recent_date(){
return
realm
.
objects
(
'Waste'
).
max
(
"date"
);
}
export
function
get_today_data
(
today
){
let
wastes
=
realm
.
objects
(
'Waste'
);
// export function get_today_data(today){
// let wastes = realm.objects('Waste');
// var list = [];
// for(var i =0; i<wastes.length; i++){
// if(get_date(wastes[i].date) == get_date(today)){
// temp = [waste[i].date, waste[i].diff, waste[i].weight]
// list.append(temp);
// }
// }
// return list;
// }
export
function
get_today_data
(){
var
today_start
=
get_today_start
();
console
.
log
(
"today_start: "
,
today_start
)
let
wastes
=
realm
.
objects
(
'Waste'
).
filtered
(
'date >= $0'
,
today_start
);
var
list
=
[];
for
(
var
i
=
0
;
i
<
wastes
.
length
;
i
++
){
if
(
get_date
(
wastes
[
i
].
date
)
==
get_date
(
today
)){
temp
=
[
waste
[
i
].
date
,
waste
[
i
].
diff
,
waste
[
i
].
weight
]
list
.
append
(
temp
);
}
for
(
var
i
=
0
;
i
<
wastes
.
length
;
i
++
){
var
save_time
=
new
Date
(
wastes
[
i
].
date
);
var
temp
=
[
save_time
.
getHours
()
+
":"
+
save_time
.
getMinutes
()
+
":"
+
save_time
.
getSeconds
(),
wastes
[
i
].
diff
,
wastes
[
i
].
weight
+
"g"
]
list
.
push
(
temp
);
}
console
.
log
(
list
);
console
.
log
(
"count:"
,
wastes
.
length
)
return
list
;
}
export
function
delete_all_data
(
today
){
let
all_wastes
=
realm
.
objects
(
'Waste'
);
realm
.
delete
(
all_wastes
);
let
all_wastes
=
realm
.
objects
(
'Waste'
);
realm
.
write
(()
=>
{
realm
.
delete
(
all_wastes
);
})
var
wastes
=
realm
.
objects
(
'Waste'
)
console
.
log
(
"delete, count: "
,
wastes
.
length
)
}
var
get_date
=
function
(
date
){
return
pad
(
date
.
getFullyear
(),
4
)
+
pad
(
date
.
getMonth
()
+
1
,
2
)
+
pad
(
date
.
getDate
(),
2
)
function
get_today_start
(){
var
today
=
new
Date
();
var
dd
=
today
.
getDate
();
var
mm
=
today
.
getMonth
();
var
yyyy
=
today
.
getFullYear
();
var
togettime
=
new
Date
(
2019
,
11
,
13
).
getTime
();
console
.
log
(
togettime
)
return
togettime
;
}
\ No newline at end of file
...
...
source/component/HistoryGraph.js
View file @
73cb7ec
...
...
@@ -6,10 +6,10 @@ import * as d3 from 'd3'
// import Showkg from './ShowKg'
const
GRAPH_MARGIN
=
20
const
GRAPH_BAR_WIDTH
=
5
const
GRAPH_BAR_WIDTH
=
10
const
colors
=
{
axis
:
'#E4E4E4'
,
bars
:
'#
15AD13
'
,
bars
:
'#
0066cc
'
,
bardefult
:
'#CED4DA'
}
...
...
@@ -40,7 +40,7 @@ export default class HistoryGraph extends PureComponent {
render
()
{
// Dimensions
const
SVGHeight
=
300
const
SVGWidth
=
30
0
const
SVGWidth
=
45
0
const
graphHeight
=
SVGHeight
-
2
*
GRAPH_MARGIN
const
graphWidth
=
SVGWidth
-
2
*
GRAPH_MARGIN
const
data
=
this
.
props
.
data
...
...
@@ -74,7 +74,7 @@ export default class HistoryGraph extends PureComponent {
x
=
{
graphWidth
}
textAnchor
=
"end"
y
=
{
y
(
topValue
)
*
-
1
-
5
}
fontSize
=
{
1
2
}
fontSize
=
{
1
5
}
fill
=
"black"
fillOpacity
=
{
0.4
}
>
{
topValue
+
' '
+
this
.
props
.
unit
}
...
...
@@ -130,15 +130,26 @@ export default class HistoryGraph extends PureComponent {
{
data
.
map
(
item
=>
(
<
SvgText
key
=
{
'label'
+
item
.
label
}
fontSize
=
"
8
"
fontSize
=
"
12
"
x
=
{
x
(
item
.
label
)}
y
=
"10"
textAnchor
=
"middle"
>
{
item
.
label
}
<
/SvgText
>
))}
<
/G
>
<
/Svg
>
<
View
style
=
{
style
.
container
}
>
<
Text
>
{
this
.
state
.
kg
}
<
/Text
>
<
/View
>
<
/View
>
)
}
}
\ No newline at end of file
}
const
style
=
StyleSheet
.
create
({
container
:
{
flex
:
8.8
,
backgroundColor
:
"rgba(230,230,230,0.5)"
,
justifyContent
:
'center'
,
padding
:
25
,
}
});
\ No newline at end of file
...
...
Please
register
or
login
to post a comment