All files / src/views AboutPortalPage.vue

0% Statements 0/90
0% Branches 0/10
0% Functions 0/37
0% Lines 0/90

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
<template>
    <v-row v-if="alldata.feedback.last_comment.time_create=='1990-01-01'">
    <v-col class="text-h6 text-grey text-center align-self-center text--lighten-1 font-weight-light">
      <v-progress-circular
      :size="150"
      :width="7"
      color="cyan-darken-3"
      indeterminate
    ></v-progress-circular>
        </v-col>
  </v-row>
<v-row v-else no-gutters class="gap ma-1 flex-column">
  <v-col class="d-flex flex-column w100 pa-0 flex-grow-0">
    <toolbar-filter :nStaff=alldata.staff />
   
</v-col>
<v-col class="d-flex " >
  <v-row no-gutters class="gap" >
    <v-col lg=2 class=" d-flex flex-column">
      <v-row no-gutters class="gap ma-0 flex-column">
        <v-col lg=4 class="flex-column d-flex w100">
          <portal-traffic :alldata=alldata />
        </v-col>
        <v-col class="flex-column d-flex w100">
          <v-row no-gutters class="flex-column gap" >
            <v-col v-for="x in cardtotal" :key=x>
              <card-total :indicator=x />
            </v-col>
          </v-row>
        </v-col>
      </v-row>
    </v-col>
    <v-col class="d-flex flex-column">
      <v-row no-gutters class="flex-column gap">
        <v-col lg=4 class="w100">
          <line-chart 
            :key = "`${filterStore.date_period.startdate}-${filterStore.date_period.enddate}`"
            :dataLineChart="dataLineChart" 
            :period="{before:alldata.beforperiod,period:alldata.period}"
            :filter = filter
            @getCRR = "getCRR"
          />
        </v-col>
        <v-col class=" d-flex flex-column">
          <v-row no-gutters class="gap">
            <v-col>
              <rating-page :pages_count=alldata.period /> 
            </v-col>
            <v-col>
              <top-user
                    :activusers = alldata.period
                  />
            </v-col>
          </v-row>
        </v-col>
 
      </v-row>
    </v-col>
    <v-col lg=2 >
      <feedmodul
            :feedback="alldata.feedback"
          />
    </v-col>
  </v-row>
</v-col>
</v-row>
 

</template>

<script>
import { ref, watch } from 'vue'

import {pagecounter, splitname, formatDash} from '@/utils/universal_functions'

import { axiosApiInstance } from '@/utils/axios-api'
import { usePortalFilterStore } from '@/store/AboutPortalFilter'
 
import Feedmodul from '@/components/UI/aboutportal/feedmodul.vue'
import DateSelect from '@/components/UI/date-select.vue'
import TopUser from '@/components/UI/aboutportal/top-user.vue'
import LineChart from '@/components/UI/aboutportal/line-chart.vue'
import PortalTraffic from '@/components/UI/aboutportal/portal-traffic.vue'
import ToolbarFilter from '@/components/UI/aboutportal/toolbar-filter.vue'
import RatingPage from '@/components/UI/aboutportal/rating-page.vue'
 
import CardTotal from '@/components/UI/aboutportal/card-total.vue'
// import Feedmodul from '@/components/UI/aboutportal/feedmodul.vue'
 
