diff --git a/Server/rasm-83719-export (2).json b/Server/rasm-83719-export (2).json new file mode 100644 index 0000000..c566269 --- /dev/null +++ b/Server/rasm-83719-export (2).json @@ -0,0 +1,59 @@ +{ + "Activities" : [ null, { + "ID" : 1, + "name" : "Competitive blind maze navigation", + "numRequiredRobots" : 2 + }, { + "ID" : 2, + "name" : "Collaborative semi-blind maze navigation", + "numRequiredRobots" : 2 + }, { + "ID" : 3, + "name" : "Collaborative orthogonal coordination", + "numRequiredRobots" : 2 + }, { + "ID" : 4, + "name" : "Collaborative path follow-up", + "numRequiredRobots" : 2 + }, { + "ID" : 5, + "name" : "Collaborative path follow-up & prediction", + "numRequiredRobots" : 2 + }, { + "ID" : 6, + "name" : "Individual line drawing", + "numRequiredRobots" : 2 + }, { + "ID" : 7, + "name" : "Individual line guess", + "numRequiredRobots" : 2 + }, { + "ID" : 8, + "name" : "Semi-Mathematical control", + "numRequiredRobots" : 2 + }, { + "ID" : 9, + "name" : "Mathematical expression", + "numRequiredRobots" : 0 + }, { + "ID" : 10, + "name" : "Function equation", + "numRequiredRobots" : 0 + } ], + "groups" : [ null, { + "member1name" : "sina", + "member2name" : "mina", + "member3name" : "kina", + "name" : "team1" + } ], + "inactivity" : [ { + "acID" : 1, + "groupID" : 1, + "time" : "14:19" + } ], + "progress" : { + "acID" : 1, + "groupID" : 1, + "time" : "14:19" + } +} diff --git a/student/lib/Activities/Ac7.Dart b/student/lib/Activities/Ac7.Dart index 135a775..7b38225 100644 --- a/student/lib/Activities/Ac7.Dart +++ b/student/lib/Activities/Ac7.Dart @@ -1,532 +1,525 @@ import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:student/widgets/onlineRobotMap.Dart'; import 'dart:async'; import 'package:student/Database.dart'; import 'package:student/model/Group.dart'; import 'package:student/model/Cellulo.dart'; import 'package:student/widgets/showAlertDialog.Dart'; import 'package:student/widgets/membersBar.Dart'; import 'package:student/widgets/inactivityDetector.Dart'; class Ac7 extends StatefulWidget { Ac7({Key key}) : super(key: key); @override _Ac7State createState() => _Ac7State(); } class _Ac7State extends State with SingleTickerProviderStateMixin { Timer timerCelluloPosition; Timer timerslopedetection; Timer timercleartracking; Timer timerprevCelluloPosition; final acID = 7; bool celluloxSwitch1 = true; bool celluloySwitch1 = false; bool celluloxSwitch2 = true; bool celluloySwitch2 = false; var onStop = false; bool mode = false; int wrongcounts = 0; double _progress = 0.0; final celluloSize = 60; final ScrollController _scrollController = ScrollController(); final functionFormulas = ['X ⟼ Y', 'X+1 ⟼ Y', 'X+2 ⟼ Y', '2*X ⟼ Y', '-X ⟼ Y']; Offset beginpath = Offset(0, 0); Offset endpath = Offset(10, 100); AnimationController controller; Animation animation; TextEditingController controllerinitialX = TextEditingController(); TextEditingController controllerinitialY = TextEditingController(); TextEditingController controllerXslope = TextEditingController(); TextEditingController controllerYslope = TextEditingController(); var counterfunctionImage = 0; var imagespath = [ 'assets/images/function1.svg', 'assets/images/function2.svg', 'assets/images/function3.svg', 'assets/images/Grid.svg', ]; var correctAnswer = [ 1, 3, 4, 1, ]; var onTap = [false, false, false, false, false]; // var onTap=[false,false,false,false,false]; final double mapSizeWidth = 860; final double mapSizeHeight = 860; var currentTurn = 1; var currentTap = 0; var tapCounter = 0; var progress = 0; bool waitforanimation = false; var mistakesSlope = 0; var mistakesIntrepet = 0; var inactivity = 0; var prevcelluloxPositionSlope = 0.0; var prevcelluloyPositionSlope = 0.0; // robot related bool setRun = false; var celluloxPosition = [0.0, 0.0]; var celluloyPosition = [0.0, 0.0]; List celluloxPositiontopaint = [0.0, 0.0]; List celluloyPositiontopaint = [0.0, 0.0]; var prevcelluloxPosition = [0.0, 0.0]; var prevcelluloyPosition = [0.0, 0.0]; var initialPositionCellulox = [0.0, 0.0]; var initialPositionCelluloy = [0.0, 0.0]; // screen-related var originCoordinates = [303.08, 563.08]; @override void initState() { super.initState(); group.numCurrentActivity = 7; cellulox.resetrobot(); celluloy.resetrobot(); timerCelluloPosition = new Timer.periodic(new Duration(milliseconds: 400), (time) { cellulox.getrobotx().then((val) => setState(() { celluloxPosition[0] = val; if (setRun == true) { celluloxPositiontopaint.add(val * 500 / 860); } })); cellulox.getroboty().then((val) => setState(() { celluloxPosition[1] = val; if (setRun == true) prevcelluloxPosition[1] = celluloxPosition[1]; })); celluloy.getrobotx().then((val) => setState(() { celluloyPosition[0] = val; if (setRun == true) prevcelluloyPosition[0] = celluloyPosition[0]; })); celluloy.getroboty().then((val) => setState(() { celluloyPosition[1] = val; if (setRun == true) celluloyPositiontopaint.add(val * 500 / 860); })); /* dbRef .child(group.id) .child("activity 8") .child("inactivity") .push() .set(inactivity); dbRef .child(group.id) .child("cellulox") .child("x") .push() .set(celluloxPosition); dbRef .child(group.id) .child("cellulox") .child("y") .push() .set(celluloxPosition); dbRef .child(group.id) .child("celluloy") .child("x") .push() .set(celluloyPosition); dbRef .child(group.id) .child("celluloy") .child("y") .push() .set(celluloyPosition); */ }); timerprevCelluloPosition = new Timer.periodic(new Duration(seconds: 40), (time) { setState(() { if (setRun == true) { prevcelluloxPosition[0] = celluloxPosition[0]; prevcelluloxPosition[1] = celluloxPosition[1]; prevcelluloyPosition[0] = celluloyPosition[0]; prevcelluloyPosition[1] = celluloyPosition[1]; } }); -/* - dbRef .child(group.id) .child("activity 8") .child("inactivity") .push() .set(inactivity); dbRef .child(group.id) .child("cellulox") .child("x") .push() .set(celluloxPosition); dbRef .child(group.id) .child("cellulox") .child("y") .push() .set(celluloxPosition); dbRef .child(group.id) .child("celluloy") .child("x") .push() .set(celluloyPosition); dbRef .child(group.id) .child("celluloy") .child("y") .push() .set(celluloyPosition); - */ }); // controller = AnimationController( // duration: Duration(milliseconds: 10000), vsync: this); /// /// Ask to be notified when messages related to the game /// are sent by the server /// } void slopeDtectionTimer() { timerslopedetection = new Timer.periodic(new Duration(seconds: 1), (time) { print("prev" + (((celluloxPosition[0] - prevcelluloxPositionSlope).roundToDouble() > 0) .toString())); // print("currwnt" + celluloxPosition[0].toString()); controllerXslope.text = 1.0.toString(); if ((celluloxPosition[0] - prevcelluloxPositionSlope).abs() < 10) { controllerYslope.text = "You sould move the RED robot faster"; } else { controllerYslope.text = (((prevcelluloyPositionSlope - celluloyPosition[1])) / (celluloxPosition[0] - prevcelluloxPositionSlope)) .roundToDouble() .toString(); } - //showAboutDialog(context,"elseYou sould move the RED robot faster","") - prevcelluloxPositionSlope = celluloxPosition[0]; prevcelluloyPositionSlope = celluloyPosition[1]; // print(int.parse(controllerXslope.text) > 0); print("cur" + (((celluloxPosition[0] - prevcelluloxPositionSlope).roundToDouble() > 0) .toString())); if ((celluloxPosition[0] - prevcelluloxPositionSlope).roundToDouble() > 1) { setState(() { celluloxSwitch2 = true; print(celluloxSwitch2); }); } if (((celluloxPosition[0] - prevcelluloxPositionSlope) / 100) .roundToDouble() < -1) { setState(() { celluloxSwitch2 = false; print(celluloxSwitch2); }); } if (celluloyPosition[1] - prevcelluloyPositionSlope > 0) { setState(() { celluloySwitch2 = true; print(celluloySwitch2); }); } if (celluloyPosition[1] - prevcelluloyPositionSlope < 1.0) { setState(() { celluloySwitch2 = false; print(celluloySwitch2); }); } }); } void clearTrackingTimer() { timercleartracking = new Timer.periodic(new Duration(seconds: 5), (time) { cellulox.resetrobot(); celluloy.resetrobot(); setState(() { setRun = true; }); timercleartracking.cancel(); }); } @override void dispose() { timer.cancel(); super.dispose(); } void nextPLayer() { setState(() { currentTurn = currentTurn + 1; // celluloyPositiontopaint = [0.0, 0.0]; // celluloxPositiontopaint = [0.0, 0.0]; }); } Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Activity 7: Semi-Mathematical Control'), ), backgroundColor: Colors.white, body: SingleChildScrollView( child: Column(children: [ Card( child: ListTile( title: Text( 'Choose the two points that your robots start from there and also how much the blue robot should move. '), ), ), Container( margin: const EdgeInsets.all(15.0), padding: const EdgeInsets.all(3.0), decoration: BoxDecoration( border: Border.all(color: Colors.blueAccent), borderRadius: new BorderRadius.circular(25.0), ), - height: 150.0, + height: 200.0, child: Column(children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Container( width: 250, child: new TextFormField( controller: controllerinitialX, decoration: new InputDecoration( labelText: "RED starts at this position:", fillColor: Colors.red, border: new OutlineInputBorder( borderRadius: new BorderRadius.circular(25.0), borderSide: new BorderSide(), ), //fillColor: Colors.green ), validator: (val) { if (val.length == 0) { return "Email cannot be empty"; } else { return null; } }, keyboardType: TextInputType.text, style: new TextStyle( fontFamily: "Poppins", ), ), ), Container( width: 250, child: new TextFormField( controller: controllerinitialY, decoration: new InputDecoration( labelText: "BLUE starts at this position:", fillColor: Colors.blue, border: new OutlineInputBorder( borderRadius: new BorderRadius.circular(25.0), borderSide: new BorderSide(), ), //fillColor: Colors.green ), validator: (val) { if (val.length == 0) { return "Email cannot be empty"; } else { return null; } }, keyboardType: TextInputType.text, style: new TextStyle( fontFamily: "Poppins", ), ), ), - FloatingActionButton( - onPressed: () => { - slopeDtectionTimer(), - clearTrackingTimer(), - cellulox.setGoalPosition( - originCoordinates[0] + - 100 * int.parse(controllerinitialX.text), - celluloxPosition[1]), - celluloy.setGoalPosition( - celluloyPosition[0], - originCoordinates[1] - - 100 * int.parse(controllerinitialY.text)), - }, - child: Icon(Icons.play_circle_outline), - ), ]), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 300, child: new TextFormField( enabled: false, // controller: controllerXslope, decoration: new InputDecoration( labelText: "When RED moves by 1", fillColor: Colors.red, border: new OutlineInputBorder( borderRadius: new BorderRadius.circular(25.0), borderSide: new BorderSide(), ), //fillColor: Colors.green ), validator: (val) { if (val.length == 0) { return "Email cannot be empty"; } else { return null; } }, keyboardType: TextInputType.text, style: new TextStyle( fontFamily: "Poppins", ), ), ), Column(children: [ Container( child: Switch( value: celluloxSwitch1, onChanged: (value) { setState(() { // celluloxSwitch1 = value; }); }, activeTrackColor: Colors.lightGreenAccent, activeColor: Colors.green, inactiveTrackColor: Colors.lightGreenAccent, inactiveThumbColor: Colors.green, )), Text(celluloxSwitch1 ? 'Right' : 'Left') ]), SizedBox(width: 20), Container( width: 300, child: new TextFormField( decoration: new InputDecoration( labelText: "Then Blue should move by:", fillColor: Colors.blue, border: new OutlineInputBorder( borderRadius: new BorderRadius.circular(25.0), borderSide: new BorderSide(), ), //fillColor: Colors.green ), validator: (val) { if (val.length == 0) { return "Email cannot be empty"; } else { return null; } }, keyboardType: TextInputType.text, style: new TextStyle( fontFamily: "Poppins", ), )), Column(children: [ RotatedBox( quarterTurns: 1, child: Switch( value: celluloySwitch1, onChanged: (value) { setState(() { celluloySwitch1 = value; }); }, activeTrackColor: Colors.lightGreenAccent, activeColor: Colors.green, inactiveTrackColor: Colors.lightGreenAccent, inactiveThumbColor: Colors.green, )), Text(celluloySwitch1 ? 'Down' : 'Up') ]), ]), + FloatingActionButton( + onPressed: () => { + cellulox.setGoalPosition( + originCoordinates[0] + + 100 * int.parse(controllerinitialX.text), + celluloxPosition[1]), + celluloy.setGoalPosition( + celluloyPosition[0], + originCoordinates[1] - + 100 * int.parse(controllerinitialY.text)), + }, + child: Icon(Icons.play_circle_outline), + ), ])), SizedBox( height: 5, ), celluloMap(context), SizedBox( - height: 10, + height: 15, ), MembersBar(), ]))); } Widget celluloMap(BuildContext context) { final double mapSizeScreenWidth = 500; final double mapSizeScreenHeight = 500; final double scaleWidth = mapSizeScreenWidth / mapSizeWidth; final double scaleHeight = mapSizeScreenHeight / mapSizeHeight; return Container( height: mapSizeScreenWidth, width: mapSizeScreenHeight, decoration: BoxDecoration(border: Border.all(color: Colors.blueAccent)), child: Stack(children: [ Container( height: mapSizeScreenWidth, width: mapSizeScreenHeight, child: SvgPicture.asset(imagespath[currentTurn - 1])), Container( height: mapSizeScreenWidth, width: mapSizeScreenHeight, child: SvgPicture.asset("assets/images/GridOnlyPositive.svg")), Align( alignment: Alignment( 2 * (celluloxPosition[0] * scaleWidth / mapSizeScreenWidth) - 1, 1), child: Card( child: SvgPicture.asset("assets/images/cellulox.svg", height: 60, width: 60), ), ), Align( alignment: Alignment( -1, 2 * (celluloyPosition[1] * scaleHeight / mapSizeScreenHeight) - 1), child: Card( child: SvgPicture.asset("assets/images/celluloy.svg", height: 60, width: 60), ), ), CustomPaint( size: Size(mapSizeScreenWidth, mapSizeScreenHeight), painter: LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), ), ])); } } diff --git a/student/lib/Database.dart b/student/lib/Database.dart index 7b6c4e9..c948c52 100644 --- a/student/lib/Database.dart +++ b/student/lib/Database.dart @@ -1,3 +1,3 @@ import 'package:firebase_database/firebase_database.dart'; -final dbRef = FirebaseDatabase.instance.reference().child("Groups"); +final dbRef = FirebaseDatabase.instance.reference(); diff --git a/student/lib/loginpage_names.dart b/student/lib/loginpage_names.dart index 5e56dd1..4b9adc5 100644 --- a/student/lib/loginpage_names.dart +++ b/student/lib/loginpage_names.dart @@ -1,145 +1,155 @@ import 'package:flutter/material.dart'; import 'package:student/loginpage_robots.dart'; import 'package:student/SoCKet.dart'; import 'dart:convert'; import 'package:student/Data/data.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:student/Database.dart'; import 'package:student/model/Group.dart'; +import 'package:student/Database.dart'; class LoginPage extends StatefulWidget { LoginPage({Key key, this.websocket}) : super(key: key); final SoCKet websocket; @override _LoginPageState createState() => _LoginPageState(); } class _LoginPageState extends State { TextEditingController controller1 = TextEditingController(); TextEditingController controller2 = TextEditingController(); TextEditingController controller3 = TextEditingController(); TextEditingController controller4 = TextEditingController(); final teamname = "1"; @override void initState() { super.initState(); - - } - @override + @override void dispose() { super.dispose(); } + void setupDatabase() { + dbRef.child("groups").child("bb").child("inactivity").remove(); + } + + void cleanDatabase() { + dbRef.child("groups").child("bb").child("inactivity").remove(); + } + Widget nextButton() { return InkWell( onTap: () { print(controller4.text); group.member1name = controller1.text; group.member2name = controller2.text; group.member3name = controller3.text; group.id = controller4.text; dbRef.child(controller4.text).set(group.toJson()); Navigator.push(context, MaterialPageRoute(builder: (context) => RobotsLoginPage())); }, child: Container( width: MediaQuery.of(context).size.width, padding: EdgeInsets.symmetric(vertical: 13), alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(5)), boxShadow: [ BoxShadow( color: Color(0xffdf8e33).withAlpha(100), offset: Offset(2, 4), blurRadius: 8, spreadRadius: 2) ], color: Colors.white), child: Text( 'Lets go', style: TextStyle(fontSize: 20, color: Color(0xfff7892b)), ), ), ); } Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Login'), ), backgroundColor: Colors.white, body: SingleChildScrollView( child: Padding( padding: EdgeInsets.all(30.0), child: Column(children: [ Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border( bottom: BorderSide(color: Colors.grey[100]))), child: TextField( controller: controller1, decoration: InputDecoration( border: InputBorder.none, hintText: "Member 1: Enter your name", hintStyle: TextStyle(color: Colors.grey[400])), ), ), SizedBox( height: 100, ), Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border( bottom: BorderSide(color: Colors.grey[100]))), child: TextField( controller: controller2, decoration: InputDecoration( border: InputBorder.none, hintText: "Member 2: Enter your name", hintStyle: TextStyle(color: Colors.grey[400])), ), ), SizedBox( height: 100, ), Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border( bottom: BorderSide(color: Colors.grey[100]))), child: TextField( controller: controller3, decoration: InputDecoration( border: InputBorder.none, hintText: "Member 3: Enter your name", hintStyle: TextStyle(color: Colors.grey[400])), ), ), SizedBox( height: 100, ), Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( border: Border( bottom: BorderSide(color: Colors.grey[100]))), child: TextField( controller: controller4, decoration: InputDecoration( border: InputBorder.none, hintText: "Enter your group name", hintStyle: TextStyle(color: Colors.grey[400])), ), ), + SizedBox( + height: 50, + ), nextButton() ])))); } }