File size: 7,617 Bytes
1e4dbc4
 
 
 
 
 
 
 
 
28606a3
1e4dbc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28606a3
 
a9d450c
28606a3
1e4dbc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28606a3
1e4dbc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49ed66b
a9d450c
8a1e178
1e4dbc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a9d450c
 
 
1e4dbc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66dc6af
1e4dbc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28606a3
1e4dbc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import io
import cv2
import datetime
import calendar
import numpy as np
import pandas as pd
import gradio as gr
import matplotlib.pyplot as plt

from PIL import ImageFont, ImageDraw, Image
from datetime import date, timedelta
from collections import Counter
from typing import NamedTuple

class Reward():
  def __init__(self):
    self.stellar_jade = {}
    self.special_pass = {}
    self.oneiric_shard = 0

def weekday_count(start_date, end_date):
  week = {}
  for i in range((end_date - start_date).days):
    day       = calendar.day_name[(start_date + datetime.timedelta(days=i+1)).weekday()]
    week[day] = week[day] + 1 if day in week else 1
  return week

def daterange(start_date, end_date):
    for n in range(int((end_date - start_date).days)):
        yield start_date + timedelta(n)

def estimator(start_patch, end_patch, mode, equilibrium, data_patch, updating, play_memory_of_chaos, EXPRESS_SUPPLY, BP):

    limited_event, permanent_event, explore, moc_n_pf = updating


    duration = abs(start_patch - end_patch).days

    n_weekdays = weekday_count(start_patch, end_patch)
    n_weeks = Counter(n_weekdays.values()).most_common(1)[0][0]

    if mode == 1:
      start_half = start_patch
      end_half = start_half + datetime.timedelta(days = duration // 2 )

      duration = abs(start_half - end_half).days

    if mode == 2:
      start_half = start_patch + datetime.timedelta(days = duration // 2 )
      end_half = end_patch

      duration = abs(start_half - end_half).days

    reward = Reward()
    reward_SU = {0:75, 1:75, 2:105, 3:135, 4:165, 5:195, 6:225}

    reward.stellar_jade['daily_quest'] = 60 * duration
    # reward.stellar_jade['chat'] = 5 * duration

    if (mode == 0 or mode == 1) : 
      reward.stellar_jade['update'] = 600
      reward.stellar_jade['permanent_event'] = np.sum([permanent_event[i]['reward'] for i in permanent_event])
      reward.stellar_jade['explore'] = explore


    special_event = 'gift_odyssey'

    if mode == 0: 
      reward.stellar_jade['daily_login'] = 80
      reward.stellar_jade['SU'] = reward_SU[equilibrium] * n_weekdays['Monday']
      reward.stellar_jade['character_tryout'] = 20 * data_patch['n_character_banner']
      reward.stellar_jade['character_quest'] = 100 * np.sum([data_patch['n_character_quest'][i] for i in data_patch['n_character_quest']])
      reward.special_pass['Ember'] = 5 * Counter([single_date.day for single_date in daterange(start_patch, end_patch)])[1]

      #edit every patch
      reward.stellar_jade['event'] = np.sum([limited_event[i]['reward'] for i in limited_event if i != special_event])
      reward.special_pass['event'] = limited_event[special_event]['reward']

      if play_memory_of_chaos: 
          reward.stellar_jade['moc_n_pf'] = 720 * moc_n_pf['MoC']
          reward.stellar_jade['moc_n_pf'] += 720 * moc_n_pf['PF']

      if EXPRESS_SUPPLY: 
        reward.stellar_jade['EXPRESS_SUPPLY'] = 90 * duration
        reward.oneiric_shard = int(300 * np.ceil(duration/30))

      if BP:
        reward.stellar_jade['BP'] = 680
        reward.special_pass['BP'] = 4

      reward.stellar_jade['redeem_code_next_patch'] = 300
      
    else: 
      reward.stellar_jade['daily_login'] = 40
      reward.stellar_jade['SU'] = reward_SU[equilibrium] * (n_weekdays['Monday'] // 2)

      #companion quest
      if mode == 1: reward.stellar_jade['character_quest'] = 100 * data_patch['n_character_quest']['first_half']
      elif mode == 2: reward.stellar_jade['character_quest'] = 100 * data_patch['n_character_quest']['second_half']

      #temporary
      reward.stellar_jade['character_tryout'] = 20 * (data_patch['n_character_banner'] // 2)
      reward.special_pass['Ember'] = 5 * Counter([single_date.day for single_date in daterange(start_half, end_half)])[1]

      #edit every patch
      reward.stellar_jade['event'] = np.sum([limited_event[i]['reward'] for i in limited_event if (i != special_event) and (limited_event[i]['date'][0] >= start_half and limited_event[i]['date'][0] + datetime.timedelta(days = 7) < end_half)])
      reward.special_pass['event'] = limited_event[special_event]['reward'] if (limited_event[special_event]['date'][0] >= start_half and start_half + datetime.timedelta(days = 7)  < end_half) else 0

      if play_memory_of_chaos:
        if mode == 1:
          reward.stellar_jade['moc_n_pf'] = 720 * (moc_n_pf['MoC'] + moc_n_pf['PF'] - 1)
        else: 
          reward.stellar_jade['moc_n_pf'] = 720

      if EXPRESS_SUPPLY:
        reward.stellar_jade['EXPRESS_SUPPLY'] = 90 * duration
        reward.oneiric_shard = int(300 * np.ceil(duration/30))

      if BP:
        if mode == 2:
          reward.stellar_jade['BP'] = 680
          reward.special_pass['BP'] = 4

      if mode == 2 : reward.stellar_jade['redeem_code_next_patch'] = 300

    return reward


def export_to_image(data):
  template = cv2.imread('./template.png')

  font = ImageFont.truetype("./DMSans-Regular.ttf", 80)
  color = (0, 78, 53)

  image_rgb = cv2.cvtColor(template, cv2.COLOR_BGR2RGB)
  pil_image = Image.fromarray(image_rgb)
  draw = ImageDraw.Draw(pil_image)

  pos = [(500, 50), (500, 280), (500, 530)]
  text = [int(sum(data.stellar_jade.values())), int(sum(data.special_pass.values())), int(data.oneiric_shard)]
  for d, position in zip(text, pos):
    draw.text(position, str(d), font=font, fill=color)

  return pil_image

def export_to_graph(data):

  df = pd.DataFrame(sorted(data.stellar_jade.items(), key = lambda x:x[1], reverse = True), columns = ['source', 'stellar jade'])

  source_map = {'daily_quest':'Daily Quest', 'explore':'Exploration', 'permanent_event':'Permanent Event', 'event':'Limited Event', 'moc_n_pf': 'MoC & Pure Fiction', 'SU':'Simulate Universe', 'update':'Update', 'redeem_code_next_patch':'Code live next patch', 'character_quest':'Companion Quest', 'daily_login':'Website daily login', 'character_tryout':'Character trial', 'EXPRESS_SUPPLY':'Express supply', 'BP':'Battle pass', 'chat':'Daily Chat'}

  filtered = df[df['stellar jade'] != 0]

  source = [source_map[i] for i in filtered['source']]

  filtered['source'] = source

  df = filtered

  df['stellar jade'] = df['stellar jade'].astype('int')

  total_jade = df['stellar jade'].sum()

  # Figure Size
  fig, ax = plt.subplots(figsize =(16, 9))
  
  stellar_jade = df['stellar jade']

  # Horizontal Bar Plot
  ax.barh(source, stellar_jade)
  
  # Remove axes splines
  for s in ['top', 'bottom', 'left', 'right']:
      ax.spines[s].set_visible(False)
  
  # Remove x, y Ticks
  ax.xaxis.set_ticks_position('none')
  ax.yaxis.set_ticks_position('none')
  
  # Add padding between axes and labels
  ax.xaxis.set_tick_params(pad = 5)
  ax.yaxis.set_tick_params(pad = 10)
  
  # Add x, y gridlines
  ax.grid(color ='grey',linestyle ='--', linewidth = 0.5,alpha = 0.4)
  
  # Show top values
  ax.invert_yaxis()
  
  # Add annotation to bars
  for index, i in enumerate(ax.patches):
      if index < 3 :
        number_color = 'red'
      elif index < 6:
        number_color = 'orange'
      else: number_color = 'grey'

      plt.text(i.get_width()+10, i.get_y()+0.5,
              str(round((i.get_width()), 2)) + ' ({0}%)'.format(round(100 * (i.get_width() / total_jade), 2)),
              fontsize = 10,
              color = number_color)
  
  title = 'The Stellar Jade Counter'

  ax.set_title(title,
              loc ='left', )
  
  # Add Text watermark
  fig.text(0.9, 0.15, 'CHAYEN', fontsize = 12,
          color ='grey', ha ='right', va ='bottom',
          alpha = 0.7)
 
  buf = io.BytesIO()
  fig.savefig(buf)
  buf.seek(0)
  img = Image.open(buf)

  return img