Skip to content

Commit

Permalink
Push local changes I forgot about
Browse files Browse the repository at this point in the history
  • Loading branch information
nucular committed Jan 4, 2019
1 parent 865cf79 commit c592640
Show file tree
Hide file tree
Showing 7 changed files with 1,826 additions and 18 deletions.
27 changes: 25 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
var app = new Vue({
el: "#app"
const routes = [
{
path: "/",
name: "about",
component: About
},
{
path: "/test/:question",
name: "test",
component: Test
},
{
path: "/report",
name: "report",
component: Report
}
];

const router = new VueRouter({
routes: routes
});

const app = new Vue({
el: "#app",
router: router
});
8 changes: 8 additions & 0 deletions components/linechart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Vue.component("line-chart", {
extends: VueChartJs.Line,
mixins: [VueChartJs.mixins.reactiveProp],
props: ["options"],
mounted: function() {
this.renderChart(this.chartData, this.options);
}
});
1,594 changes: 1,594 additions & 0 deletions data/scales.json

Large diffs are not rendered by default.

89 changes: 73 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,88 @@
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="container" id="app">
<header class="header clearfix">
<nav class="nav nav-pills float-right">
<router-link class="nav-link" to="/">About</router-link>
<router-link class="nav-link" to="/test">Test</router-link>
<router-link class="nav-link" to="/report">Report</router-link>
</nav>
<h3 class="text-muted">MMPI-2 for all</h3>
</header>
<main role="main" id="app">
<div class="jumbotron">
<h1 class="display-3">Take the MMPI-2</h1>
<p class="lead">
The Minnesota Multiphasic Personality Inventory (MMPI) is a standardized psychometric test of adult personality and psychopathology.
</p>
<p><a class="btn btn-lg btn-success" href="#" role="button">Start</a></p>
</div>

<article class="article">
</article>
</main>
<router-view></router-view>
<footer class="footer">
<p>Unlicensed. Dedicated to Liberty. <a href="https://github.com/nucular/mmpi-2">Fork me on GitHub.</a></p>
</footer>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script type="text/x-template" id="about-view-template">
<div class="jumbotron">
<h1 class="display-3">Take the MMPI-2</h1>
<p class="lead">
The Minnesota Multiphasic Personality Inventory (MMPI) is a standardized psychometric test of adult personality and psychopathology.
</p>
<p><router-link class="btn btn-lg btn-success" to="/test/1" role="button">Start</router-link></p>
</div>
</script>

<script type="text/x-template" id="test-view-template">
<div class="jumbotron">
<div class="progress">
<div class="progress-bar" role="progressbar"
:aria-valuenow="currentQuestion"
aria-valuemin="1" :aria-valuemax="questions.length"
style="min-width: 2em;"
:style="{width: (currentQuestion / questions.length) * 100 + '%'}">
{{Math.floor((currentQuestion / questions.length) * 100)}}%
</div>
</div>
<h1 class="display-4">Question {{currentQuestion + 1}}</h1>
<h2>
{{questions[currentQuestion]}}
</h2>
<div class="btn-group">
<button type="button" class="btn btn-success" on:click="answer(true);">True</button>
<button type="button" class="btn" on:click="answer(null);">Unsure</button>
<button type="button" class="btn btn-danger" on:click="answer(false);">False</button>
</div>
<nav aria-label="Question navigation">
<ul class="pagination pagination-lg flex justify-content-center">
<li class="page-item" :class="{disabled: currentQuestion <= 0}">
<router-link class="page-link" :to="'/test/' + currentQuestion" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</router-link>
</li>
<li v-for="n in paginationEnd - paginationStart" class="page-item" :class="{active: n + paginationStart == currentQuestion + 1}">
<router-link class="page-link" :to="'/test/' + (n + paginationStart)">{{n + paginationStart}}</router-link>
</li>
<li class="page-item" :class="{disabled: currentQuestion == questions.length - 1}">
<router-link class="page-link" :to="'/test/' + (currentQuestion + 2)" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</router-link>
</li>
</ul>
</nav>
</div>
</script>

<script type="text/x-template" id="report-view-template">
<div>
<line-chart :chart-data="charts[0]"></line-chart>
</div>
</script>

<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<script src="https://unpkg.com/vue-chartjs/dist/vue-chartjs.min.js"></script>
<script src="components/linechart.js"></script>
<script src="views/about.js"></script>
<script src="views/test.js"></script>
<script src="views/report.js"></script>
<script src="app.js"></script>
</body>
</html>
</html>
3 changes: 3 additions & 0 deletions views/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const About = Vue.component("about-view", {
template: "#about-view-template"
});
89 changes: 89 additions & 0 deletions views/report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const Report = Vue.component("report-view", {
template: "#report-view-template",
data: function() {
return {
scaleCategories: [],
answers: {},
gender: "male",
scores: {},
charts: [
{
labels: ["VRIN", "TRIN", "F", "Fp", "FBS", "L", "K", "S", "Hs", "D", "Hy", "Pd", "Mf", "Pa", "Pt", "Sc", "Ma", "Si"],
datasets: [{
data: [],
lineTension: 0
}]
}
]
};
},
created: function() {
var vm = this;
$.getJSON("data/scales.json", function(data) {
vm.scaleCategories = data;
});

var a = "TTFTFFTFFFFFFTFTFFFTTTFFFTFFTFTFFTFTTTTFTFFFFTTTFTTTTFTTTFTFFTTFTTTFTTTFTFF"
+ "TTFFFTTFFTFTTTFTTTFFFFTFFFFFFTFTTFTFFFFTFTTFTFFTFFFTTTTFFFFTFTFTFFFTFFFTFFT"
+ "FFFTTTFTTFTFTTFTTFFFTTFFTTFTTTTFFFTTFFFTFTFFTTFFTFFFFTFFTFTFFFFTTFTFTFFTFTF"
+ "TFFTFTTTFTTFTFFFFTFFFFFTTTFTFFTFTTTFFTTTTTTTFFFTFTTTTTFFFFTTFFFTFFFTFTFFFFF"
+ "TFTFFTFTTTTFFTFTFFFTFFFFTTFFFTFFFFFFTFTFTFFTFFTTTFFFTFFFTFFFFTFTTFFTFFTTFTF"
+ "TTTFTFFTTTTTFFTTFFTFFFFTTTFFTTFFTTFTTFFFFFTFTFFTTFFTFFFTTTTFFTFTTFTFFFTFFFT"
+ "TTFTTFFTTFTTTTTFTFTFFTTTTTFFTTFTTFTTTFTFTTFFFFTFTFTTFTTTFFTFTFFTTTTTTTFFTFF"
+ "TTFFTFTTFFFFFTFTFFFFFTFFTFFTTFFFTFFFTFTTTF";
for (var i = 0; i < a.length; i++) {
vm.answers[i] = a.charAt(i) == "T";
}
},
methods: {
calculateTScore: function(rawScore, scale) {
var tScores = scale.tScores[this.gender];
if (scale.kCorrection) {
var kScore = this.scores["K"] * scale.kCorrection + rawScore;
rawScore = Math.floor(kScore + 0.5);
}
if (scale.scoreOffsets) {
rawScore -= scale.scoreOffsets[this.gender];
}
return tScores[Math.max(0, Math.min(rawScore, tScores.length - 1))];
},
gradeScale: function(scale) {
var vm = this;
if (scale.gender && scale.gender != vm.gender) return;
var rawScore = 0;
scale.answers.forEach(function(v) {
for (var i = 0; i < v.length; i += 2) {
var question = v[i],
answer = v[i+1];
if (vm.answers[question] != answer)
return
}
if (v.length % 2 == 1)
rawScore += v[v.length - 1];
else
rawScore++;
});
if (scale.subScales) {
scale.subScales.forEach(vm.gradeScale)
}
if (scale.tScores)
vm.scores[scale.name] = vm.calculateTScore(rawScore, scale);
else
vm.scores[scale.name] = rawScore;
},

grade: function() {
var vm = this;
vm.scaleCategories.forEach(function(category) {
category.items.forEach(vm.gradeScale);
});
vm.charts.forEach(function(chart) {
chart.labels.forEach(function(name) {
chart.datasets.forEach(function(dataset) {
dataset.data.push(vm.scores[name]);
});
});
});
}
}
});
34 changes: 34 additions & 0 deletions views/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const Test = Vue.component("test-view", {
template: "#test-view-template",
data: function() {
return {
questions: [],
answers: {},
currentRoute: "1"
};
},
created: function() {
var self = this;
$.getJSON("data/questions.json", function(data) {
self.questions = data;
});
},
computed: {
currentQuestion: function() {
return parseInt(this.$route.params.question) - 1;
},
paginationStart: function() {
return Math.max(0, this.currentQuestion - 2);
},
paginationEnd: function() {
return Math.min(this.paginationStart + 5, this.questions.length - 1);
}
},
methods: {
answer: function(state) {
var vm = this;
vm.answers[vm.currentQuestion] = state;
vm.$router.push({name: "test", params: {question: vm.currentQuestion + 1}});
}
}
});

0 comments on commit c592640

Please sign in to comment.