유희정

get today data from db

......@@ -2,7 +2,7 @@ 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} from'../component/DBhelper.js';
import {get_now_weight, get_today_data} from'../component/DBhelper.js';
var date = new Date();
date.setHours(date.getHours()+9);
......@@ -19,12 +19,7 @@ export default class HomeTab extends Component {
// today : date.getFullYear() + "." + month + "." + date.getDate(),
today : "1576237044146.4011",
current_weight : get_now_weight() ,
table_contents : [['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','4:27:52', '+0.12kg', 'Total : 1.38kg'],
['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],
['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],
['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],
['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg']
]
table_contents : get_today_data()
}
}
......@@ -37,7 +32,7 @@ export default class HomeTab extends Component {
},
body:JSON.stringify({
ras_id : this.state.ID,
//date : this.state.today,
//date : date,
date : "1576237047226.6567"
}),
})
......@@ -56,7 +51,7 @@ export default class HomeTab extends Component {
return (
<View style={style.container}>
<View style={style.header}>
<Text style={style.tabName}>Home {this.state.ID}</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'}}>
......@@ -79,8 +74,8 @@ export default class HomeTab extends Component {
<Text style={style.history}>Today's History</Text>
<Table>
<TableWrapper>
<Row data={['시간', '증감량', '총량']} flexArr={[2.5, 1.5, 1.5]} textStyle={style.row_style1}/>
<Rows data={this.state.table_contents} flexArr={[1, 1.5, 1.5, 1.5]} textStyle={style.row_style2}/>
<Row data={['시간', '증감량', '총량']} flexArr={[1, 1, 1]} textStyle={style.row_style1}/>
<Rows data={this.state.table_contents} flexArr={[1, 1, 1]} textStyle={style.row_style2}/>
</TableWrapper>
</Table>
......
......@@ -54,7 +54,7 @@ export function add_data(responseJson){
}
return responseJson.length;
}
}
export function get_now_weight(){
let wastes = realm.objects('Waste');
......@@ -68,4 +68,20 @@ export function get_now_weight(){
export function get_recent_date(){
return realm.objects('Waste').max("date");
}
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;
}
var get_date = function (date){
return pad(date.getFullyear(),4)+pad(date.getMonth()+1, 2)+ pad(date.getDate(), 2)
}
\ No newline at end of file
......