В админ панель добавлены итоги голосования, процент проголосовавших Мой коллега самый лучший
This commit is contained in:
1 parent
af1f9f752c
commit
e3661db5cb
2 files changed
+45
-7
No files matched your search
@@ -64,7 +64,7 @@ class GetBest(APIView):
|
|||||||
def get(self, request):
|
def get(self, request):
|
||||||
# Группировка кандидатов по имени и подсчет каждого
|
# Группировка кандидатов по имени и подсчет каждого
|
||||||
count_bests = BestVote.objects.values(
|
count_bests = BestVote.objects.values(
|
||||||
'cand_name').annotate(total=Count('id'))
|
'department_user', 'cand_name').annotate(total=Count('id'))
|
||||||
return Response(count_bests)
|
return Response(count_bests)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,15 +11,18 @@
|
|||||||
</v-card>
|
</v-card>
|
||||||
<v-card elevation="0">
|
<v-card elevation="0">
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
88
|
{{ perc_bst }}%
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
</v-card>
|
</v-card>
|
||||||
<v-card color="teal-darken-1" class="ma-2">
|
<v-card color="teal-darken-1" class="ma-2">
|
||||||
<v-card-title>Лидер номинации</v-card-title>
|
<v-card-title>Лидер номинации</v-card-title>
|
||||||
</v-card>
|
</v-card>
|
||||||
<v-card elevation="0">
|
<v-card v-for="(employees, department) in max_bst" :key="department" elevation="0">
|
||||||
|
<v-card-title>{{ department }}</v-card-title>
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
ФИО
|
<div v-for="employee in employees" :key="employee.name">
|
||||||
|
{{ employee.name }}
|
||||||
|
</div>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
</v-card>
|
</v-card>
|
||||||
<v-card color="teal-darken-1" class="ma-2">
|
<v-card color="teal-darken-1" class="ma-2">
|
||||||
@@ -78,8 +81,10 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
|
import { computed } from "vue";
|
||||||
import { clearAxios } from "@/utils/axios-api";
|
import { clearAxios } from "@/utils/axios-api";
|
||||||
import { objectToString } from "@vue/shared";
|
import { objectToString } from "@vue/shared";
|
||||||
|
import { useAccountStore } from '@/store/AccountStore';
|
||||||
import PercThn from '@/components/vote/PercThn.vue';
|
import PercThn from '@/components/vote/PercThn.vue';
|
||||||
|
|
||||||
|
|
||||||
@@ -88,11 +93,15 @@ export default {
|
|||||||
PercThn,
|
PercThn,
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
|
let account_login = useAccountStore().user.login;
|
||||||
let result_thn = ref([]);
|
let result_thn = ref([]);
|
||||||
let result_bst = ref([]);
|
let result_bst = ref([]);
|
||||||
let all_voted_bst = ref([]);
|
let all_voted_bst = ref([]);
|
||||||
let all_voted_thn = ref([]);
|
let all_voted_thn = ref([]);
|
||||||
let max_thn = ref();
|
let max_thn = ref();
|
||||||
|
let max_bst = ref({});
|
||||||
|
let all_cod = ref([]);
|
||||||
|
let perc_bst = ref();
|
||||||
|
|
||||||
const getNotVoted = () => {
|
const getNotVoted = () => {
|
||||||
clearAxios.get(`/api/vote/getnotvotethn/`).then((data) => {
|
clearAxios.get(`/api/vote/getnotvotethn/`).then((data) => {
|
||||||
@@ -112,17 +121,46 @@ export default {
|
|||||||
max_thn.value = all_voted_thn.filter(item => item.total === max_total).map(item => item.cand_name)
|
max_thn.value = all_voted_thn.filter(item => item.total === max_total).map(item => item.cand_name)
|
||||||
});
|
});
|
||||||
|
|
||||||
clearAxios.get(`/api/vote/getbest/`).then((data) => {
|
clearAxios.get(`api/vote/get_for_thn/?login=${account_login}`).then((data) => {
|
||||||
all_voted_bst = data.data;
|
all_cod.value = data.data;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
clearAxios.get(`/api/vote/getbest/`).then((data) => {
|
||||||
|
all_voted_bst.value = data.data;
|
||||||
|
// Групировка по департаметам
|
||||||
|
const groupedEmployees = {}
|
||||||
|
all_voted_bst.value.forEach(item => {
|
||||||
|
const { department_user, cand_name, total } = item;
|
||||||
|
if (!groupedEmployees[department_user]) {
|
||||||
|
groupedEmployees[department_user] = [];
|
||||||
|
}
|
||||||
|
groupedEmployees[department_user].push({ name: cand_name, total });
|
||||||
|
});
|
||||||
|
// Нахождение лучших сотрудников в каждом департаменте
|
||||||
|
for (const department in groupedEmployees) {
|
||||||
|
const employees = groupedEmployees[department];
|
||||||
|
// Поиск максимального количества голосов
|
||||||
|
const maxTotal = Math.max(...employees.map(emp => emp.total));
|
||||||
|
|
||||||
|
// Фильтрация сотрудников с максимальным количетсвом голосов
|
||||||
|
max_bst.value[department] = employees.filter(emp => emp.total === maxTotal);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
console.log(max_bst);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
perc_bst = computed(() => Math.round(all_voted_bst.value.length / all_cod.value.length * 100))
|
||||||
|
|
||||||
getPercAndWin();
|
getPercAndWin();
|
||||||
getNotVoted();
|
getNotVoted();
|
||||||
return {
|
return {
|
||||||
max_thn,
|
max_thn,
|
||||||
|
max_bst,
|
||||||
|
perc_bst,
|
||||||
result_thn,
|
result_thn,
|
||||||
result_bst,
|
result_bst,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user