@baravak/risloo-profile-cli 4.18.0 → 4.19.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baravak/risloo-profile-cli",
3
- "version": "4.18.0",
3
+ "version": "4.19.0",
4
4
  "description": "**Risloo Profile CLI** is a library for creating profiles, reports and sheets for *psychological* samples.",
5
5
  "main": "bin/risloo.js",
6
6
  "publishConfig": {
@@ -0,0 +1,9 @@
1
+ // ceil Helper
2
+ // Get the `Math.round()` of the given value.
3
+
4
+ function round(value, decimals = 0) {
5
+ const factor = Math.pow(10, decimals);
6
+ return Math.round(value * factor) / factor;
7
+ };
8
+
9
+ module.exports = round;
@@ -37,6 +37,7 @@ const first = require("./helpers/first");
37
37
  const last = require("./helpers/last");
38
38
  const ceil = require("./helpers/ceil");
39
39
  const floor = require("./helpers/floor");
40
+ const round = require("./helpers/round");
40
41
 
41
42
  const polygon = require("./helpers/profiles/polygon");
42
43
  const gauge = require("./helpers/profiles/gauge");
@@ -82,6 +83,7 @@ const helpers = {
82
83
  last,
83
84
  ceil,
84
85
  floor,
86
+ round,
85
87
  polygon,
86
88
  gauge,
87
89
  bar,
@@ -91,13 +91,12 @@
91
91
  }
92
92
  ],
93
93
  "score": {
94
- "raw": 159,
95
- "problem_solving": 6,
96
- "roles": 36,
97
- "affective_responsiveness": 27,
98
- "communication": 14,
99
- "affective_involvement": 8,
100
- "behaviour_control": 18,
101
- "overall_performance": 50
94
+ "overall_performance": 24,
95
+ "problem_solving": 12,
96
+ "communication": 19,
97
+ "roles": 22,
98
+ "affective_involvement": 14,
99
+ "behaviour_control": 16,
100
+ "affective_responsiveness": 9
102
101
  }
103
102
  }
@@ -1,31 +1,106 @@
1
- const MMAFD93 = require("./MMFAD93");
1
+ const round = require("../handlebars/helpers/round");
2
+ const { Profile, FS } = require("../Profile");
2
3
 
