Обратная связь 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')
|
utility = serializers.CharField(source='usercom.utility')
|
||||||
namecrit = serializers.CharField(source='crit.name')
|
namecrit = serializers.CharField(source='crit.name')
|
||||||
ico = serializers.CharField(source='crit.ico')
|
ico = serializers.CharField(source='crit.ico')
|
||||||
rating = serializers.CharField(source='crit.rating')
|
|
||||||
color = serializers.CharField(source='crit.color')
|
color = serializers.CharField(source='crit.color')
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = RatingStatus
|
model = RatingStatus
|
||||||
fields ='__all__'
|
fields ='__all__'
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<pre>
|
<div v-for="(val, key) in average()" :key = key>
|
||||||
<!-- {{feedback}} -->
|
|
||||||
{{average()}}
|
{{key}}
|
||||||
</pre>
|
{{val}}
|
||||||
|
</div>
|
||||||
|
{{total}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -13,6 +14,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
feedback: {
|
feedback: {
|
||||||
@@ -22,22 +25,67 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setup(props, context) {
|
setup(props, context) {
|
||||||
|
const total = ref(0)
|
||||||
|
|
||||||
const average = () => {
|
const crit = () => {
|
||||||
|
const basecrit =
|
||||||
props.feedback.reduce((acc, item) => {
|
props.feedback.reduce((acc, item) => {
|
||||||
console.log(acc, item);
|
if (!acc[item.usercom]) {
|
||||||
|
acc[item.usercom] = 0
|
||||||
|
}
|
||||||
|
acc[item.usercom] += 1
|
||||||
return acc
|
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 {
|
return {
|
||||||
average
|
average,
|
||||||
|
total
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
<v-row>
|
<v-row>
|
||||||
<v-col class="bg-red">
|
<v-col class="bg-red">
|
||||||
<feedmodul :feedback="feedback"/>
|
<feedmodul :feedback="feedback"/>
|
||||||
|
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -194,6 +193,8 @@ setup(){
|
|||||||
feedback.value = result.data.feedback
|
feedback.value = result.data.feedback
|
||||||
|
|
||||||
})}
|
})}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class Counter(ListAPIView):
|
|||||||
# Обратная связь
|
# Обратная связь
|
||||||
feed = RatingStatus.objects.all()
|
feed = RatingStatus.objects.all()
|
||||||
feedback = RatingStatusStatSerializer(feed, many=True).data
|
feedback = RatingStatusStatSerializer(feed, many=True).data
|
||||||
# print(feed, '++++++++++++++++++++++++++++++++++++++')
|
print(feedback, '++++++++++++++++++++++++++++++++++++++')
|
||||||
return Response({'result':result, 'feedback':feedback})
|
return Response({'result':result, 'feedback':feedback})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user