-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenshin_wishes_functions.py
515 lines (479 loc) · 18.3 KB
/
genshin_wishes_functions.py
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
def print_menu(user_menu):
print("Main menu:")
for key, value in user_menu.items():
print('{} - {}'.format(key,value))
def check_option(option,menu):
if (type(option) == int) or (option.isdigit() == True):
if option in menu:
return 'valid'
else:
print('Hey! {} is an invalid option.'.format(option))
print('Please enter a valid option.')
return 'invalid'
else:
print('Hey! {} is not an integer.'.format(option))
print('Please enter an integer.')
return 'invalid'
# option 1
def valid_stars(wish):
if (wish == "3") or (wish == "4") or (wish == "5"):
return True
else:
return False
def star_checker(wish):
while True:
if valid_stars(wish) == False:
print(f"There's no such thing as a {wish} star wish.")
print("Would you like to change this entry? (Y/N)")
user_choice = input("> ")
if user_choice == "Y":
print("Enter the new value for this entry:")
new_entry = input("> ")
wish = new_entry
continue
else:
return None
elif valid_stars(wish) == True:
return True
def data_entry():
print("Enter how many stars each of your wishes has, separated by a space:")
user_input = input("> ")
user_list = user_input.split()
for (index,entry) in enumerate(user_list):
if star_checker(entry) == True:
user_list[index] = entry
return user_list
# option 2
def add_data(user_list):
print("Would you like to add wishes? (Y/N)")
user_choice = input("> ")
if user_choice == "Y":
print("Enter the rarities of the wishes you would like to add, separated by a space:")
user_input = input("> ")
input_list = user_input.split()
for entry in input_list:
user_list.append(entry)
return user_list
else:
return None
# option 4
def update_data(user_list):
print("Would you like to update wishes? (Y/N)")
user_choice = input("> ")
if user_choice == "Y":
print("These are the current wishes:")
print(user_list)
print("How many wishes would you like to update? (number pls)")
user_input = int(input("> "))
for i in range(user_input):
print("Enter the index number you would like to update: (ex. first wish is 1)")
user_index = int(input("> "))
print("Enter the new value for this position:")
user_entry = input("> ")
user_list[user_index-1] = user_entry
else:
return None
# option 5
def delete_data(user_list):
print("Would you like to delete wishes? (Y/N)")
user_choice = input("> ")
if user_choice == "Y":
print("These are the current wishes:")
print(user_list)
print("How many wishes would you like to delete? (number pls)")
user_input = int(input("> "))
for i in range(user_input):
print("Enter the index number you would like to delete:")
user_index = int(input("> "))
del user_list[user_index-1]
print('Deleted!')
else:
return None
# option 6
def total_wishes(user_list):
wishcount = len(user_list)
return wishcount
def four_star_pity(user_list):
#if there is a 4 (or 5) in the list,
#have one pointer at the first 4 in the list,
#and count the number of entries until you reach another 4. (reset)
#return number of entries after the 4.
#else if there is no 4 in the list,
#count from beginning of list.
user_pity = 0
for (index,entry) in enumerate(user_list):
if entry == '4' or entry == '5':
user_pity = 0
continue
else:
user_pity += 1
continue
return user_pity
def five_star_pity(user_list):
#if there is a 5 in the list,
#have one pointer at the first 5 in the list,
#and count the number of entries until you reach another 5. (reset)
#return number of entries after the 5.
#else if there is no 5 in the list,
#count from beginning of list.
user_pity = 0
for (index,entry) in enumerate(user_list):
if entry == '5':
user_pity = 0
continue
else:
user_pity += 1
continue
return user_pity
def four_star_counter(user_list):
four_stars = 0
four_star_index = []
for (index,entry) in enumerate(user_list):
if entry == "4":
four_stars += 1
four_star_index.append(index)
return [four_stars, four_star_index]
def five_star_counter(user_list):
five_stars = 0
five_star_index = []
for (index, entry) in enumerate(user_list):
if entry == "5":
five_stars += 1
five_star_index.append(index)
return [five_stars, five_star_index]
def four_star_gap(user_list):
gap = []
for (index, entry) in enumerate(user_list):
if index == 0:
continue
else:
gap.append(int(entry) - int(user_list[index - 1]))
return sum(gap)/len(gap)
def five_star_gap(user_list):
gap = []
for (index, entry) in enumerate(user_list):
if index == 0:
continue
else:
gap.append(int(entry) - int(user_list[index - 1]))
return sum(gap)/len(gap)
def wish_stats(user_list):
wish_total = total_wishes(user_list)
four_star_total = four_star_counter(user_list)[0]
five_star_total = five_star_counter(user_list)[0]
user_4stargap = four_star_gap(four_star_counter(user_list)[1])
user_5stargap = five_star_gap(five_star_counter(user_list)[1])
user_4starpity = four_star_pity(user_list)
user_5starpity = five_star_pity(user_list)
print("You are at",user_5starpity,"five star pity, so you need",(90-user_5starpity),"more wishes to get your next guaranteed five-star.")
if user_5starpity >= 75:
print("You are also around five-star soft pity, so you should get one very soon.")
print("You are at",user_4starpity,"four star pity, so you need",(10-user_4starpity),"more wishes to get your next guaranteed four-star.")
if user_4starpity >= 8:
print("You are also around four-star soft pity, so you should get one very soon.")
print("*** ADDITIONAL STATS ***")
print("You have made a grand total of",wish_total,"wishes.")
print(f"({wish_total * 160} primogems)")
print("You have pulled a total of",four_star_total,"four stars, and a total of",five_star_total,"five stars.")
print("Average pulls for a five star:", f'{user_5stargap:.2f}')
if user_5stargap < 75:
print("Give me your luck pls.")
print("Average pulls for a four star:", f'{user_4stargap:.2f}')
#option 7
def load_data(user_list):
import csv
import os
filename = 'standard_wishes.csv'
print(f"Load the default file ({filename})? (Y/N)")
user_choice = input('> ')
if user_choice == 'Y':
while True:
if not os.path.isfile(filename):
print(f"WARNING: Cannot find a CSV file named '{filename}'")
print('::: Enter the name of an existing csv file.') #if default file doesnt exist
user_file = input('> ')
continue
print(f"Reading the database from {filename}")
new_list = load_list_from_csv(filename)
print("Resulting database:\n", new_list)
for entry in new_list:
user_list.append(entry)
break
elif user_choice == 'N':
print('::: Enter the name of the csv file to load.')
user_file = input('> ')
while True:
if '.csv' != user_file[-4:]:
print(f'WARNING: {user_file} does not end with `.csv`')
print('::: Enter the name of an existing csv file.')
user_file = input('> ')
continue
elif not os.path.isfile(user_file):
print(f"WARNING: Cannot find a CSV file named '{user_file}'")
print('::: Enter the name of an existing csv file.')
user_file = input('> ')
continue
else:
print(f"Reading the database from {user_file}")
new_list = load_list_from_csv(user_file)
print("Resulting database:\n", new_list)
for entry in new_list:
user_list.append(entry)
break
def load_list_from_csv(filename):
new_list = []
with open(filename, 'r') as file:
read_file = csv.reader(file)
if read_file == []:
return []
else:
for row in read_file:
for cell in row:
new_list.append(cell)
return new_list
# option 8
import csv
def save_data(user_list):
print('These are your currently entered wishes:')
print(user_list)
if len(user_list) == 0:
print('Skipping the creation of an empty file.')
return None
else:
print('::: Save to the default file (standard_wishes.csv)? Type Y or N')
user_choice = input('> ')
if user_choice == 'Y':
save_list_to_csv(user_list, 'standard_wishes.csv')
print('Saving the database in standard_wishes.csv')
print('Database contents:')
print(user_list)
else:
print('::: Enter a file name to save to.')
filename = input('> ')
save_list_to_csv(user_list, filename)
print(f'Saving the database in {filename}')
print('Database contents:')
print(user_list)
def save_list_to_csv(user_list, filename):
fileline = ''
with open(filename, 'w', newline = '') as file:
max_index = (len(user_list)-1)
for (index,entry) in enumerate(user_list):
if index == max_index:
fileline += f"{entry}\n"
else:
fileline += f"{entry},"
file.writelines(fileline)
return file
# character wishes modified functions
# option 1
def char_valid_stars(wish):
if (wish == "3") or (wish == "4") or (wish == "4*") or (wish == "5") or (wish == "5*"):
return True
else:
return False
def char_star_checker(wish):
while True:
if char_valid_stars(wish) == False:
print(f"There's no such thing as a {wish} star wish.")
print("Would you like to change this entry? (Y/N)")
user_choice = input("> ")
if user_choice == "Y":
print("Enter the new value for this entry:")
new_entry = input("> ")
wish = new_entry
continue
else:
return None
elif char_valid_stars(wish) == True:
return True
def char_data_entry():
print("Enter how many stars each of your wishes has, separated by a space:")
print("Denote any banner four and five stars with an asterisk (4* or 5*)")
user_input = input("> ")
user_list = user_input.split()
for (index,entry) in enumerate(user_list):
if char_star_checker(entry) == True:
user_list[index] = entry
return user_list
# option 6 modified functions
def char_four_star_pity(user_list):
user_pity = 0
guarantee = False
for (index,entry) in enumerate(user_list):
if (entry == '4'):
user_pity = 0
guarantee = True
elif entry == "4*" or (entry == '5') or (entry == '5*'):
user_pity = 0
guarantee = False
else:
user_pity += 1
continue
return [user_pity,guarantee]
def char_five_star_pity(user_list):
user_pity = 0
guarantee = False
for (index,entry) in enumerate(user_list):
if (entry == '5'):
user_pity = 0
guarantee = True
continue
elif (entry == '5*'):
user_pity = 0
guarantee = False
continue
else:
user_pity += 1
continue
return [user_pity,guarantee]
def char_four_star_counter(user_list):
four_stars = 0
featured = 0
four_star_index = []
for (index,entry) in enumerate(user_list):
if (entry == '4'):
four_stars += 1
four_star_index.append(index)
elif (entry=='4*'):
four_stars += 1
featured += 1
four_star_index.append(index)
return [four_stars,featured,four_star_index]
def char_five_star_counter(user_list):
five_stars = 0
featured = 0
five_star_index = []
for (index,entry) in enumerate(user_list):
if (entry == '5'):
five_stars += 1
five_star_index.append(index)
elif (entry == '5*'):
five_stars += 1
featured += 1
five_star_index.append(index)
return [five_stars,featured,five_star_index]
def char_four_star_gap(user_list):
gap = []
for (index, entry) in enumerate(user_list):
if index == 0:
continue
else:
gap.append(int(entry) - int(user_list[index - 1]))
return sum(gap)/len(gap)
def char_five_star_gap(user_list):
gap = []
for (index, entry) in enumerate(user_list):
if index == 0:
continue
else:
gap.append(int(entry) - int(user_list[index - 1]))
return sum(gap)/len(gap)
def char_wish_stats(user_list):
wish_total = total_wishes(user_list)
four_star_total = char_four_star_counter(user_list)
five_star_total = char_five_star_counter(user_list)
user_4starpity = char_four_star_pity(user_list)[0]
four_star_guarantee = char_four_star_pity(user_list)[1]
user_5starpity = char_five_star_pity(user_list)[0]
five_star_guarantee = char_five_star_pity(user_list)[1]
user_5stargap = char_five_star_gap(char_five_star_counter(user_list)[2])
user_4stargap = char_four_star_gap(char_four_star_counter(user_list)[2])
print("You are at",user_5starpity,"five star pity, so you need",(90-user_5starpity),"more wishes to get your next guaranteed five-star.")
if user_5starpity >= 75:
print("You are also around five star soft pity, so you should get one very soon.")
if five_star_guarantee == True:
print("Your next five star is guaranteed to be the banner character.")
elif five_star_guarantee == False:
print("You have to win the 50/50 to get the banner character.")
print("You are at",user_4starpity,"four star pity, so you need",(10-user_4starpity),"more wishes to get your next guaranteed four-star.")
if four_star_guarantee == True:
print("Your next four star is guaranteed to be one of the three banner characters.")
if user_4starpity >= 8:
print("You are also around four-star soft pity, so you should get one very soon.")
print("***ADDITIONAL STATS***")
print("You have made a grand total of",wish_total,"wishes.")
print(f"({wish_total * 160} primogems)")
print("You have pulled a total of",four_star_total[0],"four stars, and a total of",five_star_total[0],"five stars.")
print("Of those",four_star_total[1],"have been featured four stars, and",five_star_total[1],"have been the featured five star.")
print("Average pulls to get a five star:", f'{user_5stargap:.2f}')
print("Average pulls to get a four star:", f'{user_4stargap:.2f}')
if user_5stargap < 75:
print("Give me ur luck pls.")
elif 76 <= user_5stargap <= 90:
print("Looks like you have been hitting pity a lot with the five stars. sucks for you")
# option 7
import csv
def char_load_data(user_list):
import csv
import os
filename = 'character_wishes.csv'
print(f"Load the default file ({filename})? (Y/N)")
user_choice = input('> ')
if user_choice == 'Y':
while True:
if not os.path.isfile(filename):
print(f"WARNING: Cannot find a CSV file named '{filename}'")
print('::: Enter the name of an existing csv file.') #if default file doesnt exist
user_file = input('> ')
continue
print(f"Reading the database from {filename}")
new_list = load_list_from_csv(filename)
print("Resulting database:\n", new_list)
for entry in new_list:
user_list.append(entry)
break
elif user_choice == 'N':
print('::: Enter the name of the csv file to load.')
user_file = input('> ')
while True:
if '.csv' != user_file[-4:]:
print(f'WARNING: {user_file} does not end with `.csv`')
print('::: Enter the name of an existing csv file.')
user_file = input('> ')
continue
elif not os.path.isfile(user_file):
print(f"WARNING: Cannot find a CSV file named '{user_file}'")
print('::: Enter the name of an existing csv file.')
user_file = input('> ')
continue
else:
print(f"Reading the database from {user_file}")
new_list = load_list_from_csv(user_file)
print("Resulting database:\n", new_list)
for entry in new_list:
user_list.append(entry)
break
# option 8
def char_save_data(user_list):
print('These are your currently entered wishes:')
print(user_list)
if len(user_list) == 0:
print('Skipping the creation of an empty file.')
return None
else:
print('::: Save to the default file (character_wishes.csv)? Type Y or N')
user_choice = input('> ')
if user_choice == 'Y':
char_save_list_to_csv(user_list, 'character_wishes.csv')
print('Saving the database in character_wishes.csv')
print('Database contents:')
print(user_list)
else:
print('::: Enter a file name to save to.')
filename = input('> ')
char_save_list_to_csv(user_list, filename)
print(f'Saving the database in {filename}')
print('Database contents:')
print(user_list)
def char_save_list_to_csv(user_list, filename):
fileline = ''
with open(filename, 'w', newline = '') as file:
max_index = (len(user_list)-1)
for (index,entry) in enumerate(user_list):
if index == max_index:
fileline += f"{entry}\n"
else:
fileline += f"{entry},"
file.writelines(fileline)
return file