public class ModuleStats
extends java.lang.Object
Provides methods for entering answers and obtaining useful information about this data and for reading and writing recorded statistical data to local storage.
Modifier and Type | Field and Description |
---|---|
private java.util.List<ModuleAnswer> |
moduleAnswerList
All the recorded answers
|
private java.io.File |
statsFile
Reference to local storage
|
Constructor and Description |
---|
ModuleStats(Context context,
int id)
Construct an instance to be associated with the given Module
Module.id , attempts to load from local storage if the file
exists, otherwise creates an fresh instance. |
Modifier and Type | Method and Description |
---|---|
void |
addAnswer(int exerciseIndex,
boolean result)
Add an answer to
moduleAnswerList |
int |
calculateSuccessRate()
Calculates the success rate of the registered answers.
|
int |
exerciseCount(int exerciseIndex)
Returns the number of times exerciseIndex is registered.
|
int |
exercisesCompleted()
Returns the total amount of exercises completed
|
int |
exerciseSuccessRate(int exerciseIndex)
Returns the success rate in % of a particular exerciseIndex, returns 0 if no exercises were found
|
private void |
initModuleStatsFromJson(java.io.FileReader fr)
Reads an existing ModuleStats instance from a JSON file
|
boolean |
purgeStats()
Delete all statistical data for this instance.
|
void |
saveModuleStats()
Save this instance to local storage, if the file doesn't exist, creates it, otherwise overwrites existing data.
|
private void |
saveModuleStatsToJson(java.io.FileWriter fw)
Save moduleAnswerList to the given FileWriter as a JSON stream
|
private java.util.List<ModuleAnswer> moduleAnswerList
private final java.io.File statsFile
public ModuleStats(Context context, int id)
Module.id
, attempts to load from local storage if the file
exists, otherwise creates an fresh instance.context
- The application context, used for file operationsid
- the ID of the Module this instance will be associated withprivate void initModuleStatsFromJson(java.io.FileReader fr) throws java.io.IOException
fr
- The FileReader to read fromjava.io.IOException
private void saveModuleStatsToJson(java.io.FileWriter fw) throws java.io.IOException
fw
- The FileWriter to save tojava.io.IOException
public void saveModuleStats()
public void addAnswer(int exerciseIndex, boolean result)
moduleAnswerList
exerciseIndex
- The index of the exercise the answer refers toresult
- The correctness of the answerpublic int calculateSuccessRate()
public int exercisesCompleted()
An exercise is completed when the user gave the correct answer, even if there were wrong answers before that. Since one moves on to the next exercise after giving a correct answer, the number of exercises completed is the same as the number of correct answers given.
public int exerciseSuccessRate(int exerciseIndex)
exerciseIndex
- the individual exercise whose success rate to returnpublic int exerciseCount(int exerciseIndex)
exerciseIndex
- moduleAnswerList
public boolean purgeStats()