138 lines
5.9 KiB
Python
138 lines
5.9 KiB
Python
import copy
|
|
import json
|
|
import os.path
|
|
import requests
|
|
import time
|
|
import numpy as np
|
|
import datetime
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
from logger_module import logger
|
|
from src.util.utils import hg_get_new_user_token
|
|
|
|
|
|
class ArknightsInfo:
|
|
def __init__(self, phone):
|
|
self.phone = phone
|
|
self.gacha_data = {}
|
|
self.payment_data = {}
|
|
|
|
self.server_url = 'http://192.168.195.194:59001'
|
|
self.admin_key = "1145141919810"
|
|
self.get_data()
|
|
self.data_dict_by_banner, self.all_result_for_show, self.raw_pull_data = self.convert_data()
|
|
|
|
def get_data(self):
|
|
url = f'{self.server_url}/GetData'
|
|
data_dict = requests.post(url, data=json.dumps({"admin_key": self.admin_key})).json()
|
|
self.gacha_data = data_dict.get('gacha_data', {}).get(self.phone, {})
|
|
self. payment_data = data_dict.get('payment_data', {}).get(self.phone, {})
|
|
|
|
def convert_data(self):
|
|
content = self.gacha_data
|
|
banner_result = {}
|
|
banner_result_by_time = {}
|
|
total_gacha_result = []
|
|
for key, value in content.items():
|
|
pull_time = datetime.datetime.fromtimestamp(int(key)).strftime('%Y-%m-%d %H:%M:%S')
|
|
banner_result_by_time[pull_time] = (copy.deepcopy(value['c']), datetime.datetime.fromtimestamp(int(key)))
|
|
if value['p'] not in banner_result:
|
|
banner_result[value['p']] = {'gacha_result': copy.deepcopy(value['c']),
|
|
'gacha_result_by_time': {pull_time: (copy.deepcopy(value['c']), datetime.datetime.fromtimestamp(int(key)))}}
|
|
else:
|
|
banner_result[value['p']]['gacha_result'] += copy.deepcopy(value['c'])
|
|
banner_result[value['p']]['gacha_result_by_time'][pull_time] = (copy.deepcopy(value['c']), datetime.datetime.fromtimestamp(int(key)))
|
|
total_gacha_result += copy.deepcopy(value['c'])
|
|
for key, value in banner_result.items():
|
|
banner_result[key]['analysis'] = self.analyze_gacha_data(value['gacha_result'])
|
|
all_result = self.analyze_gacha_data(total_gacha_result)
|
|
banner_result['全部结果'] = {'analysis': all_result, 'gacha_result_by_time': banner_result_by_time}
|
|
|
|
return banner_result, all_result, content
|
|
|
|
@staticmethod
|
|
def analyze_gacha_data(data_list):
|
|
result = {
|
|
'by_star': {'3': 0, '4': 0, '5': 0, '6': 0},
|
|
'new_operator': []
|
|
}
|
|
if len(data_list) == 0:
|
|
return result
|
|
for data in data_list:
|
|
result['by_star'][str(data[1] + 1)] += 1
|
|
if data[2] == 1:
|
|
result['new_operator'].append(data)
|
|
result['six_star_percent'] = result['by_star']['6'] / len(data_list) * 100
|
|
result['five_star_percent'] = result['by_star']['5'] / len(data_list) * 100
|
|
result['four_star_percent'] = result['by_star']['4'] / len(data_list) * 100
|
|
result['three_star_percent'] = result['by_star']['3'] / len(data_list) * 100
|
|
result['total_pull'] = len(data_list)
|
|
return result
|
|
|
|
def show_all_gacha_data(self):
|
|
self.gacha_data_visualization(self.all_result_for_show)
|
|
|
|
@staticmethod
|
|
def gacha_data_visualization(data_dict, title='Banner'):
|
|
plt.rcParams['font.sans-serif'] = 'SimHei' # 设置中文显示
|
|
plt.figure(figsize=(6, 6))
|
|
label = ['3 Star', '4 Star', '5 Star', '6 Star']
|
|
explode = [0.01, 0.01, 0.01, 0.01]
|
|
data = [values for _key, values in data_dict['by_star'].items()]
|
|
plt.pie(data, explode=explode, labels=label, autopct='%1.2f%%')
|
|
plt.title(title)
|
|
# plt.savefig('test')
|
|
plt.show()
|
|
|
|
def get_all_banner_pull_data(self):
|
|
plt.rcParams['font.sans-serif'] = 'SimHei' # 设置中文显示
|
|
plt.figure(figsize=(6, 6))
|
|
banner_title = [item for item in self.data_dict_by_banner]
|
|
banner_data_6 = [value['analysis']['by_star']['6'] for _key, value in self.data_dict_by_banner.items()]
|
|
banner_data_5 = [value['analysis']['by_star']['5'] for _key, value in self.data_dict_by_banner.items()]
|
|
banner_data_4 = [value['analysis']['by_star']['4'] for _key, value in self.data_dict_by_banner.items()]
|
|
banner_data_3 = [value['analysis']['by_star']['3'] for _key, value in self.data_dict_by_banner.items()]
|
|
|
|
y_axis = np.arange(len(banner_title))
|
|
width = 0.25
|
|
plt.barh(y_axis - width, banner_data_6, width/2, label='6 star')
|
|
plt.barh(y_axis - width/2, banner_data_5, width/2, label='5 star')
|
|
plt.barh(y_axis, banner_data_4, width/2, label='4 star')
|
|
plt.barh(y_axis + width/2, banner_data_3, width/2, label='3 star')
|
|
|
|
plt.yticks(y_axis, banner_title)
|
|
|
|
# 添加数值标签
|
|
off_set = -0.1
|
|
for i in y_axis:
|
|
plt.text(x=banner_data_6[i] + 1, y=i - width + off_set, s=banner_data_6[i], ha='center', fontsize=8, family='Calibri')
|
|
plt.text(x=banner_data_5[i] + 1, y=i - width/2 + off_set, s=banner_data_5[i], ha='center', fontsize=8, family='Calibri')
|
|
plt.text(x=banner_data_4[i] + 1, y=i + off_set, s=banner_data_4[i], ha='center', fontsize=8, family='Calibri')
|
|
plt.text(x=banner_data_3[i] + 1, y=i + width/2 + off_set, s=banner_data_3[i], ha='center', fontsize=8, family='Calibri')
|
|
|
|
plt.legend()
|
|
plt.show()
|
|
return banner_title, banner_data_6, banner_data_5, banner_data_4, banner_data_3
|
|
|
|
|
|
def cal_gacha_probability(pull):
|
|
if pull <= 50:
|
|
return 0.98 ** pull
|
|
probability = cal_gacha_probability(50)
|
|
j = 0.04
|
|
for i in range(50, pull+1):
|
|
probability *= 1 - j
|
|
j += 0.02
|
|
return probability
|
|
|
|
|
|
if __name__ == '__main__':
|
|
ark = ArknightsInfo('18021026530')
|
|
print('111')
|
|
ark.get_all_banner_pull_data()
|
|
ark.show_all_gacha_data()
|
|
ark.gacha_data_visualization(ark.data_dict_by_banner['真理孑然']['analysis'], '真理孑然')
|
|
print('done')
|
|
# print(cal_gacha_probability(79) * 10000)
|