Stats on list responses
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ab88195607
commit
9436220685
@ -45,22 +45,33 @@
|
||||
};
|
||||
|
||||
if (!proposals) {
|
||||
if (question.kind == "int") {
|
||||
if (question.kind && (question.kind == "int" || question.kind.startsWith("list"))) {
|
||||
req_responses = question.getResponses();
|
||||
req_responses.then((responses) => {
|
||||
const values = [];
|
||||
const proposal_idx = { };
|
||||
for (const res of responses) {
|
||||
if (proposal_idx[res.value]) {
|
||||
data.datasets[0].values[proposal_idx[res.value]] += 1;
|
||||
values.push(Number(res.value));
|
||||
for (const response of responses) {
|
||||
let ress = [];
|
||||
if (question.kind.startsWith("list")) {
|
||||
ress = response.value.split('\n');
|
||||
} else {
|
||||
data.labels.push(res.value);
|
||||
ress.push(response.value);
|
||||
}
|
||||
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.value] = new String(data.labels.length - 1);
|
||||
proposal_idx[res] = new String(data.labels.length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (question.kind == "int") {
|
||||
mean = Math.trunc(values.reduce((p, e) => p + e) / values.length*10)/10;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
req_proposals = refreshProposals();
|
||||
@ -88,6 +99,8 @@
|
||||
{/if}
|
||||
{#if question.kind === "mcq"}
|
||||
<Chart data={data} type="bar" />
|
||||
{:else if question.kind === "list"}
|
||||
<Chart data={data} type="pie" />
|
||||
{:else}
|
||||
<Chart data={data} type="pie" maxSlices="9" />
|
||||
{/if}
|
||||
|
78
ui/src/components/ListInputResponses.svelte
Normal file
78
ui/src/components/ListInputResponses.svelte
Normal 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>
|
@ -12,6 +12,7 @@
|
||||
<script>
|
||||
import { user } from '../../../stores/user';
|
||||
import CorrectionPieChart from '../../../components/CorrectionPieChart.svelte';
|
||||
import ListInputResponses from '../../../components/ListInputResponses.svelte';
|
||||
import QuestionForm from '../../../components/QuestionForm.svelte';
|
||||
import SurveyAdmin from '../../../components/SurveyAdmin.svelte';
|
||||
import SurveyBadge from '../../../components/SurveyBadge.svelte';
|
||||
@ -595,6 +596,11 @@
|
||||
</table>
|
||||
</div>
|
||||
{/await}
|
||||
{:else if question.kind && question.kind.startsWith('list')}
|
||||
<ListInputResponses
|
||||
responses={responses[q]}
|
||||
{users}
|
||||
/>
|
||||
{:else}
|
||||
<div class="card mb-4">
|
||||
<ul class="list-group list-group-flush">
|
||||
|
Reference in New Issue
Block a user