bunkmate 1.0.0 → 2.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 (2) hide show
  1. package/index.js +48 -49
  2. package/package.json +4 -1
package/index.js CHANGED
@@ -1,69 +1,68 @@
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(
1
+ function calculate(
11
2
  classAttended,
12
3
  totalClasses,
13
- missClasses
4
+ missClasses,
5
+ targetAttendance
14
6
  ) {
15
- const futureTotalClasses = totalClasses + missClasses;
7
+ // Current attendance
8
+ let avg = 0;
16
9
 
17
- if (futureTotalClasses <= 0) {
18
- return 0;
10
+ if (totalClasses > 0) {
11
+ avg = Math.ceil(
12
+ (classAttended / totalClasses) * 100
13
+ );
19
14
  }
20
15
 
21
- return Math.ceil(
22
- (classAttended / futureTotalClasses) * 100
23
- );
24
- }
16
+ // Predicted attendance
17
+ const futureTotalClasses =
18
+ totalClasses + missClasses;
25
19
 
20
+ let predictedAttendance = 0;
26
21
 
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
22
+ if (futureTotalClasses > 0) {
23
+ predictedAttendance = Math.ceil(
24
+ (classAttended / futureTotalClasses) * 100
39
25
  );
40
-
41
- if (predictedAttendance >= targetAttendance) {
42
- return 0;
43
26
  }
44
27
 
45
- // 100% target cannot be reached using this formula
46
- if (targetAttendance >= 100) {
47
- return 0;
48
- }
28
+ // Recovery classes
29
+ let recoveryClasses = 0;
30
+
31
+ if (
32
+ targetAttendance > 0 &&
33
+ targetAttendance < 100
34
+ ) {
35
+ const recovery =
36
+ (
37
+ (targetAttendance * futureTotalClasses) -
38
+ (classAttended * 100)
39
+ ) /
40
+ (100 - targetAttendance);
49
41
 
50
- if (targetAttendance <= 0) {
51
- return 0;
42
+ if (recovery > 0) {
43
+ recoveryClasses = Math.ceil(recovery);
44
+ }
52
45
  }
53
46
 
54
- const recoveryClasses =
55
- (
56
- (targetAttendance * (totalClasses + missClasses)) -
57
- (classAttended * 100)
58
- ) /
59
- (100 - targetAttendance);
47
+ // Already safe
48
+ if (predictedAttendance >= targetAttendance) {
49
+ recoveryClasses = 0;
50
+ }
60
51
 
61
- return Math.ceil(recoveryClasses);
52
+ return `
53
+ ╔══════════════════════════════════════╗
54
+ ║ 📚 BUNKMATE REPORT ║
55
+ ╠══════════════════════════════════════╣
56
+ ║ ║
57
+ ║ 📊 Current Attendance : ${avg}% ║
58
+ ║ 🔮 Predicted Attendance : ${predictedAttendance}% ║
59
+ ║ 🔄 Recovery Classes : ${recoveryClasses.toString().padEnd(2)} ║
60
+ ║ ║
61
+ ╚══════════════════════════════════════╝
62
+ `;
62
63
  }
63
64
 
64
65
 
65
66
  module.exports = {
66
- calculateAttendance,
67
- calculatePredictedAttendance,
68
- calculateRecoveryClasses
67
+ calculate
69
68
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunkmate",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "BunkMate attendance calculation utilities",
5
5
  "keywords": [
6
6
  "attendance",
@@ -23,5 +23,8 @@
23
23
  "main": "index.js",
24
24
  "scripts": {
25
25
  "test": "echo \"Error: no test specified\" && exit 1"
26
+ },
27
+ "dependencies": {
28
+ "bunkmate": "^1.0.0"
26
29
  }
27
30
  }