bunkmate 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +282 -0
  2. package/index.js +69 -0
  3. package/package.json +27 -0
package/README.md ADDED
@@ -0,0 +1,282 @@
1
+ # BunkMate
2
+
3
+ Attendance calculation utilities for students.
4
+
5
+ `BunkMate` provides simple utility functions for calculating current attendance, predicting attendance after planned absences, and determining the number of recovery classes required to reach a target attendance percentage.
6
+
7
+ ## Features
8
+
9
+ - Calculate current attendance percentage.
10
+ - Predict attendance after missing additional classes.
11
+ - Calculate recovery classes required to reach a target attendance percentage.
12
+ - Predicted attendance is rounded up using `Math.ceil()`.
13
+ - Handles zero or non-positive class totals.
14
+ - Handles target-attendance edge cases.
15
+ - Uses CommonJS and can be imported with `require()`.
16
+
17
+ ## Installation
18
+
19
+ Install `bunkmate` using npm:
20
+
21
+ ```bash
22
+ npm install bunkmate
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```js
28
+ const {
29
+ calculateAttendance,
30
+ calculatePredictedAttendance,
31
+ calculateRecoveryClasses
32
+ } = require("bunkmate");
33
+ ```
34
+
35
+ ---
36
+
37
+ ## API Reference
38
+
39
+ ### `calculateAttendance(classAttended, totalClasses)`
40
+
41
+ Calculates the current attendance percentage.
42
+
43
+ #### Parameters
44
+
45
+ | Parameter | Type | Description |
46
+ |---|---|---|
47
+ | `classAttended` | `number` | Number of classes attended |
48
+ | `totalClasses` | `number` | Total number of classes |
49
+
50
+ #### Formula
51
+
52
+ ```text
53
+ Attendance = (Classes Attended / Total Classes) × 100
54
+ ```
55
+
56
+ #### Example
57
+
58
+ ```js
59
+ const { calculateAttendance } = require("bunkmate");
60
+
61
+ const attendance = calculateAttendance(8, 10);
62
+
63
+ console.log(attendance);
64
+ // 80
65
+ ```
66
+
67
+ If `totalClasses` is `0` or less, the function returns `0`.
68
+
69
+ ```js
70
+ calculateAttendance(8, 0);
71
+ // 0
72
+ ```
73
+
74
+ ---
75
+
76
+ ### `calculatePredictedAttendance(classAttended, totalClasses, missClasses)`
77
+
78
+ Calculates the predicted attendance percentage after missing a specified number of additional classes.
79
+
80
+ The result is always rounded **up** using `Math.ceil()`.
81
+
82
+ #### Parameters
83
+
84
+ | Parameter | Type | Description |
85
+ |---|---|---|
86
+ | `classAttended` | `number` | Number of classes attended |
87
+ | `totalClasses` | `number` | Current total number of classes |
88
+ | `missClasses` | `number` | Number of additional classes that will be missed |
89
+
90
+ #### Formula
91
+
92
+ ```text
93
+ Predicted Attendance =
94
+ (Classes Attended / (Total Classes + Missed Classes)) × 100
95
+ ```
96
+
97
+ The result is rounded upward.
98
+
99
+ #### Example
100
+
101
+ ```js
102
+ const { calculatePredictedAttendance } = require("bunkmate");
103
+
104
+ const predicted = calculatePredictedAttendance(8, 10, 2);
105
+
106
+ console.log(predicted);
107
+ // 67
108
+ ```
109
+
110
+ The mathematical result is approximately `66.67`, which is rounded up to `67`.
111
+
112
+ If the future total number of classes is `0` or less, the function returns `0`.
113
+
114
+ ---
115
+
116
+ ### `calculateRecoveryClasses(classAttended, totalClasses, missClasses, targetAttendance)`
117
+
118
+ Calculates the number of classes required to recover to the target attendance percentage after the planned missed classes.
119
+
120
+ The returned number of classes is rounded up because a fraction of a class cannot be attended.
121
+
122
+ #### Parameters
123
+
124
+ | Parameter | Type | Description |
125
+ |---|---|---|
126
+ | `classAttended` | `number` | Number of classes attended |
127
+ | `totalClasses` | `number` | Current total number of classes |
128
+ | `missClasses` | `number` | Number of classes that will be missed |
129
+ | `targetAttendance` | `number` | Target attendance percentage |
130
+
131
+ #### Formula
132
+
133
+ ```text
134
+ Recovery Classes =
135
+ (
136
+ (Target Attendance × (Total Classes + Missed Classes))
137
+ - (Classes Attended × 100)
138
+ )
139
+ /
140
+ (100 - Target Attendance)
141
+ ```
142
+
143
+ #### Example
144
+
145
+ ```js
146
+ const { calculateRecoveryClasses } = require("bunkmate");
147
+
148
+ const recovery = calculateRecoveryClasses(8, 10, 2, 75);
149
+
150
+ console.log(recovery);
151
+ // 4
152
+ ```
153
+
154
+ This means that after attending `8` out of `10` classes and then missing `2` additional classes, `4` further classes are required to reach the `75%` target.
155
+
156
+ If the predicted attendance is already at or above the target, the function returns `0`.
157
+
158
+ ```js
159
+ calculateRecoveryClasses(8, 10, 0, 75);
160
+ // 0
161
+ ```
162
+
163
+ A target attendance of `100%` or higher returns `0` based on the package's current implementation.
164
+
165
+ ---
166
+
167
+ ## Complete Example
168
+
169
+ ```js
170
+ const {
171
+ calculateAttendance,
172
+ calculatePredictedAttendance,
173
+ calculateRecoveryClasses
174
+ } = require("bunkmate");
175
+
176
+ const classAttended = 8;
177
+ const totalClasses = 10;
178
+ const missClasses = 2;
179
+ const targetAttendance = 75;
180
+
181
+ const currentAttendance = calculateAttendance(
182
+ classAttended,
183
+ totalClasses
184
+ );
185
+
186
+ const predictedAttendance = calculatePredictedAttendance(
187
+ classAttended,
188
+ totalClasses,
189
+ missClasses
190
+ );
191
+
192
+ const recoveryClasses = calculateRecoveryClasses(
193
+ classAttended,
194
+ totalClasses,
195
+ missClasses,
196
+ targetAttendance
197
+ );
198
+
199
+ console.log("Current Attendance:", currentAttendance);
200
+ // Current Attendance: 80
201
+
202
+ console.log("Predicted Attendance:", predictedAttendance);
203
+ // Predicted Attendance: 67
204
+
205
+ console.log("Recovery Classes:", recoveryClasses);
206
+ // Recovery Classes: 4
207
+ ```
208
+
209
+ ## API Summary
210
+
211
+ | Function | Description |
212
+ |---|---|
213
+ | `calculateAttendance()` | Calculates current attendance percentage |
214
+ | `calculatePredictedAttendance()` | Calculates predicted attendance after missing classes |
215
+ | `calculateRecoveryClasses()` | Calculates classes required to reach the target attendance |
216
+
217
+ ## CommonJS
218
+
219
+ `bunkmate` uses the CommonJS module system.
220
+
221
+ Import the package using:
222
+
223
+ ```js
224
+ const bunkmate = require("bunkmate");
225
+ ```
226
+
227
+ Or destructure the functions:
228
+
229
+ ```js
230
+ const {
231
+ calculateAttendance,
232
+ calculatePredictedAttendance,
233
+ calculateRecoveryClasses
234
+ } = require("bunkmate");
235
+ ```
236
+
237
+ ## Development
238
+
239
+ Clone the repository:
240
+
241
+ ```bash
242
+ git clone https://github.com/Adhyatm2717/BunkMate_npm.git
243
+ ```
244
+
245
+ Navigate into the project:
246
+
247
+ ```bash
248
+ cd BunkMate_npm
249
+ ```
250
+
251
+ Install dependencies:
252
+
253
+ ```bash
254
+ npm install
255
+ ```
256
+
257
+ ## Package Information
258
+
259
+ - **Package:** `bunkmate`
260
+ - **Version:** `1.0.0`
261
+ - **License:** ISC
262
+ - **Author:** Adhyatm Mudgal
263
+
264
+ ## Repository
265
+
266
+ GitHub:
267
+
268
+ https://github.com/Adhyatm2717/BunkMate_npm
269
+
270
+ ## Issues
271
+
272
+ Report bugs or request changes through the GitHub Issues page:
273
+
274
+ https://github.com/Adhyatm2717/BunkMate_npm/issues
275
+
276
+ ## Author
277
+
278
+ **Adhyatm Mudgal**
279
+
280
+ GitHub:
281
+
282
+ https://github.com/Adhyatm2717
package/index.js ADDED
@@ -0,0 +1,69 @@
1
+ function calculateAttendance(classAttended, totalClasses) {
2
+ if (totalClasses <= 0) {
3
+ return 0;
4
+ }
5
+
6
+ return (classAttended / totalClasses) * 100;
7
+ }
8
+
9
+
10
+ function calculatePredictedAttendance(
11
+ classAttended,
12
+ totalClasses,
13
+ missClasses
14
+ ) {
15
+ const futureTotalClasses = totalClasses + missClasses;
16
+
17
+ if (futureTotalClasses <= 0) {
18
+ return 0;
19
+ }
20
+
21
+ return Math.ceil(
22
+ (classAttended / futureTotalClasses) * 100
23
+ );
24
+ }
25
+
26
+
27
+ function calculateRecoveryClasses(
28
+ classAttended,
29
+ totalClasses,
30
+ missClasses,
31
+ targetAttendance
32
+ ) {
33
+ // Already at or above the target
34
+ const predictedAttendance =
35
+ calculatePredictedAttendance(
36
+ classAttended,
37
+ totalClasses,
38
+ missClasses
39
+ );
40
+
41
+ if (predictedAttendance >= targetAttendance) {
42
+ return 0;
43
+ }
44
+
45
+ // 100% target cannot be reached using this formula
46
+ if (targetAttendance >= 100) {
47
+ return 0;
48
+ }
49
+
50
+ if (targetAttendance <= 0) {
51
+ return 0;
52
+ }
53
+
54
+ const recoveryClasses =
55
+ (
56
+ (targetAttendance * (totalClasses + missClasses)) -
57
+ (classAttended * 100)
58
+ ) /
59
+ (100 - targetAttendance);
60
+
61
+ return Math.ceil(recoveryClasses);
62
+ }
63
+
64
+
65
+ module.exports = {
66
+ calculateAttendance,
67
+ calculatePredictedAttendance,
68
+ calculateRecoveryClasses
69
+ };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "bunkmate",
3
+ "version": "1.0.0",
4
+ "description": "BunkMate attendance calculation utilities",
5
+ "keywords": [
6
+ "attendance",
7
+ "bunkmate",
8
+ "college",
9
+ "student",
10
+ "bunk"
11
+ ],
12
+ "homepage": "https://github.com/Adhyatm2717/BunkMate_npm#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/Adhyatm2717/BunkMate_npm/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Adhyatm2717/BunkMate_npm.git"
19
+ },
20
+ "license": "ISC",
21
+ "author": "Adhyatm Mudgal",
22
+ "type": "commonjs",
23
+ "main": "index.js",
24
+ "scripts": {
25
+ "test": "echo \"Error: no test specified\" && exit 1"
26
+ }
27
+ }