Stats on list responses
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-09-02 16:24:00 +02:00
parent ab88195607
commit 9436220685
3 changed files with 106 additions and 9 deletions

View File

@ -45,22 +45,33 @@
}; };
if (!proposals) { if (!proposals) {
if (question.kind == "int") { if (question.kind && (question.kind == "int" || question.kind.startsWith("list"))) {
req_responses = question.getResponses(); req_responses = question.getResponses();
req_responses.then((responses) => { req_responses.then((responses) => {
const values = []; const values = [];
const proposal_idx = { }; const proposal_idx = { };
for (const res of responses) { for (const response of responses) {
if (proposal_idx[res.value]) { let ress = [];
data.datasets[0].values[proposal_idx[res.value]] += 1; if (question.kind.startsWith("list")) {
values.push(Number(res.value)); ress = response.value.split('\n');
} else { } else {
data.labels.push(res.value); ress.push(response.value);
data.datasets[0].values.push(1); }
proposal_idx[res.value] = new String(data.labels.length - 1); for (const res of ress) {
if (res == "") continue;
if (proposal_idx[res]) {
data.datasets[0].values[proposal_idx[res]] += 1;
values.push(Number(res));
} else {
data.labels.push(res);
data.datasets[0].values.push(1);
proposal_idx[res] = new String(data.labels.length - 1);
}
} }
} }
mean = Math.trunc(values.reduce((p, e) => p + e) / values.length*10)/10; if (question.kind == "int") {
mean = Math.trunc(values.reduce((p, e) => p + e) / values.length*10)/10;
}
}); });
} else { } else {
req_proposals = refreshProposals(); req_proposals = refreshProposals();
@ -88,6 +99,8 @@
{/if} {/if}
{#if question.kind === "mcq"} {#if question.kind === "mcq"}
<Chart data={data} type="bar" /> <Chart data={data} type="bar" />
{:else if question.kind === "list"}
<Chart data={data} type="pie" />
{:else} {:else}
<Chart data={data} type="pie" maxSlices="9" /> <Chart data={data} type="pie" maxSlices="9" />
{/if} {/if}

View File

@ -0,0 +1,78 @@
<script>
import CorrectionPieChart from './CorrectionPieChart.svelte';
export let responses = {};
export let users = {};
let res = {};
let labels = [];
let graph_data = { labels, datasets:[{values: []}] };
$: {
res = { };
labels = [];
responses = responses;
for (const user in responses) {
for (const ures of responses[user].split('\n')) {
if (ures === "") continue;
if (res[ures] === undefined) {
res[ures] = [];
}
res[ures].push(user);
if (res[ures].length == 2) {
labels.push(ures);
}
}
}
labels.sort((a,b) => (res[a].length - res[b].length))
graph_data.labels = labels;
graph_data.datasets[0].values = labels.map((l) => res[l].length);
console.log(graph_data);
}
</script>
<CorrectionPieChart
question={{kind: 'list'}}
proposals={[]}
data={graph_data}
/>
<div class="card mb-4">
<ul class="list-group list-group-flush">
{#each labels as rep, rid (rid)}
<li class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
<span>
{rep}
</span>
<div>
{#each res[rep] as user}
<a href="users/{user}" target="_blank" class="badge bg-dark rounded-pill">
{#if users && users[user]}
{users[user].login}
{:else}
{user}
{/if}
</a>
{/each}
</div>
</li>
{/each}
{#each Object.keys(res) as rep, rid (rid)}
{#if labels.indexOf(rep) == -1}
<li class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
<span>
{rep}
</span>
<a href="users/{res[rep]}" target="_blank" class="badge bg-dark rounded-pill">
{#if users && users[res[rep]]}
{users[res[rep]].login}
{:else}
{res[rep]}
{/if}
</a>
</li>
{/if}
{/each}
</ul>
</div>

View File

@ -12,6 +12,7 @@
<script> <script>
import { user } from '../../../stores/user'; import { user } from '../../../stores/user';
import CorrectionPieChart from '../../../components/CorrectionPieChart.svelte'; import CorrectionPieChart from '../../../components/CorrectionPieChart.svelte';
import ListInputResponses from '../../../components/ListInputResponses.svelte';
import QuestionForm from '../../../components/QuestionForm.svelte'; import QuestionForm from '../../../components/QuestionForm.svelte';
import SurveyAdmin from '../../../components/SurveyAdmin.svelte'; import SurveyAdmin from '../../../components/SurveyAdmin.svelte';
import SurveyBadge from '../../../components/SurveyBadge.svelte'; import SurveyBadge from '../../../components/SurveyBadge.svelte';
@ -595,6 +596,11 @@
</table> </table>
</div> </div>
{/await} {/await}
{:else if question.kind && question.kind.startsWith('list')}
<ListInputResponses
responses={responses[q]}
{users}
/>
{:else} {:else}
<div class="card mb-4"> <div class="card mb-4">
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">