Обратная связь 1/2
This commit is contained in:
1 parent
5a5aceb688
commit
7bc40a1825
4 files changed
+60
-13
No files matched your search
@@ -24,10 +24,8 @@ class RatingStatusStatSerializer(serializers.ModelSerializer):
|
||||
utility = serializers.CharField(source='usercom.utility')
|
||||
namecrit = serializers.CharField(source='crit.name')
|
||||
ico = serializers.CharField(source='crit.ico')
|
||||
rating = serializers.CharField(source='crit.rating')
|
||||
color = serializers.CharField(source='crit.color')
|
||||
|
||||
|
||||
class Meta:
|
||||
model = RatingStatus
|
||||
fields ='__all__'
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<template>
|
||||
<div>
|
||||
<div>
|
||||
<pre>
|
||||
<!-- {{feedback}} -->
|
||||
{{average()}}
|
||||
</pre>
|
||||
|
||||
<div v-for="(val, key) in average()" :key = key>
|
||||
|
||||
{{key}}
|
||||
{{val}}
|
||||
</div>
|
||||
{{total}}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -13,6 +14,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ref } from 'vue'
|
||||
|
||||
export default {
|
||||
props: {
|
||||
feedback: {
|
||||
@@ -22,22 +25,67 @@ export default {
|
||||
},
|
||||
|
||||
setup(props, context) {
|
||||
const total = ref(0)
|
||||
|
||||
const average = () => {
|
||||
const crit = () => {
|
||||
const basecrit =
|
||||
props.feedback.reduce((acc, item) => {
|
||||
console.log(acc, item);
|
||||
if (!acc[item.usercom]) {
|
||||
acc[item.usercom] = 0
|
||||
}
|
||||
acc[item.usercom] += 1
|
||||
return acc
|
||||
}, {}
|
||||
}, {}
|
||||
)
|
||||
return basecrit
|
||||
}
|
||||
|
||||
|
||||
|
||||
const average = () => {
|
||||
console.log(props.feedback);
|
||||
let tot = new Set()
|
||||
|
||||
const avgfeed =
|
||||
|
||||
props.feedback
|
||||
.reduce((acc, item) => {
|
||||
if (!acc[item.crit]) {
|
||||
acc[item.crit] = []
|
||||
}
|
||||
acc[item.crit].push(item.rating)
|
||||
|
||||
tot.add(item.usercom)
|
||||
|
||||
return acc
|
||||
}, {}
|
||||
)
|
||||
|
||||
for (let [key,val] of Object.entries(avgfeed))
|
||||
{
|
||||
avgfeed[key] = (val.reduce((a,b)=>{
|
||||
return a+b
|
||||
}, 0
|
||||
)/val.length).toFixed(1)
|
||||
|
||||
}
|
||||
|
||||
|
||||
total.value = tot.size
|
||||
return avgfeed
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return {
|
||||
average
|
||||
average,
|
||||
total
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
<v-row>
|
||||
<v-col class="bg-red">
|
||||
<feedmodul :feedback="feedback"/>
|
||||
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-col>
|
||||
@@ -194,6 +193,8 @@ setup(){
|
||||
feedback.value = result.data.feedback
|
||||
|
||||
})}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class Counter(ListAPIView):
|
||||
# Обратная связь
|
||||
feed = RatingStatus.objects.all()
|
||||
feedback = RatingStatusStatSerializer(feed, many=True).data
|
||||
# print(feed, '++++++++++++++++++++++++++++++++++++++')
|
||||
print(feedback, '++++++++++++++++++++++++++++++++++++++')
|
||||
return Response({'result':result, 'feedback':feedback})
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user