@@ -11,6 +11,14 @@ var assert = require('assert');
1111
1212var MIN_TIME_TASK_DAY = 450 ; // minimum of 7.5 minutes for one task on a day (except if expected time is <7.5 min)
1313
14+ /**
15+ * @class HomeworkDescription
16+ * @constructor
17+ * @param {any } subject Must be primitive, unique and fixed
18+ * @param {int[][] } locations
19+ * @param {Date } duedate
20+ * @param {any } id
21+ */
1422HomeworkDescription = function ( ) {
1523 if ( ! ( this instanceof HomeworkDescription ) ) {
1624 return new ( Function . prototype . bind . apply (
@@ -19,38 +27,76 @@ HomeworkDescription=function(){
1927 ) ) ;
2028 }
2129
22- //A unique identifier for a subject. Can be pretty much anything, lest it's a primitive type
23- // and unique and fixed, i.e. there is only one identifier per subject and only one subject per identifier.
30+ /**
31+ * A unique identifier for a subject. Can be pretty much anything, lest it's
32+ * a primitive type and unique and fixed, i.e. there is only one identifier
33+ * per subject and only one subject per identifier.
34+ *
35+ * @property subject
36+ * @type any
37+ */
2438 this . subject = arguments . length > 0 ?arguments [ 0 ] :null ;
2539
26- //Items in `location` can be multiple things, e.g.
27- //- [chapter,paragraph,exercise]
28- //- [bookid,page,exercise]
29- //- [chapter,exercise]
30- //- [bookid,page]
31- //In general, anything that can be expressed in a sequence of integers that specifies the location.
32- // (Actually, they should be index paths — think NSIndexPath)
33- //The `location` property contains an array of those, because homework can be multiple exercises, for example.
34- //Per subject, please use just one index convention. If you need to, add ones where you don't have entries.
40+ /**
41+ * Items in `location` can be multiple things, e.g.
42+ * - [chapter,paragraph,exercise]
43+ * - [bookid,page,exercise]
44+ * - [chapter,exercise]
45+ * - [bookid,page]
46+ *
47+ * In general, anything that can be expressed in a sequence of integers that
48+ * specifies the location. (Actually, they should be index paths — think
49+ * NSIndexPath) The `location` property contains an array of those, because
50+ * homework can be multiple exercises, for example. Per subject, please use
51+ * just one index convention. If you need to, add ones where you don't have
52+ * entries.
53+ *
54+ * @property location
55+ * @type int[][]
56+ */
3557 this . location = arguments . length > 1 ?arguments [ 1 ] :[ ] ;
3658
37- //A Date indicating when this homework is due
59+ /**
60+ * A Date indicating when this homework is due
61+ * @prototype duedate
62+ * @type Date
63+ */
3864 this . duedate = arguments . length > 2 ?arguments [ 2 ] :null ;
3965
40- //Some id that the outside world can decide on
66+ /**
67+ * Some id that the outside world can decide on
68+ * @property id
69+ * @type any
70+ */
4171 this . id = arguments . length > 3 ?arguments [ 3 ] :null ;
4272} ;
4373
74+ /**
75+ * @class Planner
76+ * @constructor
77+ * @param {Object } [persisted] Result from `Planner::persistable`.
78+ */
4479Planner = function ( ) {
4580 if ( ! ( this instanceof Planner ) ) return new Planner ( arguments [ 0 ] ) ;
4681
82+ /**
83+ * @property isPlannerObject
84+ * @type Boolean
85+ * @final
86+ * @default true
87+ */
4788 this . isPlannerObject = true ;
4889
4990 //PREV: Object[subject id][location index path item][value of the loc. idxp. item][samples of time taken]
5091 //Object[subject id][loc item 0][loc item 1]...[loc item n] = time taken for that index path
5192 var subjects = { } ; //The Cache
5293
53- //`timetaken` in any unit you find convenient; but please be consistent. Suggestion: seconds.
94+ /**
95+ * Learn.
96+ * @method learn
97+ * @param {HomeworkDescription } hwdesc The `HomeworkDescription` that was done.
98+ * @param {Number } timetaken Number in time unit that specifies how long the given description took.
99+ */
54100 this . learn = function ( hwdesc , timetaken ) {
55101 var i , j , idx , subj , loc ;
56102 assert ( hwdesc instanceof HomeworkDescription ) ;
@@ -74,12 +120,26 @@ Planner=function(){
74120 }
75121 } ;
76122
123+ /**
124+ * @method generalSubjectEstimate
125+ * @param {any } subjid
126+ * @param {Function } gradeFn
127+ * @return {Number }
128+ */
77129 this . generalSubjectEstimate = function ( subjid , gradeFn ) {
78130 var grade = gradeFn ( subjid ) ;
79131 return 3600 * 3 / 2 - 3600 * grade / 10 ;
80132 } ;
81133
82- this . estimateSingle = function ( hwdesc , gradeFn ) {
134+ /**
135+ * Guesses the time needed for the given `hwdesc` with a single location.
136+ * @private
137+ * @method _estimateSingle
138+ * @param {HomeworkDescription } hwdesc
139+ * @param {Function } gradeFn
140+ * @return {Number }
141+ */
142+ this . _estimateSingle = function ( hwdesc , gradeFn ) {
83143 assert ( hwdesc instanceof HomeworkDescription ) ;
84144 assert ( hwdesc . location . length == 1 ) ;
85145 if ( ! subjects [ hwdesc . subject ] ) {
@@ -98,33 +158,59 @@ Planner=function(){
98158 return rms ( timearr ) ;
99159 } ;
100160
161+ /**
162+ * Guesses the time needed for the given `hwdesc`.
163+ * @method estimate
164+ * @param {HomeworkDescription } hwdesc
165+ * @param {Function } gradeFn
166+ * @return {Number }
167+ */
101168 this . estimate = function ( hwdesc , gradeFn ) {
102169 var subj , loc ;
103170 assert ( hwdesc instanceof HomeworkDescription ) ;
104171 return sum ( hwdesc . location . map ( function ( loc ) {
105- return this . estimateSingle ( HomeworkDescription ( hwdesc . subject , [ loc ] ) , gradeFn ) ;
172+ return this . _estimateSingle ( HomeworkDescription ( hwdesc . subject , [ loc ] ) , gradeFn ) ;
106173 } . bind ( this ) ) ) ;
107174 } ;
108175
176+ /**
177+ * Converts the current Planner to a persistable object.
178+ * @method persistable
179+ * @return {Object }
180+ */
109181 this . persistable = function ( ) {
110182 return Object . clone ( subjects , true ) ;
111183 } ;
184+
185+ /**
186+ * Loads in an object created by `Planner::persistable`.
187+ * @method frompersistable
188+ * @param {Object } subj The object created by `Planner:persistable` to load.
189+ */
112190 this . frompersistable = function ( subj ) {
113191 if ( subj . isPlannerObject === true ) //they persisted the whole object ._.
114192 subjects = subj . persistable ( ) ;
115193 else subjects = Object . clone ( subj , true ) ;
116194 } ;
117195
196+ /**
197+ * @method availableTimeConvert
198+ * @param {Number } code
199+ * @return Number
200+ */
118201 this . availableTimeConvert = function ( code ) {
119202 // return [0,30*60,90*60,180*60][code];
120203 return ( 15 * code * code + 15 * code ) * 60 ;
121204 } ;
122205
123- //`items` is an Array of HomeworkDescriptions
124- //`availableFn` is a Function(Date) returning int, specifying the code for how much time (in the
125- // time unit) there is available on the given day
126- //`today` is a Date which the planner uses as "today"; will be rounded to start of day
127- //`gradeFn` is a Function(String) taking a subject identifier and returning the average grade of the student for that subject
206+ /**
207+ * @method plan
208+ * @param {HomeworkDescription[] } items
209+ * @param {Function(Date) Number } availableFn Specifies the code for how much time (in time unit) there is available for the given day.
210+ * @param {Date } today The date which the planner uses as "today"; will be rounded to start of day.
211+ * @param {Function(String) Number } gradeFn Gets a subject identifier and must return the average grade of the student for that subject.
212+ * @return {Object } The schedule.
213+ */
128214 this . plan = function ( items , availableFn , today , gradeFn ) {
129215 today = startOfDay ( today ) ;
130216 var availableCache = [ ] ;
0 commit comments