-
Notifications
You must be signed in to change notification settings - Fork 23
/
UserStatus.h
48 lines (39 loc) · 2 KB
/
UserStatus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include <G3D/G3D.h>
#include <fstream>
/** Class for handling user status */
class UserSessionStatus {
public:
String id = "anon"; ///< User ID
Array<String> sessionOrder; ///< Array containing session ordering
Array<String> completedSessions; ///< Array containing all completed session ids for this user (loaded from log)
static Array<String> defaultSessionOrder; ///< Default session order
static bool randomizeDefaults; ///< Randomize default session order when applying to individual?
UserSessionStatus() {}
UserSessionStatus(const Any& any);
Any toAny(const bool forceAll = true) const;
};
/** Class for representing user status tables */
class UserStatusTable {
public:
bool allowRepeat = false; ///< Flag for whether to (strictly) sequence these experiments (allow duplicates)
bool randomizeDefaults = false; ///< Randomize from default session order when applying to user
String currentUser; ///< Currently selected user
Array<String> defaultSessionOrder = {}; ///< Default session ordering (for all unspecified users)
Array<UserSessionStatus> userInfo = {}; ///< Array of user status
Table<String, Array<String>> completed;
String completedLogFilename; ///< File containing completed sessions
std::ofstream completedLog;
UserStatusTable() {}
UserStatusTable(const Any& any);
static UserStatusTable load(const String& filename, bool saveJSON);
Any toAny(const bool forceAll = false) const;
inline void save(const String& filename, bool json) {
toAny().save(filename, json);
};
shared_ptr<UserSessionStatus> getUserStatus(const String& id); // Get a given user's status from the table by ID
String getNextSession(String userId = ""); // Get the next session ID for a given user (by ID)
void addCompletedSession(const String& userId, const String& sessId); // Add a completed session to a given user's completedSessions array
void validate(const Array<String>& sessions, const Array<String>& users);
void printToLog() const;
};