3
- const customConfig = {
4
- test: {
5
- name: "پرسشنامه عملکرد خانواده ۶۰ سؤالی" /* Name of the test */,
6
- },
7
- raw: {
8
- maxValue: 240,
9
- },
10
- items: {
11
- maxValues: {
12
- problem_solving: 24,
13
- roles: 36,
14
- affective_responsiveness: 28,
15
- communication: 28,
16
- affective_involvement: 36,
17
- behaviour_control: 36,
18
- overall_performance: 52,
19
- } /* Maximum value of marks provided by the dataset */,
20
- },
21
- };
4
+ class MMAFD9A extends Profile {
5
+ // Number of pages
6
+ static pages = 1;
22
7
 
23
- // This profile is completely identical to MMFAD93
8
+ // Labels of the sample
9
+ labels = {
10
+ L1: { eng: "problem_solving", fr: "حل مسأله", CoP: 2.2, max: 24},
11
+ L2: { eng: "roles", fr: "نقش‌ها", CoP: 2.3, max: 44},
12
+ L3: { eng: "affective_responsiveness", fr: "پاسخ‌دهی عاطفی", CoP: 2.2, max: 24},
13
+ L4: { eng: "communication", fr: "ارتباط", CoP: 2.2, max: 36},
14
+ L5: { eng: "affective_involvement", fr: "مشارکت عاطفی", CoP: 2.1, max: 28},
15
+ L6: { eng: "behaviour_control", fr: "کنترل رفتار", CoP: 1.9, max: 36},
16
+ L7: { eng: "overall_performance", fr: "کارکرد عمومی", CoP: 2, max: 48},
17
+ };
24
18
 
25
- class MMFAD9A extends MMAFD93 {
26
- constructor(dataset, options, config = customConfig) {
27
- super(dataset, options, config);
19
+ profileSpec = {
20
+ /* "prerequisites" is synonym to "fields" in our program */
21
+ sample: {
22
+ name: "پرسشنامه عملکرد خانواده ۶۰ سؤالی" /* Name of the sample */,
23
+ multiProfile: false /* Whether the sample has multiple profiles or not */,
24
+ questions: false /* Determines whether to get questions from inital dataset or not */,
25
+ defaultFields: true /* Determines whether to have default prerequisites in the profile or not */,
26
+ fields: [] /* In case you want to get some additional fields and show in the profile */,
27
+ },
28
+ /* "profile" determines the dimensions of the drawn profile (to be used in svg tag viewbox) */
29
+ /* calculating its dimensions carefully is of great importance */
30
+ profile: {
31
+ get dimensions() {
32
+ return {
33
+ width: 634 + 2 * this.padding.x,
34
+ height: 668 + 2 * this.padding.y,
35
+ };
36
+ },
37
+ padding: {
38
+ x: 135,
39
+ y: 23,
40
+ },
41
+ },
42
+ /* "labels" part which has to be provided for each profile */
43
+ labels: Object.values(this.labels),
44
+ };
45
+
46
+ constructor(dataset, options, config = {}) {
47
+ super();
48
+ this._init(dataset, options, config);
49
+ }
50
+
51
+ _calcContext() {
52
+ const {
53
+ spec: { parameters: spec },
54
+ dataset,
55
+ } = this;
56
+
57
+ return [
58
+ {
59
+ scores: dataset.score.map((score) => {
60
+ const elements = [];
61
+ score.label.avg = round(score.mark / (score.label.max/4), 1);
62
+ const avg = round(score.label.avg, 1);
63
+ let greenLiene = 12;
64
+ for (let i = 0; i < 31; i++) {
65
+ let color = "";
66
+ let type = "";
67
+ const point = 1 + round(i * 0.1, 1);
68
+ if (point < score.label.CoP) {
69
+ greenLiene += 14;
70
+ }
71
+ if (point === avg) {
72
+ color = avg >= score.label.CoP ? "#DC2626" : "#16A34A";
73
+ type = "selected";
74
+ } else {
75
+ type = Math.round(point) === point ? "z" : "nz";
76
+ if (point === score.label.CoP) {
77
+ color = "#A8A29E";
78
+ } else if (point > avg) {
79
+ color = type === "z" ? '#F43F5E33' : "#F43F5E1A";
80
+ } else {
81
+ color = type === 'z' ? '#16A34A33' : "#16A34A1A";
82
+ }
83
+ }
84
+ elements.push({
85
+ point,
86
+ color,
87
+ type,
88
+ isCoP: point === score.label.CoP,
89
+ });
90
+ }
91
+ score.label.CoPText = score.label.CoP.toString().replace(".", "٬");
92
+ return {
93
+ ...score,
94
+ elements,
95
+ greenLiene,
96
+ redLine: 446 - greenLiene,
97
+ avgText: score.label.avg.toString().replace(".", "٬"),
98
+ avgSelected: elements.findIndex((e) => e.type === "selected")
99
+ };
100
+ }),
101
+ },
102
+ ];
28
103
  }
29
104
  }
30
105
 
31
- module.exports = MMFAD9A;
106
+ module.exports = MMAFD9A;
@@ -113,14 +113,14 @@
113
113
  <text x="52" y="46.5" dy=".6em" font-size="12" font-weight="400" fill="#94A3B8" text-anchor="start">90</text>
114
114
  <text x="68" y="66" dy=".77em" font-size="12" font-weight="400" fill="#B91C1C" text-anchor="end">بالینی</text>
115
115
 
116
- {{!-- <rect height="20" width="189" x="60" y="100" fill="#FEFCE8" opacity=".25" /> --}}
116
+ <rect height="20" width="189" x="60" y="100" fill="#FEFCE8" opacity=".25" />
117
117
  <text x="52" y="95.5" dy=".77em" font-size="12" font-weight="400" fill="#94A3B8" text-anchor="start">63</text>
118
118
  <text x="68" y="103" dy=".77em" font-size="12" font-weight="400" fill="#CA8A04" text-anchor="end">مرزی</text>
119
119
 
120
- <rect height="88" width="189" x="60" y="120" fill="#ECFDF540" opacity=".25" />
120
+ <rect height="88" width="189" x="60" y="120" fill="#ECFDF5" opacity=".25" />
121
121
  <text x="52" y="115" dy=".77em" font-size="12" font-weight="400" fill="#94A3B8" text-anchor="start">59</text>
122
122
  <text x="68" y="142" dy=".77em" font-size="12" font-weight="400" fill="#15803D" text-anchor="end">بهنجار</text>
123
- <text x="52" y="176" dy=".77em" font-size="12" font-weight="400" fill="#94A3B8" text-anchor="start">30</text>
123
+ <text x="52" y="173" dy=".77em" font-size="12" font-weight="400" fill="#94A3B8" text-anchor="start">30</text>
124
124
  <text x="52" y="203" dy=".77em" font-size="12" font-weight="400" fill="#94A3B8" text-anchor="start">0</text>
125
125
  <g transform="translate(121, 46)">
126
126
  {{#each group2 as |item index|}}
@@ -1 +1,59 @@
1
- {{> MMFAD93}}
1
+ {{#> layout}}
2
+ <defs>
3
+ <linearGradient id="red-gradient">
4
+ <stop offset="0%" stop-color="#FFE4E6" stop-opacity=".08"/>
5
+ <stop offset="100%" stop-color="#F43F5E" stop-opacity=".08"/>
6
+ </linearGradient>
7
+ <linearGradient id="green-gradient">
8
+ <stop offset="0%" stop-color="#22C55E" stop-opacity=".08"/>
9
+ <stop offset="100%" stop-color="#DCFCE7" stop-opacity=".08"/>
10
+ </linearGradient>
11
+ <linearGradient id="help-gradient">
12
+ <stop stop-color="#22C55E"/>
13
+ <stop offset="0.45" stop-color="white"/>
14
+ <stop offset="1" stop-color="#EF4444"/>
15
+ </linearGradient>
16
+ </defs>
17
+ <g transform="translate({{spec.profile.padding.x}}, {{spec.profile.padding.y}})">
18
+ <g transform="translate(113, 0)">
19
+ <text x="0" y="7" text-anchor="end" dy=".3em" fill="#16A34A" font-size="11" font-weight="500" opacity="0.5">کارکرد سالم</text>
20
+ <text x="446" y="7" text-anchor="start" dy=".3em" fill="#DC2626" font-size="11" font-weight="500" opacity="0.5">کارکرد ناسالم</text>
21
+ <rect y="12" width="446" height="2" fill="url(#help-gradient)" fill-opacity="0.1"/>
22
+ </g>
23
+ <g transform="translate(0, 38)">
24
+ {{#each scores}}
25
+ <g transform="translate(0, {{math 94 '*' @index}})">
26
+ <text x="100" y="35.5" text-anchor="start" dy=".3em" fill="#4B5563" font-size="14" font-weight="500">{{label.fr}}</text>
27
+ <text text-anchor="middle" x="129" dy=".3em" y="60" fill="#9CA3AF" font-size="12" font-weight="400">1</text>
28
+ <text text-anchor="middle" x="549" dy=".3em" y="60" fill="#9CA3AF" font-size="12" font-weight="400">4</text>
29
+ {{bar greenLiene 24 (object tr=0 tl=4 br=0 bl=4) (toRad 0) fill="url(#green-gradient)" transform="translate(116, 24)"}}
30
+ <g transform="translate({{greenLiene}}, 0)">
31
+ {{bar redLine 24 (object tr=4 tl=0 br=4 bl=0) (toRad 0) fill="url(#red-gradient)" transform="translate(116, 24)"}}
32
+ </g>
33
+ <g transform="translate(128, 20)">
34
+ <text text-anchor="middle" dy=".3em" y="-13" x="{{math (math avgSelected '*' 14) '+' 2}}" fill="{{ternary (boolean label.avg '>=' label.CoP) '#DC2626' '#16A34A'}}" font-size="16" font-weight="700">{{avgText}}</text>
35
+ {{#each elements}}
36
+ <g transform="translate({{math @index '*' 14}}, 0)">
37
+ {{#if (boolean type '==' 'selected')}}
38
+ {{bar 4 28 (object tr=2 tl=2 br=0 bl=0) (toRad 0) fill=color transform="translate(-1, 0)"}}
39
+ {{else if (boolean (boolean type '==' 'z') '||' (boolean isCoP '==' true))}}
40
+ <rect width="2" height="16" rx="1" y="8" fill="{{color}}" />
41
+ {{else}}
42
+ <rect width="2" height="12" rx="1" y="10" fill="{{color}}" />
43
+ {{/if}}
44
+ {{#if (boolean isCoP '==' true)}}
45
+ <text text-anchor="middle" dy=".3em" y="40" x="1" fill="#78716C" font-size="12" font-weight="400">{{../label.CoPText}}</text>
46
+ {{/if}}
47
+ </g>
48
+ {{/each}}
49
+ </g>
50
+ <text text-anchor="start" direction="ltr">
51
+ <tspan x="577" y="36.5" dy=".3em" fill="#6B7280" font-size="16" font-weight="600">{{mark}}</tspan>
52
+ <tspan y="36.5" dy=".3em" fill="#6B7280" font-size="12" font-weight="300">/</tspan>
53
+ <tspan y="36.5" dy=".3em" fill="#6B7280" font-size="13" font-weight="400">{{label.max}}</tspan>
54
+ </text>
55
+ </g>
56
+ {{/each}}
57
+ </g>
58
+ </g>
59
+ {{/layout}}