-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeh_tracker.py
115 lines (83 loc) · 3.26 KB
/
feh_tracker.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
# Allows you to stat units and update them as time goes on.
# Allows you to perform queries on your units
import numpy as np
import pandas as pd
import math
"""
Units are manually formatted with this data structure:
["Name", "HP", "Atk", "Spd", "Def", "Res"]
Total will be calculated when UpdateTotal gets run
"""
def CreateSheet():
listUnits = np.array([]) # Feel free to populate this in the format below.
df = pd.DataFrame(listUnits)
df.columns = ["Name", "HP", "Atk", "Spd", "Def", "Res"]
df.to_csv("UnitList.csv", index=False)
print(df.head())
def ImportSheet():
df = pd.read_csv("UnitList.csv")
return df
def AddDragonFlowers(name, stats, df):
row_ind = df.loc[df["Name"] == name].index[0]
# Update Stats Note: this will change the csv when saved
df.loc[row_ind, "HP"] = df.loc[row_ind, "HP"] + stats[0]
df.loc[row_ind, "Atk"] = df.loc[row_ind, "Atk"] + stats[1]
df.loc[row_ind, "Spd"] = df.loc[row_ind, "Spd"] + stats[2]
df.loc[row_ind, "Def"] = df.loc[row_ind, "Def"] + stats[3]
df.loc[row_ind, "Res"] = df.loc[row_ind, "Res"] + stats[4]
def RemoveDragonFlowers(name, stats, df):
row_ind = df.loc[df["Name"] == name].index[0]
# Update Stats Note: this will change the csv when saved
df.loc[row_ind, "HP"] = df.loc[row_ind, "HP"] - stats[0]
df.loc[row_ind, "Atk"] = df.loc[row_ind, "Atk"] - stats[1]
df.loc[row_ind, "Spd"] = df.loc[row_ind, "Spd"] - stats[2]
df.loc[row_ind, "Def"] = df.loc[row_ind, "Def"] - stats[3]
df.loc[row_ind, "Res"] = df.loc[row_ind, "Res"] - stats[4]
def SaveCSV(df):
"""
Note: Saves changes caused by below functions to the CSV
"""
df.to_csv("UnitList.csv", index=False)
def AddUnit(unit, df):
"""
Adds unit in the shape of:
["Name", "HP", "Atk", "Spd", "Def", "Res"]
Note: this will change the csv when saved
"""
df.loc[len(df)] = unit # Duplicate units must be added with different formatting
print(df)
def UpdateTotal(df):
"""
Will add total BST to units if missing.
Note: this will change the csv when saved
"""
total = df[["HP", "Atk", "Spd", "Def", "Res"]].agg("sum", axis=1)
df = df.assign(Total=total)
return df
def FunctionStat(stat, function, df):
"""
Performable functions:
mean, mode, max, sum, min
Will return a floored integer
"""
res = df[[stat]].agg(function, axis=0)
print("The ", function, "of the ", stat, " is:", res)
return math.floor(res[stat])
def SearchUnitByStat(stat, value, df):
res = df[df[stat] == value]
print(res)
def SearchUnitsWithGreaterThanEqualToStat(stat, value, df):
res = df[df[stat] >= value]
print(res)
def SearchUnitsWithLessThanEqualToStat(stat, value, df):
res = df[df[stat] <= value]
print(res)
df = ImportSheet() # IFF a csv named "UnitList.csv" exists otherwise CreateSheet
print(df.head()) # Do this to display the first 5 entries of the CSV
# AddDragonFlowers("LNinian", [1, 1, 1, 1, 1], df)
StatTest = "Def" # Can be changed to HP Atk Spd Def Res and Total (if UpdateTotal has been run on the CSV)
# test = FunctionStat(StatTest, "min", df) this returns a value
SearchUnitByStat(
StatTest, test, df
) # Finds the name of the units around the resulting value
SaveCSV(df)