Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F87095063
Class.dart
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Oct 10, 14:04
Size
8 KB
Mime Type
text/x-c++
Expires
Sat, Oct 12, 14:04 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21535692
Attached To
R10646 Orchestration
Class.dart
View Options
import 'package:firebase_database/firebase_database.dart';
import 'package:Teacher_Dashboard/model/Group.dart';
import 'package:flutter/widgets.dart';
import 'package:Teacher_Dashboard/model/Group.dart';
import 'package:Teacher_Dashboard/model/activities/activity.Dart';
import 'dart:async';
import 'dart:convert';
Classroom thisClass = new Classroom("1");
class Classroom extends ChangeNotifier {
int inactivity;
String sessionID = 'SPIA';
String teacherName;
int numGroups = 0;
List<Group> groups = new List();
List<String> groupIDs = new List();
Classroom(this.sessionID);
final FirebaseDatabase _database = FirebaseDatabase.instance;
StreamSubscription<Event> _ongroupAddedSubscription;
StreamSubscription<Event> _ongroupChangedSubscription;
StreamSubscription<Event> _onattemptAddedSubscription;
StreamSubscription<Event> _oninactivityAddedSubscription;
StreamSubscription<Event> _onrobotpositionAddedSubscription;
void toAggregate() {}
void desetupDatabse() {
_ongroupAddedSubscription.cancel();
_ongroupChangedSubscription.cancel();
_onattemptAddedSubscription.cancel();
}
void setupDatabse() {
_ongroupAddedSubscription = _database
.reference()
.child(thisClass.sessionID)
.child("groups")
.onChildAdded
.listen(onGroupAdded);
_ongroupChangedSubscription = _database
.reference()
.child(thisClass.sessionID)
.child("groups")
.onChildChanged
.listen(onGroupChanged);
_onattemptAddedSubscription = _database
.reference()
.child(thisClass.sessionID)
.child("attempts")
.onChildAdded
.listen(onAttemptAdded);
_oninactivityAddedSubscription = _database
.reference()
.child(thisClass.sessionID)
.child("celluloPosition")
.onChildAdded
.listen(oncelluloPositionAdded);
//Query _todoQuery;
}
onGroupAdded(Event event) {
Group newgroup = new Group(event.snapshot.value['id']);
newgroup.member1name = event.snapshot.value['member1name'];
newgroup.member2name = event.snapshot.value['member2name'];
newgroup.member3name = event.snapshot.value['member3name'];
thisClass.groups.add(newgroup);
thisClass.groupIDs.add(event.snapshot.value['id']);
notifyListeners();
}
onGroupChanged(Event event) {
//thisClass.groups.add(Group.fromSnapshot(event.snapshot));
int currentGroup = thisClass.groupIDs.indexOf(event.snapshot.key);
// print("group" + currentGroup.toString().toString());
thisClass.groups[currentGroup].currentActivity =
(event.snapshot.value)['currentActivity'].toString();
thisClass.groups[currentGroup].tabletStatus =
(event.snapshot.value)['tabletStatus'].toString();
// setState(() {});
notifyListeners();
//print(thisClass.groups[currentGroup].currentActivity.toString());
}
onAttemptAdded(Event event) {
// print(jsonDecode(event.snapshot.value)['acID'].toString());
int currentGroup =
thisClass.groupIDs.indexOf(jsonDecode(event.snapshot.value)['groupID']);
int currentActivity =
acList.indexOf(jsonDecode(event.snapshot.value)['acID'].toString());
thisClass.groups[currentGroup].currentActivity = acList[currentActivity];
int currentTurn = (jsonDecode(event.snapshot.value)['currentTurn']);
thisClass
.groups[currentGroup]
.activities[currentActivity]
.turns[currentTurn - 1]
.numAttempts = jsonDecode(event.snapshot.value)['numAttempts'];
thisClass.groups[currentGroup].activities[currentActivity].elapsedTime =
jsonDecode(event.snapshot.value)['elpasedTime'];
thisClass
.groups[currentGroup]
.activities[currentActivity]
.turns[currentTurn - 1]
.elapsedTime = jsonDecode(event.snapshot.value)['elpasedTime'];
//print(jsonDecode(event.snapshot.value)['elpasedTime']);
var progressmsg = jsonDecode((event.snapshot.value))['progress'];
thisClass.groups[currentGroup].activities[currentActivity].progress[0] =
progressmsg['turn1'];
thisClass.groups[currentGroup].activities[currentActivity].progress[1] =
progressmsg['turn2'];
thisClass.groups[currentGroup].activities[currentActivity].progress[2] =
progressmsg['turn3'];
var mistakemsg = jsonDecode(event.snapshot.value)['mistakes'];
var mistakemsgturn1 = (mistakemsg['turn1']);
var mistakemsgturn2 = (mistakemsg['turn2']);
var mistakemsgturn3 = (mistakemsg['turn3']);
thisClass.groups[currentGroup].activities[currentActivity].mistakes['slope']
[0] = mistakemsgturn1['slope'];
thisClass.groups[currentGroup].activities[currentActivity]
.mistakes['initialPoint'][0] = mistakemsgturn1['initialPoint'];
thisClass.groups[currentGroup].activities[currentActivity].mistakes['slope']
[1] = mistakemsgturn2['slope'];
thisClass.groups[currentGroup].activities[currentActivity]
.mistakes['initialPoint'][1] = mistakemsgturn2['initialPoint'];
thisClass.groups[currentGroup].activities[currentActivity].mistakes['slope']
[2] = mistakemsgturn3['slope'];
thisClass.groups[currentGroup].activities[currentActivity]
.mistakes['initialPoint'][2] = mistakemsgturn3['initialPoint'];
thisClass.groups[currentGroup].activities[currentActivity].turns[0]
.mistakes['slope'] = mistakemsgturn1['slope'];
thisClass.groups[currentGroup].activities[currentActivity].turns[0]
.mistakes['initialPoint'] = mistakemsgturn1['initialPoint'];
thisClass.groups[currentGroup].activities[currentActivity].turns[0]
.mistakes['intercept'] = mistakemsgturn1['intercept'];
thisClass.groups[currentGroup].activities[currentActivity].turns[1]
.mistakes['slope'] = mistakemsgturn2['slope'];
thisClass.groups[currentGroup].activities[currentActivity].turns[1]
.mistakes['initialPoint'] = mistakemsgturn2['initialPoint'];
thisClass.groups[currentGroup].activities[currentActivity].turns[1]
.mistakes['intercept'] = mistakemsgturn2['intercept'];
thisClass.groups[currentGroup].activities[currentActivity].turns[2]
.mistakes['slope'] = mistakemsgturn3['slope'];
thisClass.groups[currentGroup].activities[currentActivity].turns[2]
.mistakes['initialPoint'] = mistakemsgturn3['initialPoint'];
thisClass.groups[currentGroup].activities[currentActivity].turns[2]
.mistakes['intercept'] = mistakemsgturn3['intercept'];
notifyListeners();
}
onInactivityAdded(Event event) {
// print(jsonDecode(event.snapshot.value)['acID'].toString());
// int currentGroup =
// thisClass.groupIDs.indexOf(jsonDecode(event.snapshot.value)['groupID']);
// int currentActivity =
// acList.indexOf(jsonDecode(event.snapshot.value)['acID'].toString());
//thisClass.groups[currentGroup].inactivity[currentstepActivation] =
// (jsonDecode(event.snapshot.value)['inactivity']);
//print(thisClass.groups[currentGroup].inactivity);
//currentstepActivation = currentstepActivation + 1;
notifyListeners();
}
oncelluloPositionAdded(Event event) {
int currentGroup =
thisClass.groupIDs.indexOf(jsonDecode(event.snapshot.value)['groupID']);
int currentActivity =
acList.indexOf(jsonDecode(event.snapshot.value)['acID'].toString());
int currentTurn = 0;
// print(currentGroup.toString());
if (jsonDecode(event.snapshot.value)['turn'].toString() == '1')
currentTurn = 1;
if (jsonDecode(event.snapshot.value)['turn'].toString() == '2')
currentTurn = 2;
if (jsonDecode(event.snapshot.value)['turn'].toString() == '3')
currentTurn = 3;
// print(currentTurn);
// int currentActivity =
// acList.indexOf(jsonDecode(event.snapshot.value)['acID'].toString());
// print((jsonDecode(event.snapshot.value)['x']));
thisClass.groups[currentGroup].activities[currentActivity]
.turns[currentTurn - 1].cellulox.x
.add((jsonDecode(event.snapshot.value)['x'] * 90 / 860));
// print((jsonDecode(event.snapshot.value)['y']));
thisClass.groups[currentGroup].activities[currentActivity]
.turns[currentTurn - 1].celluloy.y
.add((jsonDecode(event.snapshot.value)['y'] * 90 / 860));
// thisClass.groups[currentGroup].celluloy.y
// .add((jsonDecode(event.snapshot.value)['y'] / 40))
// setState(() {});
notifyListeners();
}
}
Event Timeline
Log In to Comment