public class Module extends java.lang.Object implements java.lang.Comparable<Module>
Manages a module's data and state, generates exercises and has several I/O methods for reading and writing Module objects.
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.String> |
answerList
List of the answers for this Module's exercises
|
private java.lang.String |
description
The description of this Module's contents or purpose
|
static int |
DIFF_AMATEUR
Constants referring to the difficulty of a Module
|
static int |
DIFF_BEGINNER
Constants referring to the difficulty of a Module
|
static int |
DIFF_EXPERT
Constants referring to the difficulty of a Module
|
static int |
DIFF_INTERMEDIATE
Constants referring to the difficulty of a Module
|
private int |
difficulty
The difficulty of this Module
|
private java.util.List<Exercise> |
exerciseList
List of this Module's Exercises
|
private int |
highestNote
The lowest and highest notes this Module is allowed to use in its exercises (lowestNote, highestNote)
In these variable, 0 refers to C2 and 41 to E5
|
private int |
id
The unique ID of this Module
|
private int |
lowestNote
The lowest and highest notes this Module is allowed to use in its exercises (lowestNote, highestNote)
In these variable, 0 refers to C2 and 41 to E5
|
private Context |
mCtx |
private int |
moduleVersion
Module version number
|
private java.lang.String |
shortDescription
A short description on the Module contents
|
private ModuleStats |
stats
Reference to this Module's statistics
|
private java.lang.String |
title
The title of this Module
|
private java.lang.String |
toolVersion
The version of create_module.py used to create this Module
|
Constructor and Description |
---|
Module(Context context)
Contructs an empty (and useless) Module
|
Module(Context context,
java.io.File moduleFile)
Constructs a Module by reading a JSON from the given filename
|
Module(Context context,
java.io.InputStreamReader reader)
Constructs a Module by reading a JSON from the given InputStreamReader
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Module another)
Comparable implementation, sorts first on difficulty, then on title.
|
java.util.List<java.lang.String> |
getAnswerList() |
java.lang.String |
getDescription() |
int |
getDifficulty() |
Exercise |
getExercise(int exerciseIndex)
Generates an Exercise that can be used by
MediaFragment to generate
a WAV sample. |
int |
getExercisesCompleted() |
int |
getId() |
private int |
getLinearRandomNumber(int limit)
Generate a random number between [0 - limit>, with a linearly descending distribution from 0 to limit.
|
(package private) int |
getModuleVersion() |
java.lang.String |
getShortDescription() |
int |
getSuccessRate() |
java.lang.String |
getTitle() |
(package private) java.lang.String |
getToolVersion()
Returns the version number of the create_module.py tool that was used to create this module
|
int |
getWeightedExerciseIndex()
Returns an index to one of this Module's exercises that is random but weighted towards certain properties.
|
private void |
initModuleFromJson(java.io.Reader r)
Loads this Module's properties and data from the JSON data of the given Reader
|
boolean |
purgeModule()
Remove this Module and its associated ModuleStats file from local storage
|
void |
refreshState()
Reload this Module's statistics
|
void |
registerAnswer(int exerciseIndex,
boolean result)
Register an answer with the ModuleStats instance
|
void |
resetStats()
Reset the statistics for this Module
|
void |
saveState()
Save a Module's statistics
|
void |
setDifficulty(int difficulty)
Set the Module difficulty
|
void |
setId(int id)
Set the Module unique ID
|
void |
setModuleVersion(int moduleVersion) |
void |
setShortDescription(java.lang.String shortDescription) |
void |
setTitle(java.lang.String title)
Set the Module title
|
boolean |
writeModuleToJson()
Attempts to write this Module to the device's local storage.
|
public static final int DIFF_BEGINNER
public static final int DIFF_AMATEUR
public static final int DIFF_INTERMEDIATE
public static final int DIFF_EXPERT
private final Context mCtx
private int id
private java.lang.String title
private java.lang.String description
private int lowestNote
private int highestNote
private int difficulty
private ModuleStats stats
private java.lang.String toolVersion
private int moduleVersion
Not currently used for anything, planned use is for Module updates.
private java.lang.String shortDescription
Used in ListViews to give the user an indication of a Module's contents beyond the title
private java.util.List<java.lang.String> answerList
private final java.util.List<Exercise> exerciseList
public Module(Context context)
Used when a fully initialised Module object is not required (e.g. ListViews)
context
- public Module(Context context, java.io.File moduleFile)
context
- The application contextmoduleFile
- The File from which to read the JSON datapublic Module(Context context, java.io.InputStreamReader reader)
context
- The application contextreader
- The Reader from which to read the JSON datapublic void saveState()
ModuleStats.saveModuleStats()
public void refreshState()
private void initModuleFromJson(java.io.Reader r) throws java.io.IOException
r
- The Reader from which to read the JSON datajava.io.IOException
private int getLinearRandomNumber(int limit)
Example distribution of 10000 calls with limit == 5: Occurrences of 0: 3322 Occurrences of 1: 2630 Occurrences of 2: 2016 Occurrences of 3: 1371 Occurrences of 4: 661
limit
- the upper limit of return values.public int getWeightedExerciseIndex()
Specifically, it sorts all available exercises first on success rate and then on how often they were attempted.
It then uses getLinearRandomNumber(int)
to pick one, thus preferring items higher on the list.
public java.lang.String getTitle()
public java.lang.String getDescription()
public int getDifficulty()
public java.util.List<java.lang.String> getAnswerList()
public Exercise getExercise(int exerciseIndex)
MediaFragment
to generate
a WAV sample.
The Exercise objects in exerciseList
are an abstract representation of a sequence of notes/chords.
This function maps the Exercise at the given index to a random point between lowestNote
and highestNote
.
The result can be used by MediaFragment
to generate a WAV sample.
exerciseIndex
- The index of the Exercise to generate.public void registerAnswer(int exerciseIndex, boolean result)
exerciseIndex
- Index of the Exercise we are registering an answer forresult
- The correctness of the answerpublic int getSuccessRate()
ModuleStats.calculateSuccessRate()
public int getId()
public void setId(int id)
id
- The ID to setpublic void setTitle(java.lang.String title)
title
- The title to setpublic void setDifficulty(int difficulty)
difficulty
- The difficulty to setpublic boolean writeModuleToJson()
Write this Module to disk as a JSON file, does not save the value of ModuleStats
public boolean purgeModule()
public void resetStats()
public int compareTo(Module another)
compareTo
in interface java.lang.Comparable<Module>
Comparable
java.lang.String getToolVersion()
public int getExercisesCompleted()
ModuleStats.exercisesCompleted()
public java.lang.String getShortDescription()
public void setShortDescription(java.lang.String shortDescription)
int getModuleVersion()
public void setModuleVersion(int moduleVersion)