유희정

history tab

......@@ -3,37 +3,43 @@ 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';
import {add_data, get_week_data, get_today_data, get_month_data, get_year_data} from'../component/DBhelper.js';
var list1 = get_week_data();
var list2 = get_month_data();
var list3 = get_year_data();
//var today = new Date();
//today.setHours(today.getHours()+9);
var week = ['SUN','MON','TUE', 'WED', 'THU', 'FRI', 'SAT'];
const data1 = [
{ label: 'MON', value: 1.8 },
{ label: 'TUE', value: 4.2 },
{ label: 'WEN', value: 1.6 },
{ label: 'THU', value: 0 },
{ label: 'FRI', value: 2.0 },
{ label: 'SAT', value: 3.3 },
{ label: 'SUN', value: 1.3 }
{ label: week[list1[1][0]], value: list1[0][0] },
{ label: week[list1[1][1]], value: list1[0][1] },
{ label: week[list1[1][2]], value: list1[0][2] },
{ label: week[list1[1][3]], value: list1[0][3] },
{ label: week[list1[1][4]], value: list1[0][4] },
{ label: week[list1[1][5]], value: list1[0][5] },
{ label: week[list1[1][6]], value: list1[0][6] }
]
const data2 = [
{ label: '1', value: 4.6 },
{ label: '8', value: 3.7 },
{ label: '15', value: 3.0 },
{ label: '22', value: 5.2 },
{ label: '29', value: 3.1 }
{ label: '1', value: list2[0] },
{ label: '7', value: list2[1] },
{ label: '14', value: list2[2]},
{ label: '21', value: list2[3] },
{ label: '28', value: list2[4] }
]
const data3 = [
{ label: 'Jan', value: 500 },
{ label: 'Feb', value: 312 },
{ label: 'Mar', value: 424 },
{ label: 'Apr', value: 745 },
{ label: 'May', value: 89 },
{ label: 'Jun', value: 434 },
{ label: 'Jul', value: 650 },
{ label: 'Aug', value: 980 },
{ label: 'Sep', value: 123 },
{ label: 'Oct', value: 186 },
{ label: 'Nov', value: 689 },
{ label: 'Dec', value: 643 }
{ label: 'Jan', value: list3[0] },
{ label: 'Feb', value: list3[1] },
{ label: 'Mar', value: list3[2] },
{ label: 'Apr', value: list3[3] },
{ label: 'May', value: list3[4] },
{ label: 'Jun', value: list3[5] },
{ label: 'Jul', value: list3[6] },
{ label: 'Aug', value: list3[7] },
{ label: 'Sep', value: list3[8] },
{ label: 'Oct', value: list3[9] },
{ label: 'Nov', value: list3[10] },
{ label: 'Dec', value: list3[11] }
]
const data4 = [
......@@ -45,9 +51,16 @@ const data4 = [
{ label: 'E', value: 434 }
]
const kg1 = "총 3.5kg"
const kg2 = "총 9,6kg"
const kg3 = "총 21.3kg"
function total(list){
var total=0;
for(var i =0; i< list.length; i++)
total += list[i]
return total
}
const kg1 = "총 " + total(list1[0]) + "kg"
const kg2 = "총 " + total(list2) + "kg"
const kg3 = "총 " + total(list3) + "kg"
export default class HomeTab extends Component {
constructor(){
......@@ -55,7 +68,7 @@ export default class HomeTab extends Component {
this.state = {
selectedIndex: 0,
data: data1,
title: "총 3.5kg",
title: "총 " + total(list1[0]) + "kg",
spane: "",
refreshing: false
}
......
......@@ -47,7 +47,7 @@ export default class MainScreen extends Component {
title: 'FW IOT' }
render() {
//registerID(this.state.ID);
registerID(this.state.ID);
return <AppTabContainet/>; // AppTabContainet 컴포넌트를 리턴한다.
}
}
......
......@@ -112,6 +112,199 @@ export function get_today_data(){
return list;
}
export function get_week_data(){
var today = new Date();
var daybefore1 = new Date();
daybefore1.setDate(today.getDate()-1);
var daybefore2 = new Date();
daybefore2.setDate(today.getDate()-2);
var daybefore3 = new Date();
daybefore3.setDate(today.getDate()-3);
var daybefore4 = new Date();
daybefore4.setDate(today.getDate()-4);
var daybefore5 = new Date();
daybefore5.setDate(today.getDate()-5);
var daybefore6 = new Date();
daybefore6.setDate(today.getDate()-6);
var day = [daybefore6.getDay(), daybefore5.getDay(),daybefore4.getDay(),
daybefore3.getDay(),daybefore2.getDay(),daybefore1.getDay(), today.getDay()]
today = today.getTime();
daybefore1 = daybefore1.getTime();
daybefore2 = daybefore2.getTime();
daybefore3 = daybefore3.getTime();
daybefore4 = daybefore4.getTime();
daybefore5 = daybefore5.getTime();
daybefore6 = daybefore6.getTime();
let wastes1 = realm.objects('Waste').filtered('date >= $0 && date <$1', daybefore6, daybefore5);
let wastes2 = realm.objects('Waste').filtered('date >= $0 && date <$1', daybefore5, daybefore4);
let wastes3 = realm.objects('Waste').filtered('date >= $0 && date <$1', daybefore4, daybefore3);
let wastes4 = realm.objects('Waste').filtered('date >= $0 && date <$1', daybefore3, daybefore2);
let wastes5 = realm.objects('Waste').filtered('date >= $0 && date <$1', daybefore2, daybefore1);
let wastes6 = realm.objects('Waste').filtered('date >= $0 && date <$1', daybefore1, today);
let wastes7 = realm.objects('Waste').filtered('date >= $0', today);
var list = [];
var total1 =0, total2=0, total3=0, total4=0, total5=0, total6=0, total7 = 0;
for(var i = 0; i< wastes1.length; i++){
total1 += wastes1[i].diff;
}
for(var i = 0; i< wastes2.length; i++){
total2 += wastes2[i].diff;
}
for(var i = 0; i< wastes3.length; i++){
total3 += wastes3[i].diff;
}
for(var i = 0; i< wastes4.length; i++){
total4 += wastes4[i].diff;
}
for(var i = 0; i< wastes5.length; i++){
total5 += wastes5[i].diff;
}
for(var i = 0; i< wastes6.length; i++){
total6 += wastes6[i].diff;
}
for(var i = 0; i< wastes7.length; i++){
total7 += wastes7[i].diff;
}
list = [[total1, total2, total3, total4, total5, total6, total7],day]
return list;
}
export function get_month_data(){
var today = new Date();
var sep1 = new Date(today.getFullYear(), today.getMonth()-1, 1);
var sep2 = new Date(today.getFullYear(), today.getMonth()-1, 7);
var sep3 = new Date(today.getFullYear(), today.getMonth()-1, 14);
var sep4 = new Date(today.getFullYear(), today.getMonth()-1, 21);
var sep5 = new Date(today.getFullYear(), today.getMonth()-1, 28);
var sep6 = new Date(today.getFullYear(), today.getMonth(), 1)
sep1 = sep1.getTime();
sep2 = sep2.getTime();
sep3 = sep3.getTime();
sep4 = sep4.getTime();
sep5 = sep5.getTime();
sep6 = sep6.getTime();
let wastes1 = realm.objects('Waste').filtered('date >= $0 && date <$1', sep1, sep2);
let wastes2 = realm.objects('Waste').filtered('date >= $0 && date <$1', sep2, sep3);
let wastes3 = realm.objects('Waste').filtered('date >= $0 && date <$1', sep3, sep4);
let wastes4 = realm.objects('Waste').filtered('date >= $0 && date <$1', sep4, sep5);
let wastes5 = realm.objects('Waste').filtered('date >= $0 && date <$1', sep5, sep6);
var list = [];
var total1 =0, total2=0, total3=0, total4=0, total5=0;
for(var i = 0; i< wastes1.length; i++){
total1 += wastes1[i].diff;
}
for(var i = 0; i< wastes2.length; i++){
total2 += wastes2[i].diff;
}
for(var i = 0; i< wastes3.length; i++){
total3 += wastes3[i].diff;
}
for(var i = 0; i< wastes4.length; i++){
total4 += wastes4[i].diff;
}
for(var i = 0; i< wastes5.length; i++){
total5 += wastes5[i].diff;
}
list = [total1, total2, total3, total4, total5]
return list;
}
export function get_year_data(){
var today = new Date();
var mon1 = new Date(today.getFullYear()-1, 0, 1);
var mon2 = new Date(today.getFullYear()-1, 1, 1);
var mon3 = new Date(today.getFullYear()-1, 2, 1);
var mon4 = new Date(today.getFullYear()-1, 3, 1);
var mon5 = new Date(today.getFullYear()-1, 4, 1);
var mon6 = new Date(today.getFullYear()-1, 5, 1);
var mon7 = new Date(today.getFullYear()-1, 6, 1);
var mon8 = new Date(today.getFullYear()-1, 7, 1);
var mon9 = new Date(today.getFullYear()-1, 8, 1);
var mon10 = new Date(today.getFullYear()-1, 9, 1);
var mon11 = new Date(today.getFullYear()-1, 10, 1);
var mon12 = new Date(today.getFullYear()-1, 11, 1);
var nYear = new Date(today.getFullYear(), 0, 1);
mon1 = mon1.getTime();
mon2 = mon2.getTime();
mon3 = mon3.getTime();
mon4 = mon4.getTime();
mon5 = mon5.getTime();
mon6 = mon6.getTime();
mon7 = mon7.getTime();
mon8 = mon8.getTime();
mon9 = mon9.getTime();
mon10 = mon10.getTime();
mon11 = mon11.getTime();
mon12 = mon12.getTime();
nYear = nYear.getTime();
let wastes1 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon1, mon2);
let wastes2 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon2, mon3);
let wastes3 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon3, mon4);
let wastes4 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon4, mon5);
let wastes5 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon5, mon6);
let wastes6 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon6, mon7);
let wastes7 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon7, mon8);
let wastes8 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon8, mon9);
let wastes9 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon9, mon10);
let wastes10 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon10, mon11);
let wastes11 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon11, mon12);
let wastes12 = realm.objects('Waste').filtered('date >= $0 && date <$1', mon12, nYear);
var list = [];
var total1 =0, total2=0, total3=0, total4=0, total5=0,
total6 =0, total7=0, total8=0, total9=0, total10=0,
total11 =0, total12=0;
for(var i = 0; i< wastes1.length; i++){
total1 += wastes1[i].diff;
}
for(var i = 0; i< wastes2.length; i++){
total2 += wastes2[i].diff;
}
for(var i = 0; i< wastes3.length; i++){
total3 += wastes3[i].diff;
}
for(var i = 0; i< wastes4.length; i++){
total4 += wastes4[i].diff;
}
for(var i = 0; i< wastes5.length; i++){
total5 += wastes5[i].diff;
}
for(var i = 0; i< wastes6.length; i++){
total6 += wastes6[i].diff;
}
for(var i = 0; i< wastes7.length; i++){
total7 += wastes7[i].diff;
}
for(var i = 0; i< wastes8.length; i++){
total8 += wastes8[i].diff;
}
for(var i = 0; i< wastes9.length; i++){
total9 += wastes9[i].diff;
}
for(var i = 0; i< wastes10.length; i++){
total10 += wastes10[i].diff;
}
for(var i = 0; i< wastes11.length; i++){
total11 += wastes11[i].diff;
}
for(var i = 0; i< wastes12.length; i++){
total12 += wastes12[i].diff;
}
list = [total1, total2, total3, total4, total5,total6, total7, total8, total9, total10,total11, total12]
return list;
}
export function delete_all_data(today){
let all_wastes = realm.objects('Waste');
realm.write(() => {
......