@@ -257,21 +257,35 @@ def ranking(self, auth, current_page, page_size, with_valid=True):
257257 def export (self , auth , with_valid = True ):
258258 if with_valid :
259259 self .is_valid (raise_exception = True )
260+ token_count = HomePageSerializer .TokensAggregation (data = self .data ).aggregation (auth )
260261 queryset , asker_map = self .get_queryset (auth )
261262 workbook = openpyxl .Workbook (write_only = True )
262263 worksheet = workbook .create_sheet (title = 'Sheet1' )
263264 headers = [gettext ('ranking' ),
264265 gettext ('User Name' ),
265266 gettext ('Token consumption' ),
267+ gettext ('proportion' ),
266268 gettext ('number of questions' ),
269+ gettext ('Average tokens per request' ),
267270 ]
268271 worksheet .append (headers )
269272 index = 0
270273 for item in queryset :
271274 index += 1
272- row = [ index , asker_map .get (
275+ user_info = asker_map .get (
273276 (item ["chat_user_id" ], item ["chat_user_type" ])
274- ).get ('username' ), item ['total_tokens' ], item ['chat_record_count' ]]
277+ ) or {}
278+ username = user_info .get ("username" , "" )
279+ total_tokens = item .get ("total_tokens" , 0 )
280+ chat_record_count = item .get ("chat_record_count" , 0 )
281+ row = [
282+ index ,
283+ username ,
284+ total_tokens ,
285+ total_tokens / token_count if token_count else 0 ,
286+ chat_record_count ,
287+ total_tokens / chat_record_count if chat_record_count else 0 ,
288+ ]
275289 worksheet .append (row )
276290 response = HttpResponse (content_type = "application/vnd.ms-excel" )
277291 response ["Content-Disposition" ] = f'attachment; filename="data.xlsx"'
@@ -414,19 +428,29 @@ def ranking(self, auth, current_page, page_size, with_valid=True):
414428 def export (self , auth , with_valid = True ):
415429 if with_valid :
416430 self .is_valid (raise_exception = True )
431+ chat_record_number = HomePageSerializer .ChatRecordAggregation (data = self .data ).aggregation (auth )
417432 queryset = self .get_queryset (auth )
418433 workbook = openpyxl .Workbook (write_only = True )
419434 worksheet = workbook .create_sheet (title = 'Sheet1' )
420435 headers = [gettext ('ranking' ),
421436 gettext ('Application Name' ),
422437 gettext ('number of questions' ),
423- gettext ('active users' )
438+ gettext ('proportion' ),
439+ gettext ('active users' ),
440+ gettext ('Average Number of Conversation Turns per Person' )
424441 ]
425442 worksheet .append (headers )
426443 index = 0
427444 for item in queryset :
428445 index += 1
429- row = [index , item .name , item .chat_record_count_total , item .chat_user_count ]
446+ row = [
447+ index ,
448+ item .name ,
449+ item .chat_record_count_total ,
450+ item .chat_record_count_total / chat_record_number if chat_record_number != 0 else 0 ,
451+ item .chat_user_count ,
452+ item .chat_user_count / item .chat_record_count_total if item .chat_record_count_total != 0 else 0
453+ ]
430454 worksheet .append (row )
431455 response = HttpResponse (content_type = "application/vnd.ms-excel" )
432456 response ["Content-Disposition" ] = f'attachment; filename="data.xlsx"'
@@ -528,19 +552,33 @@ def ranking(self, auth, current_page, page_size, with_valid=True):
528552 def export (self , auth , with_valid = True ):
529553 if with_valid :
530554 self .is_valid (raise_exception = True )
555+ tokens_total = HomePageSerializer .TokensAggregation (data = self .data ).aggregation (auth )
531556 queryset = self .get_queryset (auth )
532557 workbook = openpyxl .Workbook (write_only = True )
533558 worksheet = workbook .create_sheet (title = 'Sheet1' )
534559 headers = [gettext ('ranking' ),
535560 gettext ('Application Name' ),
536561 gettext ('Token consumption' ),
537- gettext ('number of questions' )
562+ gettext ('proportion' ),
563+ gettext ('number of questions' ),
564+ gettext ('active users' ),
565+ gettext ('Average tokens per request' ),
538566 ]
539567 worksheet .append (headers )
540568 index = 0
541569 for item in queryset :
542570 index += 1
543- row = [index , item .name , item .total_tokens , item .chat_record_count_total ]
571+ total_tokens = item .total_tokens
572+ chat_record_count_total = item .chat_record_count_total
573+ row = [
574+ index ,
575+ item .name ,
576+ total_tokens ,
577+ total_tokens / tokens_total if tokens_total else 0 ,
578+ item .chat_user_count ,
579+ chat_record_count_total ,
580+ total_tokens / chat_record_count_total if chat_record_count_total else 0 ,
581+ ]
544582 worksheet .append (row )
545583 response = HttpResponse (content_type = "application/vnd.ms-excel" )
546584 response ["Content-Disposition" ] = f'attachment; filename="data.xlsx"'
0 commit comments