export default {
  components: {
    Feedmodul,
    DateSelect,
    TopUser,
    LineChart,
    PortalTraffic,
    ToolbarFilter,
    RatingPage,
 
    CardTotal,
 
  },


setup(){


  const dataLineChart = ref({})
  const cardtotal = ref(
    {
  "crr": {
    "title": "Удержание",
    "abb": "(CRR)",
    "tooltip": "Customer retention rate - коэффициент удержания пользователей. Retention является одной из важнейших метрик продукта - он показывает, есть ли проблемы с вовлечением новых пользователей, и помогает спрогнозировать, будет ли проект успешным в перспективе",
    "data": 0
  },
  "br": {
    "title": "Отказы",
    "abb": "(BR)",
    "tooltip": "Bounce Rate - термин в веб-аналитике, обозначающий процентное соотношение количества посетителей, покинувших сайт прямо со страницы входа или просмотревших не более одной страницы сайта к общему количеству посетителей",
    "data": 0
  },
  "ppv": {
    "title": "Страниц за визит",
    "abb": "(PPV)",
    "tooltip": "Pages Per Visit - глубина просмотра страниц. Поведенческая метрика, которая показывает, сколько страниц на сайте в среднем просматривает пользователь",
    "data": 0
  }
 
  })
 
 
 
 
 
  const filterStore = usePortalFilterStore()
    const alldata =ref({period: [], staff: 0, beforperiod: [], feedback: {criteria: [], feed: [], last_comment:{time_create:'1990-01-01'}}})
    const visition = () => {
 
    axiosApiInstance.get(`api/watcher/dataforstatistics/?start=${formatDash(filterStore.date_period.startdate)}&end=${formatDash(filterStore.date_period.enddate)}`).then(result => {
    alldata.value = preparedata(result.data)
 
    totalfn()
 
    
  })}
 
  visition()
  const preparedata=(data)=>{
      let beforperiod = []
      data.beforperiod.forEach((e)=>{
        let ind = beforperiod.findIndex(el=>el.visitdate===e.visitdate)        
        if(ind>-1){
          beforperiod[ind].user.push(e.user__user_id)          
        }else{
          beforperiod.push({visitdate: e.visitdate, user:[e.user__user_id]})
        }
      })
      data.beforperiod=beforperiod
 
      return data
  }
  
  
  
  const totalfn = () => {
    let beforperiodusers = new Set([])
    alldata.value.beforperiod.forEach(e => beforperiodusers.add(...e.user)) 
    

    let periodusers = new Set([])
    let brdata = {}
    let filtr = alldata.value.period
   
   

    if  (formatDash(filterStore.date_period.enddate) !=formatDash(new Date())) {
      filtr = filtr.filter(e => e.visitdate != formatDash(new Date()))
      }
 
      filtr.forEach((e) => {
     
      periodusers.add(e.user.id)
      if (!brdata[e.visitdate]) {
        brdata[e.visitdate] =  {}

      }
      let user = splitname(e.user)
      if (!brdata[e.visitdate][user]) {
        brdata[e.visitdate][user] =  []
      }
      brdata[e.visitdate][user].push({page:e.fullPath, total:e.count})
      
 
    }) 

    let traffic ={}
 
    for (let [key, val] of Object.entries(brdata)) {
      traffic[key] ={unic: Object.keys(val), count: 0, br:0, pages: 0}

      let arr = Object.values(val)
      traffic[key].br = arr.filter(e=>e.length==1).length
      arr.forEach(e=> traffic[key].pages += e.length)
      arr.flat().reduce((acc, item) => {
        
        traffic[key].count +=item.total
       
        return acc
      },traffic[key].count)
      
    }
 

    sumtraffic(traffic)
    dataLineChart.value =  traffic
  }

  const getCRR = (val) => {
  
    cardtotal.value.crr.data = val
 
  }

  const sumtraffic= (data) => {

    let ob = {brtot:0, ppvtot: 0, unictot: 0, pagetot: 0}
    Object.values(data).flat().forEach((e) => {
      ob.brtot += e.br
      ob.ppvtot += e.count
      ob.unictot += e.unic.length
      ob.pagetot += e.pages
     
    }
 
    )

    cardtotal.value.br.data = ob.brtot/ob.unictot*100
    cardtotal.value.ppv.data = ob.pagetot/ob.unictot
    
  }
 
  watch(()=>filterStore.date_period,()=>{
   
        visition()
 
      
    }, {deep:true})
 
  pagecounter()
 
  
 
  return {
    alldata,
    cardtotal,
    dataLineChart,
    filterStore,
    getCRR,
    filter: ref('d'),
   
    
  }
 
 
 
}
   
}
 
</script>

<style>
 
</style>