Commit 7f212daf authored by Boteju W.J.M.'s avatar Boteju W.J.M.

2020-10-09

parent f4210851
Pipeline #1724 failed with stages
......@@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:fitnessapp/globals.dart' as globals;
class SearchService {
static String ip = 'http://192.168.1.5:8000';
static String ip = 'http://192.168.1.3:8000';
static int dog = 1;
static String username = 'Janadi';
static String password = 'janadi2.';
......@@ -89,6 +89,26 @@ class SearchService {
return response.body;
}
static Future<String> getTotalMinutesPerHour(day) async {
String url = '$ip/getTotalMinutesPerDay';
var body = jsonEncode({
"activity": globals.activityId,
"dog": dog,
"date": day,
});
http.Response response = await http
.post(url,
headers: {
"Content-Type": "application/json",
'authorization': basicAuth
},
body: body)
.then((http.Response response) {
return response;
});
return response.body;
}
static Future<String> getTotalMinutesPerDay(day) async {
String url = '$ip/getTotalMinutesPerDay';
var body =
......
import 'dart:convert';
import 'package:fitnessapp/constants.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:fitnessapp/loading.dart';
import 'package:intl/intl.dart';
import '../service.dart';
class DailyChart extends StatefulWidget {
@override
......@@ -9,13 +12,65 @@ class DailyChart extends StatefulWidget {
}
class _DailyChartState extends State<DailyChart> {
bool loading = true;
static dynamic data = [];
List<double> timePeriods = new List(24);
getCurrentDate() {
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd').format(now);
getTotalMinutesPerHour(formattedDate);
}
getTotalMinutesPerHour(date) async {
SearchService.getTotalMinutesPerHour(date).then((responseBody) {
dynamic data = jsonDecode(responseBody);
setState(() {
data = data[0]['hour array'];
timePeriods[0] = data[0].toDouble();
timePeriods[1] = data[1].toDouble();
timePeriods[2] = data[2].toDouble();
timePeriods[3] = data[3].toDouble();
timePeriods[4] = data[4].toDouble();
timePeriods[5] = data[5].toDouble();
timePeriods[6] = data[6].toDouble();
timePeriods[7] = data[7].toDouble();
timePeriods[8] = data[8].toDouble();
timePeriods[9] = data[9].toDouble();
timePeriods[10] = data[10].toDouble();
timePeriods[11] = data[11].toDouble();
timePeriods[12] = data[12].toDouble();
timePeriods[13] = data[13].toDouble();
timePeriods[14] = data[14].toDouble();
timePeriods[15] = data[15].toDouble();
timePeriods[16] = data[16].toDouble();
timePeriods[17] = data[17].toDouble();
timePeriods[18] = data[18].toDouble();
timePeriods[19] = data[19].toDouble();
timePeriods[20] = data[20].toDouble();
timePeriods[21] = data[21].toDouble();
timePeriods[22] = data[22].toDouble();
timePeriods[23] = data[23].toDouble();
});
loading = false;
});
}
@override
void initState() {
super.initState();
getCurrentDate();
}
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 1.7,
child: BarChart(
BarChartData(
barGroups: getBarGroups(),
barGroups: getBarGroups(timePeriods),
borderData: FlBorderData(show: false),
titlesData: FlTitlesData(
leftTitles: SideTitles(
......@@ -37,18 +92,19 @@ class _DailyChartState extends State<DailyChart> {
}
}
getBarGroups() {
List<double> barChartDatas = [
0,
0,
0,
5,
5,
10,
0,
3,
0,
2,
getBarGroups(List<double> barChartData) {
// List<double> barChartDatas = [
// 0,
// 0,
// 0,
// 5,
// 5,
// 10,
// 0,
// 3,
// 0,
// 2,
// 3,
// 0.5,
// 5,
......@@ -63,7 +119,7 @@ getBarGroups() {
// 2,
// 2,
// 5
];
// ];
List<BarChartGroupData> barChartGroups = [];
barChartDatas.asMap().forEach(
(i, value) => barChartGroups.add(
......@@ -72,7 +128,6 @@ getBarGroups() {
barRods: [
BarChartRodData(
y: value,
//This is not the proper way, this is just for demo
color: i == 9 ? kTextLightColor : kPrimaryColor,
width: 5,
)
......@@ -105,34 +160,34 @@ String getDay(double value) {
return '08:00';
case 9:
return '09:00';
// case 10:
// return '10:00';
// case 11:
// return '11:00';
// case 12:
// return '12:00';
// case 13:
// return '13:00';
// case 14:
// return '14:00';
// case 15:
// return '15:00';
// case 16:
// return '16:00';
// case 17:
// return '17:00';
// case 18:
// return '18:00';
// case 19:
// return '19:00';
// case 20:
// return '20:00';
// case 21:
// return '21:00';
// case 22:
// return '22:00';
// case 23:
// return '23:00';
case 10:
return '10:00';
case 11:
return '11:00';
case 12:
return '12:00';
case 13:
return '13:00';
case 14:
return '14:00';
case 15:
return '15:00';
case 16:
return '16:00';
case 17:
return '17:00';
case 18:
return '18:00';
case 19:
return '19:00';
case 20:
return '20:00';
case 21:
return '21:00';
case 22:
return '22:00';
case 23:
return '23:00';
default:
return '';
}
......
......@@ -13,9 +13,7 @@ class MonthlyChart extends StatefulWidget {
class _MonthlyChartState extends State<MonthlyChart> {
bool loading = true;
double time;
static dynamic data = [];
List<dynamic> weekNumbers = [];
List<double> timePeriods = new List(5);
getCurrentMonth() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment